/* Fonts are served from this site (no third-party requests). Both are SIL Open Font License. */
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('../fonts/bricolage.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #EFEBFF;
  --ink: #1E1B4B;
  --muted: #5B5790;
  --card: #FFFFFF;
  --pink: #FF4F8B;
  --teal: #17B890;
  --amber: #FFB020;
  --line: #CFC7F5;
  --display: 'Bricolage Grotesque', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --text: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17142F;
    --ink: #F1EEFF;
    --muted: #A9A3D9;
    --card: #231F45;
    --line: #3A3466;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17142F; --ink: #F1EEFF; --muted: #A9A3D9; --card: #231F45; --line: #3A3466;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.0625rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 env(safe-area-inset-bottom, 0px);
}

main { width: 100%; max-width: 440px; flex: 1; }

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

/* ---------- top bar ---------- */
.topbar {
  width: 100%; max-width: 440px;
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 0 6px;
}
.brand { font-family: var(--display); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em; }
.puzzle-no { color: var(--muted); font-size: 0.95rem; }

.screen { text-align: center; padding-bottom: 24px; }

/* ---------- buttons ---------- */
.btn {
  font: 800 1.15rem/1 var(--display);
  letter-spacing: -0.01em;
  color: #1E1B4B;
  background: var(--card);
  border: 3px solid #1E1B4B;
  border-radius: 999px;
  padding: 16px 28px;
  cursor: pointer;
  box-shadow: 0 5px 0 #1E1B4B;
  transition: transform 80ms ease, box-shadow 80ms ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #1E1B4B; }
.btn:focus-visible { outline: 3px solid var(--teal); outline-offset: 4px; }
.btn-primary { background: var(--pink); width: 100%; }
.btn-look { background: var(--amber); padding: 18px 44px; font-size: 1.4rem; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn { border-color: #0E0C20; box-shadow: 0 5px 0 #0E0C20; }
}

/* ---------- home ---------- */
.hero-title {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.6rem, 12vw, 4.2rem);
  line-height: 0.92;
  letter-spacing: -0.045em;
  margin: 18px 0 6px;
}
.hero-art { width: 62%; max-width: 250px; margin: 0 auto; aspect-ratio: 1; }
.hero-art canvas { width: 100%; height: 100%; display: block; }
.how {
  list-style: none; padding: 0; margin: 4px auto 26px;
  display: grid; gap: 6px; max-width: 320px;
}
.how b { font-weight: 700; }
.stats-line { color: var(--muted); font-size: 0.95rem; margin-top: 18px; min-height: 1.5em; }

/* ---------- round ---------- */
.progress { display: flex; justify-content: center; gap: 8px; margin: 12px 0 10px; }
.progress span {
  width: 34px; height: 8px; border-radius: 99px; background: var(--line);
}
.progress span.done { background: var(--teal); }
.progress span.now { background: var(--pink); }
.round-count { margin: 0; color: var(--muted); font-size: 0.95rem; }
.prompt {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(1.5rem, 6.4vw, 1.9rem);
  line-height: 1.12; letter-spacing: -0.02em;
  margin: 4px 0 14px; min-height: 2.24em;
  display: flex; align-items: center; justify-content: center;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #FFFFFF;
  border: 3px solid #1E1B4B;
  border-radius: 24px;
  overflow: hidden;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; visibility: hidden; }
.stage[data-state="viewing"] canvas,
.stage[data-state="solving"] canvas,
.stage[data-state="reveal"] canvas { visibility: visible; }

.cover {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: #1E1B4B;
}
.cover p { margin: 0; color: #5B5790; }
.stage[data-state="ready"] .cover-ready { display: flex; }
.stage[data-state="hidden"] .cover-hidden { display: flex; }
.cover-hidden {
  background:
    repeating-linear-gradient(45deg, #F4F1FF 0 14px, #E9E3FF 14px 28px);
}
.cover-hidden span {
  font: 800 7rem/1 var(--display); color: #CFC7F5;
}

.timer { position: absolute; left: 0; right: 0; bottom: 0; height: 10px; display: none; background: #E9E3FF; }
.stage[data-state="viewing"] .timer,
.stage[data-state="solving"] .timer { display: block; }
.timer-bar { height: 100%; width: 100%; background: var(--pink); transform-origin: left; }
.timer-bar.run { animation: drain var(--reveal-ms, 3000ms) linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.guess { margin-top: 18px; }
.solve-clock {
  margin: 0 0 6px;
  font: 800 1.2rem/1.2 var(--display);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.solve-clock.urgent { color: #D6336C; }
.guess-row { display: flex; justify-content: center; align-items: baseline; gap: 8px; }
.guess-input {
  font: 800 3.4rem/1.1 var(--display);
  letter-spacing: -0.03em;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 4px solid var(--ink);
  width: 4.2ch;
  text-align: center;
  padding: 0 0 2px;
  border-radius: 0;
}
.guess-input:focus { outline: none; border-bottom-color: var(--pink); }
.guess-input::placeholder { color: var(--line); }
.guess-unit { font-size: 1.05rem; color: var(--muted); min-width: 1ch; text-align: left; }
.guess-slider { width: 100%; margin: 16px 0 0; accent-color: var(--pink); height: 32px; }
.guess-error { color: #D6336C; min-height: 1.5em; margin: 6px 0 8px; font-size: 0.95rem; }

.reveal { margin-top: 16px; }
.reveal-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.reveal-nums > div {
  background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 10px 6px 8px;
  display: flex; flex-direction: column;
}
.num { font: 800 2.4rem/1.05 var(--display); letter-spacing: -0.03em; }
.num-you { color: var(--pink); }
.lbl { color: var(--muted); font-size: 0.9rem; }
.verdict { font: 800 1.35rem/1.2 var(--display); margin: 14px 0 16px; }

/* ---------- results ---------- */
.results-kicker { margin: 18px 0 0; color: var(--muted); }
.big-score {
  font: 800 clamp(4.6rem, 26vw, 6.4rem)/0.9 var(--display);
  letter-spacing: -0.05em; margin: 4px 0 6px;
}
.big-score small { font-size: 0.32em; letter-spacing: -0.01em; color: var(--muted); margin-left: 4px; }
.emoji-line { font-size: 1.6rem; letter-spacing: 0.12em; margin: 0 0 6px; }
.rank { font: 800 1.25rem/1.3 var(--display); margin: 0 0 18px; min-height: 1.3em; }
.toast { min-height: 1.5em; margin: 8px 0 0; color: var(--teal); font-weight: 700; }

.breakdown {
  width: 100%; border-collapse: collapse; margin: 14px 0 4px;
  font-size: 0.98rem; font-variant-numeric: tabular-nums;
}
.breakdown th { font-weight: 400; color: var(--muted); font-size: 0.85rem; padding: 4px 4px 6px; }
.breakdown th:first-child, .breakdown td:first-child { text-align: left; }
.breakdown td { padding: 9px 4px; border-top: 2px solid var(--line); }
.breakdown td.you { color: var(--pink); font-weight: 700; }
.crowd-note { color: var(--muted); font-size: 0.9rem; margin: 6px 0 20px; min-height: 1.3em; }

.mystats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0 18px; }
.mystats div { display: flex; flex-direction: column; }
.mystats b { font: 800 1.7rem/1.1 var(--display); }
.mystats span { color: var(--muted); font-size: 0.8rem; line-height: 1.2; }
.next-in { color: var(--muted); }
.next-in span { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

.foot { padding: 12px 0 20px; font-size: 0.9rem; }
.foot a { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}

/* ---------- text pages (about, privacy, 404) ---------- */
main.doc { text-align: left; max-width: 640px; padding: 8px 0 40px; }
.doc h1 { font-family: var(--display); font-weight: 800; letter-spacing: -0.03em; font-size: 2.2rem; line-height: 1.1; margin: 12px 0; text-wrap: balance; }
.doc h2 { font-family: var(--display); font-weight: 800; font-size: 1.3rem; line-height: 1.2; margin: 30px 0 6px; text-wrap: balance; }
.doc h3 { font-family: var(--display); font-weight: 800; font-size: 1.05rem; margin: 18px 0 2px; }
.doc p, .doc li { line-height: 1.6; }
.doc a { color: var(--ink); }
.doc ul, .doc ol { padding-left: 1.2em; }
.doc li + li { margin-top: 6px; }
.doc .lede { font-size: 1.15rem; color: var(--muted); }
.doc a.cta { display: inline-block; margin-top: 10px; text-decoration: none; width: auto; color: #1E1B4B; }
.brand-link { color: inherit; text-decoration: none; }
.foot { display: flex; gap: 18px; justify-content: center; }

/* ---------- winning number, streaks, stats ---------- */
.topbar-right { display: flex; align-items: baseline; gap: 10px; }
.streak-badge {
  font: 800 0.95rem/1 var(--display); font-variant-numeric: tabular-nums;
  background: var(--card); border: 2px solid var(--line); border-radius: 99px; padding: 4px 10px;
}

.target-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin: 0 auto 22px; max-width: 320px;
  padding: 12px 16px 14px;
  background: var(--card); border: 3px solid var(--ink); border-radius: 22px;
}
.target-label { font-size: 0.9rem; color: var(--muted); }
.target-num { font: 800 3rem/1 var(--display); letter-spacing: -0.03em; color: var(--pink); font-variant-numeric: tabular-nums; }
.target-note { font-size: 0.92rem; line-height: 1.35; text-wrap: balance; }

.running { margin: -6px 0 16px; color: var(--muted); font-size: 0.98rem; min-height: 1.5em; }

.solution {
  background: var(--card); border: 2px solid var(--line); border-radius: 18px;
  padding: 12px 14px; margin: 0 0 14px;
}
.sv-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font: 800 1.15rem/1.3 var(--display); }
.sv { white-space: nowrap; }
.sh-a { color: #FF4F8B; } .sh-b { color: #17B890; } .sh-c { color: #FFB020; } .sh-d { color: #8B5CF6; }
.sv-expr { margin: 6px 0 0; font: 800 1.3rem/1.3 var(--display); font-variant-numeric: tabular-nums; }
.trap { margin: 6px 0 0; font-size: 0.92rem; color: var(--muted); }

.result-banner {
  font: 800 clamp(2.2rem, 11vw, 3rem)/1 var(--display); letter-spacing: -0.035em;
  margin: 6px 0 4px; color: var(--teal);
}
.result-banner.lost { color: var(--ink); }
.result-sub { margin: 4px 0 8px; text-wrap: balance; }

.stats-title { font: 800 1.15rem/1.2 var(--display); margin: 22px 0 8px; }
.dist { display: grid; gap: 6px; margin: 4px 0 18px; }
.dist-row { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px; font-size: 0.85rem; }
.dist-label { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.dist-track { display: block; }
.dist-bar {
  display: block; min-width: 26px; padding: 2px 8px; border-radius: 8px;
  background: var(--line); color: var(--ink); font-weight: 700; text-align: right; font-variant-numeric: tabular-nums;
}
.dist-row.mine .dist-bar { background: var(--pink); color: #1E1B4B; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }
