/* Race view, deal popup, finish-first bonus and TV mode (docs/API.md "Race view, finish-first bonus, dealt picks, TV mode").
   rs-  the small race strip on the play screen and rsb- the big track (web/js/ui/race-strip.js)
   dp-  the deal popup (web/js/ui/deal-popup.js; its picture is dpx- in css/cards-fx.css)
   rc-  race bits on phone screens: dealt panels, bonus lines, TV entry and join (party, match, result, party-new, tv-join)
   tv-  the TV screen (web/js/screens/tv.js), landscape, sized in em from one base font so 720p and 1080p both fit.
   Zone colours read the Cinerama tokens (--p1 Start, --p2 Trick Shot, --p3 End). Reads tokens.css only. */

/* ---------- Small race strip (play screen): one ~32px row, never wraps ---------- */
.rs { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 6px; margin-top: var(--s3); }
.rs-zone {
  --zc: var(--p1);
  position: relative; display: flex; align-items: center; justify-content: center; gap: 0; min-width: 0; height: 32px;
  padding: 0 6px; border-radius: 10px;
  background: color-mix(in srgb, var(--zc) 22%, var(--bg-raised)); box-shadow: inset 0 -3px 0 var(--zc);
}
.rs-zone.trick { --zc: var(--p2); }
.rs-zone.end { --zc: var(--p3); }
.rs-label { font: 800 11px/1 var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); white-space: nowrap; }
.rs-run { position: relative; display: inline-flex; flex: none; }
.rs-run + .rs-run { margin-left: -6px; }
.rs-run .avatar { width: 24px; height: 24px; font-size: 11px; border: 2px solid var(--bg-raised); }
.rs-run.me .avatar { border-color: var(--cream); box-shadow: 0 0 0 1px var(--bg); }
.rs-place {
  position: absolute; right: -6px; bottom: -5px; padding: 0 3px; border-radius: 6px;
  font: 800 9px/13px var(--font-body); font-style: normal; background: var(--cream); color: var(--text-inverse); white-space: nowrap;
}
.rs-place.p1 { background: var(--gold); }
.rs-more { flex: none; margin-left: 4px; font: 800 12px/1 var(--font-body); color: var(--text); }
.core-race .rs { margin-top: var(--s3); }

/* ---------- Big track (TV, party lobby once started) ---------- */
.rsb-lane { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 10px; }
.rsb-zone {
  --zc: var(--p1);
  min-width: 0; border-radius: 16px; padding: var(--s3) var(--s2) var(--s4);
  background: color-mix(in srgb, var(--zc) 16%, var(--bg-raised)); box-shadow: inset 0 -5px 0 var(--zc);
}
.rsb-zone.trick { --zc: var(--p2); }
.rsb-zone.end { --zc: var(--p3); }
.rsb-label { font: 800 var(--fs-xs)/1 var(--font-body); letter-spacing: .14em; text-transform: uppercase; color: var(--zc); text-align: center; filter: brightness(1.25); }
.rsb-runners { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s3) var(--s2); margin-top: var(--s3); min-height: 64px; }
.rsb-run { display: grid; justify-items: center; gap: 2px; width: 72px; min-width: 0; text-align: center; }
.rsb-run.out { opacity: .55; }
.rsb-av { position: relative; display: inline-flex; }
.rsb-av .avatar { width: 44px; height: 44px; font-size: var(--fs-sm); border: 3px solid var(--bg); }
.rsb-run.me .rsb-av .avatar { border-color: var(--cream); }
.rsb-av .rs-place { font-size: 11px; line-height: 16px; padding: 0 4px; right: -10px; bottom: -4px; }
.rsb-name { max-width: 100%; font: 700 var(--fs-xs)/1.2 var(--font-body); overflow-wrap: anywhere; }
.rsb-sub { font-size: 11px; color: var(--text-2); font-weight: 700; }
.rc-track { margin-top: var(--s5); }

