:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #e9ebee;
  --text: #16181d;
  --text-dim: #5c6470;
  --line: #d4d8de;
  --accent: #0a66c2;
  --green: #0f7b3f;
  --purple: #7a3ff0;
  --amber: #b07a00;
  --red: #c0392b;
  --flag-green: #0f7b3f;
  --flag-yellow: #b07a00;
  --flag-red: #c0392b;
  --flag-sc: #b07a00;
  --flash: color-mix(in srgb, var(--accent) 26%, transparent);
  --shadow: 0 1px 3px rgb(0 0 0 / 12%);
  --track-tarmac: #363b44;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'Cascadia Mono', 'JetBrains Mono', Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #101216;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #e8eaee;
    --text-dim: #9aa3b0;
    --line: #2e343e;
    --accent: #58a6ff;
    --green: #3fb96a;
    --purple: #b18cff;
    --amber: #e3b341;
    --red: #f0716a;
    --flag-green: #3fb96a;
    --flag-yellow: #e3b341;
    --flag-red: #f0716a;
    --flag-sc: #e3b341;
    --flash: color-mix(in srgb, var(--accent) 34%, transparent);
    --shadow: 0 1px 3px rgb(0 0 0 / 50%);
    --track-tarmac: #4b525d;
  }
}
:root[data-theme='dark'] {
  --bg: #101216;
  --surface: #181b21;
  --surface-2: #22262e;
  --text: #e8eaee;
  --text-dim: #9aa3b0;
  --line: #2e343e;
  --accent: #58a6ff;
  --green: #3fb96a;
  --purple: #b18cff;
  --amber: #e3b341;
  --red: #f0716a;
  --flag-green: #3fb96a;
  --flag-yellow: #e3b341;
  --flag-red: #f0716a;
  --flag-sc: #e3b341;
  --flash: color-mix(in srgb, var(--accent) 34%, transparent);
  --shadow: 0 1px 3px rgb(0 0 0 / 50%);
  --track-tarmac: #4b525d;
  color-scheme: dark;
}
:root[data-theme='light'] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);

  font: 13px/1.45 var(--font-mono);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  font-family: var(--font-ui);
}
.hamburger {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 38px;
  min-height: 32px;
  font-size: 17px;
  line-height: 1.2;
  cursor: pointer;
}
.hamburger[aria-expanded='true'] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Live-data heartbeat: a dot on the title that pulses as updates land
   (pingHeart adds .beat), sits steady while live, red when stalled. */
.feed-heart {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 7px;
  border-radius: 50%;
  vertical-align: 1px;
  background: var(--text-dim);
}
.feed-heart.live {
  background: var(--green);
}
.feed-heart.stalled {
  background: var(--red);
  animation: sc-pulse 1s ease-in-out infinite;
}
.feed-heart.idle {
  opacity: 0.4;
}
.feed-heart.beat {
  animation: heartbeat 0.6s ease-out;
}

.battery-chip {
  display: inline-flex;
  align-items: center;
  width: 24px;
  height: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--amber);
  vertical-align: middle;
}
.battery-chip::before {
  content: '';
  width: 18px;
  height: 10px;
  border-radius: 2px;
  background: currentColor;
}
.battery-chip::after {
  content: '';
  width: 3px;
  height: 6px;
  border-radius: 0 1px 1px 0;
  background: currentColor;
}

@keyframes heartbeat {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.9);
  }
  100% {
    transform: scale(1);
  }
}
@media (prefers-reduced-motion: reduce) {
  .feed-heart.beat {
    animation: none;
  }
}
/* Mode + track status read as one unit. */
.hdr-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.gate-chip {
  border: none;
  background: var(--accent);
  font: 700 13px var(--font-mono);
  font-variant-numeric: tabular-nums;
  min-height: 32px;
  padding: 3px 12px;
  border-radius: 16px;
  cursor: pointer;
}
.gate-chip.gate-soon {
  background: var(--red);
  animation: sc-pulse 1.2s ease-in-out infinite;
}

.menu {
  position: absolute;
  top: 44px;
  left: 10px;
  z-index: 60;
  width: 250px;
  max-width: calc(100vw - 20px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  font-family: var(--font-ui);
}
.menu-section {
  padding: 4px 0;
}
.menu-section + .menu-section {
  border-top: 1px solid var(--line);
}
.menu-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.menu-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  padding: 10px 10px;
  cursor: pointer;
}
.menu-item:hover {
  background: var(--surface-2);
}
.menu-state {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.menu-state::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 0;
  background: var(--text-dim);
}
.menu-item[aria-checked='true'] .menu-state,
.menu-item[aria-pressed='true'] .menu-state {
  background: color-mix(in srgb, var(--green) 20%, transparent);
  color: var(--green);
  border-color: var(--green);
}
.menu-item[aria-checked='true'] .menu-state::before {
  background: var(--green);
}
.menu .info-btn {
  padding: 4px 8px;
  font-size: 13px;
}
a.menu-item {
  color: var(--text);
  text-decoration: none;
}
.menu-item.menu-title {
  font-weight: 700;
  cursor: default;
}
.menu-item.menu-title:hover {
  background: none;
}
.menu-select select {
  flex: 1;
  min-width: 0;
  max-width: 150px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 4px;
  font: inherit;
  font-size: 12px;
}

.sc-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 7px 12px;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a1a1a;
  background: var(--flag-yellow);
  border-bottom: 2px solid color-mix(in srgb, var(--flag-yellow) 60%, #000);
  animation: sc-pulse 1.6s ease-in-out infinite;
}
.sc-banner.sc-red {
  color: #fff;
  background: var(--flag-red);
  border-bottom-color: color-mix(in srgb, var(--flag-red) 60%, #000);
}
.sc-banner::before {
  content: '⚠';
  font-size: 17px;
  animation: none;
}
@keyframes sc-pulse {
  50% {
    opacity: 0.72;
  }
}

/* Dismissible status toasts (replacing the old fixed prerace/demo
   banners): a stack that sits above the grid content, each card removable
   with its ✕. */
.toast-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px 0;
}
.toast-stack:empty {
  display: none;
}
.toast-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--purple);
  border: 1px solid color-mix(in srgb, var(--purple) 55%, #000);
  box-shadow: var(--shadow);
}
.toast-item.hidden {
  display: none;
}
.toast-item[data-variant='accent'] {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 55%, #000);
}
.toast-item[data-variant='idle'] {
  font-weight: 400;
  color: var(--text-dim);
  background: var(--surface);
  border-color: var(--line);
}
.toast-item .toast-text {
  flex: 1;
}
.toast-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: rgb(255 255 255 / 0.18);
  color: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.toast-close:hover {
  background: rgb(255 255 255 / 0.32);
}
.toast-item[data-variant='idle'] .toast-close {
  background: color-mix(in srgb, var(--text-dim) 20%, transparent);
}

