/* ===== Accessibility, controls and device adaptation (DEC-250..DEC-254) ===== */

/* Text size (HUD, captions, menus): most sizes are in rem/em, so the root size scales them. */
html { font-size: calc(100% * var(--ws-text-scale, 1)); }

/* ---------- on-screen controls built from each sport's actions (DEC-250) ---------- */
#proto-touch.tl {
  display: none; position: absolute; inset-inline: 0; bottom: 0; z-index: 4; direction: ltr; pointer-events: none;
  padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  grid-template-columns: 1fr 1fr; grid-template-areas: "strip strip" "move act" "padl padr"; gap: 8px 10px; align-items: end;
  --s: var(--tl-scale, 1);
}
body.touch-on #proto-touch.tl { display: grid; }
@media (pointer: coarse), (max-width: 760px) { body.touch-auto #proto-touch.tl { display: grid; } }
body.touch-off .touch, body.touch-off #proto-touch.tl { display: none !important; }
body.touch-on #touch { display: flex; }
.has-results #proto-touch.tl { display: none !important; }
#proto-touch.tl.tl-mirror { grid-template-areas: "strip strip" "act move" "padl padr"; }
.tl > * { pointer-events: none; }
.tl .touch-btn, .tl .tl-stick { pointer-events: auto; }
.tl-strip { grid-area: strip; display: flex; gap: 6px; overflow-x: auto; justify-self: stretch; pointer-events: auto !important; padding-bottom: 2px; scrollbar-width: thin; }
.tl-move { grid-area: move; justify-self: start; }
.tl-act { grid-area: act; justify-self: end; display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; align-items: flex-end; gap: 8px; max-width: calc(3 * 60px * var(--s) + 2 * 8px + 84px * var(--s)); }
.tl-mirror .tl-move { justify-self: end; }
.tl-mirror .tl-act { justify-self: start; justify-content: flex-start; }
.tl-padslot-l { grid-area: padl; justify-self: start; }
.tl-padslot-r { grid-area: padr; justify-self: end; }
#proto-touch.tl .touch-btn {
  width: auto; max-width: none; aspect-ratio: auto; min-width: calc(54px * var(--s)); min-height: calc(54px * var(--s));
  padding: 0 calc(10px * var(--s)); border-radius: 14px; font-size: calc(0.98rem * var(--s)); line-height: 1.1;
  -webkit-touch-callout: none; touch-action: none;
}
#proto-touch.tl .tl-primary { min-width: calc(84px * var(--s)); min-height: calc(84px * var(--s)); border-radius: 50%; font-size: calc(1.15rem * var(--s)); border-color: var(--accent); }
#proto-touch.tl .tl-pad { width: calc(96px * var(--s)); height: calc(96px * var(--s)); border-radius: 50%; font-size: calc(1.9rem * var(--s)); font-weight: 900; }
#proto-touch.tl .tl-small { min-width: calc(46px * var(--s)); min-height: calc(46px * var(--s)); font-size: calc(0.85rem * var(--s)); flex: 0 0 auto; }
.tl-dpad { display: grid; grid-template-columns: repeat(3, auto); grid-template-areas: ". up ." "left . right" ". down ."; gap: 4px; }
.tl-dir-up { grid-area: up; } .tl-dir-down { grid-area: down; } .tl-dir-left { grid-area: left; } .tl-dir-right { grid-area: right; }
.tl-rocker { display: flex; gap: 6px; }
.tl-rocker-vertical { flex-direction: column; }
#proto-touch.tl .tl-rock { min-width: calc(64px * var(--s)); }
.tl-stickwrap { position: relative; width: calc(176px * var(--s)); height: calc(176px * var(--s)); }
.tl-stick { position: absolute; inset: calc(46px * var(--s)); border-radius: 50%; background: rgba(20, 30, 40, 0.72); border: 2px solid rgba(255, 255, 255, 0.5); touch-action: none; }
.tl-stick.pressed { border-color: var(--accent); }
.tl-knob { position: absolute; left: 25%; top: 25%; width: 50%; height: 50%; border-radius: 50%; background: rgba(255, 255, 255, 0.6); pointer-events: none; }
#proto-touch.tl .tl-sdir { position: absolute; min-width: calc(46px * var(--s)); min-height: calc(46px * var(--s)); width: calc(46px * var(--s)); height: calc(46px * var(--s)); padding: 0; border-radius: 50%; font-size: calc(1.1rem * var(--s)); }
.tl-sdir-up { left: 50%; top: 0; transform: translateX(-50%); }
.tl-sdir-down { left: 50%; bottom: 0; transform: translateX(-50%); }
.tl-sdir-left { left: 0; top: 50%; transform: translateY(-50%); }
.tl-sdir-right { right: 0; top: 50%; transform: translateY(-50%); }
/* Phones held sideways: the rhythm pads sit at the two edges, everything else between them. */
@media (orientation: landscape) and (max-height: 520px) {
  #proto-touch.tl { grid-template-columns: auto 1fr 1fr auto; grid-template-areas: "strip strip strip strip" "padl move act padr"; }
  #proto-touch.tl.tl-mirror { grid-template-areas: "strip strip strip strip" "padl act move padr"; }
  .tl-stickwrap { width: calc(150px * var(--s)); height: calc(150px * var(--s)); }
  .tl-stick { inset: calc(40px * var(--s)); }
}
/* The HUD stays above the controls (no overlap): --touch-h is the visible controls' height (0 when hidden). */
#proto-hud .hud-bottom { bottom: calc(var(--touch-h, 0px) + 14px + env(safe-area-inset-bottom)); }
@media (max-width: 760px) { #proto-hud .hud-bottom { bottom: calc(var(--touch-h, 0px) + 8px + env(safe-area-inset-bottom)); } }
#proto-touch .touch-btn.pressed, .tl-stick.pressed .tl-knob { background: var(--accent); color: var(--accent-ink); }
#touch .touch-btn { width: calc(32vw * var(--tl-scale, 1)); max-width: calc(150px * var(--tl-scale, 1)); }

/* Scanning steps through the on-screen controls, so they are shown whenever scanning is on (not over results). */
body.scanning #proto-touch.tl { display: grid !important; }
body.scanning #touch { display: flex !important; }
body.scanning.has-results #proto-touch.tl, body.scanning.has-results #touch { display: none !important; }

/* ---------- assisted practice badge (DEC-252) ---------- */
.assist-badge { display: none; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); margin: 0; z-index: 6; pointer-events: none;
  background: #4b2a7a; color: #fff; border: 1px solid #c9a7ff; border-radius: 999px; padding: 2px 12px; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.04em; }
body.assisted-run #proto-hud .assist-badge, body.assisted-run #hud .assist-badge { display: block; }

/* ---------- settings dialog ---------- */
.access-open-btn { margin-top: 8px; padding: 0.45em 0.9em; font-size: 0.88rem; border-color: var(--focus); }
.access-dialog { position: fixed; inset: 0; z-index: 80; display: grid; place-items: safe center; padding: 16px; overflow: auto; background: rgba(3, 6, 10, 0.72); }
.access-card { width: min(980px, 100%); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; padding: 18px 22px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6); }
.access-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.access-head h2 { margin: 0; font-size: 1.3rem; }
.access-head h2:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 6px; }
.access-intro { margin: 6px 0 10px; color: var(--muted); }
.access-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px 18px; align-items: start; }
.access-group { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 10px; margin: 0; display: grid; gap: 6px; min-width: 0; }
.access-group legend { font-weight: 800; color: var(--text); font-size: 0.95rem; padding: 0 4px; }
.access-group .field { margin: 0; }
.access-group .check { align-items: flex-start; line-height: 1.35; }
.access-group .check input { margin-top: 0.2em; flex: 0 0 auto; width: 1.15em; height: 1.15em; }
.access-group select { width: 100%; min-width: 0; }
.small { font-size: 0.82rem; color: var(--muted); margin: 0; }
.acc-swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.acc-swatches .sw { display: inline-grid; place-items: center; width: 2em; height: 1.5em; border-radius: 5px; font-size: 0.75rem; font-weight: 800; color: #000; text-shadow: 0 0 2px #fff, 0 0 2px #fff; border: 1px solid rgba(255, 255, 255, 0.5); }
.access-remap summary { cursor: pointer; font-weight: 700; min-height: 32px; }
.acc-keys-wrap { max-height: 40vh; overflow: auto; }
.acc-keys { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.acc-keys th, .acc-keys td { text-align: start; padding: 4px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.acc-keys thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.acc-keys tbody th { font-weight: 600; }
.acc-keys td { font-family: var(--mono); unicode-bidi: isolate; }
.acc-keys td.unbound { color: var(--danger); }
.acc-keys button { min-height: 36px; padding: 0.3em 0.8em; font-size: 0.82rem; font-family: var(--font); }
.acc-keys button.capturing { background: var(--accent); color: var(--accent-ink); }
body.access-open { overflow: hidden; }

/* ---------- sound captions (DEC-253) ---------- */
.sound-captions { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--touch-h, 0px) + 96px + env(safe-area-inset-bottom)); z-index: 16; pointer-events: none;
  max-width: min(640px, calc(100% - 24px)); display: grid; gap: 4px; justify-items: center; }
.sound-captions .cap { margin: 0; background: rgba(0, 0, 0, 0.88); color: #fff; border-radius: 8px; padding: 4px 12px; font-size: 1.05rem; font-weight: 700; text-align: center; }
.sound-captions .cap-signal { color: #ffe066; }

/* ---------- one-switch scanning (DEC-251) ---------- */
.scan-hl { outline: 4px dashed #ffd400 !important; outline-offset: 3px !important; box-shadow: 0 0 0 9px rgba(255, 212, 0, 0.32) !important; }
.scan-switch { position: fixed; z-index: 90; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom)); min-width: 200px; min-height: 64px; font-size: 1.2rem;
  background: #ffd400; color: #000; border: 3px solid #000; border-radius: 16px; }
@media (pointer: fine) and (min-width: 761px) { .scan-switch { min-height: 48px; min-width: 140px; font-size: 1rem; inset-inline-end: 16px; left: auto; transform: none; } }

/* ---------- reduce flashing and motion of interface effects (DEC-253) ---------- */
.reduce-flash .call.pop, .reduce-flash .tl * { animation: none !important; }
.reduce-flash *, .reduce-flash *::before, .reduce-flash *::after { animation-duration: 0s !important; animation-iteration-count: 1 !important; transition-duration: 0s !important; }

/* ---------- visible focus everywhere ---------- */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.seg label:has(input:focus-visible), .check:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

/* ---------- high contrast (DEC-253) ---------- */
:root.hc { --panel: #000; --panel-solid: #000; --line: #ffffff; --text: #ffffff; --muted: #f0f0f0; --accent: #ffd400; --accent-ink: #000; --focus: #ffd400; --teal: #6ff7ee; --danger: #ff7a7a; }
.hc .menu-card, .hc .hud-box, .hc .coach, .hc #results-inner, .hc #proto-results-inner, .hc #champ-inner, .hc .guide, .hc .access-card, .hc .captions, .hc .proto-hint {
  background: #000 !important; border: 2px solid #fff !important; backdrop-filter: none !important; }
.hc button { background: #000; color: #fff; border: 2px solid #fff; }
.hc button:hover { background: #222; }
.hc button.primary, .hc .touch-btn.pressed { background: #ffd400; color: #000; border-color: #ffd400; }
.hc input[type="text"], .hc select { background: #000; color: #fff; border: 2px solid #fff; }
.hc select optgroup, .hc select option { background: #000; color: #fff; }
.hc :focus-visible { outline: 4px solid #ffd400; outline-offset: 2px; box-shadow: 0 0 0 7px #000; }
.hc .tag { background: #000; border: 1px solid #fff; }
.hc .call { text-shadow: none; background: #000; border-radius: 8px; padding: 0 0.3em; }
.hc .label, .hc small, .hc .sub, .hc .fineprint, .hc .proto-note { color: #f0f0f0; }
.hc .bar { background: #333; outline: 1px solid #fff; }
.hc .screen { background: rgba(0, 0, 0, 0.85); }
.hc .ai-tag { background: #6ff7ee; color: #000; }
.hc .you-tag { background: #ffd400; color: #000; }
.hc .esc-hint { background: #000; border: 1px solid #fff; color: #fff; }
.hc #proto-touch .touch-btn, .hc #touch .touch-btn, .hc .tl-stick { background: #000; border: 3px solid #fff; color: #fff; }
.hc .dev-notice, .hc .draft-note { background: #000; color: #ffd400; border-color: #ffd400; }

/* ---------- fixes from the automated audit (docs/worldsport/qa/a11y-audit.md) ---------- */
/* Race calls are drawn over the 3D scene: a translucent backing keeps them ≥ 3:1 (large text) over a white sky or ice. */
@media (max-width: 640px) { #proto-hud.has-call .proto-panel { visibility: hidden; } }
/* Text scaling and long calls: offsets below the clock follow the root size (rem), long calls use a smaller size so
   they stay at one or two lines above the hint, and on phones the clock box leaves room for the archery/shooting sight. */
#proto-call.long { font-size: clamp(1.2rem, 2.8vw, 2.1rem); max-width: min(34rem, 100%); }
#proto-hud .proto-hint { top: 8rem; }
@media (max-width: 760px) {
  #proto-hud .proto-hint { top: calc(6rem + 16px); }
  #proto-hud:has(#proto-sight:not([hidden])) .clock-box { margin-inline-end: 166px; }
}
/* Phones held sideways: the board shows the leaders and you, so it does not run into the bottom panels. */
@media (orientation: landscape) and (max-height: 520px) {
  .board { font-size: 0.74rem; gap: 0; }
  .board li:nth-child(n + 5):not(.me) { display: none; }
  #proto-call, #proto-call.long { font-size: clamp(1.1rem, 6vh, 1.8rem); margin-top: 8px; }
  #proto-hud .sight { width: 170px; height: 170px; bottom: 112px; }
}
.call:not(:empty):not(.fs) { background: rgba(0, 0, 0, 0.62); border-radius: 10px; padding: 0 0.35em; }
/* The spectator fine print sat directly on the scene (1.9:1 over bright frames). */
#spectate .sp-fine { background: var(--panel); padding: 2px 8px; border-radius: 6px; }
