:root {
  --brand: #0020a5; --brand-2: #253cc0; --violet: #4648d4; --deep: #001676;
  --paper: #fbfcfe; --text: #161a2b; --muted: #5b6275; --up: #0e7a52; --dn: #c8372d; --hl: #ffe066;
  --head: 'Plus Jakarta Sans', system-ui, sans-serif; --body: 'Inter', system-ui, sans-serif; --script: 'Kalam', 'Comic Sans MS', cursive;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--text); font: 15px/1.45 var(--body); -webkit-tap-highlight-color: transparent;
  background-color: var(--brand);
  background-image: linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 24px 24px;
}
#stage { position: relative; max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
@media (min-width: 1024px) { #stage { max-width: 1240px; } }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.screen[hidden] { display: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #ffd54a; outline-offset: 2px; }
.small { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.disclaim { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; text-align: center; }
.disclaim.dark { color: rgba(255,255,255,.72); margin: auto 0 10px; padding-top: 8px; }

/* ---------- brand panels + buttons ---------- */
.panel { background: #fff; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; border-radius: 18px 18px 0 0; box-shadow: 0 -8px 24px rgba(0,0,0,.2); }
.btn { display: block; width: 100%; text-align: center; text-decoration: none; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--brand); background: #fff; color: var(--brand); font: 700 16px/1.2 var(--head); cursor: pointer; transition: transform .08s; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 0 #00137a; }
.btn-primary:active { box-shadow: 0 1px 0 #00137a; transform: translateY(3px); }
.btn-quiet { border-color: transparent; background: #eef0fb; color: var(--brand-2); font-size: 14px; padding: 10px; }
.row-btns { display: flex; gap: 8px; }
.goal { margin: 0 0 4px; font: 600 16px/1.4 var(--head); }

/* ---------- the chart sheet (play surface) ---------- */
.sheet { position: relative; background: var(--paper); border-radius: 6px; box-shadow: 0 1px 0 #c9d2e6, 0 16px 30px rgba(0,10,60,.35); }
.sheet svg { display: block; width: 100%; height: auto; }
svg .ax { font: 500 9.5px var(--body); fill: #7a8397; font-variant-numeric: tabular-nums; }
svg .lg, svg .lg text { font: 600 9.5px var(--body); fill: #5b6275; }
svg .lvt { font: 700 10px var(--body); fill: #3a4256; paint-order: stroke; stroke: var(--paper); stroke-width: 3px; }
svg .q { font: 700 64px var(--script); fill: #c7cee0; text-anchor: middle; }
svg .calltx { font: 700 15px var(--script); fill: var(--violet); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
svg .mk { font: 700 17px var(--script); fill: var(--violet); paint-order: stroke; stroke: var(--paper); stroke-width: 5px; }
svg .marker { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .55s cubic-bezier(.4,0,.2,1) forwards; }
svg .hl { animation: hlin .3s ease-out both; transform-box: fill-box; transform-origin: left center; }
svg .lvl.strong { stroke: var(--violet); }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes hlin { from { transform: scaleX(0); } }

/* ---------- title ---------- */
.scr-title { min-height: 100dvh; }
.title-top { flex: 1; padding: 22px 16px 16px; color: #fff; display: flex; flex-direction: column; justify-content: center; }
.title-top h1 { margin: 0; font: 800 46px/0.95 var(--head); letter-spacing: -0.03em; }
.title-sub { margin: 6px 0 14px; font: 500 16px var(--body); color: rgba(255,255,255,.85); }
.title-sheet { transform: rotate(-1.2deg); width: min(100%, calc((100dvh - 400px) * 1.13)); align-self: center; }
.scrawl { position: absolute; right: 18px; top: 10px; margin: 0; font: 700 22px var(--script); color: var(--violet); transform: rotate(-6deg); }
#best-line:empty { display: none; }
.rail-slot:empty { display: none; }

/* ---------- play: a fixed-height shell. Layout rules: docs/DESKTOP.md ---------- */
.scr-play {
  /* chart width: never wider than the column, never taller than the viewport leaves room for */
  --cw: min(calc(100% - 32px), calc((100dvh - 362px) * 1.0886));
  height: 100dvh; min-height: 0; overflow: hidden;
}
.hud { display: flex; align-items: center; gap: 10px; padding: 8px 16px 6px; color: #fff; }
.hud-l { display: flex; flex-direction: column; line-height: 1.15; flex: 1; min-width: 0; }
.hud-l b { font: 700 15px var(--head); }
.hud-l span { font-size: 12px; opacity: .8; }
.hud-streak { font: 800 15px var(--head); padding: 4px 10px; border-radius: 99px; background: rgba(255,255,255,.14); min-width: 44px; text-align: center; }
.hud-streak.hot { background: var(--hl); color: #3a2c00; }
.hud-streak.pulse { animation: pulse .45s cubic-bezier(.3,1.6,.5,1); }
.hud-streak.squash { animation: squash .4s ease-out; }
.hud-score { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.hud-score span { font-size: 11px; opacity: .75; }
.hud-score b { font: 800 20px var(--head); font-variant-numeric: tabular-nums; }
@keyframes pulse { 40% { transform: scale(1.35); } }
@keyframes squash { 30% { transform: scale(1.3, .6); } 60% { transform: scale(.9, 1.1); } }

.play-grid { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.play-side { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chart-wrap { position: relative; width: var(--cw); margin: 0 auto; flex: none; touch-action: none; user-select: none; -webkit-user-select: none; }
.chart-wrap.can-call .sheet { cursor: ns-resize; }
.timer { height: 5px; background: rgba(255,255,255,.18); border-radius: 3px; margin-bottom: 6px; overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: #fff; border-radius: 3px; transform-origin: left; }
.timer.low i { background: #ff8a7a; }
.chart-wrap.shake { animation: shake .32s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake { 15% { transform: translate(-5px, 2px); } 30% { transform: translate(5px, -2px); } 45% { transform: translate(-3px, 1px); } 60% { transform: translate(3px, 0); } 80% { transform: translate(-1px, 0); } }
.chart-wrap.nudge { animation: nudge .35s ease-out; }
@keyframes nudge { 30% { transform: translateY(-6px); } 60% { transform: translateY(3px); } }

.stamps, .pops { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.stamp { position: absolute; left: 50%; top: 36%; padding: 5px 14px; border: 3.5px solid currentColor; border-radius: 8px; font: 800 26px/1 var(--head); letter-spacing: .02em; background: rgba(251,252,254,.82); white-space: nowrap; }
.stamp.ok { color: var(--up); } .stamp.no { color: var(--dn); } .stamp.none { color: #6a7184; }
.stamp.settle { left: 10px; top: 10px; transform: rotate(-4deg) scale(.62) !important; transform-origin: left top; transition: all .35s cubic-bezier(.3,0,.2,1); animation: none; }
.stamp.fresh { animation: slam .2s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes slam { from { transform: var(--t) scale(2.3); opacity: 0; } 60% { opacity: 1; } to { transform: var(--t) scale(1); } }
.pop { position: absolute; transform: translate(-50%, -50%); font: 800 22px var(--head); color: var(--up); animation: rise .9s ease-out forwards; text-shadow: 0 2px 0 #fff; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); } to { opacity: 0; transform: translate(-50%, -160%); } }

.stage-card { position: absolute; inset: 0; background: rgba(0,22,118,.95); color: #fff; border-radius: 6px; display: flex; flex-direction: column; justify-content: center; padding: 20px; gap: 6px; }
.stage-card[hidden] { display: none; }
.sc-k { margin: 0; font-size: 13px; opacity: .8; }
.stage-card h2 { margin: 0; font: 800 26px/1.1 var(--head); }
.stage-card p { margin: 0; font-size: 15px; line-height: 1.45; max-width: 46ch; }

/* the dock: reserved space under (phones) or beside (desktop) the chart. Its panels swap in place. */
.dock { position: relative; flex: 1 1 250px; min-height: 250px; max-height: 330px; margin: 10px 16px 0; }
.dk { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; }
.dk[hidden] { display: none; }
.dk-foot { display: flex; flex-direction: column; gap: 8px; }
.prompt { margin: 0; color: #fff; font: 600 15px/1.4 var(--head); }
.prompt.tut { background: var(--hl); color: #2b2300; padding: 8px 11px; border-radius: 9px; }
.keys { display: none; margin: 0; font-size: 12.5px; color: rgba(255,255,255,.7); }

.controls { display: flex; gap: 10px; }
.call { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 15px 10px; border-radius: 12px; border: 0; font: 800 18px var(--head); cursor: pointer; background: #fff; color: var(--brand); box-shadow: 0 4px 0 #8f9de0; }
.call svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.call:active { transform: translateY(3px); box-shadow: 0 1px 0 #8f9de0; }
.call:disabled { opacity: .45; cursor: default; }
.call.hint { animation: nudge .6s ease-in-out 3; }
.btn-onblue, .end-actions .btn-primary { background: #fff; color: var(--brand); border-color: #fff; box-shadow: 0 4px 0 #8f9de0; }
.btn-onblue:active, .end-actions .btn-primary:active { box-shadow: 0 1px 0 #8f9de0; }

.reveal { background: #fff; border-radius: 14px; padding: 12px 12px 12px; 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; }
.rv-you { margin: 0 0 2px; font-size: 12.5px; color: var(--muted); }
.reveal h3 { margin: 0 0 4px; font: 800 18px/1.2 var(--head); color: var(--brand); }
.rv-line { margin: 0 0 8px; font-size: 14.5px; line-height: 1.45; }
.rv-out { margin: 0 0 8px; font-size: 13.5px; font-weight: 600; padding: 6px 9px; border-radius: 7px; background: #e9f5ef; color: #0b5b3d; }
.rv-out.failed { background: #fdeceb; color: #8a231c; }
.rv-meta { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.rv-meta span:empty { display: none; }
.rv-src { font-size: 11px; line-height: 1.35; color: var(--muted); }
.disclaim.dark { flex: none; color: rgba(255,255,255,.72); margin: auto 0 0; padding: 6px 16px calc(6px + env(safe-area-inset-bottom)); }

/* ---------- end ---------- */
.end-top { padding: 24px 16px 18px; color: #fff; }
.end-k { margin: 0; font-size: 14px; opacity: .8; }
.end-top h2 { margin: 2px 0 14px; font: 800 36px/1.05 var(--head); letter-spacing: -0.02em; }
.end-stats { display: flex; gap: 28px; }
.end-stats div { display: flex; flex-direction: column; }
.end-stats b { font: 800 34px/1 var(--head); font-variant-numeric: tabular-nums; }
.end-stats span { font-size: 13px; opacity: .8; }
.end-grid { display: flex; gap: 5px; margin-top: 16px; flex-wrap: wrap; }
.end-grid i { width: 26px; height: 26px; border-radius: 5px; display: grid; place-items: center; font-style: normal; font: 800 14px var(--head); }
.end-grid .ok { background: #2fbf86; color: #04331f; } .end-grid .no { background: #ff8a7a; color: #4a0e08; } .end-grid .none { background: rgba(255,255,255,.25); }
.best-stamp { display: inline-block; margin-top: 12px; padding: 3px 10px; border: 3px solid var(--hl); color: var(--hl); font: 800 18px var(--head); border-radius: 6px; transform: rotate(-4deg); animation: slam .3s cubic-bezier(.2,1.6,.4,1) both; --t: rotate(-4deg); }
.end-promo { padding: 0 16px 16px; }
/* phones: Share / New charts live in a fixed bottom bar, always in reach */
.end-actions { position: fixed; z-index: 5; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 520px); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--deep); box-shadow: 0 -6px 18px rgba(0,0,30,.3); }
.end-actions .small { color: rgba(255,255,255,.8); max-height: 3.2em; overflow: hidden; }
.end-actions .small:empty { display: none; }
.btn-onblue-quiet { background: transparent; color: #fff; border-color: rgba(255,255,255,.55); }
.end-panel { padding-bottom: 96px; }
.honest { margin: 0; font-size: 14.5px; background: #f2f4fc; border-left: 4px solid var(--violet); padding: 9px 11px; border-radius: 4px; }
.deb-h { margin: 10px 0 0; font: 800 17px var(--head); }
.debrief { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.debrief li { display: grid; grid-template-columns: 74px 1fr 22px; gap: 10px; align-items: center; padding: 8px; border: 1px solid #e3e7f2; border-radius: 10px; }
.debrief svg { width: 74px; height: 44px; display: block; background: var(--paper); border-radius: 4px; }
.debrief b { display: block; font: 700 14px/1.25 var(--head); }
.debrief span { font-size: 13px; color: var(--muted); }
.debrief .fail { color: #8a231c; }
.debrief .mark { font: 800 16px var(--head); text-align: center; }
.debrief .mark.ok { color: var(--up); } .debrief .mark.no { color: var(--dn); }

/* ---------- tablets and up: a wider single column ---------- */
@media (min-width: 600px) and (max-width: 1023px) {
  #stage { max-width: 600px; }
  .end-actions { width: min(100%, 600px); }
}

/* ---------- desktop (1024+): two columns, everything for the current step inside the viewport ---------- */
@media (min-width: 1024px) {
  .scr-play {
    --side: 320px;
    --cw: min(780px, calc((100dvh - 128px) * 1.0886), calc(100vw - 72px - var(--side)));
    padding: 8px 24px 0;
  }
  .hud { width: calc(var(--cw) + 24px + var(--side)); margin: 0 auto; padding: 6px 0 8px; }
  .play-grid { display: grid; flex: none; grid-template-columns: var(--cw) var(--side); gap: 24px; justify-content: center; align-items: stretch; }
  .chart-wrap { width: 100%; }
  .play-side { padding-top: 11px; gap: 12px; }
  .dock { flex: 1 1 auto; max-height: none; min-height: 0; margin: 0; border-radius: 14px; }
  .dk-call, .dk-card { padding: 16px; border-radius: 14px; background: rgba(255,255,255,.07); box-shadow: inset 0 0 0 1px rgba(255,255,255,.16); }
  .prompt { font-size: 17px; }
  .reveal { padding: 16px; }
  .reveal h3 { font-size: 21px; }
  .rv-line { font-size: 15px; }
  .disclaim.dark { margin-top: auto; }
  .scr-title { flex-direction: row; align-items: center; justify-content: center; gap: 48px; padding: 24px; }
  .title-top { flex: 0 1 600px; padding: 0; }
  .title-top h1 { font-size: 64px; }
  .title-sheet { width: min(100%, calc((100dvh - 260px) * 1.13)); align-self: flex-start; }
  .scr-title .panel { flex: 0 0 360px; border-radius: 18px; padding: 22px; }
  .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-top { padding: 0 0 16px; }
  .end-promo { padding: 0; }
  .end-actions { grid-area: actions; position: static; transform: none; width: auto; padding: 14px 0 0; background: none; box-shadow: none; }
  .end-panel { grid-area: panel; min-height: 0; border-radius: 18px; overflow-y: auto; padding-bottom: 18px; box-shadow: none; }
}
@media (min-width: 1024px) and (hover: hover) { .keys { display: block; } }
@media (min-width: 1280px) { .scr-play { --side: 360px; } }

body.nomotion *, body.nomotion *::before, body.nomotion *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition: none !important; }
