/* Stream Lab layout + animation. Tokens, the page frame (.shell/.read/.build/.lobe) and base components come from
   shared/theme.css. The timeline is drawn in ink on the pond-blue lobe; windows are cream openings in it.
   Phones differ by lane and shape, never by colour. Coral means "wrong count" or "dropped". */
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.brief p { margin: 14px 0 0; font-size: 17px; line-height: 1.45; }

/* controls, then the toolbar that ends in Run */
.tools { display: grid; gap: 14px; }
#controls, .actions, .opts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#controls { gap: 12px 24px; align-items: flex-end; }
.actions { gap: 10px; }
.actions .target-chip { margin-right: auto; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .cap { font: 700 14px/1.3 var(--font); color: var(--ink); }
legend { padding: 0; margin-bottom: 6px; }
#fixed { margin: 0; min-height: 40px; display: flex; align-items: center; font-size: 14px; color: var(--muted); }
/* the real radio covers its capsule, invisibly, so mouse, touch and keyboard all hit a native control */
.opt { position: relative; }
.opt input { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.opt span {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 52px; min-height: 40px; padding: 0 14px;
  font: 700 15px/1 var(--font); color: var(--ink); background: var(--water);
  border: 2px solid var(--line-strong); border-radius: var(--pill);
  transition: transform var(--t) var(--bounce), background-color .2s, color .2s;
}
.opt:hover span { background: var(--panel-2); transform: translateY(-2px); }
/* selected: the ink capsule with a ticked chip on its leading edge, like the current level stop */
.opt input:checked + span { background: var(--ink); color: var(--water); padding-left: 5px; }
.opt input:checked + span::before { content: ''; flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent) var(--pic-tick) center / 14px no-repeat; }
.opt input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 3px; }
#delay { width: 200px; height: 40px; margin: 0; }
#delayOut { font: 700 15px/1 var(--font); font-variant-numeric: tabular-nums; min-width: 13ch; }

/* stage: one time axis, left to right; every x position is a percentage of the stream's duration */
.hud { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-bottom: 14px; }
#legend { display: contents; }
#legend .chip { padding: 0; border: 0; background: none; min-height: 0; gap: 8px; font: 600 14px/1.3 var(--font); }
#clock { margin-left: auto; }
#clock, #wm { font-variant-numeric: tabular-nums; }

/* clicks: ink, one shape per phone */
.swatch, .ev { width: 12px; height: 12px; background: var(--ink); }
.s0 { border-radius: 50%; }
.s1 { border-radius: 1px; }
.s2 { border-radius: 1px; rotate: 45deg; scale: .88; }

#stage { position: relative; margin: 0 12px; padding-bottom: 24px; } /* the padding is the watermark label's row */
/* the path: tick labels on top, then one ink line with a tick per label. The 26px under it is the "now" badge's row. */
#axis { position: relative; height: 32px; margin-bottom: 26px; font: 600 12px/16px var(--mono); color: var(--ink); }
#axis::after { content: ''; position: absolute; left: -12px; right: -12px; top: 23px; height: 3px; border-radius: 2px; background: var(--ink); }
#axis span { position: absolute; transform: translateX(-50%); }
#axis span::after { content: ''; position: absolute; left: 50%; top: 20px; width: 9px; height: 9px; margin-left: -4.5px; border-radius: 50%; background: var(--ink); }
#lanes { position: relative; }
.lane { position: absolute; left: 0; right: 0; height: 26px; }
.lane::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--line); } /* one track per phone */
.tail { position: absolute; height: 0; margin-top: -1px; border-top: 2px dashed var(--ink); } /* how late: happened here, arrived there */
.tail.past { opacity: .35; }
.cap { display: block; margin: 16px 0 6px; }

/* windows are cream openings along the path: frameless while open, ink-framed once final */
#buckets { position: relative; height: 116px; }
.bucket {
  position: absolute; top: 0; bottom: 0; margin: 0 2px; display: grid; align-content: end; justify-items: center; padding-bottom: 5px;
  background: var(--water); border: 2px solid transparent; border-radius: 18px;
  transition: border-color .2s, background-color .2s;
}
.bucket::before { content: attr(data-zone); position: absolute; top: 7px; left: 0; right: 0; text-align: center; font: 600 12px/1 var(--mono); color: var(--muted); white-space: nowrap; }
.bucket b { font: 700 20px/1 var(--mono); }
.bucket small { font: 700 13px/14px var(--font); height: 14px; white-space: nowrap; }
.bucket.live { background: var(--panel-2); }
.bucket.live::before { color: var(--ink); }
.bucket.final { border-color: var(--ink); }
.bucket.ok { animation: pop var(--t) var(--bounce) both; animation-delay: calc(var(--i) * 70ms); }
.bucket.bad { background: var(--coral); animation: shake var(--t); }
.bucket.bad::before { color: var(--ink); }
@keyframes pop { from { transform: scale(.85); } }
@keyframes shake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

