:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --line: #e2e2dc;
  --text: #16181d;
  --muted: #6b7079;
  --red: #e8141a;
  --red-deep: #b80000;
  --gold: #ffc629;
  --gold-ink: #9a6b00;
  --green: #16a34a;
  --amber: #d97706;
  --shadow: 0 1px 2px rgba(22, 24, 29, 0.05), 0 8px 24px -12px rgba(22, 24, 29, 0.18);
  --display: 'Bebas Neue', 'Anton', Impact, sans-serif;
  --body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 18px;
  --pad: max(16px, env(safe-area-inset-left));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(232, 20, 26, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(232, 20, 26, 0.04), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 500 17px/1.45 var(--body);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}
input { -webkit-user-select: text; user-select: text; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; }
h1, h2, h3 { margin: 0; font-weight: 400; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hl { color: var(--red); }

#app {
  min-height: 100%;
  padding: env(safe-area-inset-top) var(--pad) calc(24px + env(safe-area-inset-bottom));
  max-width: 1180px;
  margin: 0 auto;
}

.boot { display: grid; place-items: center; min-height: 80vh; }
.boot img { width: 120px; opacity: 0.9; animation: pulse 1.2s ease-in-out infinite; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border-radius: 999px;
  font: 700 16px/1 var(--body); letter-spacing: 0.01em;
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 8px 22px -10px rgba(232, 20, 26, 0.6); }
.btn-primary:disabled { background: var(--surface-2); color: var(--muted); box-shadow: none; }
.btn-ghost { background: var(--surface-2); border: 1px solid var(--line); }
.btn-link { color: var(--muted); min-height: 44px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.btn-wide { width: 100%; }
.btn-huge { font: 400 44px/1 var(--display); letter-spacing: 0.06em; min-height: 88px; padding: 0 64px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 20px;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0 8px; }
.brand { display: flex; align-items: center; gap: 12px; font: 400 30px/1 var(--display); letter-spacing: 0.04em; }
.brand img { width: 46px; height: 46px; }
.brand b { font-weight: 400; color: var(--red); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.live {
  display: inline-flex; align-items: center; gap: 6px;
  font: 800 12px/1 var(--body); letter-spacing: 0.14em; color: var(--red);
  padding: 6px 10px; border-radius: 999px; background: rgba(232, 20, 26, 0.08);
}
.live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: pulse 1.4s ease-in-out infinite; }

/* ---------- home ---------- */
.home {
  display: grid; gap: 20px;
  grid-template-columns: 1fr;
  grid-template-areas: 'hero' 'tiles' 'cup' 'ticker';
}
@media (min-width: 900px) {
  .home { grid-template-columns: 1fr 1fr; grid-template-areas: 'hero hero' 'tiles tiles' 'cup ticker'; }
}
.hero { grid-area: hero; padding: 20px 0 4px; }
.hero h1 { font: 400 clamp(64px, 11vw, 120px)/0.85 var(--display); letter-spacing: 0.01em; }
.hero p { margin: 10px 0 0; color: var(--muted); font-size: 19px; max-width: 34em; }

.tiles { grid-area: tiles; display: grid; gap: 14px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 210px; padding: 20px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: rise 0.45s both cubic-bezier(0.2, 0.8, 0.2, 1);
  transition: transform 0.15s ease, border-color 0.2s;
}
.tile::after {
  content: ''; position: absolute; inset: auto -40% -60% auto; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 20, 26, 0.10), transparent 70%);
}
.tile-board { background: linear-gradient(160deg, rgba(232, 20, 26, 0.08), var(--surface)); }
.tile-board .tile-go { background: var(--text); color: var(--bg); }
.tile:active { transform: scale(0.97); border-color: var(--red); }
.tile-icon { font-size: 44px; line-height: 1; }
.tile-name { font: 400 32px/0.95 var(--display); letter-spacing: 0.02em; margin-top: 8px; }
.tile-tag { color: var(--muted); font-size: 14px; line-height: 1.35; flex: 1; }
.tile-go {
  align-self: flex-start; font: 800 12px/1 var(--body); letter-spacing: 0.16em;
  padding: 9px 14px; border-radius: 999px; background: var(--red); color: #fff;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.cup-panel { grid-area: cup; }
.ticker-panel { grid-area: ticker; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font: 400 30px/1 var(--display); letter-spacing: 0.03em; }
.panel-head small { font: 600 14px var(--body); color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.panel-link { display: block; margin-top: 14px; color: var(--muted); font-weight: 600; font-size: 15px; }


/* club cup */
.cup { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cup-row {
  display: grid; grid-template-columns: 28px 110px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
  animation: rise 0.4s both;
}
.cup-row:first-child { background: linear-gradient(90deg, rgba(255, 198, 41, 0.28), var(--surface-2)); }
.cup-row:first-child .cup-rank { color: var(--gold-ink); }
.cup-rank { font: 400 24px/1 var(--display); color: var(--muted); text-align: center; }
.cup-name { font-weight: 700; }
.cup-bar { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.cup-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--red-deep), var(--red)); transform-origin: left; transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1); }
.cup-pts { font: 400 24px/1 var(--display); min-width: 64px; text-align: right; }
.cup-compact .cup-row { padding: 8px 10px; }

