/* shell.css — production overrides on top of tokens.css + tvos.css (the design canvas mocks fixed frames). */
html.tv-root { font-size: calc(100vw / 120); }          /* 16px @1080p, 32px @2160p: every rem on the TV scales */
body { margin: 0; background: var(--c-bg); color: var(--c-ink); cursor: none; }
.tv, .tv-app { width: 100vw; height: 100vh; }
[hidden] { display: none !important; }
.tv-qr__plate img { image-rendering: auto; }       /* our QR is an SVG, not a bitmap */
.tv-tile.is-empty { justify-content: space-between; }

/* app surface */
.tv-app__view { background: var(--c-bg); }
.tv-app.is-bleed .tv-app__slate { display: none; }   /* games draw their own HUD */
.tv-view { position: absolute; inset: 0; padding: calc(var(--tv-safe-y) + 6.5rem) var(--tv-safe-x) var(--tv-safe-y); display: flex; flex-direction: column; gap: 2rem; }
.tv-head { font: 800 var(--tv-t-head)/.92 var(--f-display); font-stretch: 68%; text-transform: uppercase; }
.tv-display { font: 900 18rem/.85 var(--f-display); font-stretch: 62%; text-transform: uppercase; letter-spacing: .02em; }
.tv-mono { font: 500 var(--tv-t-body)/1.3 var(--f-mono); color: var(--c-muted); }
.tv-rows { display: flex; flex-direction: column; }
.tv-row { display: grid; grid-template-columns: 6rem minmax(0, 1fr) auto; gap: 2rem; align-items: baseline; padding: 1rem 0; border-bottom: var(--tv-hair) solid var(--c-rule); font: 500 var(--tv-t-title)/1 var(--f-display); font-stretch: 84%; }
.tv-row .num { font: 500 var(--tv-t-body)/1 var(--f-mono); color: var(--c-muted); }
.tv-row.is-first { color: var(--c-accent); font-size: var(--tv-t-tile); font-weight: 800; font-stretch: 68%; text-transform: uppercase; }
.tv-row.is-first .num { color: var(--c-accent); }
.tv-log { list-style: none; margin: 0; padding: 0; font: 500 var(--tv-t-body)/1.5 var(--f-mono); }
.tv-log li { border-bottom: var(--tv-hair) solid var(--c-rule); padding: .5rem 0; display: flex; gap: 2rem; }
.tv-log li b { color: var(--c-accent); font-weight: 600; min-width: 14rem; }
canvas.tennis { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #5a9cc9; }
.tv-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5rem; background: rgba(14,15,12,.72); }
.tv-overlay small { font: 500 var(--tv-t-body)/1 var(--f-mono); color: var(--c-accent); text-transform: uppercase; letter-spacing: .08em; }