#target { display: flex; height: 30px; }
#target div { flex: 1; margin: 0 2px; display: grid; place-content: center; font: 600 15px/1 var(--mono); background: var(--water); border: 1.5px solid var(--ink); border-radius: var(--pill); }
/* where clicks go that arrived after their window closed */
#tray { height: 32px; border: 2px dashed var(--ink); border-radius: var(--pill); transition: background-color .2s; }
#tray.has { border-style: solid; background: var(--coral); }

.ev {
  position: absolute; margin: -6px; pointer-events: none;
  transition: left var(--t) var(--bounce), top var(--t) var(--bounce), opacity .2s;
}
.ev.pending { opacity: .22; }
.ev.transit { outline: 2px solid var(--ink); outline-offset: 2px; animation: blink .7s ease-in-out infinite alternate; } /* ringed only while a click is in flight */
.ev.dropped { border-radius: 0; rotate: none; scale: 1.5; mask: var(--i-x) center / contain no-repeat; } /* the drawn cross on the coral tray: shape and colour both say "not counted" */
@keyframes blink { to { transform: scale(1.3); } }

/* The clock (solid, ink label) and the watermark (dashed, cream label) both start under the tick labels and cross the path. */
#now, #wmLine { position: absolute; top: 18px; bottom: 24px; width: 0; pointer-events: none; }
#now { border-left: 2px solid var(--ink); }
#wmLine { border-left: 2px dashed var(--ink); bottom: 12px; }
#now b, #wmLine b { position: absolute; left: -1px; font: 700 12px/1 var(--font); padding: 4px 8px; border: 1.5px solid var(--ink); border-radius: var(--pill); transform: translateX(-50%); white-space: nowrap; }
#now b { top: 16px; background: var(--ink); color: var(--water); }
#wmLine b { bottom: -12px; background: var(--water); color: var(--ink); }
/* near either end the label leans inward, so it never leaves the stage */
:is(#now, #wmLine)[data-side="start"] b { transform: translateX(-12px); }
:is(#now, #wmLine)[data-side="end"] b { transform: translateX(calc(-100% + 12px)); }

/* result: the counts as a table on the water */
.scroll { overflow-x: auto; }
#out table.data { width: 100%; margin: 4px 0 10px; }
#out table.data :is(th, td) { padding: 5px 8px 5px 0; vertical-align: top; }
td.ok::before, td.err::before { content: '' / 'matches: '; display: inline-block; width: 1em; height: 1em; margin-right: 5px; vertical-align: -.14em; background: currentColor; mask: var(--i-tick) center / contain no-repeat; }
td.err::before { content: '' / 'wrong: '; mask-image: var(--i-x); }
#out table.data td.err { padding-left: 6px; }
/* confetti stays behind the result text */
#out { position: relative; z-index: 1; }
#verdict { scroll-margin-bottom: 12px; }
[data-state="win"] .result-stars { animation: pop var(--t) var(--bounce) both; }
.btn.arrow kbd { order: 1; } /* Next level → N */
.confetti { position: absolute; left: 50%; top: 60px; pointer-events: none; }
.confetti i { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); animation: burst 1s ease-out both; }
.confetti i:nth-child(odd) { background: var(--accent); }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }

/* phones: every control is a 44px touch target */
@media (max-width: 640px) {
  .opt span { min-height: 44px; }
  #delay { height: 44px; }
  .actions { justify-content: flex-end; } /* Reset and Run at the right end, as in every game */
  #fixed { min-height: 0; }
  #clock { margin-left: 0; }
  .bucket { border-radius: 14px; }
  .bucket b { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .ev.transit { animation: none; } /* an infinite animation at ~0ms duration would just thrash */
  .confetti { display: none; }
  .bucket.ok { animation-delay: 0s; } /* the end state at once, no stagger */
}