.ticker { display: grid; gap: 6px; }
.tick-row { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.tick-row:last-child { border-bottom: 0; }
.tick-icon { font-size: 22px; text-align: center; }
.tick-text b { color: var(--text); }
.tick-text { color: var(--muted); }
.tick-time { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- leaderboards ---------- */
.board { display: grid; gap: 16px; padding-top: 8px; }
.board-head { display: flex; align-items: center; gap: 14px; }
.board-head h1 { font: 400 clamp(48px, 8vw, 72px)/0.9 var(--display); }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 12px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-weight: 700; font-size: 15px; white-space: nowrap;
}
.tab.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg-row { display: inline-flex; justify-self: start; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.seg { padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 15px; color: var(--muted); }
.seg.on { background: var(--red); color: #fff; }
.board-body { display: grid; gap: 12px; }
.scores { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.score-row {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px;
  padding: 14px 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: rise 0.35s both;
}
.score-row.podium { padding: 18px; }
.score-row.p1 { background: linear-gradient(90deg, rgba(255, 198, 41, 0.25), var(--surface)); border-color: rgba(200, 150, 0, 0.35); }
.score-row.me { outline: 2px solid var(--red); box-shadow: 0 0 24px -8px rgba(232, 20, 26, 0.5); }
.score-rank { font: 400 30px/1 var(--display); color: var(--muted); text-align: center; }
.podium .score-rank { font-size: 34px; }
.score-name { font-weight: 800; font-size: 19px; display: flex; flex-direction: column; }
.score-name small { font-weight: 600; font-size: 13px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.score-pts { font: 400 36px/1 var(--display); letter-spacing: 0.02em; }
.empty { text-align: center; padding: 30px; background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--line); }
.empty p { color: var(--muted); margin: 0 0 14px; }
.board-play { margin-top: 8px; }

/* ---------- play ---------- */
.play { display: flex; flex-direction: column; min-height: calc(100vh - 40px); min-height: calc(100dvh - 40px); }
.hud { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px; padding: 14px 0 10px; }
.hud-title { font: 400 26px/1 var(--display); letter-spacing: 0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-round { color: var(--muted); }
.hud-score { position: relative; text-align: right; }
.hud-score-num { font: 400 40px/1 var(--display); color: var(--text); }
.hud-delta {
  position: absolute; right: calc(100% + 10px); top: 8px; font: 400 26px/1 var(--display); color: var(--green); opacity: 0; pointer-events: none;
}
.hud-delta.show { animation: floatUp 0.9s ease-out; }
.timebar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.timebar i { display: block; height: 100%; background: var(--red); transform-origin: left; transform: scaleX(0); }
.timebar.progress i { background: linear-gradient(90deg, var(--red-deep), var(--red)); transition: transform 0.4s ease; }
.timebar i.low { background: var(--amber); animation: blink 0.5s steps(2) infinite; }
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 20px 0; }

.intro { text-align: center; display: grid; justify-items: center; gap: 14px; animation: rise 0.4s both; }
.intro-icon { font-size: 96px; line-height: 1; }
.intro h1 { font: 400 clamp(56px, 10vw, 96px)/0.9 var(--display); }
.intro p { color: var(--muted); font-size: 20px; margin: 0 0 16px; }
.count { text-align: center; font: 400 min(40vw, 260px)/1 var(--display); color: var(--red); animation: countPop 0.65s ease-out both; }

.question { display: grid; gap: 18px; animation: rise 0.35s both; width: 100%; max-width: 900px; margin: 0 auto; }
.q-text { font: 800 clamp(24px, 3.6vw, 34px)/1.2 var(--body); text-align: center; text-wrap: balance; }
.answers { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) { .answers { grid-template-columns: 1fr; } }
.answers-stack { grid-template-columns: 1fr; }
.answer {
  display: flex; align-items: center; gap: 14px; text-align: left;
  min-height: 76px; padding: 14px 18px; border-radius: 16px;
  background: var(--surface); border: 2px solid var(--line); box-shadow: var(--shadow);
  font-weight: 700; font-size: 19px; line-height: 1.25;
  animation: rise 0.3s both; transition: transform 0.1s, background 0.2s, border-color 0.2s, opacity 0.2s;
}
.answer:not(:disabled):active { transform: scale(0.97); border-color: var(--text); }
.answer-key {
  flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font: 400 22px/1 var(--display);
}
.answer-long { font-weight: 600; font-size: 18px; min-height: 70px; }
.answer.is-right { background: rgba(22, 163, 74, 0.12); border-color: var(--green); animation: correct 0.45s ease; }
.answer.is-right .answer-key { background: var(--green); color: #fff; }
.answer.is-wrong { background: rgba(232, 20, 26, 0.10); border-color: var(--red); animation: shake 0.4s ease; }
.answer.is-ok { background: rgba(217, 119, 6, 0.12); border-color: var(--amber); }
.answer.is-dim { opacity: 0.4; }
.why { text-align: center; color: var(--muted); min-height: 1.4em; margin: 0; font-size: 17px; }

/* body chart */
.body-wrap { display: grid; place-items: center; }
.body-chart { width: min(100%, 620px); height: auto; max-height: 48vh; }
.body-base * { fill: #e4e4df; }
.muscle * { fill: #c3c5ca; stroke: #fff; stroke-width: 1.5; transition: fill 0.25s; }
.muscle.lit * { fill: var(--red); filter: drop-shadow(0 0 5px rgba(232, 20, 26, 0.6)); animation: glow 1s ease-in-out infinite alternate; }
.muscle.miss * { fill: var(--amber); }
.tappable .muscle { cursor: pointer; }
.tappable .muscle * { stroke: transparent; stroke-width: 10; paint-order: stroke; }
.tappable .muscle:active * { fill: var(--text); }
.body-label { fill: var(--muted); font: 400 14px var(--display); letter-spacing: 0.2em; text-anchor: middle; }

/* speed */
.speed { display: grid; gap: 22px; width: 100%; max-width: 820px; margin: 0 auto; position: relative; }
.streak { display: flex; justify-content: center; align-items: center; gap: 12px; color: var(--muted); font-weight: 700; min-height: 40px; }
.mult { background: var(--gold); color: #1a1400; font: 400 26px/1 var(--display); padding: 6px 12px; border-radius: 10px; animation: countPop 0.3s both; }
.speed-card {
  min-height: 230px; display: grid; place-items: center; text-align: center; padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow);
}
.speed-card p { margin: 0; font: 800 clamp(26px, 4vw, 38px)/1.2 var(--body); text-wrap: balance; }
.speed-card p.big { font: 400 120px/1 var(--display); color: var(--red); }
.speed-card p.small { font: 600 18px var(--body); color: var(--muted); }
.speed-card.pop { animation: cardIn 0.22s ease-out; }
.tf-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tf { min-height: 130px; border-radius: 24px; font: 400 56px/1 var(--display); letter-spacing: 0.05em; transition: transform 0.08s; }
.tf:active { transform: scale(0.95); }
.tf-true { background: var(--green); color: #fff; }
.tf-false { background: var(--red); color: #fff; }
.tf:disabled { opacity: 0.35; }
.speed-flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; }
.speed-flash.good { background: radial-gradient(circle, rgba(22, 163, 74, 0.16), transparent 70%); }
.speed-flash.bad { background: radial-gradient(circle, rgba(232, 20, 26, 0.16), transparent 70%); }
.speed-flash.show { animation: flash 0.35s ease-out; }

/* macros */
.macro-round { display: grid; justify-items: center; gap: 8px; text-align: center; width: 100%; max-width: 640px; margin: 0 auto; animation: rise 0.35s both; }
.food-emoji { font-size: 110px; line-height: 1.05; animation: countPop 0.4s both; }
.food-name { font: 400 clamp(40px, 6vw, 60px)/0.95 var(--display); }
.food-serving { margin: 0; color: var(--muted); font-size: 18px; font-weight: 600; }
.macro-ask { font: 800 24px/1.2 var(--body); margin-top: 10px; }
.guess-value { font: 400 96px/1 var(--display); display: flex; align-items: baseline; gap: 4px; }
.guess-value small { font-size: 40px; color: var(--muted); }
.slider-row { display: grid; grid-template-columns: 60px 1fr 60px; align-items: center; gap: 14px; width: 100%; }
.nudge { height: 60px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); font-size: 30px; font-weight: 700; }
.nudge:active { transform: scale(0.94); }
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 14px; border-radius: 99px; background: var(--surface-2); outline: none; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 44px; height: 44px; border-radius: 50%; background: var(--red); border: 4px solid #fff; box-shadow: 0 4px 14px rgba(22, 24, 29, 0.3); }
.slider::-moz-range-thumb { width: 44px; height: 44px; border-radius: 50%; background: var(--red); border: 4px solid #fff; }
.slider-scale { display: flex; justify-content: space-between; width: calc(100% - 148px); color: var(--muted); font-size: 13px; font-weight: 700; }
.macro-round .btn-wide { margin-top: 14px; max-width: 420px; }
.reveal { min-height: 90px; display: grid; gap: 10px; justify-items: center; }
.reveal-verdict { margin: 8px 0 0; font-weight: 800; font-size: 22px; animation: rise 0.3s both; }
.macro-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; animation: rise 0.3s 0.1s both; }
.chip { padding: 8px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: 15px; }
.chip b { color: var(--text); }
.chip-hl { border-color: var(--red); background: rgba(232, 20, 26, 0.08); }

/* scenarios */
.scenario { display: grid; gap: 14px; width: 100%; max-width: 780px; margin: 0 auto; animation: rise 0.35s both; }
.who { margin: 0; color: var(--red); font: 800 13px/1 var(--body); letter-spacing: 0.16em; text-transform: uppercase; text-align: center; }
.says { margin: 0; font: 800 clamp(24px, 3.4vw, 32px)/1.25 var(--body); text-align: center; text-wrap: balance; }
.prompt { margin: 4px 0 0; color: var(--muted); text-align: center; font-weight: 700; }
.coach { display: grid; gap: 6px; }
.coach:empty { display: none; }
.coach { padding: 16px 18px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); animation: rise 0.3s both; }
.coach b { font-size: 20px; }
.coach p { margin: 0; color: var(--muted); }
.coach .best { color: var(--text); }

/* ---------- results ---------- */
.results { display: grid; justify-items: center; text-align: center; gap: 6px; padding-top: 16px; max-width: 640px; margin: 0 auto; }
.result-game { margin: 0; color: var(--muted); font-weight: 700; letter-spacing: 0.04em; }
.result-score { font: 400 clamp(110px, 22vw, 180px)/0.85 var(--display); color: var(--text); text-shadow: 0 6px 40px rgba(232, 20, 26, 0.25); }
.result-label { margin: 0 0 14px; color: var(--red); font: 400 26px/1 var(--display); letter-spacing: 0.3em; }
.save-form { width: 100%; display: grid; gap: 10px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); animation: rise 0.4s 0.3s both; }
.form-label { font: 800 12px/1 var(--body); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
.name-input {
  width: 100%; min-height: 62px; padding: 0 18px; border-radius: 14px;
  background: var(--bg); border: 2px solid var(--line); color: var(--text);
  font: 800 24px/1 var(--body); outline: none;
}
.name-input:focus { border-color: var(--red); }
.club-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.club-chip { min-height: 50px; border-radius: 12px; background: var(--bg); border: 2px solid var(--line); font-weight: 700; }
.club-chip.on { border-color: var(--red); background: rgba(232, 20, 26, 0.08); color: var(--red-deep); }
.form-err { margin: 0; min-height: 1.3em; color: var(--amber); font-weight: 600; font-size: 15px; }
.save-form .btn-link { justify-self: center; }
.after { width: 100%; display: grid; gap: 16px; }
.rank-card { padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); animation: rise 0.4s both; }
.rank-card p { margin: 0; }
.pb { color: var(--gold-ink); font-weight: 800; font-size: 18px; margin-bottom: 6px !important; }
.rank { font: 400 44px/1.1 var(--display); letter-spacing: 0.02em; }
.rank b { color: var(--red); font-weight: 400; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes blink { 50% { opacity: 0.5; } }
@keyframes floatUp { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30px); } }
@keyframes countPop { from { opacity: 0; transform: scale(1.6); } to { opacity: 1; transform: scale(1); } }
@keyframes cardIn { from { opacity: 0.2; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes correct { 40% { transform: scale(1.04); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes glow { to { filter: drop-shadow(0 0 10px rgba(232, 20, 26, 0.8)); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 560px) {
  .brand span { display: none; }
  .cup-row { grid-template-columns: 24px 92px 1fr auto; gap: 8px; }
  .tf { min-height: 110px; font-size: 44px; }
  .food-emoji { font-size: 84px; }
  .guess-value { font-size: 76px; }
}