.hdr-left,
.hdr-mid,
.hdr-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.session-name {
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.lap-counter {
  color: var(--text-dim);
  white-space: nowrap;
}
.stat {
  color: var(--text-dim);
  white-space: nowrap;
}
.clock {
  font-size: 14px;
}
body[data-mode='wall'] .clock {
  font-size: 22px;
  color: var(--text);
}
.chip {
  padding: 1px 8px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  white-space: nowrap;
}
.flag-green {
  background: var(--flag-green);
}
.flag-yellow,
.flag-sc,
.flag-vsc {
  background: var(--flag-yellow);
  color: #222;
}
.flag-red {
  background: var(--flag-red);
}
/* Broadcast-delay indicator (item 4): a live, tappable chip so the viewer
   always knows the timing is deliberately held behind the real feed. */
.delay-chip {
  background: var(--accent);
  border: 0;
  cursor: pointer;
  font-family: var(--font-ui);
}
.health-live {
  background: var(--green);
}
.health-stalled,
.health-idle {
  background: var(--text-dim);
}
.mode-live {
  background: var(--green);
}
.mode-replay {
  background: var(--accent);
}
.mode-sim {
  background: var(--purple);
}
.mode-idle {
  background: var(--text-dim);
}
.mode-stalled {
  background: var(--red);
}
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 10px;
  font: inherit;
  font-family: var(--font-ui);
  cursor: pointer;
}
.btn.small {
  padding: 3px 6px;
  font-size: 11px;
}
.btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
a.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--text);
}

.stale-overlay {
  position: fixed;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: var(--text-dim);
  color: var(--bg);
  padding: 4px 14px;
  border-radius: 4px;
  box-shadow: var(--shadow);
}

body.admin-page {
  height: auto;
  min-height: 100%;
  overflow: visible;
  display: block;
}
.admin-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-family: var(--font-ui);
}
.admin-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.admin-card h2 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.admin-card .hint {
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.45;
}
.admin-card input:not([type='checkbox']),
.admin-card select {
  flex: 1 1 220px;
  min-width: 0;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  font: inherit;
}
.admin-card select#demo-year {
  flex: 0 0 84px;
}
.f1-steps {
  margin: 0 0 8px;
  padding-left: 20px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.7;
}
.f1-steps a.btn {
  margin-right: 2px;
}
.f1-cookie {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  font: 12px/1.4 var(--font-mono);
  word-break: break-all;
}
.f1-preview {
  margin: 2px 0;
}

.f1-expiry {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 15px;
  text-align: center;
  padding: 9px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.f1-expiry-ok {
  color: #fff;
  background: var(--green);
}
.f1-expiry-warn {
  color: #1a1a1a;
  background: var(--flag-yellow);
}
.admin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.admin-card input#admin-speed {
  flex: 0 0 56px;
}
.admin-label {
  color: var(--text-dim);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.admin-state {
  color: var(--text-dim);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-state.f1-state-warn {
  color: var(--amber);
  font-weight: 700;
}
.admin-state.f1-state-expired {
  color: var(--red);
  font-weight: 700;
}
.admin-msg {
  color: var(--amber);
  font-size: 12px;
  min-height: 1em;
}
.admin-card .btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* who's watching — live client presence */
.clients-dist {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dist-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.dist-label {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 0 0 52px;
}
.dist-chip {
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.clients-table-wrap {
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.clients-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.clients-table th,
.clients-table td {
  padding: 3px 8px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.clients-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
}
.clients-table tbody tr:last-child td {
  border-bottom: none;
}
.clients-table tr.stage-paywall td {
  background: color-mix(in srgb, var(--amber) 12%, transparent);
}
.clients-table tr.stage-checkout td {
  background: color-mix(in srgb, var(--green, #29a745) 14%, transparent);
}
.clients-table .err {
  color: var(--red);
  font-weight: 700;
  cursor: help;
}
.clients-empty {
  color: var(--text-dim);
  padding: 10px;
}

.hidden {
  display: none;
}
body.stale #grid {
  filter: grayscale(0.7) opacity(0.75);
}

#ribbon {
  position: relative;
  height: 44px;
}
.ribbon-scale {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 10px;
  padding: 2px 0 4px;
}
.rchip {
  position: absolute;
  top: 8px;
  width: 30px;
  height: 22px;
  margin-left: -15px;
  border-radius: 4px;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: left 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  z-index: 1;
}
.rchip.hunter {
  animation: pulse-edge 1.2s ease-in-out infinite;
}
@keyframes pulse-edge {
  0%,
  100% {
    border-color: transparent;
  }
  50% {
    border-color: var(--amber);
  }
}
.rchip.ghost {
  opacity: 0.45;
  border: 1px dashed var(--text);
  pointer-events: none;
}

.rchip.ghost.faint {
  opacity: 0.2;
  z-index: 0;
}
.rchip.winner {
  outline: 2px solid var(--green);
}
.rchip.loser {
  outline: 2px solid var(--red);
}
.rchip.inpit {
  opacity: 0.5;
  top: 26px;
  height: 14px;
  font-size: 9px;
}
.window-band {
  position: absolute;
  top: 4px;
  height: 32px;
  background: color-mix(in srgb, var(--green) 22%, transparent);
  border: 1px solid var(--green);
  border-radius: 4px;
  pointer-events: none;
}
.lap-divider {
  position: absolute;
  top: 2px;
  height: 38px;
  border-left: 1px dashed var(--text-dim);
  color: var(--text-dim);
  font-size: 10px;
  padding-left: 3px;
}
/* Lapped-car rows (item 9): +1/+2 lap cars drop to rows beneath the lead
   lap, placed by their on-track position, with a dotted tether up to the
   pack so their position on track is clear. The ribbon grows to fit the
   extra rows only when there are lapped cars. */
#ribbon.has-tiers {
  height: 92px;
}
#ribbon.has-tiers .rchip[data-tier='1'] {
  top: 40px;
}
#ribbon.has-tiers .rchip[data-tier='2'] {
  top: 66px;
}
.lap-tether {
  position: absolute;
  border-left: 1px dotted var(--text-dim);
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
}
#ribbon.has-tiers .lap-tether[data-tier='1'] {
  top: 8px;
  height: 34px;
}
#ribbon.has-tiers .lap-tether[data-tier='2'] {
  top: 8px;
  height: 60px;
}
#ribbon-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 19px;
  height: 2px;
  background: repeating-linear-gradient(
    to right,
    var(--line) 0 6px,
    color-mix(in srgb, var(--line) 40%, transparent) 6px 12px
  );
  z-index: 0;
}
#ribbon-head {
  position: absolute;
  left: 3%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 13px;
  line-height: 1;
}

/* --- Widget grid: the composable home screen --------------------------
   Every panel is a .widget the viewer arranges (✎ Edit): four column
   spans (s/m/l/full), reorder, remove, re-add from the tray. The same
   chrome carries ⛶ full screen and ⧉ own-window on every panel. */

#grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  /* Masonry: a fine row unit + JS-measured row-spans + dense flow let a
     shorter tile's neighbour pack up into the gap beneath it, instead
     of every tile in a row starting below the tallest one. layoutMasonry
     in app.js sets each tile's grid-row span; vertical spacing comes
     from the span slack (see the +GAP there), so row-gap stays 0. */
  grid-auto-rows: 4px;
  grid-auto-flow: row dense;
  column-gap: 10px;
  row-gap: 0;
  padding: 10px;
  align-items: start;
  align-content: start;
  overflow-y: auto;
}
.widget {
  grid-column: span 12;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.widget[data-size='s'] {
  grid-column: span 4;
}
.widget[data-size='m'] {
  grid-column: span 6;
}
.widget[data-size='l'] {
  grid-column: span 8;
}
.widget[data-size='full'] {
  grid-column: span 12;
}
.widget.off {
  display: none;
}

.widget-head {
  position: relative; /* anchors the ⚙ settings popover */
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  font-family: var(--font-ui);
}
.widget-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.widget-title .info-btn {
  font-size: 13px;
  padding: 0 6px;
}
.widget-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}
/* One button family for all panel chrome (also the focus panel). */
.wbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 30px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font: 15px/1 var(--font-ui);
  text-decoration: none;
  cursor: pointer;
}
.wbtn:hover,
.wbtn:focus-visible {
  background: var(--surface-2);
  color: var(--text);
}
.widget-edit-tools {
  display: none;
  align-items: center;
  gap: 4px;
}
.w-size {
  border: 1px solid var(--line);
  padding: 0 10px;
}
.w-size-label {
  font: 600 11px var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.w-remove {
  color: var(--red);
}
.w-settings.active {
  background: var(--surface-2);
  color: var(--text);
}

/* Per-pane settings popover (the ⚙ dropdown). */
.pane-pop {
  position: absolute;
  top: calc(100% + 2px);
  right: 6px;
  z-index: 20;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  font-family: var(--font-ui);
}
.pane-pop.hidden {
  display: none;
}
.pane-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 6px;
}
.pane-label {
  font-size: 13px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
.pane-seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  flex: none;
}
.pane-seg-btn {
  background: var(--surface-2);
  color: var(--text-dim);
  border: none;
  min-height: 30px;
  padding: 2px 10px;
  font: 600 12px var(--font-ui);
  cursor: pointer;
}
.pane-seg-btn + .pane-seg-btn {
  border-left: 1px solid var(--line);
}
.pane-seg-btn.active {
  background: var(--accent);
  color: #fff;
}
.pane-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  padding: 0;
}
.pane-toggle-state {
  flex: none;
  font: 700 11px var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.pane-toggle[aria-pressed='true'] .pane-toggle-state {
  background: color-mix(in srgb, var(--green) 20%, transparent);
  color: var(--green);
  border-color: var(--green);
}

/* The edit affordance lives in the header's top-right corner. */
.hdr-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 32px;
  padding: 3px 12px;
  font: 600 13px var(--font-ui);
  cursor: pointer;
  white-space: nowrap;
}
.hdr-edit:hover {
  border-color: var(--text-dim);
}
.hdr-edit[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.hdr-edit-icon {
  font-size: 15px;
  line-height: 1;
}
body[data-dash] .hdr-edit,
body[data-mode='wall'] .hdr-edit,
body.has-max .hdr-edit {
  display: none;
}

.widget-body {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  overflow: auto;
}

/* Data-rich but bounded: unbounded panels scroll inside their card
   instead of stretching the page. */
.widget[data-widget='ribbon'] .widget-body {
  padding: 10px 16px 4px;
  overflow: hidden;
}
.widget[data-widget='board'] .widget-body {
  padding: 0;
}
.widget[data-widget='events'] .widget-body {
  max-height: 620px;
  font-family: var(--font-ui);
}
/* The visual panes want room, scaled to the tile's size — a small
   track map should be compact, a full-width one large.
   flex:none is load-bearing: the default .widget-body is flex:1
   (flex-basis 0%), so in a fixed-row grid the explicit height is
   ignored and the pane collapses to just its header. flex:none makes
   the height the pane's actual size. :not(.max) so a maximised/own-
   window pane reverts to flex:1 and fills the screen instead. */
.widget[data-size='s'] {
  --pane-h: 340px;
}
.widget[data-size='m'] {
  --pane-h: 520px;
}
.widget[data-size='l'] {
  --pane-h: 680px;
}
.widget[data-size='full'] {
  --pane-h: min(78vh, 780px);
}
.widget[data-widget='track']:not(.max) .widget-body,
.widget[data-widget='sectors']:not(.max) .widget-body,
.widget[data-widget='outlook']:not(.max) .widget-body,
.widget[data-widget='ribbon'][data-view='circles']:not(.max) .widget-body {
  flex: none;
  height: var(--pane-h);
}
/* Sector pace only needs room for the field, not a full-height pane. */
.widget[data-widget='sectors']:not(.max) .widget-body {
  height: calc(var(--pane-h) * 0.72);
}
.widget[data-widget='standings'] .widget-body {
  max-height: 620px;
}

/* ✎ edit mode — iPhone-style arranging. */
body.editing .widget-edit-tools {
  display: inline-flex;
}
body.editing .w-pop,
body.editing .w-max {
  display: none;
}
body.editing .widget-body {
  opacity: 0.55;
  pointer-events: none;
}
body.editing .widget {
  outline: 2px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: -2px;
  animation: wiggle 2.4s ease-in-out infinite;
}
@keyframes wiggle {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}
@media (prefers-reduced-motion: reduce) {
  body.editing .widget {
    animation: none;
  }
}

.widget-tray {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 8px 12px 12px;
  font-family: var(--font-ui);
}
.tray-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.tray-head span {
  flex: 1;
}
.tray-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tray-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--text);
  font: 600 13px var(--font-ui);
  padding: 10px 14px;
  cursor: pointer;
}
.tray-card:hover {
  border-color: var(--accent);
}
.tray-plus {
  color: var(--accent);
  font-weight: 700;
}
.tray-empty {
  color: var(--text-dim);
  font-size: 12px;
}

/* ⛶ full screen in place: the widget covers the viewport, its ⛶ turns
   into ✕, Esc goes back. Dashboard windows reuse exactly this. */
body.has-max #grid {
  overflow: hidden;
}
.widget.max {
  /* display beats .off: a widget that isn't on the home screen can
     still be maximised (that's how its ?dash= window works). */
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 70;
  border-radius: 0;
  box-shadow: none;
  animation: none;
}
.widget.max .widget-body {
  max-height: none;
  height: auto;
}
.widget.max .w-pop {
  display: none;
}

/* A maximised ribbon gets the big-screen treatment (shared with the
   ?dash=ribbon window). */
.widget[data-widget='ribbon'].max .widget-body {
  justify-content: center;
  padding: 0 28px;
}
.widget[data-widget='ribbon'].max #ribbon {
  height: 130px;
}
.widget[data-widget='ribbon'].max #ribbon-track {
  top: 62px;
}
.widget[data-widget='ribbon'].max .rchip {
  top: 45px;
  width: 46px;
  height: 34px;
  margin-left: -23px;
  font-size: 14px;
  border-radius: 6px;
}
.widget[data-widget='ribbon'].max .rchip.inpit {
  top: 88px;
  height: 20px;
  font-size: 11px;
}
.widget[data-widget='ribbon'].max .window-band {
  top: 36px;
  height: 52px;
}
.widget[data-widget='ribbon'].max .lap-divider {
  top: 24px;
  height: 84px;
}
.widget[data-widget='ribbon'].max #ribbon.has-tiers {
  height: 176px;
}
.widget[data-widget='ribbon'].max #ribbon.has-tiers .rchip[data-tier='1'] {
  top: 92px;
}
.widget[data-widget='ribbon'].max #ribbon.has-tiers .rchip[data-tier='2'] {
  top: 132px;
}
.widget[data-widget='ribbon'].max #ribbon.has-tiers .lap-tether[data-tier='1'] {
  top: 45px;
  height: 52px;
}
.widget[data-widget='ribbon'].max #ribbon.has-tiers .lap-tether[data-tier='2'] {
  top: 45px;
  height: 92px;
}
.widget[data-widget='ribbon'].max .ribbon-scale {
  font-size: 12px;
}

