:root {
  --tray: #E4ECE8;
  --steel: #B9C6C2;
  --ink: #16302B;
  --ink-soft: #4F6660;
  --liquid: #5FB7C8;
  --paper: #F7F2E4;
  --pass: #2E8B57;
  --near: #D9A441;
  --miss: #C2453A;
  --card: rgba(255,255,255,0.86);
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--tray); color: var(--ink); font-family: var(--font); overflow: hidden; }
body { -webkit-text-size-adjust: 100%; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#c.dragging { cursor: grabbing; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; border-radius: 12px; min-height: 44px; min-width: 44px; padding: 0 18px; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.btn-primary { background: var(--ink); color: #fff; font-weight: 800; letter-spacing: 0.01em; }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost { background: transparent; border: 2px solid var(--steel); font-weight: 600; }
a { color: var(--ink); }
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: flex-start; padding: calc(12px + var(--sat)) 16px calc(12px + var(--sab)); }
.hud > * { pointer-events: none; }
.hud button { pointer-events: auto; }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.slip { position: relative; background: var(--paper); padding: 14px 16px 12px; border-radius: 4px 4px 10px 10px; box-shadow: 0 6px 14px -8px rgba(22,48,43,0.5); max-width: 62vw; transform: rotate(-1.2deg); transition: opacity .4s, transform .4s; }
.slip-pin { position: absolute; top: -6px; left: 50%; width: 12px; height: 12px; border-radius: 50%; background: var(--miss); box-shadow: inset -2px -2px 3px rgba(0,0,0,.3); transform: translateX(-50%); }
.slip-title { font-size: 11px; color: var(--ink-soft); font-weight: 600; }
.slip-order { font-size: clamp(16px, 4.6vw, 22px); font-weight: 800; line-height: 1.2; }
.slip-weight { font-size: 14px; margin-top: 4px; font-weight: 600; }
.slip.hidden-slip { opacity: 0; transform: rotate(-1.2deg) translateY(-12px); }
.slip.flutter { animation: flutter .6s ease-out forwards; }
@keyframes flutter { 30% { transform: rotate(3deg) translateY(4px); } 60% { transform: rotate(-4deg) translateY(10px); } 100% { opacity: .45; transform: rotate(2deg) translateY(16px); filter: grayscale(1); } }
.status { text-align: right; white-space: nowrap; }
.score { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.score small { font-size: 12px; margin-left: 4px; color: var(--ink-soft); font-weight: 600; }
.streak { display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 800; background: var(--ink); color: #fff; padding: 3px 8px; border-radius: 999px; }
.lvl { font-size: 12px; color: var(--ink-soft); font-weight: 600; margin-top: 6px; }
.timer { position: fixed; left: 0; right: 0; top: calc(var(--sat)); height: 4px; background: rgba(22,48,43,.12); }
.timer-fill { height: 100%; width: 100%; background: var(--ink); transform-origin: left; transition: background .3s; }
.timer-fill.low { background: var(--miss); }

.hud-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-top: auto; }
.vial-card { background: var(--card); backdrop-filter: blur(6px); border-radius: 10px; padding: 10px 14px; border-left: 6px solid var(--liquid); max-width: 55vw; }
.vial-title { font-size: 11px; color: var(--ink-soft); font-weight: 600; }
.vial-text { font-size: clamp(15px, 4.2vw, 20px); font-weight: 800; line-height: 1.2; }
.vial-sub { font-size: 11px; color: var(--ink-soft); }
.readout-wrap { text-align: right; }
.readout { font-size: clamp(34px, 9vw, 52px); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; letter-spacing: -0.02em; transition: opacity .3s; }
.readout.dim { opacity: .55; }
.readout.pop { animation: pop .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { 40% { transform: scale(1.12); } }
.readout-unit { font-size: .4em; margin-left: 4px; color: var(--ink-soft); font-weight: 600; }
.readout-toggle { margin-top: 4px; font-size: 12px; min-height: 32px; padding: 0 10px; background: var(--card); border: 1px solid var(--steel); }
.controls { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 10px; }
.btn-fine { background: var(--card); border: 2px solid var(--steel); font-size: 22px; font-weight: 800; width: 48px; }
.controls .btn-primary { min-width: 140px; }
.hint { position: fixed; left: 50%; top: calc(132px + var(--sat)); transform: translateX(-50%); max-width: calc(100vw - 32px); white-space: normal; text-align: center; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 999px; }

/* ---------- Precision ring ---------- */
.ring { position: fixed; width: 120px; height: 120px; transform: translate(-50%, -50%); pointer-events: none; }
.ring svg { display: block; overflow: visible; }
.ring-track { fill: none; stroke: rgba(22,48,43,.18); stroke-width: 6; }
.ring-band { fill: none; stroke: var(--near); stroke-width: 6; opacity: .7; }
.ring-core { fill: none; stroke: var(--pass); stroke-width: 6; }
.ring-needle { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; transform-origin: 60px 60px; transition: transform .45s cubic-bezier(.3,1.4,.4,1); }
.ring-hub { fill: var(--ink); }
.ring-word { position: absolute; left: 50%; top: 100%; transform: translate(-50%, 4px) scale(.6); opacity: 0; font-weight: 800; font-size: 15px; white-space: nowrap; padding: 4px 10px; border-radius: 999px; color: #fff; transition: transform .3s cubic-bezier(.2,1.6,.4,1), opacity .2s; }
.ring.show .ring-word { opacity: 1; transform: translate(-50%, 4px) scale(1); }
.ring.perfect .ring-word { background: var(--pass); }
.ring.near .ring-word { background: var(--near); color: var(--ink); }
.ring.miss .ring-word { background: var(--miss); }
.ring.perfect .ring-track { stroke: rgba(46,139,87,.35); }
.ring.miss .ring-track { stroke: rgba(194,69,58,.35); }
.ring.flash svg { animation: ringflash .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes ringflash { 0% { transform: scale(1.3); } 100% { transform: scale(1); } }
.float { position: fixed; transform: translate(-50%, 0); font-weight: 800; font-size: 22px; color: var(--pass); pointer-events: none; animation: floatup 1s ease-out forwards; }
@keyframes floatup { to { transform: translate(-50%, -60px); opacity: 0; } }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: linear-gradient(180deg, rgba(228,236,232,.2), rgba(228,236,232,.9)); }
.screen-card { width: min(440px, 100%); background: var(--card); backdrop-filter: blur(8px); border-radius: 18px; padding: 28px 24px; box-shadow: 0 24px 50px -30px rgba(22,48,43,.5); }
.start-card h1 { font-size: clamp(34px, 9vw, 46px); margin: 0; letter-spacing: -0.03em; line-height: 1; }
.lede { margin: 10px 0 20px; color: var(--ink-soft); font-weight: 600; font-size: 15px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.best { margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.how-step { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; text-align: center; }
.how-step svg { width: 64px; height: 64px; }
.credits { margin-top: 16px; font-size: 13px; line-height: 1.5; }
.credits p { margin: 6px 0; }
.mute { margin-top: 16px; font-size: 12px; min-height: 36px; background: transparent; border: 1px solid var(--steel); }
.screen h2 { margin: 0 0 6px; font-size: 28px; letter-spacing: -0.02em; }
.sum-score { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; line-height: 1; }
.sum-counts { margin: 10px 0 14px; display: flex; gap: 14px; font-size: 14px; font-weight: 600; }
.sum-counts b { display: block; font-size: 20px; }
.sum-bars { display: grid; gap: 6px; margin-bottom: 14px; }
.sum-bar { display: grid; grid-template-columns: 56px 1fr 44px; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.sum-bar i { display: block; height: 10px; border-radius: 5px; background: var(--ink); }
.sum-bar span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.missed { list-style: none; padding: 0; margin: 0 0 16px; font-size: 13px; }
.missed li { padding: 6px 10px; border-left: 3px solid var(--miss); background: rgba(194,69,58,.06); margin-bottom: 6px; border-radius: 0 8px 8px 0; }
.loading { position: fixed; inset: auto 0 24px 0; text-align: center; font-size: 13px; font-weight: 600; color: var(--ink-soft); }

/* ---------- Debrief sheet ---------- */
.sheet { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; }
.sheet-card { pointer-events: auto; width: min(520px, 100%); background: #fff; border-radius: 20px 20px 0 0; padding: 20px 20px calc(20px + var(--sab)); box-shadow: 0 -16px 40px -24px rgba(22,48,43,.6); animation: sheetup .35s cubic-bezier(.2,1,.3,1); }
@keyframes sheetup { from { transform: translateY(100%); } }
.verdict { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.verdict.perfect { color: var(--pass); } .verdict.near { color: #9A6E1C; } .verdict.miss { color: var(--miss); }
.verdict-sub { font-size: 14px; font-weight: 600; color: var(--ink-soft); margin: 2px 0 10px; }
.steps { margin: 0 0 12px; padding-left: 20px; font-size: 15px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.points { font-size: 18px; font-weight: 800; margin-bottom: 12px; }
.sheet .btn-primary { width: 100%; }

/* ---------- Landscape ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .sheet { align-items: center; justify-content: flex-end; padding-right: 24px; }
  .sheet-card { border-radius: 20px; width: 380px; animation: none; }
  .slip { max-width: 360px; }
  .vial-card { max-width: 360px; }
  .controls { position: fixed; right: 24px; bottom: calc(24px + var(--sab)); margin: 0; }
  .readout-wrap { position: fixed; right: 24px; bottom: calc(96px + var(--sab)); }
  .readout { font-size: 48px; }
  .hint { top: auto; bottom: calc(112px + var(--sab)); left: 24px; transform: none; max-width: 360px; }
}
@media (max-width: 400px) {
  .slip { max-width: 60vw; padding: 10px 12px 8px; }
  .score { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .ring-needle { transition: none; }
  .sheet-card { animation: none; }
  .ring.flash svg, .readout.pop, .slip.flutter { animation: none; }
}