/* phone */
.ph { width: 100%; height: 100dvh; min-height: 100vh; padding: calc(env(safe-area-inset-top, 0px) + 16px) var(--ph-pad) calc(env(safe-area-inset-bottom, 0px) + 18px); }
html, body { overscroll-behavior: none; -webkit-touch-callout: none; touch-action: pan-y; }   /* no pinch / double-tap zoom anywhere on the remote; pan-y keeps an overflowing control list scrollable */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }   /* iOS inflates text when the phone turns landscape (the tennis pad): looks like a zoom */
/* a held key must never turn into a pan/zoom gesture (Safari fires pointercancel and the key "releases") */
.w-key, .w-big, .w-dpad, .w-gamepad { touch-action: none; -webkit-user-select: none; user-select: none; }
.ph.is-offline .ph-controls button { pointer-events: none; opacity: .45; }
.ph-controls > .w-nav { margin-top: 4px; }
.ph-hint { font: 500 var(--ph-t-label)/1.3 var(--f-mono); color: var(--c-danger); text-transform: uppercase; letter-spacing: .06em; min-height: 1em; }
.w-dpad { width: min(310px, 100%); align-self: center; }
.w-big { height: min(360px, 42dvh); }
.w-gamepad .w-dpad { width: 100%; }
.w-gamepad__ab .w-key { height: 84px; font-size: 18px; }
.w-key.is-pressed { transform: translateY(4px); background: var(--c-raised-down); box-shadow: 0 0 0 var(--c-shadow), inset 0 2px 3px rgba(0,0,0,.55); }
.w-key--primary.is-pressed { background: #E09B00; }
.w-key--hold.is-pressed::after { transform: scaleX(1); transition: transform var(--m-hold) var(--e-linear); }
.w-label__text { overflow-wrap: anywhere; }

/* pad layout: the whole phone is a controller; a hold-to-leave arrow lives in the readout */
.ph-readout { grid-template-columns: auto auto 1fr auto auto; }
.ph-readout__actions { display: flex; gap: 6px; }
.ph-readout__actions:empty, .ph-back[hidden] { display: none; }
.ph-back, .ph-readout__actions .w-key { height: 36px; min-height: 36px; min-width: 44px; padding: 0 10px; font-size: 22px; box-shadow: 0 2px 0 var(--c-shadow); }
.ph.is-pad #top, .ph.is-pad .ph-meta, .ph.is-pad .ph-hint:empty { display: none; }
.ph.is-pad .ph-controls { flex: 1; min-height: 0; margin-top: 12px; }
.w-pad { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.15fr 1fr; gap: 12px; touch-action: none; }
.w-stick { position: relative; overflow: hidden; background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--r-1); touch-action: none; }
.w-stick::before { content: "MOVE · DRAG ANYWHERE"; position: absolute; left: 12px; top: 10px; font: 500 11px/1 var(--f-mono); color: var(--c-muted); letter-spacing: .08em; }
.w-stick__ring, .w-stick__thumb { position: absolute; left: 0; top: 0; border-radius: 50%; pointer-events: none; opacity: 0; }
.w-stick__ring { width: 150px; height: 150px; margin: -75px 0 0 -75px; border: 2px solid var(--c-rule-strong); }
.w-stick__thumb { width: 64px; height: 64px; margin: -32px 0 0 -32px; background: var(--c-accent); box-shadow: 0 4px 0 #6B4A00; }
.w-stick.is-active .w-stick__ring, .w-stick.is-active .w-stick__thumb { opacity: 1; }
.w-stick__dir { position: absolute; left: 12px; bottom: 10px; font: 600 12px/1 var(--f-mono); color: var(--c-accent); letter-spacing: .1em; min-height: 1em; }
.w-face { display: grid; grid-template-columns: 1.25fr 1fr; grid-template-rows: 1fr 1fr; gap: 12px; min-height: 0; align-items: center; justify-items: center; }
.w-face .w-key { width: 100%; max-width: 150px; aspect-ratio: 1; height: auto; border-radius: 50%; font-size: 17px; }
.w-face .w-key--primary { grid-row: span 2; max-width: 190px; }
.ph-readout > * { white-space: nowrap; }
.w-face .w-key--primary { font-size: 24px; }
.ph.is-pad .ph-readout__link { font-size: 0; }   /* just the green dot; the word would clip */

/* landscape controller: when the phone is held upright we rotate the whole remote 90° (works under rotation lock) */
.ph.is-pad { padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 10px); }
.ph.is-pad.is-rot { position: fixed; top: 50%; left: 50%; width: 100dvh; height: 100vw; min-height: 0; transform: translate(-50%, -50%) rotate(90deg); transform-origin: center; padding: 10px 24px 10px 14px; }
.ph.is-pad .ph-readout { height: 40px; }
.ph.is-pad .ph-controls { margin-top: 10px; }
.ph.is-pad .w-pad { grid-template-columns: 1.1fr 1fr; gap: 16px; }
.ph.is-pad .w-face { gap: 12px 18px; padding: 4px 6px; }
.ph.is-pad .w-face .w-key { max-width: 130px; }
.ph.is-pad .w-face .w-key--primary { max-width: 200px; }
.ph.is-pad .w-stick__ring { width: 130px; height: 130px; margin: -65px 0 0 -65px; }

