:root {
  --bg: #0F1226;
  --bg-2: #171B36;
  --card: #1C2142;
  --card-2: #252B55;
  --line: rgba(255, 255, 255, 0.08);
  --text: #F7F3EA;
  --muted: #A9A8C3;
  --amber: #FFB000;
  --amber-ink: #241A00;
  --mint: #3DDC97;
  --coral: #FF5C6C;
  --violet: #9D8CFF;
  --sky: #5BC0FF;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #FFF8EC;
  --bg-2: #FFEFD4;
  --card: #FFFFFF;
  --card-2: #FFF3DE;
  --line: rgba(15, 18, 38, 0.1);
  --text: #171A33;
  --muted: #6B6A86;
  --amber: #F2A100;
  --amber-ink: #241A00;
  --mint: #12A86A;
  --coral: #E5384A;
  --violet: #6E5BEA;
  --sky: #1E8FD6;
  --shadow: 0 10px 24px rgba(23, 26, 51, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #FFF8EC;
    --bg-2: #FFEFD4;
    --card: #FFFFFF;
    --card-2: #FFF3DE;
    --line: rgba(15, 18, 38, 0.1);
    --text: #171A33;
    --muted: #6B6A86;
    --amber: #F2A100;
    --mint: #12A86A;
    --coral: #E5384A;
    --violet: #6E5BEA;
    --sky: #1E8FD6;
    --shadow: 0 10px 24px rgba(23, 26, 51, 0.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, var(--bg-2), var(--bg)) fixed, var(--bg);
  color: var(--text);
  font-family: "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--sky); }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 16px calc(120px + var(--safe-bottom));
  min-height: 100dvh;
}

/* ---------- header ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar h1 { font-size: 26px; font-weight: 900; margin: 0; letter-spacing: -0.5px; }
.topbar .sub { color: var(--muted); font-size: 13px; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: var(--card); box-shadow: var(--shadow); font-size: 18px; font-weight: 900;
}
.icon-btn:active { transform: scale(0.94); }

.mascot { flex: none; }
.mascot svg { display: block; }
.mascot.bob svg { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  animation: slideUp 0.28s ease both;
}
.card h2, .card h3 { margin: 0 0 6px; }
.card .muted, .muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 900; margin: 20px 4px 8px; }

@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; text-align: center; padding: 18px 12px; }
.scoreboard .name { font-weight: 800; color: var(--muted); font-size: 14px; }
.scoreboard .wins { font-size: 44px; font-weight: 900; line-height: 1; }
.scoreboard .pts { font-size: 12px; color: var(--muted); margin-top: 2px; }
.scoreboard .vs { font-weight: 900; color: var(--amber); font-size: 14px; padding: 0 8px; }
.scoreboard .me .wins { color: var(--amber); }
.streak { text-align: center; font-weight: 800; font-size: 14px; margin-top: 8px; color: var(--text); }

.challenge-card { display: flex; align-items: center; gap: 12px; }
.challenge-card .emoji { font-size: 30px; width: 44px; text-align: center; flex: none; }
.challenge-card .body { flex: 1; min-width: 0; }
.challenge-card .title { font-weight: 900; font-size: 17px; overflow-wrap: anywhere; }
.challenge-card.hot { border: 2px solid var(--amber); }
.pill-progress { height: 6px; border-radius: 99px; background: var(--card-2); overflow: hidden; margin-top: 8px; }
.pill-progress > i { display: block; height: 100%; background: var(--amber); border-radius: 99px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 16px; font-weight: 900; font-size: 16px;
  background: var(--card-2); color: var(--text); transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--amber); color: var(--amber-ink); box-shadow: 0 6px 0 rgba(0,0,0,0.25); }
.btn.primary:active { box-shadow: 0 2px 0 rgba(0,0,0,0.25); transform: translateY(3px); }
.btn.ghost { background: transparent; border: 2px solid var(--line); }
.btn.danger { color: var(--coral); }
.btn.block { width: 100%; }
.btn.big { min-height: 62px; font-size: 19px; border-radius: 20px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.dock .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; }
.dock .inner > .btn { flex: 1; }

/* ---------- segmented / chips ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; background: var(--card-2); padding: 5px; border-radius: 16px; }
.seg button { min-height: 44px; border-radius: 12px; font-weight: 800; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 14px; border-radius: 99px; font-weight: 800; background: var(--card-2);
  border: 2px solid transparent; display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { border-color: var(--amber); background: color-mix(in srgb, var(--amber) 16%, var(--card)); }
.field-label { font-weight: 900; margin: 14px 2px 8px; display: block; }
.input, textarea.input {
  width: 100%; min-height: 52px; border-radius: 16px; border: 2px solid var(--line); background: var(--card-2);
  padding: 12px 14px; font-size: 17px; outline: none;
}
.input:focus { border-color: var(--amber); }
textarea.input { resize: none; min-height: 72px; }

/* ---------- play ---------- */
.play-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.progress { flex: 1; height: 10px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--amber), #FFD25E); border-radius: 99px; transition: width 0.3s ease; }
.counter { font-weight: 900; color: var(--muted); font-size: 14px; min-width: 52px; text-align: right; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 900; font-size: 13px; padding: 6px 12px; border-radius: 99px; }
.badge.factual { background: color-mix(in srgb, var(--violet) 22%, transparent); color: var(--violet); }
.badge.estimate { background: color-mix(in srgb, var(--sky) 22%, transparent); color: var(--sky); }
.badge.matchup { background: color-mix(in srgb, var(--coral) 22%, transparent); color: var(--coral); }
.prompt { font-size: 25px; font-weight: 900; line-height: 1.2; margin: 14px 2px 18px; letter-spacing: -0.3px; overflow-wrap: anywhere; }
.choice {
  width: 100%; min-height: 60px; text-align: left; padding: 14px 16px; border-radius: 18px; margin-bottom: 10px;
  background: var(--card); border: 2px solid var(--line); font-weight: 800; font-size: 17px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
.choice .key { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; background: var(--card-2); font-size: 14px; flex: none; }
.choice:active { transform: scale(0.98); }
.choice.right { border-color: var(--mint); background: color-mix(in srgb, var(--mint) 18%, var(--card)); }
.choice.wrong { border-color: var(--coral); background: color-mix(in srgb, var(--coral) 16%, var(--card)); }

.wager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.wager .lbl { font-weight: 900; font-size: 14px; color: var(--muted); margin-right: 2px; }
.wager .w { width: 48px; height: 44px; border-radius: 14px; background: var(--card-2); font-weight: 900; border: 2px solid transparent; }
.wager .w.on { border-color: var(--amber); color: var(--amber); }
.steal { margin-left: auto; min-height: 44px; padding: 0 12px; border-radius: 14px; background: var(--card-2); font-weight: 900; font-size: 14px; border: 2px dashed var(--line); }
.steal.on { border: 2px solid var(--coral); color: var(--coral); }
.steal[disabled] { opacity: 0.4; }

.vs-wrap { display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; gap: 8px; margin-bottom: 12px; }
.side {
  min-height: 120px; border-radius: 20px; background: var(--card); border: 3px solid var(--line); padding: 12px;
  font-weight: 900; font-size: 18px; box-shadow: var(--shadow); display: grid; place-items: center; text-align: center; overflow-wrap: anywhere;
}
.side.on { border-color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, var(--card)); transform: scale(1.02); }
.vs-badge { align-self: center; font-weight: 900; color: var(--amber); font-size: 18px; }

.numpad-input { font-size: 34px; font-weight: 900; text-align: center; min-height: 72px; letter-spacing: 0.5px; }
.unit-hint { text-align: center; color: var(--muted); font-weight: 800; margin-top: 6px; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5, 6, 16, 0.55); z-index: 40; animation: fade 0.2s ease both; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88dvh; overflow-y: auto;
  background: var(--card); border-radius: 26px 26px 0 0; padding: 18px 18px calc(18px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,0.4); animation: sheetUp 0.32s cubic-bezier(.2,.9,.3,1.2) both;
}
.sheet .inner { max-width: 560px; margin: 0 auto; }
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.verdict { font-size: 30px; font-weight: 900; margin: 4px 0; }
.verdict.good { color: var(--mint); }
.verdict.bad { color: var(--coral); }
.verdict.meh { color: var(--amber); }
.answer-line { font-size: 18px; font-weight: 800; }
.flash-good { animation: flashGood 0.5s ease; }
.flash-bad { animation: flashBad 0.5s ease, shake 0.35s ease; }
@keyframes flashGood { 0% { box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--mint) 35%, transparent); } 100% { box-shadow: none; } }
@keyframes flashBad { 0% { box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--coral) 30%, transparent); } 100% { box-shadow: none; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.numline { position: relative; height: 70px; margin: 14px 8px 4px; }
.numline .track { position: absolute; left: 0; right: 0; top: 34px; height: 6px; border-radius: 9px; background: var(--card-2); }
.numline .pin { position: absolute; top: 0; transform: translateX(-50%); text-align: center; font-size: 12px; font-weight: 900; white-space: nowrap; }
.numline .pin .dot { width: 16px; height: 16px; border-radius: 50%; margin: 4px auto 0; border: 3px solid var(--card); }
.numline .pin.target .dot { background: var(--amber); width: 20px; height: 20px; }
.numline .pin.me .dot { background: var(--sky); }
.numline .pin.them .dot { background: var(--violet); }
.numline .pin.below { top: 30px; }
.numline .pin.below .dot { margin: 0 auto 4px; }

.thumbs { display: flex; gap: 8px; }
.thumbs button { min-width: 48px; min-height: 44px; border-radius: 14px; background: var(--card-2); font-size: 20px; }
.thumbs button.on { background: color-mix(in srgb, var(--amber) 24%, var(--card-2)); }

/* ---------- results ---------- */
.winner-banner { text-align: center; padding: 22px 16px; }
.winner-banner .big { font-size: 34px; font-weight: 900; margin: 6px 0; }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.totals .t { background: var(--card-2); border-radius: 16px; padding: 12px; }
.totals .t .n { font-size: 30px; font-weight: 900; }
.boast { border-left: 5px solid var(--amber); }
.qrow .q { font-weight: 900; margin-bottom: 6px; }
.qrow .ans { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.qrow .ans > div { background: var(--card-2); border-radius: 14px; padding: 10px; font-size: 14px; overflow-wrap: anywhere; }
.qrow .ans .who { font-weight: 900; font-size: 12px; color: var(--muted); }
.qrow .pts { font-weight: 900; font-size: 16px; }
.pos { color: var(--mint); }
.neg { color: var(--coral); }
.note { font-size: 12px; color: var(--muted); }
.quip { margin-top: 8px; font-style: italic; color: var(--muted); }

/* ---------- misc ---------- */
.center { text-align: center; }
.empty { text-align: center; padding: 26px 10px; color: var(--muted); }
.generating { min-height: 70dvh; display: grid; place-items: center; text-align: center; }
.generating .msg { font-size: 20px; font-weight: 900; margin-top: 16px; min-height: 2.6em; }
.spinner-dots span { display: inline-block; width: 10px; height: 10px; margin: 0 4px; border-radius: 50%; background: var(--amber); animation: dot 1s infinite ease-in-out; }
.spinner-dots span:nth-child(2) { animation-delay: 0.15s; }
.spinner-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%,80%,100% { transform: scale(0.5); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

#toast {
  position: fixed; left: 50%; top: calc(12px + var(--safe-top)); transform: translateX(-50%) translateY(-20px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 16px; font-weight: 800;
  opacity: 0; pointer-events: none; transition: all 0.25s ease; z-index: 60; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; width: 100vw; height: 100dvh; }

.rules li { margin-bottom: 8px; }
.ai-status { text-align: center; font-size: 12px; color: var(--muted); margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