#timing-board {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 6px;
  overflow: hidden;
}
#timing-board th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
}
/* Numeric headers must right-align with their data (the base
   #timing-board th rule out-specifies .col-num otherwise). */
#timing-board th.col-num {
  text-align: right;
}
#timing-board td {
  padding: 2px 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
  height: 24px;
  white-space: nowrap;
}
#timing-board tbody tr {
  cursor: pointer;
}
#timing-board tbody tr:hover {
  background: var(--surface-2);
}
#timing-board tbody tr.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
#timing-board tbody tr.problem {
  filter: saturate(0.25);
}
#timing-board tbody tr.gain {
  box-shadow: inset 3px 0 0 var(--green);
}
#timing-board tbody tr.loss {
  box-shadow: inset 3px 0 0 var(--red);
}

@keyframes cell-flash {
  from {
    background-color: var(--flash);
  }
  to {
    background-color: transparent;
  }
}
#timing-board tbody td.flash {
  animation: cell-flash 2.4s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  #timing-board tbody td.flash {
    animation: none;
  }
}
.col-pos {
  width: 26px;
}
.col-num,
td.num {
  text-align: right;
}
.team-swatch {
  display: inline-block;
  width: 4px;
  height: 14px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -2px;
}

.t-best {
  color: var(--green);
  font-weight: 700;
}
.t-fastest {
  color: var(--purple);
  font-weight: 700;
}
.t-slow {
  color: var(--amber);
}
.tyre-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: -1px;
  border: 1px solid var(--line);
}
.tyre-S {
  background: #e11;
}
.tyre-M {
  background: #fc0;
}
.tyre-H {
  background: #eee;
}
.tyre-I {
  background: #2a2;
}
.tyre-W {
  background: #26c;
}

.ind-grid {
  display: inline-grid;
  grid-auto-flow: column;
  grid-template-columns: repeat(7, 16px);
  align-items: center;
  justify-items: center;
  gap: 1px;
}
.ind {
  margin-left: 0;
  font-size: 12px;
  line-height: 1;
}
.ind-off {
  opacity: 0.13;
  filter: grayscale(1);
}
.ind.catch-amber {
  color: var(--amber);
  animation: blink 1.4s infinite;
}
.ind.catch-red {
  color: var(--red);
  animation: blink 0.8s infinite;
}
.ind.power-up {
  color: var(--red);
}
.ind.power-down {
  color: var(--accent);
}
.ind.window-open {
  color: var(--green);
}
.ind.window-closing {
  color: var(--amber);
}
.ind.problem {
  color: var(--amber);
}

.ind.boost {
  display: inline-block;
  width: 14px;
  height: 7px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
  vertical-align: 1px;
  cursor: pointer;
}
.ind.boost i {
  display: block;
  height: 100%;
  background: var(--green);
}

.deg {
  display: inline-flex;
  align-items: flex-end;
  gap: 1px;
  margin-left: 5px;
  vertical-align: -1px;
  cursor: pointer;
}
.deg i {
  width: 3px;
  border-radius: 1px;
  background: var(--line);
}
.deg i:nth-child(1) {
  height: 5px;
}
.deg i:nth-child(2) {
  height: 8px;
}
.deg i:nth-child(3) {
  height: 11px;
}
/* The bar reads as tyre life REMAINING: full and green on a fresh tyre,
   shrinking toward a single short red bar as it degrades. */
.deg-0 i {
  background: var(--green);
}
.deg-1 i:nth-child(-n + 2) {
  background: var(--amber);
}
.deg-2 i:nth-child(1) {
  background: var(--red);
}
@keyframes blink {
  50% {
    opacity: 0.35;
  }
}
.status-note {
  color: var(--text-dim);
  font-size: 10px;
}
/* A car in the pit lane: plain PIT letters in attention-blue (not the
   dimmed grey of a retired/stopped car), so pit entry reads at a glance. */
.status-note.pit {
  color: var(--accent);
  font-weight: 700;
}

.mini-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 1px;
  height: 12px;
  width: 18px;
  margin-left: 5px;
  vertical-align: -1px;
}
.mini-bars i {
  display: block;
  flex: 1;
  min-height: 2px;
  background: var(--text-dim);
  border-radius: 1px;
  opacity: 0.6;
}
.mini-bars i:last-child {
  background: var(--accent);
  opacity: 1;
}

#focus-panel h2 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
/* Multi-column flow, filled top-to-bottom: P1 sits top-left, P2 under
   it, so a column reads like the race order. */
#exit-rows {
  columns: 178px;
  column-gap: 10px;
}
.exit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  padding: 2px 6px;
  margin-bottom: 4px;
  border-radius: 4px;
  border-left: 3px solid var(--line);
  cursor: pointer;
  break-inside: avoid;
}
.exit-row:hover {
  background: var(--surface-2);
}

.exit-row.pinned {
  background: var(--surface-2);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.exit-driver {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.exit-verdict {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 1px 7px;
  border-radius: 10px;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-dim);
}
.exit-row.rag-green {
  border-left-color: var(--green);
}
.exit-row.rag-green .exit-verdict {
  background: color-mix(in srgb, var(--green) 18%, transparent);
  color: var(--green);
}
.exit-row.rag-amber {
  border-left-color: var(--amber);
}
.exit-row.rag-amber .exit-verdict {
  background: color-mix(in srgb, var(--amber) 20%, transparent);
  color: var(--amber);
}
.exit-row.rag-red {
  border-left-color: var(--red);
}
.exit-row.rag-red .exit-verdict {
  background: color-mix(in srgb, var(--red) 18%, transparent);
  color: var(--red);
}
.exit-row.rag-grey {
  opacity: 0.72;
}

#event-filters {
  position: relative;
  margin-bottom: 6px;
}
/* The single filter popup: both sections (types + drivers) in one floating
   card anchored under the Filter button, so the widget body stays compact. */
.event-filter-pop {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  min-width: 240px;
  max-width: min(340px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px;
}
.efp-section + .efp-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.efp-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-ui);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.efp-actions {
  display: inline-flex;
  gap: 6px;
}
.efp-actions button {
  font: inherit;
  font-family: var(--font-ui);
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 1px 8px;
  cursor: pointer;
}
.filter-chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 14px;
  font-family: var(--font-ui);
  font-size: 12px;
  min-height: 28px;
  padding: 2px 12px;
  cursor: pointer;
}
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.event-cat-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
/* Category chips are multi-select "tune out" toggles, mostly on — so a
   shown chip gets a light tint (not a heavy fill) and a muted one is
   dimmed and struck through. */