/* board layout (a map widget): readout carries ↻ and the hold-to-leave arrow; the map flexes into the leftover height */
.ph.is-board .ph-meta, .ph.is-board .ph-hint:empty { display: none; }
.ph.is-board .ph-top { gap: 8px; }
.ph.is-board .ph-readout__ch { display: none; }
.ph.is-board .ph-readout__link { font-size: 0; }   /* just the green dot: the title needs the room */
.ph.is-board .w-label__text { font-size: 26px; }
.ph.is-board .ph-controls { flex: 1 1 0; min-height: 0; margin-top: 10px; gap: 8px; }
.ph.is-board .w-map { flex: 1 1 0; min-height: 140px; justify-content: center; }
.ph.is-board .ph-controls .w-key--small { height: 46px; min-height: 46px; }
.ph.is-board .w-card { padding: 4px 4px 3px; }
.ph.is-board .w-card__icon { font-size: 18px; }
.ph.is-board .w-card__n { font-size: 18px; }
/* keys fire on pointerdown, so a board screen can't lean on scrolling: everything must fit. Real phones lose
   ~180px to Safari's bars (390×844 → ~390×660), so short screens get a one-line label and shorter keys. */
@media (max-height: 760px) {
  .ph.is-board .w-label { gap: 3px; }
  .ph.is-board .w-label__text { font-size: 22px; }
  .ph.is-board .w-label__sub { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ph.is-board .ph-controls { gap: 6px; }
  .ph.is-board .w-grid { gap: 6px; }
  .ph.is-board .ph-controls .w-key--small { height: 40px; min-height: 40px; padding-top: 2px; padding-bottom: 2px; }
  .ph.is-board .w-map { min-height: 120px; }
}
/* landscape: board on the left, hand + keys stacked on the right (a full-width board pushed them off screen) */
@media (orientation: landscape) {
  .ph.is-board { padding-top: calc(env(safe-area-inset-top, 0px) + 8px); padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); }
  .ph.is-board .ph-readout { height: 40px; }
  .ph.is-board .w-label { flex-direction: row; align-items: baseline; gap: 10px; min-width: 0; }
  .ph.is-board .w-label__kicker:empty { display: none; }
  .ph.is-board .w-label__text { font-size: 20px; white-space: nowrap; }
  .ph.is-board .w-label__sub { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .ph.is-board .ph-controls { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); grid-template-rows: repeat(3, auto) minmax(0, 1fr); align-content: start; margin-top: 6px; overflow: hidden; }
  .ph.is-board .ph-controls > * { grid-column: 2; }
  .ph.is-board .ph-controls > .w-map { grid-column: 1; grid-row: 1 / -1; min-height: 0; height: 100%; contain: size; }
}