/* ---------- Deal popup ---------- */
.dp { text-align: center; overflow: hidden; animation: pop-in var(--dur) var(--ease-spring); }
.dp.won { border-color: var(--red); box-shadow: 0 0 0 2px var(--red-edge), var(--shadow-pop); }
.dp-title { margin-top: var(--s3); position: relative; text-wrap: balance; }
.dp-sad { margin-top: var(--s1); color: var(--text-2); font-style: italic; font-weight: 700; }
.dp-body { margin-top: var(--s3); font-size: var(--fs-lg); font-weight: 700; position: relative; }
.dp .actions { position: relative; }
@media (prefers-reduced-motion: reduce) { .dp { animation: none; } }

/* ---------- Party lobby: dealt panels, deal button, notes ---------- */
.soc-trio .cine-panel.rc-locked { filter: saturate(.55) brightness(.8); cursor: default; }
.soc-trio .cine-panel.rc-mine { outline: 3px solid var(--cream); outline-offset: 3px; }
.rc-owner { font: 800 11px/1.2 var(--font-body); opacity: .9; }
.rc-note { margin-top: var(--s3); text-align: center; color: var(--text-2); font-size: var(--fs-sm); font-weight: 700; }
.rc-note.ranked { color: var(--good); }
.rc-next { margin-top: var(--s2); }

/* ---------- Finish-first bonus (result screen, match result) ---------- */
.rc-bonus { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--s2); margin-top: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--gold-tint); color: var(--cream); font-weight: 700; text-align: center; }
.rc-bonus b { color: var(--gold); }
.rc-bonus .mono { white-space: nowrap; }
.rc-bonus.pending { background: var(--bg-card); border: 1px dashed var(--gold-edge); }
.rc-chip { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--gold); color: var(--text-inverse); font: 800 var(--fs-xs)/1.4 var(--font-body); white-space: nowrap; }
.ip-side .rc-chip { margin-top: 2px; }

/* ---------- Party start: the TV card; /tv/join ---------- */
.rc-tv-card { margin-top: var(--s5); display: grid; gap: var(--s3); }
.rc-tv-card .muted { font-size: var(--fs-sm); }
.rc-join { margin-top: var(--s6); display: grid; gap: var(--s3); }
.rc-join input { font: 700 1.6rem/1 var(--font-display); letter-spacing: .3em; text-align: center; text-transform: uppercase; }
.rc-join input::placeholder { letter-spacing: .1em; font-size: var(--fs-md); font-family: var(--font-body); }