.cat-chip.active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
  color: var(--text);
}
.cat-chip:not(.active) {
  opacity: 0.55;
  text-decoration: line-through;
}
.event-driver-filter {
  max-height: 42vh;
  overflow-y: auto;
}
.edf-team {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 3px 0;
}
.edf-team-name {
  font: inherit;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  min-width: 78px;
  text-align: left;
  padding: 0;
}
.edf-team-name.muted {
  text-decoration: line-through;
  opacity: 0.5;
}
.edf-drivers {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.edf-driver {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 8px;
  cursor: pointer;
}
.edf-driver.muted {
  opacity: 0.4;
  text-decoration: line-through;
}
#event-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
#event-feed li {
  padding: 5px 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
#event-feed .lap-tag {
  color: var(--text-dim);
  font-size: 10px;
  min-width: 34px;
}
.evt-msg {
  flex: 1;
  min-width: 0;
}
/* "how long ago" — pushed to the right, before the 🔊 button. */
.evt-time {
  flex: none;
  color: var(--text-dim);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#event-feed li.p1 {
  border-left: 3px solid var(--red);
  font-weight: 700;
}
#event-feed li.p2 {
  border-left: 3px solid var(--amber);
}
#event-feed li.p3 {
  border-left: 3px solid var(--line);
  color: var(--text-dim);
}
/* Race director / race-control notes: an accent rail and an "RC" badge so
   they read as official communications, not our own calls. */
#event-feed li.cat-director {
  border-left-color: var(--accent);
  color: var(--text);
}
.evt-tag {
  flex: none;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--accent);
  border-radius: 3px;
  padding: 0 4px;
  align-self: center;
}
body[data-mode='wall'] #event-feed li {
  font-size: 15px;
}
.speak-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  margin-left: auto;
  opacity: 0.5;
}
.speak-btn:hover {
  opacity: 1;
}

/* Driver detail: a slide-in drawer on every screen size — tap a driver
   anywhere to open it, ✕ (or the backdrop, or Esc) to close. */
.focus-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgb(0 0 0 / 45%);
}
body.focus-open:not([data-mode='wall']) .focus-backdrop {
  display: block;
}
#focus-panel {
  display: flex;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  width: min(400px, calc(100vw - 24px));
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  overflow: auto;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.25s ease;
}
body.focus-open #focus-panel {
  transform: translateX(0);
}
@media (prefers-reduced-motion: reduce) {
  #focus-panel {
    transition: none;
  }
}
/* Wall display pins the detail panel open beside the grid. */
body[data-mode='wall'].focus-open #grid {
  margin-right: min(400px, 34vw);
}
body[data-mode='wall'] #focus-panel {
  width: min(400px, 34vw);
}
.focus-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.focus-head h2 {
  margin: 0;
  flex: 1;
}
.focus-empty {
  color: var(--text-dim);
}
.focus-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 14px;
  font-size: 12px;
}
.focus-grid .label {
  color: var(--text-dim);
}
.spark-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0 5px;
  margin-top: 2px;
}
.spark-y {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: right;
  font-size: 9px;
  color: var(--text-dim);
  padding: 1px 0;
}
.spark-plot {
  width: 100%;
  height: 46px;
}
.spark-grid {
  stroke: var(--line);
  stroke-width: 0.5;
}
.spark-x {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-dim);
}
.exit-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  cursor: pointer;
}
.exit-strip .xs {
  flex: none;
  width: 13px;
  height: 16px;
  border-radius: 2px;
}
.exit-strip .xs.xc-none {
  background: var(--surface-2);
  opacity: 0.4;
}
.xs-now {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
}
.bar > i.boost-fill {
  background: var(--green);
}
.focus-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.compare-btn {
  margin-top: 8px;
}
.focus-btns .compare-btn {
  margin-top: 0;
}
body[data-mode='wall'] .compare-btn {
  display: none;
}
.power-over {
  color: var(--red);
  font-weight: 700;
}
.power-cons {
  color: var(--accent);
  font-weight: 700;
}
.advice-box {
  color: var(--green);
  font-weight: 700;
}
.advice-stay {
  color: var(--text-dim);
}
.advice-marginal {
  color: var(--amber);
}

/* The key/legend now lives at the foot of the timing board, shown via
   the board's own ⚙ "Show key" setting. */
#legend {
  flex: none;
  padding: 6px 10px;
  color: var(--text-dim);
  font-size: 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.widget[data-widget='board'][data-legend='off'] #legend {
  display: none;
}

/* --- Simple vs Detailed (per timing board) -----------------------------
   Simple keeps the essentials (P, driver, gap, last, tyre) in larger
   type; Detailed is the full pit-wall picture. */
.widget[data-widget='board'][data-detail='simple'] #timing-board th:nth-child(3),
.widget[data-widget='board'][data-detail='simple'] #timing-board td:nth-child(3),
.widget[data-widget='board'][data-detail='simple']
  #timing-board
  th:nth-child(n + 6):nth-child(-n + 8),
.widget[data-widget='board'][data-detail='simple']
  #timing-board
  td:nth-child(n + 6):nth-child(-n + 8),
.widget[data-widget='board'][data-detail='simple'] #timing-board th:nth-child(10),
.widget[data-widget='board'][data-detail='simple'] #timing-board td:nth-child(10),
.widget[data-widget='board'][data-detail='simple'] #timing-board th:nth-child(11),
.widget[data-widget='board'][data-detail='simple'] #timing-board td:nth-child(11) {
  display: none;
}
.widget[data-widget='board'][data-detail='simple'] #timing-board {
  font-size: 15px;
}
.widget[data-widget='board'][data-detail='simple'] #timing-board td {
  height: 30px;
  padding-top: 4px;
  padding-bottom: 4px;
}
.pb-sw {
  color: var(--green);
}
.sb-sw {
  color: var(--purple);
}
.legend-item {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  font-size: 10px;
  padding: 0;
  margin-right: 4px;
  cursor: pointer;
}
.legend-item:hover {
  text-decoration: underline;
}

.info-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  padding: 2px 5px;
  cursor: pointer;
  vertical-align: 1px;
  opacity: 0.75;
}
.info-btn:hover,
.info-btn:focus-visible {
  opacity: 1;
}
th .info-btn {
  text-transform: none;
  font-weight: 400;
}
.info-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.info-modal.hidden {
  display: none;
}
.info-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 45%);
}
.info-modal-card {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  max-width: 360px;
  margin: 16px;

  font-family: var(--font-ui);
}
.info-modal-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.info-modal-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
}
.info-modal-body p {
  margin: 0 0 8px;
}
.info-modal-body p:last-child {
  margin-bottom: 0;
}
.info-modal-body ul {
  margin: 0 0 8px;
  padding-left: 18px;
}
.info-modal-body li {
  margin: 2px 0;
}
.info-modal-body b {
  color: var(--text);
}

.info-key {
  list-style: none;
  padding-left: 0;
}
.info-key li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.amber-sw {
  color: var(--amber);
}
.red-sw {
  color: var(--red);
}
.accent-sw {
  color: var(--accent);
}
.info-modal-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  min-width: 36px;
  min-height: 34px;
}
.info-modal-close:hover {
  background: var(--surface-2);
}
.info-modal-close:hover {
  color: var(--text);
}
body[data-mode='wall'] .info-btn,
body[data-mode='wall'] .focus-close {
  display: none;
}