/* effects pushed from the TV: a full-screen flash, amber for a point won, red for a point lost */
body.flash-win  { animation: flash-win .7s steps(3, jump-none); }
body.flash-lose { animation: flash-lose .7s steps(3, jump-none); }
@keyframes flash-win  { 0% { background: var(--c-accent); } 100% { background: var(--c-bg); } }
@keyframes flash-lose { 0% { background: var(--c-danger-fill); } 100% { background: var(--c-bg); } }
.tv-serve-hint { position: absolute; left: 50%; bottom: 7rem; transform: translateX(-50%); padding: .9rem 1.6rem; background: var(--c-bg); border: var(--tv-hair) solid var(--c-accent); color: var(--c-accent); font: 600 var(--tv-t-body)/1 var(--f-mono); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
canvas.tv-cart { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--c-bg); }   /* letterbox instead of stretching on non-16:9 windows */
.tv-banner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); padding: 1.2rem 2.4rem; background: var(--c-bg); border: var(--tv-hair) solid var(--c-accent); text-align: center; }
.tv-banner__text { font: 800 var(--tv-t-head)/.95 var(--f-display); font-stretch: 68%; text-transform: uppercase; color: var(--c-ink); }
.tv-banner__sub { font: 500 var(--tv-t-body)/1.2 var(--f-mono); color: var(--c-accent); text-transform: uppercase; letter-spacing: .08em; margin-top: .5rem; }
.tv-qr__code { font-size: 2.4rem; letter-spacing: .04em; overflow-wrap: anywhere; }   /* 8-char pair codes must fit the rail */
.tv-grid__head { grid-column: 1 / -1; font: 600 var(--tv-t-meta)/1 var(--f-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--c-accent); padding: .5rem 0 0; }
.tv-grid { grid-template-columns: repeat(4, minmax(0,1fr)); grid-auto-rows: auto; align-content: start; }
.tv-tile, .tv-tile.is-empty { min-height: 5.2rem; padding: .7rem .9rem .5rem; }
.tv-tile__sub { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.tv-tile__name { font-size: calc(var(--tv-t-tile) * .48); line-height: .95; }
.tv-grid { gap: .7rem; }
.tv-grid__head { padding: 0; }
.tv-tile__name { font-size: calc(var(--tv-t-tile) * .55); overflow-wrap: anywhere; }
.tv-tile.is-empty .tv-tile__name { font-size: calc(var(--tv-t-title) * .8); }
.w-map { width: 100%; display: flex; flex-direction: column; align-items: center; border: var(--tv-hair, 1px) solid var(--c-rule); border-radius: var(--r-1); overflow: hidden; touch-action: none; position: relative; }
.w-map canvas { display: block; }
.w-map__hint { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; font: 600 13px/1.6 var(--f-mono); color: var(--c-accent-ink, #1A1200); background: var(--c-accent); letter-spacing: .06em; text-transform: uppercase; }
.w-map__hint:empty { display: none; }
.w-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: var(--ph-gap); }
.w-key--tall { height: auto; min-height: var(--ph-tap); padding: 8px 10px; flex-direction: column; gap: 2px; }
.w-key--tall small { text-transform: none; letter-spacing: 0; white-space: normal; }
.w-hand { display: flex; gap: 6px; flex-wrap: wrap; }
.w-card { --card: var(--c-surface2); flex: 1 1 0; min-width: 52px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; border: 1px solid var(--c-rule-strong); border-radius: var(--r-1); background: var(--card); color: #fff; }
.w-card.is-dim { background: var(--c-surface); color: var(--c-muted); border-color: var(--c-rule); }
.w-card__icon { font-size: 24px; line-height: 1; }
.w-card__n { font: 700 22px/1 var(--f-mono); }
.w-card__label { font: 500 11px/1 var(--f-mono); color: inherit; opacity: .8; text-transform: uppercase; letter-spacing: .06em; }
.w-hand__note { flex: 1 0 100%; font: 500 12px/1.3 var(--f-mono); color: var(--c-muted); }
.ph-controls { overflow-y: auto; min-height: 0; }   /* board + hand + a menu can run past a short phone: scroll rather than clip */
.ph-readout__app { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }   /* long app titles ellipsize instead of pushing the link status off-screen */
.ph-readout__link { flex-shrink: 0; white-space: nowrap; }
#name { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }   /* tap to rename */

/* map zoom: a "Fit board" chip shows while zoomed in */
.w-map__reset { position: absolute; top: 6px; right: 6px; height: 32px; padding: 0 10px; border: 1px solid var(--c-accent); border-radius: var(--r-1); background: rgba(14, 15, 12, .82); color: var(--c-accent); font: 600 12px/1 var(--f-mono); letter-spacing: .06em; text-transform: uppercase; touch-action: none; }
.w-map__reset[hidden] { display: none; }

/* key grids: N keys share the row; the 56px minimum tap width overflowed a 6-digit + ⌫ row on narrow phones */
.w-grid > .w-key { min-width: 0; padding-left: 4px; padding-right: 4px; }

/* gamepad face: size the round keys by the cell's height too, or a short (landscape) pad stacks them on top of each other */
.w-face { container-type: size; }
.w-face .w-key { width: min(100%, calc(50cqh - 8px)); }
.w-face .w-key--primary { width: min(100%, calc(100cqh - 8px)); }
.w-face:has(> .w-key:nth-child(4)) { grid-template-rows: repeat(3, 1fr); }   /* hero + three: hero left, the rest stacked right */
.w-face:has(> .w-key:nth-child(4)) .w-key { width: min(100%, calc(33.3cqh - 10px)); }
.w-face:has(> .w-key:nth-child(4)) .w-key--primary { grid-row: span 3; width: min(100%, calc(100cqh - 8px)); }

/* short phones (SE / mini): the d-pad scales with height; tighter gaps so Back/Home stay on screen */
.w-dpad { width: min(310px, 100%, 36dvh); }
@media (max-height: 720px) {
  .ph-top { gap: 8px; }
  .ph-controls { gap: 8px; }
  .ph-controls .w-key--small { height: 50px; min-height: 50px; }
  .w-label--big .w-label__text { font-size: 34px; }
}
