:root {
  --bg: #0E2730; --panel: #143640; --panel-2: #1B4552; --bone: #EEE7D6; --bone-dim: #B9B3A5;
  --lo: #4A86FF; --ok: #8BC7A3; --hi: #F4A93A; --crit: #FF5C5C;
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--bone); font-family: var(--font); font-weight: 400; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
body { display: flex; justify-content: center; }
#stage { position: relative; width: 100%; max-width: 560px; height: 100dvh; overflow: hidden; background: var(--bg); touch-action: none; user-select: none; -webkit-user-select: none; }
#stage.w360 { max-width: 360px; box-shadow: 0 0 0 1px #2a5361; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* HUD */
#hud { position: absolute; top: 0; left: 0; right: 0; height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 10px 0 14px; font-size: 15px; font-weight: 600; background: linear-gradient(var(--bg), transparent); z-index: 2; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud-score { font-size: 20px; min-width: 56px; font-variant-numeric: tabular-nums; }
#hud-level { color: var(--bone-dim); }
#hud-progress { margin-left: auto; color: var(--bone-dim); font-variant-numeric: tabular-nums; }
.mult { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--bone-dim); font-size: 13px; transform-origin: center; }
.mult.on { color: var(--bg); background: var(--ok); }
.mult.pop { animation: pop .35s cubic-bezier(.34,1.56,.64,1); }
#hud-strikes { display: inline-flex; gap: 5px; }
#hud-strikes i { width: 10px; height: 10px; border-radius: 50%; background: var(--panel-2); border: 1px solid #2d5a68; transition: background .2s; }
#hud-strikes i.lit { background: var(--crit); border-color: var(--crit); box-shadow: 0 0 8px var(--crit); }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; color: var(--bone-dim); font: 600 14px var(--font); cursor: pointer; border-radius: 8px; }
.icon-btn:hover, .icon-btn:focus-visible { color: var(--bone); background: var(--panel-2); outline: none; }

/* Hint (guided first tubes) */
#hint { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); z-index: 2; background: var(--panel-2); color: var(--bone); padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; white-space: nowrap; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.35); }

/* Critical action chips */
#action { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; padding: 12px 12px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(14,39,48,.92) 22%, var(--bg) 60%); }
#action-title { margin: 0 0 8px; font-size: 14px; color: var(--crit); font-weight: 600; }
#action-ring { height: 4px; background: var(--panel-2); border-radius: 2px; margin-bottom: 10px; overflow: hidden; }
#action-timer { display: block; height: 100%; width: 100%; background: var(--crit); transform-origin: left; }
#chips { display: grid; gap: 8px; }
.chip { min-height: 44px; border: 1px solid #2d5a68; background: var(--panel); color: var(--bone); border-radius: var(--radius); padding: 10px 12px; text-align: left; font: 400 15px/1.3 var(--font); cursor: pointer; display: flex; gap: 10px; align-items: center; opacity: 0; transform: translateY(8px); transition: transform .12s, background .12s, border-color .12s, opacity .25s; }
.chip.in { opacity: 1; transform: none; }
.chip b { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--panel-2); color: var(--bone-dim); display: grid; place-items: center; font-size: 13px; }
.chip:hover, .chip:focus-visible { border-color: var(--bone-dim); outline: none; transform: translateY(-1px); }
.chip.right { background: #1f5a3f; border-color: var(--ok); }
.chip.right b { background: var(--ok); color: var(--bg); }
.chip.wrong { opacity: .45; }
.chip.picked-wrong { background: #5a2525; border-color: var(--crit); opacity: 1; }
#action-why { margin: 10px 2px 0; font-size: 13px; color: var(--bone-dim); line-height: 1.35; }

/* Screens */
.screen { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 20px 16px; background: rgba(14,39,48,.78); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); overflow-y: auto; animation: fade .3s; }
.screen[hidden] { display: none; }
.screen-body { width: 100%; max-width: 420px; text-align: center; }
#debrief .screen-body { animation: slide-in .3s cubic-bezier(.2,.8,.2,1); }
h1 { font-size: 44px; line-height: 1; margin: 6px 0 10px; font-weight: 600; letter-spacing: -.02em; }
h2 { font-size: 30px; line-height: 1.05; margin: 6px 0 10px; font-weight: 600; letter-spacing: -.01em; }
.shift { margin: 0; color: var(--bone-dim); font-size: 14px; }
.promise { font-size: 18px; margin: 0 0 14px; }
.how { color: var(--bone-dim); font-size: 15px; line-height: 1.4; margin: 0 auto 22px; max-width: 34ch; }
.how b, .caps b { font-weight: 600; }
.lo { color: var(--lo); } .ok { color: var(--ok); } .hi { color: var(--hi); }
.best { color: var(--bone-dim); margin: 14px 0 4px; font-size: 15px; }
.controls { color: var(--bone-dim); font-size: 13px; margin: 0 0 18px; }
.row { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.primary { min-width: 180px; min-height: 52px; border: 0; border-radius: 999px; background: var(--bone); color: var(--bg); font: 600 18px var(--font); cursor: pointer; transition: transform .12s; }
.primary:hover, .primary:focus-visible { transform: translateY(-2px); outline: 3px solid var(--ok); outline-offset: 3px; }
.link { background: none; border: 0; color: var(--bone-dim); font: 400 15px var(--font); cursor: pointer; min-height: 44px; padding: 0 8px; text-decoration: underline; text-underline-offset: 3px; border-radius: 6px; }
.link:hover, .link:focus-visible { color: var(--bone); outline: 2px solid var(--ok); }
#intro-rule, #debrief-sub { color: var(--bone-dim); font-size: 16px; line-height: 1.4; max-width: 36ch; margin: 0 auto 16px; }
.caps { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0 0 22px; }
.cap { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border-radius: 999px; background: var(--panel); font-size: 14px; font-weight: 600; }
.cap i { width: 14px; height: 18px; border-radius: 4px 4px 3px 3px; display: inline-block; }
#debrief-list, #end-levels { list-style: none; padding: 0; margin: 0 auto 18px; max-width: 400px; text-align: left; max-height: 44dvh; overflow-y: auto; }
#debrief-list li, #end-levels li { background: var(--panel); border-radius: 10px; padding: 9px 12px; margin-bottom: 6px; font-size: 14px; line-height: 1.35; }
#debrief-list li b { font-weight: 600; }
#debrief-list li .act { display: block; color: var(--bone-dim); margin-top: 3px; font-size: 13px; }
#debrief-list li.none { color: var(--bone-dim); text-align: center; }
.big { font-size: 48px; font-weight: 600; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
#sources p { color: var(--bone-dim); font-size: 15px; line-height: 1.45; text-align: left; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--bone); }
.hidden { display: none !important; }

@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .mult.pop, .screen, #debrief .screen-body { animation: none; }
  .chip { transition: opacity .15s; transform: none; }
}