.compare-card {
  max-width: 560px;
  width: calc(100vw - 32px);
  font-family: var(--font-mono);
}
.compare-card .label {
  color: var(--text-dim);
  font-size: 11px;
}
.compare-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
#compare-b {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font: inherit;
}
.compare-svg {
  width: 100%;
  height: 72px;
  margin: 2px 0 8px;
}
.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}
.compare-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--line);
  padding: 2px 6px;
}
.compare-table td {
  padding: 2px 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
}
.compare-table td.num {
  text-align: right;
}
.compare-stints {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 12px;
  margin-bottom: 6px;
}
.compare-note {
  font-size: 10px;
  color: var(--text-dim);
}

/* Per-lap telemetry traces (A9). */
.compare-trace-head {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.trace-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 6px 0 4px;
  font-size: 12px;
}
.trace-picks label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.trace-picks select {
  font: inherit;
  font-size: 12px;
}
.trace-chart {
  margin: 4px 0 2px;
}
.trace-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0 5px;
}
.trace-yaxis {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 14px;
  text-align: right;
  font-size: 9px;
  color: var(--text-dim);
  padding-top: 1px;
}
.trace-unit {
  margin-top: auto;
  opacity: 0.7;
}
.trace-plot {
  width: 100%;
  height: 150px;
}
.trace-grid {
  stroke: var(--line);
  stroke-width: 0.5;
}
.trace-axis {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-dim);
  margin-left: calc(2ch + 5px);
}
.trace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: center;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}
.trace-panels {
  color: var(--text-dim);
}
.trace-key {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
}
.trace-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
}
.trace-key.faded {
  opacity: 0.6;
}

/* --- Lap-trace pane ---------------------------------------------------- */
.trace-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.trace-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
}
.trace-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 6px;
}
.trace-pick {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
}
.trace-pick select {
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 4px;
}
.trace-chs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.trace-ch {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 2px 9px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.trace-ch.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-color: var(--accent);
  color: var(--text);
}
.trace-remove {
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 5px;
  width: 22px;
  height: 22px;
  line-height: 1;
  cursor: pointer;
}
.trace-add {
  margin-top: 10px;
}
.trace-band {
  margin: 3px 0;
}
.trace-band-head {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.trace-band-name {
  font-weight: 700;
}
.trace-band-plot {
  width: 100%;
  height: 42px;
  display: block;
}
.trace-cursor {
  stroke: var(--accent);
  stroke-width: 1;
  opacity: 0.7;
  stroke-dasharray: 2 2;
}
/* The pane lays the axis/legend out in a plain column, not the focus
   panel's grid — reset the grid-only offsets. */
.trace-chart-inner .trace-axis {
  grid-column: auto;
  margin-left: 0;
}

/* Merged two-graph layout (speed & gear over throttle & brake). Each graph
   is a fixed 126px so the whole pane keeps a constant height whatever
   channels are toggled — about 150% of the old four-strip height. */
.trace-band-row {
  display: grid;
  grid-template-columns: 3.4ch minmax(0, 1fr) 3.4ch;
  gap: 0 5px;
  align-items: stretch;
}
.trace-merged .trace-band-plot {
  height: 126px;
}
.trace-merged .trace-band-row .trace-yaxis {
  justify-content: space-between;
  gap: 0;
  padding: 1px 0;
}
.trace-yaxis.right {
  text-align: left;
}
/* Units sit under their axes: km/h at the far left, mph at the far right
   (the axes are the outermost columns, so space-between aligns them). */
.trace-band-units {
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  color: var(--text-dim);
  opacity: 0.75;
  margin-top: 1px;
}
.trace-merged .trace-axis {
  margin-left: calc(3.4ch + 5px);
  margin-right: calc(3.4ch + 5px);
}

body[data-mode='wall'] {
  cursor: none;
}
body[data-mode='wall'] #legend,
body[data-mode='wall'] .widget-head,
body[data-mode='wall'] #widget-tray {
  display: none;
}

/* --- Own-window dashboards (?dash=…) ---------------------------------- */
/* A dashboard window is the matching widget, maximised, with a big
   ✕ close pill (and view toggle where a view has two looks). */

.dash-close {
  position: fixed;
  top: 8px;
  right: 10px;
  z-index: 120;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 17px;
  font: 600 13px var(--font-ui);
  color: var(--text-dim);
  text-decoration: none;
  padding: 4px 14px;
}
.dash-close:hover {
  color: var(--text);
  border-color: var(--text-dim);
}
.dash-close.hidden {
  display: none;
}
/* Panes inside widgets are plain flex columns; the standalone panes
   (driver focus, circles) only exist in their dashboard windows. */
.dash-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
}
.dash-pane.standalone {
  display: none;
}
.dash-caption {
  flex: none;
  color: var(--text-dim);
  font: 11px/1.5 var(--font-ui);
  margin-bottom: 8px;
}
/* Planner key sits at the foot of the pane, toggled by its ⚙ Show key. */
#dash-exit .dash-caption {
  margin: 8px 0 0;
  padding-top: 6px;
  border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.widget[data-widget='outlook'][data-legend='off'] .dash-caption {
  display: none;
}
.dash-empty {
  color: var(--text-dim);
  font: 13px/1.5 var(--font-ui);
  padding: 24px;
  max-width: 480px;
}
#dash-track {
  align-items: center;
  justify-content: center;
}
#dash-standings {
  overflow: auto;
}
#dash-sectors {
  flex-direction: row;
  gap: 10px;
}

body[data-dash] #header,
body[data-dash] #menu,
body[data-dash] #toast-stack,
body[data-dash] #legend,
body[data-dash] #widget-tray {
  display: none;
}
body[data-dash] .widget.max .w-max {
  display: none;
}
/* A dashboard window shows one panel only — nothing behind it. */
body[data-dash] #grid .widget:not(.max) {
  display: none;
}
/* Clear the fixed close/view pills in the top-right corner. */
body[data-dash] .widget.max .widget-head {
  padding-right: 96px;
}

/* Live gaps: line vs circles, chosen by the pane's own view setting.
   Circles = leader on the outer ring, start/finish at 12 o'clock, each
   car on its own circumference. */