/* ---------- TV screen (/tv): the whole window, landscape ---------- */
:root:has(.tv-screen) { --col: 100%; }
:root:has(.tv-screen) .app { border: 0; background: none; }
.tv-screen {
  --perspective: 1800px; /* a wide screen needs a deeper Cinerama curve, or the outer panels swing off the edge */
  --cine-angle: 16deg;
  font-size: clamp(16px, 2.25vh, 34px);
  min-height: 100dvh; padding: 1.6em 2.4em 1.4em; display: flex; flex-direction: column;
  background: radial-gradient(90vw 70vh at 50% -10%, #1c2a4c 0%, var(--bg) 65%);
  overflow: hidden;
}
.tv-head { display: flex; align-items: center; gap: 1em; }
.tv-brand { font: 700 1.2em/1 var(--font-display); letter-spacing: .08em; display: flex; gap: .3em; }
.tv-brand span:nth-child(1) { color: var(--cyan); }
.tv-brand span:nth-child(2) { color: #ff5c80; }
.tv-brand span:nth-child(3) { color: var(--gold); }
.tv-head .grow { flex: 1; }
.tv-pill { padding: .3em .9em; border-radius: var(--radius-pill); background: var(--bg-card); border: 1px solid var(--line-strong); font-weight: 800; white-space: nowrap; }
.tv-pill b { letter-spacing: .14em; color: var(--gold); }
.tv-body { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; padding-top: 1em; }
.tv-h1 { font: 700 2.4em/1.1 var(--font-display); text-align: center; text-wrap: balance; }
.tv-sub { margin-top: .4em; text-align: center; color: var(--text-2); font-size: 1.1em; font-weight: 700; }
.tv-status { margin-top: 1em; text-align: center; font: 700 1.3em/1.2 var(--font-display); color: var(--text-2); }
.tv-status.ok { color: var(--good); }
.tv-status.bad { color: var(--danger); }
.tv-msg { text-align: center; display: grid; gap: .6em; justify-items: center; }
.tv-screen .avatar { width: 3.2em; height: 3.2em; font-size: 1em; }

/* Lobby: QR left, code and players right */
.tv-lobby { display: grid; grid-template-columns: auto 1fr; gap: 3em; align-items: center; }
.tv-qr { margin: 0; width: min(56vh, 40vw); aspect-ratio: 1; padding: .8em; border-radius: 1.2em; background: #fff; box-shadow: 0 .4em 0 var(--gold-edge), 0 1.2em 3em rgba(0, 0, 0, .4); }
.tv-qr svg { display: block; width: 100%; height: 100%; }
.tv-qr-fallback { display: grid; place-items: center; height: 100%; color: var(--text-inverse); font: 700 1.2em/1.3 var(--font-display); text-align: center; }
.tv-join { min-width: 0; }
.tv-join .tv-h1 { text-align: left; }
.tv-code { font: 700 6em/1 var(--font-display); letter-spacing: .18em; color: var(--gold); margin-top: .1em; }
.tv-url { font-size: 1.15em; color: var(--text-2); font-weight: 700; }
.tv-url b { color: var(--text); }
.tv-players { display: flex; flex-wrap: wrap; gap: 1em 1.4em; margin-top: 1.4em; min-height: 4.6em; }
.tv-player { display: grid; justify-items: center; gap: .3em; max-width: 7em; text-align: center; font-weight: 700; overflow-wrap: anywhere; animation: tv-in var(--dur-slow) var(--ease-spring); }
.tv-player .tv-host-tag { font-size: .7em; padding: 0 .5em; border-radius: var(--radius-pill); background: var(--gold); color: var(--text-inverse); font-weight: 800; }
.tv-empty { color: var(--text-2); font-weight: 700; align-self: center; }
.tv-hostline { margin-top: 1em; font-weight: 700; }
.tv-note { margin-top: .4em; color: var(--text-2); font-weight: 700; }
.tv-note.ranked { color: var(--good); }
@keyframes tv-in { from { opacity: 0; transform: scale(.6); } }

/* Picking: the three panels with the dealt player on each */
.tv-trio { margin: 1.4em auto 0; width: min(100%, 72em); }
.tv-trio .cine-panel { min-height: 9em; padding: 1em .6em 2.4em; }
.tv-trio .cine-panel .slot { font-size: .8em; }
.tv-trio .cine-panel .film { font-size: 1.8em; }
.tv-trio .cine-panel .year { font-size: .8em; }
.tv-trio .tv-picking { font: 700 1.1em/1.2 var(--font-display); opacity: .85; }
.tv-dealt { position: absolute; left: 50%; bottom: -1.6em; transform: translateX(-50%); display: grid; justify-items: center; gap: .2em; font: 800 .8em/1.1 var(--font-body); color: var(--text); white-space: nowrap; }
.tv-dealt .avatar { width: 3em; height: 3em; border: .2em solid var(--bg); font-size: 1.1em; }
.tv-popcorn { margin-top: 3em; text-align: center; font-weight: 700; color: var(--text-2); font-size: 1.1em; }
.tv-popcorn b { color: var(--text); }

/* Racing: small trio, then the big track full width */
.tv-race .tv-h1 { font-size: 1.8em; }
.tv-race .tv-trio { margin-top: .6em; width: min(100%, 60em); }
.tv-race .tv-trio .cine-panel { min-height: 5em; padding: .6em; }
.tv-race .tv-trio .cine-panel .film { font-size: 1.3em; }
.tv-race .rsb { margin-top: 1.4em; }
.tv-screen .rsb-lane { gap: 1em; }
.tv-screen .rsb-zone { border-radius: 1em; padding: 1em .8em 1.4em; }
.tv-screen .rsb-label { font-size: 1em; }
.tv-screen .rsb-runners { gap: 1em; min-height: 8em; margin-top: 1em; }
.tv-screen .rsb-run { width: 7em; }
.tv-screen .rsb-av .avatar { width: 4.2em; height: 4.2em; font-size: 1.3em; border-width: .18em; }
.tv-screen .rsb-av .rs-place { font-size: .85em; line-height: 1.5; padding: 0 .4em; right: -.6em; bottom: -.3em; border-radius: .5em; }
.tv-screen .rsb-name { font-size: 1em; }
.tv-screen .rsb-sub { font-size: .8em; }
.tv-screen .rs-more { font-size: 1.2em; align-self: center; }

/* Results: podium 2nd | 1st | 3rd */
.tv-podium { display: grid; grid-template-columns: repeat(3, minmax(0, 14em)); justify-content: center; align-items: end; gap: 1.4em; margin-top: 1.4em; }
.tv-pod { display: grid; justify-items: center; gap: .35em; text-align: center; min-width: 0; }
.tv-pod.first { order: 2; }
.tv-pod.second { order: 1; }
.tv-pod.third { order: 3; }
.tv-pod .avatar { width: 4.4em; height: 4.4em; font-size: 1.4em; }
.tv-pod.first .avatar { width: 5.6em; height: 5.6em; font-size: 1.8em; box-shadow: 0 0 0 .18em var(--gold); }
.tv-pod-name { font: 700 1.2em/1.2 var(--font-display); max-width: 100%; overflow-wrap: anywhere; }
.tv-pod-score { font: 700 1.6em/1 var(--font-display); }
.tv-pod-score small { font-size: .55em; color: var(--text-2); }
.tv-pod-delta { font: 700 1em var(--font-mono); color: var(--text-2); }
.tv-pod-delta.up { color: var(--good); }
.tv-pod-delta.down { color: var(--danger); }
.tv-step { width: 100%; border-radius: .8em .8em 0 0; display: grid; place-items: center; font: 700 1.6em/1 var(--font-display); color: var(--text-inverse); }
.tv-pod.first .tv-step { height: 5em; background: var(--gold); box-shadow: inset 0 -.25em 0 var(--gold-edge); }
.tv-pod.second .tv-step { height: 3.6em; background: var(--cyan); box-shadow: inset 0 -.25em 0 var(--cyan-edge); }
.tv-pod.third .tv-step { height: 2.6em; background: var(--red); color: var(--cream); box-shadow: inset 0 -.25em 0 var(--red-edge); }
.tv-screen .rc-chip { font-size: .8em; }
.tv-rest { list-style: none; margin: 1em auto 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: .6em 1.6em; color: var(--text-2); font-weight: 700; }
.tv-rest b { color: var(--text); }
.tv-next { margin-top: 1.2em; text-align: center; font: 700 1.2em/1.2 var(--font-display); color: var(--gold); }
.tv-offline { position: fixed; right: 1.2em; bottom: 1em; padding: .3em .9em; border-radius: var(--radius-pill); background: var(--red-tint); color: var(--cream); font-weight: 800; font-size: clamp(14px, 1.8vh, 24px); }

@media (prefers-reduced-motion: reduce) { .tv-player { animation: none; } }
/* A TV that's taller than wide (a laptop window snapped narrow): stack the lobby. */
@media (max-aspect-ratio: 1/1) {
  .tv-lobby { grid-template-columns: 1fr; justify-items: center; gap: 1.4em; }
  .tv-qr { width: min(48vh, 80vw); }
  .tv-join .tv-h1, .tv-join { text-align: center; }
  .tv-players { justify-content: center; }
}
