/* ── Reset & Base ────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #FFF3E8;
  --surface: #FFFFFF;
  --surface-2: #FFF8F2;
  --primary: #FF7A3D;
  --primary-dark: #E5622A;
  --primary-soft: #FFD4BC;
  --text: #3D1E00;
  --text-muted: #9A7055;
  --accent: #FF9A5C;
  --danger: #E8556B;
  --success: #5CB88A;
  --gold: #E8B34A;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(180, 100, 40, 0.10);
  --shadow-lg: 0 8px 32px rgba(180, 100, 40, 0.15);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Floating Background ─────────────────────────────── */
.floating-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.floater {
  position: absolute;
  bottom: -60px;
  opacity: 0.18;
  animation: floatUp linear infinite;
  filter: blur(0.5px);
}
@keyframes floatUp {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 0;
  }
  5% {
    opacity: 0.18;
  }
  50% {
    transform: translateY(-50vh) rotate(180deg) scale(1.1);
    opacity: 0.22;
  }
  95% {
    opacity: 0.12;
  }
  100% {
    transform: translateY(-110vh) rotate(360deg) scale(0.9);
    opacity: 0;
  }
}

/* ── Screens ─────────────────────────────────────────── */
.screen { display: none; flex: 1; flex-direction: column; min-height: 100vh; position: relative; z-index: 1; }
.screen.active { display: flex; }
.hidden { display: none !important; }
.center { text-align: center; }

/* ── Home ────────────────────────────────────────────── */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 2rem;
  gap: 2.5rem;
}
.logo { text-align: center; }
.logo h1 {
  font-size: clamp(2.8rem, 8vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--primary), #FF9A5C);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 340px;
}
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--primary-soft);
}
.join-form { display: flex; flex-direction: column; gap: 0.75rem; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  padding: 0.65rem 1.25rem;
  font-size: 1rem;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: var(--primary-soft); cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--primary); border: 2px solid var(--primary); }
.btn-secondary:hover { background: var(--primary-soft); }
.btn-ghost { background: none; color: var(--primary); text-decoration: underline; padding: 0.3rem 0.6rem; }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1.1rem; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* ── Inputs ──────────────────────────────────────────── */
.input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 2px solid var(--primary-soft);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  text-align: center;
}
.input:focus { outline: none; border-color: var(--primary); }
.input::placeholder { color: var(--text-muted); }

.select {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--primary-soft);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
}

/* ── Modal ───────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(61, 30, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: center;
}
.modal-box h2 { font-size: 1.3rem; font-weight: 700; }
.error-msg { color: var(--danger); font-size: 0.9rem; }

/* ── Container & Cards ───────────────────────────────── */
.container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}
.center-content { text-align: center; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card h2, .card h3 { margin-bottom: 0.75rem; font-weight: 700; }

/* ── Room Code Banner ────────────────────────────────── */
.room-code-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.room-code-banner .label { color: var(--text-muted); font-size: 0.85rem; }
.code-display {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--primary);
}

/* ── Player List ─────────────────────────────────────── */
.player-list { list-style: none; }
.player-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--primary-soft);
  font-weight: 500;
}
.player-row:last-child { border-bottom: none; }
.host-tag {
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: auto;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Player Avatar ───────────────────────────────────── */
.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
  background: var(--pc-bg, #ddd);
  color: var(--pc-fg, #333);
}

.pcolor-coral   { --pc-bg: #FFADAD; --pc-fg: #5E1818; }
.pcolor-teal    { --pc-bg: #A5E8D8; --pc-fg: #0F4A3A; }
.pcolor-purple  { --pc-bg: #D4AAFF; --pc-fg: #3A1A5E; }
.pcolor-green   { --pc-bg: #B5E8A5; --pc-fg: #1A4A0F; }
.pcolor-amber   { --pc-bg: #FFD6A5; --pc-fg: #5E3A0F; }
.pcolor-blue    { --pc-bg: #A5D8FF; --pc-fg: #0F3A5E; }
.pcolor-rose    { --pc-bg: #FFB3D1; --pc-fg: #5E0F2A; }
.pcolor-navy    { --pc-bg: #A5B4FC; --pc-fg: #1E1B4B; }
.pcolor-mint    { --pc-bg: #A7F3D0; --pc-fg: #064E3B; }
.pcolor-gold    { --pc-bg: #FDE68A; --pc-fg: #78350F; }

/* ── Settings ────────────────────────────────────────── */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.count-badge {
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}
.muted-text { color: var(--text-muted); font-size: 0.9rem; }
.action-area { margin-top: 1.5rem; }

/* ── Round Screen ────────────────────────────────────── */
.round-badge {
  display: inline-block;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 0.35rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.prompt-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-lg);
  margin-bottom: 2rem;
}
.prompt-text {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}
.prompt-scale {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Answer Buttons ──────────────────────────────────── */
.answer-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.6rem;
  max-width: 360px;
  margin: 0 auto 1.5rem;
}
.answer-buttons.locked .btn-answer:not(.selected) {
  opacity: 0.35;
  pointer-events: none;
}
.btn-answer {
  aspect-ratio: 1;
  border: 2px solid var(--primary-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}
.btn-answer:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.btn-answer.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(255, 122, 61, 0.35);
}

.submitted-badge {
  display: inline-block;
  background: var(--success);
  color: #fff;
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.answer-status {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Reveal Screen ───────────────────────────────────── */
.number-line-wrapper {
  padding: 2rem 1rem 1rem;
  margin-bottom: 1rem;
}
.number-line {
  position: relative;
  height: 60px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-end;
}
.tick {
  flex: 1;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-bottom: 0.4rem;
  font-weight: 600;
}
.avg-marker {
  position: absolute;
  top: -8px;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}
.answer-dot {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  background: var(--pc-bg, #ddd);
  color: var(--pc-fg, #333);
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.outlier-dot {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(232, 85, 107, 0.3);
}

.outlier-callout {
  background: #FFF0E8;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: 1rem;
  color: var(--text);
}

.reveal-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.reveal-table th {
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
.reveal-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #f0e0d0;
  font-weight: 500;
}
.reveal-table td:first-child {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.answer-cell { text-align: center; font-size: 1.1rem; font-weight: 700; }
.pts-cell { text-align: center; color: var(--success); font-weight: 700; }
.outlier-row { background: #FFF5EE; }
.outlier-row .answer-cell { color: var(--danger); }

/* ── Final Screen ────────────────────────────────────── */
.final-title {
  font-size: 2.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}
.winner-announce {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}
.winner-announce span {
  color: var(--primary);
  font-weight: 700;
}

.scoreboard-list {
  list-style: none;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.score-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0e0d0;
}
.score-row:last-child { border-bottom: none; }
.score-row.winner {
  background: linear-gradient(90deg, #FFF8F0, #FFF3E8);
}
.rank {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.winner .rank {
  background: var(--gold);
  color: #fff;
}
.score-name { flex: 1; font-weight: 600; text-align: left; }
.score-pts {
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 420px) {
  .answer-buttons { gap: 0.4rem; }
  .btn-answer { font-size: 1.1rem; }
  .prompt-text { font-size: 1.15rem; }
  .container { padding: 1rem 0.75rem 2rem; }
}