.widget[data-widget='ribbon'][data-view='circles'] #ribbon-line {
  display: none;
}
.widget[data-widget='ribbon'][data-view='line'] #ribbon-circles {
  display: none;
}
.ribbon-circles {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ribbon-circles svg {
  height: 100%;
  max-width: 100%;
}
.circles-ring {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  opacity: 0.55;
}
.circles-sf {
  stroke: var(--text-dim);
  stroke-width: 2;
  stroke-dasharray: 6 5;
}
.circles-sf-label {
  font-size: 26px;
  text-anchor: middle;
}
.circles-car text {
  fill: #fff;
  font: 700 13px var(--font-mono);
  text-anchor: middle;
}
.circles-car.inpit {
  opacity: 0.45;
}

/* Pit stop planner (exit outlook): drivers vertically in race order,
   one column per lap; past + live + pace-projected future. */
#exit-matrix {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
/* Fill the tile width: fixed layout so all laps share the space and the
   matrix fits without a horizontal scrollbar, whatever the tile size. */
#exit-matrix table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
}
#exit-matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  font: 600 9px var(--font-mono);
  color: var(--text-dim);
  min-width: 0;
  padding: 2px 1px;
  text-align: center;
}
#exit-matrix thead th:first-child,
#exit-matrix tbody th {
  width: 42px;
}
#exit-matrix tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg);
  font: 700 11px var(--font-mono);
  color: var(--text);
  text-align: left;
  padding: 2px 10px 2px 2px;
  white-space: nowrap;
}
#exit-matrix thead th:first-child {
  left: 0;
  z-index: 3;
}
#exit-matrix th.xc-nowcol {
  color: var(--accent);
}
.xc {
  min-width: 0;
  height: 20px;
  border: 1px solid var(--bg);
  border-radius: 2px;
}
.xc-green {
  background: color-mix(in srgb, var(--green) 72%, transparent);
}
.xc-amber {
  background: color-mix(in srgb, var(--amber) 72%, transparent);
}
.xc-red {
  background: color-mix(in srgb, var(--red) 72%, transparent);
}
.xc-grey {
  background: var(--surface-2);
}
.xc-none {
  background: transparent;
}
.xc-fc {
  opacity: 0.45;
}
.xc-now {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.xc {
  text-align: center;
  padding: 0;
}
.xc-pit {
  outline: 1px solid color-mix(in srgb, var(--text-dim) 70%, transparent);
  outline-offset: -2px;
}
.xc-pit-mark {
  font-size: 9px;
  line-height: 1;
  vertical-align: middle;
  filter: grayscale(0.15);
}
.xc-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: -1px;
}

/* Championship if the race finished in the current order. */
#standings-table {
  border-collapse: collapse;
  min-width: 420px;
}
#standings-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
}
#standings-table th.col-num {
  text-align: right;
}
#standings-table td {
  padding: 3px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
  white-space: nowrap;
}
#standings-table td.total {
  font-weight: 700;
}
.delta-up {
  color: var(--green);
  font-weight: 700;
}
.delta-down {
  color: var(--red);
  font-weight: 700;
}
.delta-none {
  color: var(--text-dim);
  opacity: 0.5;
}

/* Sector pace: one panel per sector, lap timeline across, drivers
   ordered fastest→slowest, red→green cells (or the times themselves,
   coloured the same way). */
.sector-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
}
.sector-col h3 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.sector-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.sector-scroll table {
  border-collapse: collapse;
}
.sector-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  font: 600 9px var(--font-mono);
  color: var(--text-dim);
  min-width: 15px;
  padding: 1px;
  text-align: center;
}
.sector-scroll tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  font: 700 11px var(--font-mono);
  text-align: left;
  padding: 1px 8px 1px 2px;
  white-space: nowrap;
}
.sector-scroll thead th:first-child {
  left: 0;
  z-index: 3;
}
.sc-cell {
  min-width: 15px;
  height: 18px;
  border: 1px solid var(--surface);
}
.sc-fill {
  background: hsl(var(--rag) 65% 45% / 0.92);
}
.sc-time {
  min-width: 40px;
  font-size: 10px;
  padding: 0 3px;
  text-align: right;
  color: hsl(var(--rag) 85% 32%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .sc-time {
    color: hsl(var(--rag) 70% 58%);
  }
}
:root[data-theme='dark'] .sc-time {
  color: hsl(var(--rag) 70% 58%);
}
.sc-none {
  background: transparent;
}

/* Driver focus: everything about one car, picked across the top —
   a dashboard window of its own (reached from the detail panel). */
body[data-dash='driver'] #grid,
body[data-dash='driver'] #focus-panel,
body[data-dash='driver'] .focus-backdrop {
  display: none;
}
body[data-dash='driver'] #dash-driver {
  display: flex;
  gap: 10px;
  overflow: auto;
  padding: 54px 14px 14px;
}
.drv-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.drv-chip {
  font: 700 11px var(--font-mono);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 4px solid var(--team);
  border-radius: 4px;
  padding: 3px 7px;
  cursor: pointer;
  white-space: nowrap;
}
.drv-chip:hover {
  background: var(--surface-2);
}
.drv-chip.active {
  background: var(--team);
  border-color: var(--team);
  color: #fff;
}
.drv-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 700 15px var(--font-ui);
}
.drv-head .hint {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-dim);
}
.drv-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}
.drv-card {
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  min-width: 0;
  font-size: 12px;
}
.drv-card h3 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.drv-card .spark-plot {
  height: 80px;
}
.drv-laps {
  flex: none;
  overflow-x: auto;
}
.drv-laps table {
  border-collapse: collapse;
  width: 100%;
}
.drv-laps th {
  text-align: right;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-bottom: 1px solid var(--line);
}
.drv-laps td {
  padding: 2px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
  white-space: nowrap;
}

@media (max-width: 640px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }
  body {
    overflow-y: auto;
    overflow-x: hidden;
  }
  /* The header stays put so Edit and the menu are always reachable
     while the widgets scroll under it. */
  #header {
    position: sticky;
    top: 0;
    z-index: 55;
  }
  /* One column: every widget full width in the user's order (stretch,
     not the grid's align-items:start, or they shrink to content). */
  #grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: visible;
  }
  .widget {
    flex: none;
  }
  .widget.max {
    position: fixed;
  }
  .widget[data-widget='events'] .widget-body {
    max-height: 45vh;
  }
  /* Detailed board scrolls sideways within its card rather than
     widening the page; Simple already fits. */
  .widget[data-widget='board'] .widget-body {
    overflow-x: auto;
    overflow-y: hidden;
  }
  .widget[data-widget='track']:not(.max) .widget-body,
  .widget[data-widget='sectors']:not(.max) .widget-body,
  .widget[data-widget='outlook']:not(.max) .widget-body,
  .widget[data-widget='ribbon'][data-view='circles']:not(.max) .widget-body {
    height: 66vh;
  }
  /* Comfortable thumb targets on touch screens. */
  .wbtn {
    min-width: 40px;
    min-height: 36px;
  }
  #timing-board td,
  #timing-board th {
    padding-left: 4px;
    padding-right: 4px;
  }
  .mini-bars {
    width: 26px;
    height: 14px;
  }

  .hdr-mid {
    display: none;
  }
  /* Combine mode + track status: the flag becomes a colour chip beside
     the mode chip so DEMO·GREEN read as one compact unit. */
  .hdr-status #flag-chip {
    width: 12px;
    height: 18px;
    padding: 0;
    font-size: 0;
    border-radius: 3px;
  }
  /* Icon-only Edit on a phone to keep the header on one row. */
  .hdr-edit {
    padding: 3px 9px;
  }
  .hdr-edit-label {
    display: none;
  }
  .menu {
    left: 6px;
    right: 6px;
    width: auto;
  }
  .gate-banner {
    gap: 8px;
    flex-wrap: wrap;
  }

  /* Sector pace on a phone: the three sector panels stack. */
  #dash-sectors {
    flex-direction: column;
    overflow-y: auto;
  }
  .sector-col {
    flex: none;
  }
  .sector-scroll {
    max-height: 42vh;
  }
}

/* Stylised track map: shape keyed by session, positions from live
   timing gaps. */
