/* Mission Control: F1 race-control look. Flag colours are the only colours;
   ARF red appears only in the logo slash. No inline styles anywhere (CSP). */
:root {
  --bg: #0c0e12; --panel: #14181d; --raise: #1a1f26; --line: #252b33; --edge: #333a44;
  --text: #e8eaed; --muted: #8b929c;
  --green: #22c55e; --yellow: #facc15; --red: #ef4444; --grey: #5b626c;
  --green-text: #4ade80; --yellow-text: #fde047; --red-text: #f87171;
  --brand: #e60023;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select { font: inherit; color: inherit; }
button {
  min-height: 44px; padding: 8px 14px; border: 1px solid var(--edge); border-radius: 6px;
  background: var(--raise); cursor: pointer; touch-action: manipulation;
}
button:disabled { opacity: .6; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.primary { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.ghost { background: transparent; }
input, select {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--edge);
  border-radius: 6px; background: var(--bg);
  font-size: 16px;   /* under 16px, iPhone Safari zooms in on focus */
}
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.note { padding: 32px 16px; text-align: center; color: var(--muted); }
.msg { min-height: 1.4em; margin: 0; font-size: 13px; color: var(--red-text); }
.msg.ok { color: var(--green-text); }

/* Header */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; letter-spacing: .3px; }
.mark { width: 7px; height: 18px; background: var(--brand); transform: skewX(-18deg); }
.spacer { flex: 1; }
.who { font-size: 14px; }
.light { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.light::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.light.live { color: var(--green-text); }
.light.reconnecting { color: var(--yellow-text); }
.light.offline { color: var(--red-text); }
.banner { padding: 10px 16px; background: #2d1213; color: var(--red-text); border-bottom: 1px solid #5c1d1f; }

/* Filter tabs */
.tabs { display: flex; align-items: center; gap: 6px; padding: 10px 16px; overflow-x: auto; }
.tabs-label { margin-right: 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; }
.tab { min-width: 84px; color: var(--muted); background: var(--panel); border-color: var(--line); }
.tab.on { color: var(--bg); background: var(--text); border-color: var(--text); font-weight: 600; }

/* Layout: judge panel on the left, board on the right */
.dash { display: grid; gap: 12px; padding: 0 16px 16px; }
.dash.with-panel { grid-template-columns: 220px minmax(0, 1fr); align-items: start; }
.board { min-width: 0; transition: opacity .2s; }
.stale .board { opacity: .55; }

/* Judge panel */
.panel {
  position: sticky; top: 8px; display: grid; gap: 8px; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.big { font-size: 28px; font-weight: 600; }
.states { display: grid; gap: 8px; }
.state { min-height: 56px; font-weight: 600; }
.state.on.empty { background: var(--green); border-color: var(--green); color: #04210f; }
.state.on.occupied { background: var(--yellow); border-color: var(--yellow); color: #1a1503; }
.state.on.judging { background: var(--red); border-color: var(--red); color: #fff; }
.state.on.off { background: var(--grey); border-color: var(--grey); color: #fff; }

/* Category tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.tile {
  display: flex; width: 100%; min-height: 0; padding: 0; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
div.tile { cursor: default; }
.flag { flex: none; width: 6px; align-self: stretch; }
.tile-body { flex: 1; display: grid; gap: 2px; min-width: 0; padding: 10px 12px; }
.tile-top { display: grid; gap: 2px; }   /* field number, then status and team under it */
.num { font-size: 22px; font-weight: 600; white-space: nowrap; }
.label { font-weight: 600; }
.timer { font-size: 20px; }
.people { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; font-size: 13px; }
.person { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.person.online { color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5b626c; }
.person.online .dot { background: var(--green); }
.tag {
  margin-left: 2px; padding: 0 6px; border-radius: 4px; font-size: 11px;
  background: var(--raise); border: 1px solid var(--edge); color: var(--text);
}

/* Status colours */
.empty .flag { background: var(--green); }
.occupied .flag { background: var(--yellow); }
.judging .flag { background: var(--red); }
.off .flag { background: var(--grey); }
.empty .label, .empty .timer[data-at] { color: var(--green-text); }
.occupied .label, .occupied .timer[data-at] { color: var(--yellow-text); }
.judging .label, .judging .timer[data-at] { color: var(--red-text); }
.off .label, .off .timer[data-at] { color: var(--muted); }
.tile.mine.empty { border-color: var(--green); }
.tile.mine.occupied { border-color: var(--yellow); }
.tile.mine.judging { border-color: var(--red); }
.tile.mine.off { border-color: var(--grey); }

/* All view: one band per category, tiles 4 across */
.group { display: grid; gap: 8px; margin-bottom: 20px; }
.group .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.group-head {
  display: flex; justify-content: space-between; align-items: baseline; width: 100%; min-height: 0; padding: 4px 2px;
  border: 0; background: transparent; font-weight: 600; font-size: 18px;
}

/* Judge's screen edge glows while their field is Occupied or Judging */
.glow { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.glow.occupied { box-shadow: inset 0 0 0 3px var(--yellow), inset 0 0 48px rgba(250, 204, 21, .45); }
.glow.judging { box-shadow: inset 0 0 0 3px var(--red), inset 0 0 48px rgba(239, 68, 68, .45); }

/* Opening splash: the logo animation over everything, then a fade */
#splash { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: var(--bg); transition: opacity .4s, visibility .4s; }
#splash.out { opacity: 0; visibility: hidden; }
.splash-logo { width: min(360px, 70vw); }

/* Popups. The idle question sits above the scorer window. */
#idle { z-index: 35; }
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(0, 0, 0, .65);
}
.sheet {
  width: min(420px, 100%); display: grid; gap: 12px; padding: 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.sheet h2 { margin: 0; font-size: 20px; }
.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.cats .on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.actions { display: flex; justify-content: space-between; gap: 8px; }
.signin { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.signin .logo { font-size: 22px; margin-bottom: 4px; }
#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 16px;
  background: var(--raise); border: 1px solid var(--edge); border-radius: 8px;
}

/* Phones: panel above the board, status buttons side by side */
@media (max-width: 760px) {
  .dash.with-panel { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; }
  .panel .states { grid-template-columns: repeat(2, 1fr); }
  .tab { flex: 1 1 auto; min-width: 0; padding: 8px 6px; }   /* three tabs fit without scrolling */
  .group .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Big screens */
@media (min-width: 1600px) {
  body { font-size: 17px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* Settings */
.settings { display: grid; gap: 16px; max-width: 640px; padding: 16px; }
.settings > .ghost { justify-self: start; }
.card { display: grid; gap: 12px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.card h2 { margin: 0; font-size: 18px; }
.card .primary { justify-self: start; min-width: 120px; }
.counts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

/* Judge panel's scorer button */
.open-scorer { min-height: 52px; margin-top: 4px; background: transparent; border-color: var(--text); font-weight: 600; }

/* Scorer window: centred over the dimmed, still-live dashboard; the scorer page brings its own light styles */
#scorer { z-index: 30; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.scorer-window {
  display: flex; flex-direction: column; width: min(1100px, 100%); height: min(88vh, 100%); overflow: hidden;
  background: #fff; border: 1px solid var(--edge); border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.scorer-bar {
  display: flex; align-items: center; gap: 12px; padding: 4px 4px 4px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); color: var(--text);
}
.scorer-bar button { min-width: 44px; padding: 8px 12px; }
.scorer-window iframe { flex: 1; width: 100%; border: 0; }
/* No pull-to-refresh while scoring: a reload would lose the match */
html.scoring, html.scoring body { overscroll-behavior: none; overflow: hidden; }
