/* =========================================================
   Milionarul
   One stage colour, one gold, and the answer "lozenge" from
   the TV show as the only shape the brand owns.
   ========================================================= */

:root {
  --stage: #17123A;
  --raised: #221B52;
  --raised-hover: #2C2468;
  --line: #3B3380;
  --line-soft: #2A2362;
  --text: #EEEFFF;
  --muted: #ABA8D9;
  --faint: #7570AE;
  --gold: #F5B82E;
  --gold-hover: #FFC94D;
  --gold-ink: #231800;
  --correct: #35C589;
  --correct-ink: #03261A;
  --wrong: #F0585D;
  --wrong-ink: #2E0608;

  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --page: min(1120px, 100% - 40px);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(90% 55% at 50% -12%, #2D2572 0%, rgb(45 37 114 / 0) 70%),
    var(--stage);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  font-optical-sizing: auto;
}

main { flex: 1; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: 4px;
}
[tabindex="-1"]:focus { outline: none; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* The lozenge: shared by buttons, answers and ladder rungs.
   Each element sets its own --edge. */
.btn, .answer, .answer__body, .rung {
  clip-path: polygon(
    var(--edge) 0, calc(100% - var(--edge)) 0, 100% 50%,
    calc(100% - var(--edge)) 100%, var(--edge) 100%, 0 50%
  );
}

/* ---------- Header / footer ---------- */

.site-header {
  width: var(--page);
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 0 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.02em;
}
.brand__mark { width: 34px; height: 34px; color: var(--gold); flex: none; }

.site-nav { display: flex; gap: 28px; }
.site-nav a, .quiet-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}
.site-nav a:hover, .quiet-link:hover { color: var(--text); }

.site-footer {
  width: var(--page);
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 28px 0 calc(28px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 15px;
}
.site-footer p { margin: 0; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 22px; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }

/* ---------- Buttons ---------- */

.btn {
  --edge: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 34px;
  border: 0;
  background: var(--raised);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  line-height: 1.1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--raised-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { cursor: progress; opacity: .7; }
.btn:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--gold); }

.btn--primary { background: var(--gold); color: var(--gold-ink); }
.btn--primary:hover { background: var(--gold-hover); }
.btn--primary:focus-visible { box-shadow: inset 0 0 0 3px var(--stage); }

.btn--lg { --edge: 18px; min-height: 64px; padding: 0 46px; font-size: 20px; }

/* ---------- Ladder (hero + game rail) ---------- */

.ladder {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rung {
  --edge: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
  height: 36px;
  padding: 0 22px;
  background: rgb(255 255 255 / .035);
  color: var(--faint);
  transition: background-color .25s, color .25s;
}
.rung__n {
  min-width: 2ch;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rung__level { flex: 1; font-size: 13px; }
.rung__tag { font-size: 13px; font-weight: 700; color: var(--gold); }

.rung.is-done { background: var(--raised); color: var(--muted); }
.rung.is-current { background: var(--gold); color: var(--gold-ink); }
.rung.is-current .rung__tag { color: inherit; }

/* ---------- Home ---------- */

.hero {
  width: var(--page);
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, .7fr);
  align-items: center;
  gap: 56px;
  padding: clamp(32px, 7vh, 88px) 0 clamp(56px, 10vh, 112px);
}

.hero h1 {
  margin: 0 0 28px;
  max-width: 8.5ch;
  font-size: clamp(3.1rem, 8.6vw, 6.75rem);
  font-weight: 800;
  line-height: .92;
  letter-spacing: -0.045em;
  text-wrap: balance;
}

.hero__lede {
  margin: 0 0 40px;
  max-width: 36ch;
  color: var(--muted);
  font-size: clamp(1.125rem, 1.7vw, 1.375rem);
  line-height: 1.45;
}

.hero__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 30px; }
.hero__record { margin: 0; max-width: 30ch; color: var(--muted); font-size: 15px; }
.hero__record strong { color: var(--gold); font-weight: 700; }

.ladder--hero { justify-self: end; width: min(100%, 320px); }
.ladder--hero .rung { height: 38px; }

.home-grid {
  width: var(--page);
  margin-inline: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 72px;
  padding: 56px 0 80px;
  border-top: 1px solid var(--line-soft);
}

h2 {
  margin: 0 0 20px;
  font-size: 28px;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
  display: grid;
  grid-template-columns: 2.5ch minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 18px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.lb__rank { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.lb__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb__score { font-weight: 800; font-size: 19px; font-variant-numeric: tabular-nums; }
.leaderboard li:nth-child(-n + 3) .lb__score { color: var(--gold); }
.lb__you { margin-left: 8px; color: var(--gold); font-weight: 500; font-size: 14px; }

.leaderboard li.is-skeleton span {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: var(--line-soft);
  animation: pulse 1.2s ease-in-out infinite alternate;
}
.leaderboard li.is-skeleton span:nth-child(2) { width: 55%; }
.leaderboard li.is-skeleton span:nth-child(3) { width: 3ch; }

.board__status { margin: 16px 0 0; color: var(--muted); }
.board__status:empty { display: none; }

.about p { margin: 0 0 16px; max-width: 46ch; color: var(--muted); }

.stats { display: flex; flex-wrap: wrap; gap: 20px 48px; margin: 36px 0 0; }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { color: var(--muted); font-size: 15px; }
.stats dd {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* ---------- Game ---------- */

.hud { display: flex; gap: 28px; margin-left: auto; margin-right: 12px; }
.hud__item { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.hud__label { color: var(--muted); font-size: 13px; }
.hud__value {
  display: inline-block;
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.hud__item.is-record .hud__value { color: var(--gold); }

.game {
  width: var(--page);
  margin-inline: auto;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  align-items: start;
  gap: 64px;
  padding: 24px 0 56px;
}

.ladder--rail {
  position: sticky;
  top: 16px;
  height: min(560px, calc(100dvh - 140px));
  overflow: hidden;
  overflow-anchor: none;
  /* Enough room above and below so any rung, even the first, can sit in the middle. */
  padding: 260px 0;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 14%, #000 86%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 14%, #000 86%, transparent);
}

.stage { max-width: 780px; padding-top: 12px; }

.q-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 22px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 15px;
}
.q-number { color: var(--gold); font-weight: 700; }

.difficulty { display: inline-flex; align-items: center; gap: 8px; }
.difficulty__bars { display: inline-flex; align-items: flex-end; gap: 3px; height: 14px; }
.difficulty__bars i { width: 4px; border-radius: 1px; background: var(--line); }
.difficulty__bars i:nth-child(1) { height: 6px; }
.difficulty__bars i:nth-child(2) { height: 8px; }
.difficulty__bars i:nth-child(3) { height: 10px; }
.difficulty__bars i:nth-child(4) { height: 12px; }
.difficulty__bars i:nth-child(5) { height: 14px; }
.difficulty__bars i.is-on { background: var(--gold); }

.q-text {
  margin: 0 0 26px;
  min-height: 2.4em;
  max-width: 30ch;
  font-size: clamp(1.55rem, 3.3vw, 2.4rem);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.02em;
  text-wrap: pretty;
}

/* Countdown: drains from full to empty, turns red for the last 3 seconds. */
.timer {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 22px;
}
.timer__track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--line-soft);
  overflow: hidden;
}
.timer__fill {
  height: 100%;
  border-radius: inherit;
  background: var(--gold);
  transform-origin: left center;
}
.timer__value {
  display: inline-block;
  margin: 0;
  min-width: 3.4ch;
  color: var(--gold);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.timer.is-urgent .timer__fill { background: var(--wrong); }
.timer.is-urgent .timer__value { color: var(--wrong); }
.timer.is-urgent:not(.is-stopped) .timer__value { animation: urgent .5s ease-in-out infinite alternate; }
.timer.is-stopped .timer__fill { opacity: .55; }

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}

.answer {
  --edge: 20px;
  --ring: var(--line);
  display: block;
  width: 100%;
  padding: 2px;
  border: 0;
  background: var(--ring);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: opacity .3s, background-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.answer__body {
  --edge: 19px;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 66px;
  padding: 12px 32px;
  background: var(--raised);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.3;
  transition: background-color .15s, color .15s;
}
.answer__text { flex: 1; min-width: 0; }
.answer__letter { flex: none; width: 1.1em; color: var(--gold); font-weight: 800; }

.answer:disabled { cursor: default; }
.answer:focus-visible { outline: none; --ring: var(--gold); }
@media (hover: hover) {
  .answer:not(:disabled):hover { --ring: #574EA6; }
  .answer:not(:disabled):hover .answer__body { background: var(--raised-hover); }
}

.answer.is-loading .answer__text::before {
  content: "";
  display: block;
  width: 60%;
  height: 12px;
  border-radius: 6px;
  background: var(--line-soft);
  animation: pulse 1.2s ease-in-out infinite alternate;
}

.answer.is-selected { --ring: var(--gold); }
.answer.is-selected .answer__body {
  background: var(--gold);
  color: var(--gold-ink);
  animation: lock .45s ease-in-out infinite alternate;
}
.answer.is-correct { --ring: var(--correct); }
.answer.is-correct .answer__body { background: var(--correct); color: var(--correct-ink); animation: pop .35s ease-out; }
.answer.is-wrong { --ring: var(--wrong); }
.answer.is-wrong .answer__body { background: var(--wrong); color: var(--wrong-ink); animation: shake .4s ease-out; }
.answer.is-selected .answer__letter,
.answer.is-correct .answer__letter,
.answer.is-wrong .answer__letter { color: inherit; }
.answer.is-dimmed { opacity: .38; }

.feedback {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  min-height: 64px;
  margin-top: 28px;
}
.feedback__text { margin: 0; font-size: 20px; font-weight: 700; }
.feedback__text.is-good { color: var(--correct); }
.feedback__text.is-bad { color: var(--wrong); }
.feedback__text.is-neutral { color: var(--muted); font-weight: 500; }

.error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 20px;
  margin-top: 8px;
  padding: 18px 22px;
  border-left: 3px solid var(--wrong);
  background: rgb(240 88 93 / .08);
}
.error p { flex: 1 1 260px; margin: 0; }

.kbd-hint { margin: 48px 0 0; color: var(--faint); font-size: 14px; }
@media (hover: none) { .kbd-hint { display: none; } }

/* ---------- Game over dialog ---------- */

.sheet {
  width: min(540px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 32px 32px 28px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--raised);
  color: var(--text);
}
.sheet::backdrop { background: rgb(9 7 28 / .72); backdrop-filter: blur(4px); }
.sheet[open] { animation: rise .35s cubic-bezier(.2, .8, .2, 1); }

.go-title { margin: 0; color: var(--muted); font-size: 17px; font-weight: 600; letter-spacing: 0; }
.go-score {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin: 4px 0 14px;
}
#go-score {
  color: var(--gold);
  font-size: clamp(72px, 18vw, 104px);
  font-weight: 800;
  line-height: .95;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
}
.go-score__caption { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.go-note { margin: 0 0 6px; color: var(--muted); }
.go-note:empty { display: none; }

.go-form { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.go-form label { display: block; margin-bottom: 10px; font-weight: 600; }
.field { display: flex; flex-wrap: wrap; gap: 10px; }
.field input {
  flex: 1 1 180px;
  min-width: 0;
  height: 52px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--stage);
  color: var(--text);
  font: inherit;
  font-size: 18px;
}
.field input:focus { outline: none; border-color: var(--gold); }
.go-form__msg { margin: 10px 0 0; color: var(--wrong); font-size: 15px; }
.go-form__msg:empty { display: none; }
.go-rank {
  margin: 22px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-weight: 600;
}

.sheet .btn:not(.btn--primary) { background: var(--line); }
.sheet .btn:not(.btn--primary):hover { background: #4A4196; }

.go-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-top: 28px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 10px;
  background: var(--text);
  color: var(--stage);
  font-weight: 600;
  opacity: 0;
  transform: translate(-50%, 16px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Motion ---------- */

@keyframes pulse { from { opacity: .45; } to { opacity: 1; } }
@keyframes lock { from { filter: brightness(1); } to { filter: brightness(1.18); } }
@keyframes pop { 40% { transform: scale(1.03); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes urgent { to { transform: scale(1.15); } }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }

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

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .game { grid-template-columns: minmax(0, 1fr); gap: 0; padding-top: 8px; }
  .ladder--rail { display: none; }
}

@media (max-width: 820px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .ladder--hero { display: none; }
  .home-grid { grid-template-columns: minmax(0, 1fr); gap: 56px; padding-top: 48px; }
}

@media (max-width: 640px) {
  .answers { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .answer__body { min-height: 60px; padding: 10px 28px; font-size: 17px; }
  .q-text { margin-bottom: 28px; }
  .feedback { margin-top: 20px; }
  .feedback .btn { flex: 1 1 100%; }
  .site-nav__secondary { display: none; }
  .page-game .brand__word { display: none; }
  .hud { gap: 20px; }
  .hero__actions .btn { flex: 1 1 100%; }

  .sheet {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    border-width: 1px 0 0;
    padding: 28px 22px calc(24px + env(safe-area-inset-bottom, 0px));
  }
  .go-actions .btn, .field .btn { flex: 1 1 auto; }
}