.track-title {
  width: min(100%, 980px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--text-dim);
  font: 12px/1.4 var(--font-ui);
  padding-right: 72px;
}
.track-title div,
.track-title label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.track-title b {
  flex: none;
  color: var(--text);
  font-size: 14px;
}
.track-title select {
  max-width: min(46vw, 310px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  font: inherit;
}
#track-svg-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
#dash-track svg {
  height: 100%;
  min-height: 0;
  max-width: min(100%, 1080px);
}
/* Track built up in layers (widest first = underneath): a red/white
   kerb ring, a crisp white edge line, then the asphalt on top — so it
   reads like real tarmac with painted edges rather than a faint band.
   All four <path>s share the same geometry; only stroke width/colour
   differ. */
.track-kerb-red,
.track-kerb-white,
.track-line,
.track-edge {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.track-kerb-red {
  stroke: #d62839;
  stroke-width: 28;
  stroke-dasharray: 11 11;
}
.track-kerb-white {
  stroke: #fff;
  stroke-width: 28;
  stroke-dasharray: 11 11;
  stroke-dashoffset: 11;
}
.track-edge {
  stroke: #fff;
  stroke-width: 22;
}
.track-line {
  stroke: var(--track-tarmac);
  stroke-width: 18;
}
.track-pit {
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 9;
  stroke-dasharray: 12 10;
  stroke-linecap: round;
  opacity: 0.7;
}
.track-sf {
  stroke: #fff;
  stroke-width: 6;
  stroke-linecap: butt;
}
.track-label,
.track-sector-label {
  fill: var(--text);
  font: 700 22px var(--font-ui);
  text-anchor: middle;
}
.track-sector {
  stroke: var(--amber);
  stroke-width: 4;
  stroke-linecap: round;
}
.track-sector-label {
  fill: var(--amber);
  font-size: 15px;
}
.track-corner {
  fill: var(--text-dim);
  font: 600 11px var(--font-ui);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 5;
  stroke-linejoin: round;
}
.track-exit {
  opacity: 0.78;
}
.track-exit circle {
  fill: color-mix(in srgb, var(--surface) 72%, transparent);
  stroke: var(--green);
  stroke-width: 3;
  stroke-dasharray: 5 4;
}
.track-exit text {
  fill: var(--green);
  font: 800 10px var(--font-mono);
  text-anchor: middle;
}
.track-exit.closing circle {
  stroke: var(--amber);
}
.track-exit.closing text {
  fill: var(--amber);
}
.track-car.boost circle {
  filter: drop-shadow(0 0 10px var(--purple));
  stroke: var(--purple);
  stroke-width: 5;
}
.track-car circle {
  stroke: #fff;
  stroke-width: 3;
}
.track-car text {
  fill: #fff;
  font: 800 13px var(--font-mono);
  text-anchor: middle;
}
.track-car.inpit {
  opacity: 0.5;
}
.track-legend {
  width: min(100%, 980px);
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  color: var(--text-dim);
  font: 12px var(--font-ui);
}
.open-dot::before {
  content: '';
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid var(--green);
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -2px;
}

/* --- Free-preview countdown, pay sheet, toast --------------------------
   Late in the file on purpose: these restyle .btn and the modal card,
   so they must win the cascade over the base component rules. */

.gate-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px 12px;
  font: 600 14px var(--font-ui);
  color: #fff;
  background: var(--accent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 60%, #000);
}
/* This block sits after the generic .hidden rule — restate it. */
.gate-banner.hidden {
  display: none;
}
.gate-banner #gate-banner-text {
  font-variant-numeric: tabular-nums;
}
.gate-banner-close {
  background: none;
  border: none;
  color: #fff;
  opacity: 0.75;
  font-size: 15px;
  min-width: 36px;
  min-height: 32px;
  cursor: pointer;
}
.gate-banner-close:hover {
  opacity: 1;
}

.pay-card {
  max-width: 400px;
  width: calc(100vw - 32px);
  text-align: center;
}
.pay-clock {
  font-size: 34px;
  line-height: 1;
  margin: 2px 0 6px;
}
.pay-card h3 {
  font-size: 17px;
  text-transform: none;
  letter-spacing: 0;
}
.pay-countdown {
  font: 700 30px var(--font-mono);
  font-variant-numeric: tabular-nums;
  margin: 2px 0 6px;
}
.pay-card p {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.paywall-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 10px;
}
.btn.btn-big {
  min-height: 46px;
  font: 600 15px var(--font-ui);
  border-radius: 10px;
}
.btn.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn.btn-primary:hover {
  filter: brightness(1.08);
}
.pay-methods {
  font: 600 12px var(--font-ui);
  color: var(--text-dim);
  margin-bottom: 10px;
  min-height: 1em;
}
.pay-card .pay-note {
  font-size: 12px;
  margin-bottom: 4px;
}
body.paywalled #grid {
  filter: grayscale(0.8) opacity(0.55);
  pointer-events: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 130;
  background: var(--text);
  color: var(--bg);
  font: 600 14px var(--font-ui);
  padding: 10px 18px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}

/* --- private replay (transport bar + browser) ---------------------------- */

.replay-bar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-family: var(--font-mono);
  font-size: 13px;
}
/* The bar sets display:flex above, which (same specificity, declared
   later) beat the generic `.hidden` rule — so the transport used to show
   even in the shared demo, where its buttons drive nothing. This restores
   the hide so the bar only appears during a private replay. */
.replay-bar.hidden {
  display: none;
}
body.replaying #grid {
  padding-bottom: 56px;
}
/* While a seek rebuilds server-side, show the bar is working rather than
   leaving the buttons looking dead. */
.replay-bar.seeking .rp-time::after {
  content: ' · seeking…';
  color: var(--accent);
}
.replay-bar.seeking #rp-scrub {
  animation: rp-seek-pulse 0.9s ease-in-out infinite;
}
@keyframes rp-seek-pulse {
  50% {
    opacity: 0.55;
  }
}
.rp-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 9px;
  font: inherit;
  cursor: pointer;
  min-width: 40px;
}
.rp-btn:hover {
  border-color: var(--accent);
}
.rp-play {
  min-width: 48px;
}
.rp-exit {
  color: var(--red);
}
.rp-title {
  color: var(--text-dim);
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#rp-scrub {
  flex: 1;
  min-width: 60px;
  accent-color: var(--accent);
}
.rp-time {
  color: var(--text-dim);
  white-space: nowrap;
}
@media (max-width: 560px) {
  .rp-title {
    display: none;
  }
}

.replay-blurb {
  color: var(--text-dim);
  margin: 0 0 10px;
}
.replay-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 55vh;
  overflow-y: auto;
}
.replay-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  cursor: pointer;
}
.replay-item:hover {
  border-color: var(--accent);
}
.replay-item-name {
  font-weight: 600;
}
.replay-item-meta {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

/* --- battery saver / constrained browsers (e.g. Tesla) ------------------- */
/* Saver mode trades polish for GPU/CPU headroom: no drop shadows, no
   decorative pulse animations. Data-carrying motion (cell flash) stays. */
body.saver .widget,
body.saver .menu,
body.saver .info-modal-card,
body.saver .replay-bar,
body.saver #focus-panel {
  box-shadow: none;
}
body.saver .feed-heart.beat {
  animation: none;
}
body.saver .feed-heart.stalled {
  animation: none;
}
