:root {
  --brand: #0020a5; --brand-c: #253cc0; --brand-2: #4648d4;
  --ink: #1a2230; --ink-2: #4a5468; --line: #d6dbe6;
  --page: #f3f4f8; --panel: #ffffff;
  --paper: #e8ecde; --paper-2: #dfe5d2; --paper-ink: #2c3b2f; --guilloche: rgba(44, 92, 70, .13);
  --real: #b3261e; --now: #9a7414; --good: #1e7a46; --mid: #b07d0c;
  --head: 'Plus Jakarta Sans', system-ui, sans-serif; --body: 'Inter', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.45 var(--body); -webkit-font-smoothing: antialiased; }
#stage { max-width: 520px; margin: 0 auto; min-height: 100dvh; position: relative; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; padding: 14px 16px 16px; }
.screen[hidden], [hidden] { display: none !important; }
.rail-slot:empty { display: none; }
#best-line:empty { display: none; }
h1, h2, h3 { font-family: var(--head); margin: 0; }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }

/* ---------- buttons and panels (brand) ---------- */
.btn { display: block; width: 100%; padding: 14px 16px; border-radius: 12px; border: 1.5px solid var(--brand); background: #fff; color: var(--brand); font-weight: 700; font-family: var(--head); font-size: 16px; text-align: center; text-decoration: none; cursor: pointer; margin-top: 10px; transition: transform .08s; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 3px 0 #00157a; }
.btn-primary:hover { background: var(--brand-c); }
.btn-quiet { border-color: transparent; background: transparent; font-weight: 600; font-size: 14px; padding: 10px 8px; color: var(--ink-2); }
.row-btns { display: flex; gap: 6px; }
.panel { margin-top: 16px; }
.scr-title { justify-content: center; }
.title-top { display: flex; flex-direction: column; justify-content: center; }
.goal { font-weight: 600; margin: 0 0 6px; }
.small { font-size: 13px; color: var(--ink-2); }
.about p { margin: 6px 0; }

/* ---------- the banknote card ---------- */
.note {
  position: relative; overflow: hidden; border-radius: 6px; padding: 14px 16px 16px; color: var(--paper-ink);
  background:
    radial-gradient(circle at 92% 108%, transparent 0 22px, var(--guilloche) 23px 24px, transparent 25px 30px, var(--guilloche) 31px 32px, transparent 33px 40px, var(--guilloche) 41px 42px, transparent 43px),
    repeating-radial-gradient(ellipse at 0% 50%, transparent 0 9px, var(--guilloche) 9.5px 10.5px, transparent 11px 14px),
    linear-gradient(170deg, var(--paper), var(--paper-2));
  box-shadow: 0 1px 0 #c9d0bb inset, 0 0 0 1px #c3cbb3, 0 10px 24px -14px rgba(20, 40, 30, .45);
}
.note::after { content: ''; position: absolute; inset: 7px; border: 1px solid rgba(44, 92, 70, .35); border-radius: 3px; pointer-events: none; }
.note-top { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: #4c6553; position: relative; z-index: 1; }
.t-year, .c-year {
  font-family: var(--head); font-weight: 800; font-variant-numeric: tabular-nums; line-height: .9; margin: 10px 0 4px; letter-spacing: -.03em;
  color: transparent; -webkit-text-stroke: 1.5px var(--paper-ink); background: repeating-linear-gradient(90deg, var(--paper-ink) 0 1.5px, transparent 1.5px 4px); -webkit-background-clip: text; background-clip: text;
}
.t-year { font-size: clamp(64px, 14dvh, 112px); }
.c-year { font-size: clamp(46px, 9dvh - 4px, 84px); margin: 6px 0 2px; }
.title-note h1 { font-size: 32px; color: var(--paper-ink); }
.t-line { margin: 6px 0 0; font-weight: 500; }
/* every label gets two lines of room, so the note never changes height between items */
.c-label { font-size: 20px; line-height: 1.2; height: 2.4em; display: flex; align-items: flex-end; color: var(--paper-ink); position: relative; overflow: hidden; }
.c-place { margin: 3px 0 0; font-size: 14px; line-height: 1.3; height: 1.3em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #4c6553; position: relative; }
.card.in { animation: cardIn .38s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes cardIn { from { transform: translateX(28px) rotate(1.5deg); opacity: 0; } }

/* ---------- HUD ---------- */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-size: 14px; flex: none; }
.hud-mode { font-weight: 700; font-family: var(--head); color: var(--brand); }
.hud-pips { display: flex; gap: 4px; }
.hud-pips i { width: 14px; height: 6px; border-radius: 3px; background: var(--line); }
.hud-pips i.on { background: var(--brand-2); }
.hud-pips i.t0 { background: var(--good); } .hud-pips i.t1 { background: #c9a227; } .hud-pips i.t2 { background: #d9822b; } .hud-pips i.t3 { background: var(--real); }
.hud-score b { font-family: var(--head); font-size: 18px; font-variant-numeric: tabular-nums; }
.hud-score small { color: var(--ink-2); }

/* ---------- guess readout: a fixed-height box; the reveal splits it in two, nothing below moves ---------- */
.guess { display: grid; grid-template-columns: 1fr; align-content: center; text-align: center; margin: 10px 0 6px; height: 64px; }
.guess.revealed { grid-template-columns: 1fr 1fr; }
.g-cap { margin: 0; font-size: 13px; line-height: 16px; color: var(--ink-2); font-weight: 600; }
.g-val, .g-real { margin: 0; font-family: var(--head); font-weight: 800; font-size: 38px; line-height: 44px; font-variant-numeric: tabular-nums; color: var(--brand); white-space: nowrap; }
.g-val small { font-size: 18px; font-weight: 700; }
.g-real { color: var(--real); font-size: 28px; }
.guess.revealed .g-val { font-size: 28px; color: var(--ink-2); }

/* ---------- the dial ---------- */
.dial { position: relative; flex: none; height: 80px; margin: 6px 4px 0; border-radius: 10px; background: linear-gradient(#fff, #f4f6fb); border: 1px solid var(--line); touch-action: none; cursor: ew-resize; user-select: none; -webkit-user-select: none; }
.dial.locked { cursor: default; }
.dial-ticks { position: absolute; inset: 0 12px; }
.tk { position: absolute; bottom: 0; width: 1px; height: 12px; background: #9aa3b8; }
.tk.maj { height: 24px; background: var(--ink-2); }
.tk b { position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 600; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.dial-now { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dotted var(--now); }
.dial-now span { position: absolute; top: 4px; left: 4px; font-size: 11px; font-weight: 700; color: var(--now); white-space: nowrap; }
.dial-now.flip span { left: auto; right: 4px; }
.needle { position: absolute; top: -8px; bottom: -6px; width: 0; pointer-events: none; }
.needle i { position: absolute; left: -1.5px; top: 8px; bottom: 6px; width: 3px; border-radius: 2px; }
.n-guess i { background: var(--brand); }
.n-guess::before { content: ''; position: absolute; left: -11px; bottom: -4px; width: 22px; height: 22px; border-radius: 50%; background: var(--brand); box-shadow: 0 2px 6px rgba(0, 32, 165, .4); border: 3px solid #fff; }
.dial.drag .n-guess::before { transform: scale(1.15); }
.n-real i { background: var(--real); }
.n-real::before { content: ''; position: absolute; left: -8px; top: 0; border: 8px solid transparent; border-top: 11px solid var(--real); }
.n-real.drop { animation: drop .42s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes drop { from { transform: translateY(-60px); opacity: 0; } 60% { opacity: 1; } }
.dial-band { position: absolute; top: 34px; bottom: 0; opacity: 0; transition: opacity .3s; }
.dial-band.show { opacity: .22; }
.dial-band.t0 { background: var(--good); } .dial-band.t1 { background: #c9a227; } .dial-band.t2 { background: #d9822b; } .dial-band.t3 { background: var(--real); }
.shake { animation: shake .26s; }
@keyframes shake { 25% { transform: translateX(-4px); } 50% { transform: translateX(3px); } 75% { transform: translateX(-2px); } }

/* ---------- play shell: fixed height, never a page scroll. Layout rules: docs/DESKTOP.md ---------- */
.scr-play { flex: 0 0 100dvh; height: 100dvh; min-height: 0; overflow: hidden; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.play-grid { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.play-main { position: relative; flex: none; }
.play-side { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* the dock: reserved space under (phones) or beside (desktop) the dial. On phones it sits at the bottom: the action bar. */
.dock { position: relative; flex: 1 1 230px; min-height: 216px; padding-top: 10px; }
.dk { position: absolute; inset: 10px 0 0; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; }
.dk[hidden] { display: none; }
.dk-foot { display: flex; flex-direction: column; gap: 6px; }
.dk-foot .btn, .reveal .btn { margin-top: 0; }
.prompt { margin: 0; font: 600 15px/1.4 var(--head); color: var(--ink); }
.prompt.tut { background: #fff3c4; color: #3d2f00; padding: 8px 11px; border-radius: 9px; }
.keys { display: none; margin: 0; font-size: 12.5px; color: var(--ink-2); }
.reveal { background: var(--panel); border-radius: 14px; padding: 12px 14px; border: 1px solid var(--line); }
.reveal.in { animation: fadein .25s ease-out; }
@keyframes fadein { from { opacity: 0; } }
.rv-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; outline: none; }
.verdict { margin: 0; font-family: var(--head); font-weight: 800; font-size: 18px; }
.verdict small { font-family: var(--body); font-weight: 600; font-size: 13px; color: var(--ink-2); margin-left: 6px; }
.bars { margin: 10px 0 4px; display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 8px; font-size: 13px; }
.bar span { color: var(--ink-2); font-weight: 600; }
.bar div { position: relative; height: 22px; }
.bar em { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--paper-ink); width: 0; transition: width .7s cubic-bezier(.2, .8, .2, 1); }
.bar.b-now em { background: var(--now); }
.bar.b-item em { background: var(--brand-c); }
.bar.b-neg em { background: var(--real); }
.bar b { position: absolute; top: 2px; font-style: normal; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; font-size: 13px; }
.lesson { margin: 8px 0 0; font-size: 14.5px; line-height: 1.5; }
.lesson strong { font-weight: 700; }
.rv-meta { margin: 8px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.rv-meta span:empty { display: none; }
.src { font-size: 11.5px; line-height: 1.35; color: var(--ink-2); }

/* ---------- pops ---------- */
.pops { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; transform: translate(-50%, -50%); font-family: var(--head); font-weight: 800; font-size: 26px; color: var(--good); text-shadow: 0 2px 0 #fff; animation: pop .9s ease-out forwards; }
.pop.lo { color: var(--ink-2); font-size: 20px; }
@keyframes pop { 0% { transform: translate(-50%, -30%) scale(.6); opacity: 0; } 20% { transform: translate(-50%, -60%) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -160%) scale(1); opacity: 0; } }

/* ---------- end ---------- */
.report { background: var(--panel); border-radius: 16px; padding: 18px 16px; border: 1px solid var(--line); }
.rep-head { margin: 0; font-size: 13px; font-weight: 700; color: var(--brand); }
.report h2 { font-size: 26px; margin-top: 4px; }
.end-score { margin: 8px 0 0; font-family: var(--head); }
.end-score b { font-size: 52px; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.end-score span { font-size: 20px; color: var(--ink-2); font-weight: 700; }
.end-grid { font-size: 26px; letter-spacing: 2px; margin: 6px 0; }
.end-big { font-size: 15px; margin: 8px 0 0; padding: 10px 12px; background: var(--paper); border-radius: 8px; color: var(--paper-ink); }
.end-promo { margin-top: 12px; }
.end-promo:empty { display: none; }
.deb-h { margin: 0; font-size: 17px; }
.end-panel { margin-top: 12px; }
.end-list { list-style: none; padding: 0; margin: 12px 0 8px; display: grid; gap: 8px; }
.end-list li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: start; font-size: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.end-list li:last-child { border-bottom: 0; }
.end-list .dot { width: 14px; height: 14px; border-radius: 4px; margin-top: 3px; }
.dot.t0 { background: var(--good); } .dot.t1 { background: #c9a227; } .dot.t2 { background: #d9822b; } .dot.t3 { background: var(--real); }
.end-list .it b { font-weight: 600; }
.end-list .it span { display: block; color: var(--ink-2); font-size: 13px; }
.end-list .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.best-stamp { display: inline-block; margin-top: 6px; padding: 4px 12px; border: 3px solid var(--real); color: var(--real); font-family: var(--head); font-weight: 800; transform: rotate(-6deg); border-radius: 6px; animation: stamp .35s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes stamp { from { transform: rotate(-6deg) scale(2.2); opacity: 0; } }
/* phones: Share / Free play live in a fixed bottom bar, always in reach */
.scr-end { padding-bottom: 150px; }
.end-actions { position: fixed; z-index: 5; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 520px); padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -6px 18px rgba(20, 30, 60, .14); }
.end-actions .row-btns .btn { margin-top: 0; }
.end-actions .small { margin: 6px 0 0; max-height: 3.2em; overflow: hidden; }
.end-actions .small:empty { display: none; }
.countdown { margin: 6px 0 0; text-align: center; font-size: 13px; color: var(--ink-2); }

/* ---------- tablets: the same single column, a little wider ---------- */
@media (min-width: 600px) and (max-width: 1023px) {
  #stage { max-width: 600px; }
  .end-actions { width: min(100%, 600px); }
  .c-year { font-size: clamp(56px, 9dvh, 96px); }
}

/* ---------- desktop (1024+): play area left, dock + promo rail right ---------- */
@media (min-width: 1024px) {
  #stage { max-width: 1240px; }
  .scr-play { --side: 320px; --pw: min(640px, calc(100vw - 72px - var(--side))); padding: 12px 24px 16px; }
  .hud { width: calc(var(--pw) + 24px + var(--side)); margin: 0 auto 12px; }
  .play-grid { display: grid; grid-template-columns: var(--pw) var(--side); gap: 24px; justify-content: center; align-items: stretch; }
  .play-main { align-self: center; }
  .c-year { font-size: clamp(64px, 12dvh, 104px); }
  .c-label { font-size: 24px; }
  .guess { height: 80px; }
  .g-val { font-size: 46px; line-height: 52px; }
  .guess.revealed .g-val, .g-real { font-size: 34px; }
  .dial { height: 96px; }
  .play-side { gap: 12px; }
  .dock { flex: 1 1 auto; max-height: none; min-height: 0; margin: 0; padding: 0; }
  .dk { inset: 0; }
  .dk-guess { padding: 16px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
  .prompt { font-size: 16px; }
  .reveal { padding: 16px; }
  .scr-title { flex-direction: row; align-items: center; justify-content: center; gap: 48px; padding: 24px; }
  .title-top { flex: 0 1 520px; }
  .scr-title .panel { flex: 0 0 360px; margin: 0; }
  .scr-end {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "left panel" "actions panel" ". panel"; gap: 0 32px; height: 100dvh; min-height: 0; padding: 24px; width: 100%; max-width: 1120px; margin: 0 auto;
  }
  .end-left { grid-area: left; }
  .end-actions { grid-area: actions; position: static; transform: none; width: auto; padding: 12px 0 0; background: none; box-shadow: none; }
  .end-panel { grid-area: panel; min-height: 0; overflow-y: auto; margin: 0; }
}
@media (min-width: 1024px) and (hover: hover) { .keys { display: block; } }
@media (min-width: 1280px) { .scr-play { --side: 360px; } }

body.nomotion *, body.nomotion *::before { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
