/* Courtside capture client.
   Dense, high-contrast and glare-tolerant: this is read at a scorer's table
   under arena lighting, at a glance, while typing. */

:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #131922;
  --panel2: #1a222d;
  --line: #263241;
  --fg: #e6edf3;
  --mut: #8b98a9;
  --accent: #4c9aff;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

kbd {
  font: 11px/1 ui-monospace, Consolas, monospace;
  background: var(--panel2); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px;
}

/* ---- header ---- */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.scorebug { display: flex; align-items: center; gap: 18px; }
.scorebug .team { display: flex; align-items: center; gap: 10px; }
.scorebug .nm { font-weight: 600; letter-spacing: .01em; }
.scorebug .sc {
  font: 700 30px/1 ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums; min-width: 52px; text-align: center;
}
.clock { text-align: center; padding: 0 10px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.clock .per { font-size: 11px; color: var(--mut); text-transform: uppercase; letter-spacing: .08em; }
.clock .tm { font: 700 22px/1.1 ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.clock .shot { font: 600 12px/1 ui-monospace, Consolas, monospace; color: var(--warn); }

.ctrls { display: flex; align-items: center; gap: 8px; }
button {
  background: var(--panel2); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 11px; font: inherit; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.active { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }

.pill {
  font: 11px/1 ui-monospace, Consolas, monospace;
  padding: 5px 8px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--mut);
}
.pill.good { color: var(--good); border-color: #1e4620; }
.pill.bad  { color: var(--bad);  border-color: #5c1f1b; }

/* ---- layout ---- */
main {
  display: grid;
  grid-template-columns: 260px minmax(420px, 1fr) minmax(360px, 1.1fr);
  gap: 12px; padding: 12px; align-items: start;
}
@media (max-width: 1100px) { main { grid-template-columns: 1fr; } }

.col { min-width: 0; }
h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--mut); margin: 0 0 6px; display: flex; align-items: center; gap: 8px;
}
h2 .meta { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 11px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---- rosters ---- */
.teamblock { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 12px; }
.roster { list-style: none; margin: 0; padding: 0; }
.roster li { border-radius: 5px; color: var(--mut); }
/* Each row is a button (FR-CAP-11) but must not look like one on the
   desktop console, where it reads as a roster first. */
.roster li > button {
  display: grid; grid-template-columns: 28px 1fr auto 26px;
  gap: 6px; align-items: center; padding: 4px 5px; width: 100%;
  background: none; border: 1px solid transparent; border-radius: 5px;
  color: inherit; text-align: left;
}
.roster li.picked > button { border-color: var(--accent); background: #0d2136; }
.roster li.on { background: var(--panel2); color: var(--fg); }
.roster li.out { opacity: .45; text-decoration: line-through; }
.roster .js {
  font: 700 12px/1 ui-monospace, Consolas, monospace; text-align: center;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 3px 0;
}
.roster li.on .js { border-color: var(--accent); color: var(--accent); }
.roster .pn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster .ln, .roster .fl { font: 11px/1 ui-monospace, Consolas, monospace; }
.roster .fl { text-align: right; }

/* ---- entry ---- */
.entry { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 12px; }
.side-toggle { display: flex; gap: 8px; margin-bottom: 8px; }
.side-toggle button { flex: 1; }
.entry-actions { display: flex; gap: 8px; margin-top: 8px; }
.entry-actions button { flex: 1; }
button.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 700; }
.buffer {
  min-height: 46px; display: flex; align-items: center; gap: 10px;
  background: #05080c; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
}
.buffer .ph { color: var(--mut); }
.buffer .bk {
  font: 700 20px/1 ui-monospace, Consolas, monospace; color: var(--accent);
}
.buffer .ba { font-weight: 600; }
.msgs { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.msg { font-size: 12px; padding: 5px 8px; border-radius: 5px; border-left: 3px solid; }
.msg.info  { background: #0d2136; border-color: var(--accent); }
.msg.warn  { background: #2a2210; border-color: var(--warn); }
.msg.error { background: #2d1416; border-color: var(--bad); }

/* ---- court ---- */
.courtwrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 12px; }
#court { width: 100%; height: auto; display: block; cursor: crosshair; border-radius: 6px; }
.floor { fill: #10161e; }
.ln { fill: none; stroke: #46596f; stroke-width: 2; }
.ring { fill: none; stroke: var(--warn); stroke-width: 2.5; }
.marker { fill: var(--accent); stroke: #fff; stroke-width: 2; }
.loc { margin-top: 6px; font: 11px/1.3 ui-monospace, Consolas, monospace; color: var(--mut); }

/* ---- key legend ---- */
.keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.key {
  display: flex; align-items: center; gap: 7px; padding: 4px 7px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px;
  font-size: 11px; color: var(--mut); text-align: left;
}
.key .lab { display: none; }

.tabs { display: none; }

/* ---------------------------------------------------------------------------
 * Touch — FR-CAP-11.
 *
 * Keyed on the POINTER, not the width: a 12-inch tablet in landscape gets
 * the full console with finger-sized targets, and a laptop with a mouse
 * keeps the dense one. 44px is the minimum target both the WCAG 2.5.5
 * guidance and the platform guidelines converge on.
 *
 * `touch-action: manipulation` turns off double-tap-to-zoom, which on a
 * scorer's tablet is two quick taps on the same jersey zooming the page
 * instead of recording anything.
 */
@media (pointer: coarse) {
  button, .roster li > button, .key { min-height: 44px; touch-action: manipulation; }
  .key { font-size: 13px; }
  #court { touch-action: manipulation; }
  kbd { display: none; }
}

/* ---------------------------------------------------------------------------
 * Phone layout — AF-FED-01.
 *
 * One volunteer, one phone, the whole game. Four panes behind a tab bar,
 * and everything needed to record a play — who, what, Record — on the
 * first one without scrolling on a 375 x 812 screen. Both rosters are
 * shown at once because half the compound events need a player from each
 * side (the stealer, the blocker, the player fouled).
 */
body[data-layout="phone"] { padding-bottom: 60px; font-size: 14px; }
body[data-layout="phone"] kbd { display: none; }
body[data-layout="phone"] .bar { flex-direction: column; align-items: stretch; gap: 6px; padding: 6px 8px; }
body[data-layout="phone"] .scorebug { justify-content: space-between; gap: 8px; }
body[data-layout="phone"] .scorebug .nm { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
body[data-layout="phone"] .scorebug .sc { font-size: 24px; min-width: 36px; }
body[data-layout="phone"] .clock .tm { font-size: 18px; }
body[data-layout="phone"] .ctrls { overflow-x: auto; flex-wrap: nowrap; gap: 6px; padding-bottom: 2px; }
body[data-layout="phone"] .ctrls > * { flex: none; }
body[data-layout="phone"] #btnUndo { display: none; }   /* it is beside Record */

body[data-layout="phone"] main { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 8px; }
body[data-layout="phone"] .col { display: contents; }
body[data-layout="phone"] .entry { order: 1; margin: 0; padding: 8px; }
body[data-layout="phone"] .rosters { order: 2; }
body[data-layout="phone"] .keys { order: 3; }
body[data-layout="phone"] [data-pane] { display: none; }
body[data-layout="phone"][data-tab="capture"] [data-pane="capture"],
body[data-layout="phone"][data-tab="court"] [data-pane="court"],
body[data-layout="phone"][data-tab="log"] [data-pane="log"],
body[data-layout="phone"][data-tab="box"] [data-pane="box"] { display: block; }
body[data-layout="phone"][data-tab="capture"] .rosters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
body[data-layout="phone"][data-tab="capture"] .keys {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
}

/* The team toggle is redundant here: tapping a player chooses the team. */
body[data-layout="phone"] .side-toggle { display: none; }
body[data-layout="phone"] .buffer { min-height: 40px; padding: 6px 10px; }
/* The newest message only, two lines at most, because a paragraph here
   pushes the action pad off screen. Tapping it shows the rest. */
body[data-layout="phone"] .msgs .msg:nth-child(n+2) { display: none; }
body[data-layout="phone"] .msgs .msg {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  /* No bottom padding while clamped: overflow clips at the PADDING edge,
     so a padded box shows the top of a third line beneath the second. */
  line-height: 1.35; padding-bottom: 0; max-height: calc(2.7em + 5px);
}
body[data-layout="phone"] .msgs.open .msg { -webkit-line-clamp: unset; max-height: none; padding-bottom: 5px; }
body[data-layout="phone"] .entry-actions button { min-height: 44px; }

body[data-layout="phone"] .teamblock { margin: 0; padding: 6px; }
body[data-layout="phone"] .teamblock h2 { flex-wrap: wrap; font-size: 11px; }
body[data-layout="phone"] .teamblock h2 .meta { margin-left: 0; width: 100%; }
body[data-layout="phone"] .roster { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
body[data-layout="phone"] .roster li > button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; min-height: 44px; padding: 2px;
  border-color: var(--line); touch-action: manipulation;
}
body[data-layout="phone"] .roster li.on > button { border-color: var(--accent); }
body[data-layout="phone"] .roster li.picked > button { background: var(--accent); color: #04121f; }
body[data-layout="phone"] .roster .js { background: none; border: 0; font-size: 17px; padding: 0; color: inherit; }
body[data-layout="phone"] .roster .pn { font-size: 10px; max-width: 100%; }
body[data-layout="phone"] .roster .ln { display: none; }
body[data-layout="phone"] .roster .fl { font-size: 10px; }

body[data-layout="phone"] .key {
  justify-content: center; min-height: 46px; padding: 2px;
  font: 700 13px/1 ui-sans-serif, system-ui, sans-serif; color: var(--fg);
  touch-action: manipulation;
}
body[data-layout="phone"] .key .hint { display: none; }
body[data-layout="phone"] .key .lab { display: inline; }
body[data-layout="phone"] .pbp { max-height: none; }

body[data-layout="phone"] .tabs {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--panel); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  gap: 6px;
}
body[data-layout="phone"] .tabs button { flex: 1; min-height: 44px; }

/* ---- feed ---- */
.pbp { list-style: none; margin: 0 0 14px; padding: 0; max-height: 260px; overflow-y: auto;
       background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.pbp li {
  display: grid; grid-template-columns: 26px 44px 1fr auto;
  gap: 8px; padding: 5px 9px; border-bottom: 1px solid var(--line); align-items: baseline;
}
.pbp li:last-child { border-bottom: 0; }
.pbp .q, .pbp .c, .pbp .s { font: 11px/1 ui-monospace, Consolas, monospace; color: var(--mut); }
.pbp .s { color: var(--fg); font-weight: 600; }

.boxwrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table.box { border-collapse: collapse; width: 100%; font: 11px/1.3 ui-monospace, Consolas, monospace; }
table.box th, table.box td { padding: 4px 6px; text-align: right; white-space: nowrap; }
table.box th { color: var(--mut); font-weight: 500; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
table.box .l { text-align: left; }
table.box .b { font-weight: 700; }
table.box tr.th td { background: var(--panel2); font-weight: 700; padding: 5px 6px; font-family: ui-sans-serif, system-ui, sans-serif; }
table.box tr.tot td { border-top: 1px solid var(--line); color: var(--mut); font-weight: 600; }
table.box tbody tr:hover td { background: #182029; }

/* ---------------------------------------------------------------------------
 * The official game sheet, on paper — FR-REP-02.
 *
 * Two jobs. On screen the sheet is hidden: the capture UI is a keyboard
 * surface and this would be in the way. On paper the capture UI is hidden
 * and the sheet is the only thing printed, because a page of dark-themed
 * scoring console is a page of toner and no information.
 *
 * Printed black on white whatever the screen theme is. The console is dark
 * by design -- it is read in an arena -- and printing it would empty a
 * cartridge per game and come out unreadable.
 */
.sheet { display: none; }

@media print {
  /* Everything that is not the sheet. `visibility` rather than `display`
   * would keep the hidden boxes' page space and print blank sheets. */
  body > header,
  body > main,
  body > nav,
  body > footer { display: none !important; }

  :root, body {
    background: #fff !important;
    color: #000 !important;
  }

  .sheet {
    display: block !important;
    font: 9pt/1.35 ui-sans-serif, system-ui, sans-serif;
    color: #000;
  }

  .sheet h1 { font-size: 14pt; margin: 0; }
  .sheet h2 { font-size: 10pt; margin: 10pt 0 3pt; }
  .sheet .subtitle { margin: 2pt 0 6pt; color: #444; }

  .sheet .score { font-size: 22pt; font-weight: 700; margin: 4pt 0 8pt; }
  .sheet .score .muted { color: #777; }
  .sheet .score .dash { color: #777; font-size: 14pt; padding: 0 4pt; }

  /* `sheet-box` and not `box`: the capture UI has its own `table.box`,
   * styled for a dark console with sticky headers and a hover colour, and
   * it is NOT inside a media query -- so it matches on paper too. Two
   * tables sharing a class name means restyling the screen silently
   * restyles the printed document, which nobody is looking at until it
   * comes out of a printer in a competition office.
   *
   * `sticky` headers in particular repeat nothing and position wrongly in
   * paged media, and `background: #182029` on hover is a black rectangle
   * on a page that is about to be signed. */
  .sheet table { border-collapse: collapse; width: 100%; }
  .sheet table.sheet-box th { position: static; background: #eee; }
  .sheet th, .sheet td {
    border-bottom: 0.4pt solid #bbb;
    padding: 1.6pt 3pt;
    text-align: right;
  }
  .sheet thead th { background: #eee; font-size: 7.5pt; color: #333; }
  .sheet .a-left { text-align: left; }
  .sheet .a-centre { text-align: center; }
  .sheet tfoot td { font-weight: 700; border-top: 0.8pt solid #333; }
  .sheet tr.starter td { font-weight: 600; }
  /* A player who fouled out, marked in ink rather than in colour: this
   * comes out of a mono laser in a competition office. */
  .sheet tr.out td:nth-child(2)::after { content: " (out)"; font-weight: 400; }

  .sheet .periods { width: auto; margin-bottom: 6pt; }
  .sheet .periods th[scope="row"] { text-align: left; }

  /* The signature blocks must not be split across a page: half a block is
   * a document somebody signs in the wrong place. */
  .sheet .signatures { break-inside: avoid; page-break-inside: avoid; margin-top: 12pt; }
  .sheet .signs { display: flex; gap: 14pt; }
  .sheet .sign { flex: 1 1 0; }
  .sheet .sign .role { font-weight: 700; margin: 0 0 18pt; }
  .sheet .sign .rule { border-bottom: 0.6pt solid #333; margin: 0 0 1pt; height: 0; }
  .sheet .sign .caption { margin: 0 0 16pt; font-size: 7pt; color: #555; }

  .sheet .digest {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 7pt; color: #444; margin: 0;
  }
  .sheet .sheet-foot { margin-top: 10pt; font-size: 7.5pt; color: #444; }
  .sheet .sheet-foot p { margin: 1pt 0; }
  .sheet .side { break-inside: auto; }

  @page { size: A4 portrait; margin: 12mm; }
}
