@font-face {
  font-family: "Bebas Neue Pro";
  src: url("/assets/BebasNeuePro-Regular.otf") format("opentype");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --background: #f1f1f2;
  --surface: #ffffff;
  --surface-2: #ececee;
  --surface-3: #dcdcdf;
  --border: #cfcfd3;
  --text: #161616;
  --secondary-text: #505055;
  --muted-text: #717176;
  --brand-red: #af0101;
  --red-hover: #8e0000;
  --red-light: #f7e7e7;
  --red-accent: #af0101;
  --success: #187747;
  --warning: #8a5800;
  --info: #256a9b;
  --error: #af0101;
  --shadow: 0 8px 24px rgb(0 0 0 / 8%);
  --topbar-height: 60px;
  --gap: 12px;
  --touch: 48px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #0d0d0e;
  --surface: #17171a;
  --surface-2: #202024;
  --surface-3: #2b2b30;
  --border: #3a3a40;
  --text: #f7f7f7;
  --secondary-text: #c0c0c4;
  --muted-text: #8e8e94;
  --red-hover: #cf1010;
  --red-light: #341516;
  --red-accent: #ff7474;
  --success: #54c58a;
  --warning: #f1b64b;
  --info: #6cb0df;
  --error: #ff7474;
  --shadow: 0 10px 30px rgb(0 0 0 / 35%);
}

* {
  box-sizing: border-box;
}

/* `hidden` must win over component display rules (links styled as buttons are inline-flex). */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  color: var(--text);
  background: var(--background);
  font: 15px/1.35 Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
.link-button {
  font: inherit;
  touch-action: manipulation;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: "Bebas Neue Pro", Impact, sans-serif;
  font-weight: 400;
  letter-spacing: 0.03em;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  width: 150px;
  height: 32px;
  object-fit: contain;
  object-position: left center;
}

:root[data-theme="dark"] .logo-light,
:root[data-theme="light"] .logo-dark {
  display: none;
}

.brand h1 {
  overflow: hidden;
  font-size: 28px;
  line-height: 1;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.connection {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 6px;
  color: var(--muted-text);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.connection span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted-text);
}

.connection.is-live {
  color: var(--success);
}

.connection.is-live span {
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 20%, transparent);
}

.connection.is-lost {
  color: var(--error);
}

.connection.is-lost span {
  background: var(--error);
}

/* ---------- Board: every graphic on one screen ---------- */

/* Three columns in running order: Scorebug over Left Slab, Top Hat over Flag Overlay,
   Lower 3rd over Driver Info. */
.board {
  --preview-max: clamp(56px, 13vh, 150px);
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.25fr) minmax(0, 1fr);
  gap: var(--gap);
  min-height: 0;
  padding: var(--gap) max(var(--gap), env(safe-area-inset-right)) max(var(--gap), env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
  overflow: auto;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
  min-height: 0;
}

.stack > .tile {
  flex: 1 1 auto;
}

.tile {
  position: relative;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tile::before {
  position: absolute;
  inset: -1px auto -1px -1px;
  width: 5px;
  border-radius: 12px 0 0 12px;
  background: var(--surface-3);
  content: "";
}

.tile.is-visible::before {
  background: var(--brand-red);
}

.tile.is-dirty::before {
  background: var(--warning);
}

.tile.is-visible.is-dirty::before {
  background: linear-gradient(var(--brand-red) 50%, var(--warning) 50%);
}

.tile-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.tile-head h2 {
  flex: 1;
  overflow: hidden;
  font-size: 30px;
  line-height: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status-pill,
.dirty-pill {
  flex: none;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pill {
  color: var(--muted-text);
  background: var(--surface-2);
}

.status-pill.is-on {
  color: #fff;
  background: var(--brand-red);
}

.dirty-pill {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 16%, transparent);
}

.more-button {
  flex: none;
  width: 40px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  color: var(--secondary-text);
  background: var(--surface-2);
  font-size: 22px;
  line-height: 1;
}

/* Live preview: the real output page in preview mode, fed this tile's unsent edits. */
.preview {
  position: relative;
  flex: none;
  width: 100%;
  max-height: var(--preview-max);
  aspect-ratio: var(--ratio);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: repeating-conic-gradient(#303035 0 25%, #26262a 0 50%) 0 0 / 16px 16px;
}

.preview-fill {
  flex: 1 1 140px;
  min-height: 140px;
  max-height: none;
  aspect-ratio: auto;
}

.preview iframe {
  /* Match the output page's light-only scheme, or Chrome paints an opaque backdrop behind it. */
  color-scheme: light;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  pointer-events: none;
}

.preview-tag {
  position: absolute;
  top: 5px;
  left: 5px;
  border-radius: 4px;
  padding: 2px 6px;
  color: #fff;
  background: rgb(0 0 0 / 60%);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  pointer-events: none;
  text-transform: uppercase;
}

.tile.is-dirty .preview {
  border-color: var(--warning);
}

.tile.is-dirty .preview-tag::after {
  content: " · not sent";
  color: var(--warning);
}

.tile-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.tile-note {
  margin: 0;
  color: var(--muted-text);
}

.tile-actions {
  display: grid;
  flex: none;
  grid-template-columns: 1.4fr 1fr;
  gap: 8px;
}

.tile-actions.single {
  grid-template-columns: 1fr;
}

.pair,
.trio,
.wide-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 10px;
}

.trio {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
}

.wide-pair {
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
}

/* ---------- Form controls ---------- */

label {
  display: grid;
  gap: 5px;
  color: var(--secondary-text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: var(--touch);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--background);
  font-family: Arial, sans-serif;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

input[type="url"] {
  font-family: Consolas, monospace;
  font-size: 14px;
}

input:focus,
select:focus {
  border-color: var(--brand-red);
  outline: 3px solid color-mix(in srgb, var(--brand-red) 22%, transparent);
}

button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  color: #fff;
  background: var(--brand-red);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background 120ms ease, transform 120ms ease, opacity 120ms ease;
}

button:hover,
.link-button:hover {
  background: var(--red-hover);
}

button:active,
.link-button:active {
  transform: scale(0.97);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.action-toggle {
  min-height: 60px;
  font-size: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* On air the toggle becomes Pull: dark with a red ring so it reads differently from Push at a glance. */
.action-toggle.is-pull {
  color: var(--text);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 3px var(--brand-red);
}

.action-toggle.is-pull:hover {
  background: var(--border);
}

.action-update,
.quiet-button,
.bar-button {
  color: var(--text);
  background: var(--surface-3);
}

.action-update {
  min-height: 60px;
  font-size: 17px;
}

.action-update:hover,
.quiet-button:hover,
.bar-button:hover {
  background: var(--border);
}

.action-update.is-primed {
  color: #111;
  background: var(--warning);
}

.bar-button {
  min-height: 42px;
  padding: 8px 14px;
  font-size: 14px;
}

.switch-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.switch-field.compact {
  font-size: 13px;
}

.switch-field input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
}

.switch {
  position: relative;
  flex: none;
  width: 50px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background 150ms ease;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition: transform 150ms ease;
}

.switch-field input:checked + .switch {
  background: var(--brand-red);
}

.switch-field input:checked + .switch::after {
  transform: translateX(22px);
}

.switch-field input:focus-visible + .switch {
  outline: 3px solid color-mix(in srgb, var(--brand-red) 40%, transparent);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

.check-field input {
  width: 22px;
  min-height: 22px;
  height: 22px;
  accent-color: var(--brand-red);
}

/* ---------- Flag overlay ---------- */

.flag-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.flag-push,
.flag-swatch {
  color: #111;
}

.flag-push {
  min-height: 60px;
  padding: 8px 6px;
  font-size: 16px;
  text-transform: uppercase;
}

/* Same gradients as Riivet's flag images and the on-air card. */
.flag-green {
  background: linear-gradient(#00ff00, #00bd00);
}

.flag-yellow {
  background: linear-gradient(#ffff00, #bcbc00);
}

.flag-white {
  background: linear-gradient(#ffffff, #bdbdbd);
}

.flag-push:hover {
  filter: brightness(0.92);
}

.flag-push.is-live {
  box-shadow: inset 0 0 0 4px var(--brand-red), 0 0 0 2px var(--surface);
}

.flag-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.flag-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.flag-column {
  display: grid;
  gap: 10px;
  min-width: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface-2);
}

.flag-column legend {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  font-family: "Bebas Neue Pro", Impact, sans-serif;
  font-size: 22px;
  letter-spacing: 0.03em;
}

.hold-field {
  max-width: 320px;
}

/* ---------- Driver Info ---------- */

.driver-side,
.driver-fields {
  display: grid;
  gap: 10px;
  align-content: start;
}

/* A wide Driver Info tile puts the presets beside the lines instead of above them. */
/* Presets sit beside the lines only when the tile can give three preset columns readable labels;
   narrower (a portrait iPad's two-column board), they stack on top at full width. */
@container (min-width: 520px) {
  .driver-body {
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    align-content: start;
  }
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.preset-button {
  min-height: 40px;
  padding: 4px 3px;
  color: var(--text);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 13px;
  line-height: 1.1;
}

.preset-button:hover {
  background: var(--surface-3);
}

.preset-button.is-active {
  box-shadow: inset 0 0 0 2px var(--brand-red);
}

.preset-button.is-hard-luck {
  color: #111;
  background: var(--warning);
}


/* ---------- Sheets (dialogs) ---------- */

.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 30px 80px rgb(0 0 0 / 45%);
}

.sheet[open] {
  display: grid;
  gap: 14px;
  align-content: start;
}

.sheet::backdrop {
  background: rgb(0 0 0 / 55%);
}

.sheet h3 {
  font-size: 30px;
}

.wide-sheet {
  width: min(960px, calc(100vw - 24px));
}

.sheet-note {
  margin: 0;
  color: var(--muted-text);
  font-size: 14px;
}

.placement-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.sheet-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sheet-actions > * {
  flex: 1;
}

/* Reset lives at the bottom of the position sheet, behind a confirmation, so it is never a stray tap. */
.danger-zone {
  display: flex;
  justify-content: flex-end;
  border-top: 1px dashed var(--border);
  padding-top: 14px;
}

.reset-button {
  color: var(--error);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--error);
  font-size: 14px;
}

.reset-button:hover {
  color: #fff;
  background: var(--brand-red);
}

.settings-sheet {
  width: min(1000px, calc(100vw - 24px));
  height: calc(100dvh - 24px);
  overflow: auto;
}

.settings-head {
  position: sticky;
  top: -20px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -20px -20px 0;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  background: var(--surface);
}

.settings-section {
  display: grid;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head h4 {
  font-size: 24px;
}

.section-head small {
  margin-left: 8px;
  color: var(--muted-text);
  font-family: Arial, sans-serif;
  font-size: 12px;
  letter-spacing: 0;
}

.output-url {
  color: var(--secondary-text);
  overflow-wrap: anywhere;
}

.logo-drop {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  color: var(--muted-text);
  text-align: center;
}

.logo-drop.is-dragging {
  border-color: var(--brand-red);
  background: var(--red-light);
}

.logo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.logo-list:empty {
  display: none;
}

.logo-list li {
  display: grid;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: var(--surface-2);
}

.logo-list img {
  width: 100%;
  height: 80px;
  border-radius: 6px;
  object-fit: contain;
  background: #555;
}

.logo-list span {
  overflow: hidden;
  color: var(--secondary-text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logo-list .delete-logo {
  min-height: 40px;
  color: var(--text);
  background: var(--surface-3);
  font-size: 13px;
}

.feed-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.feed-list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  border-left: 3px solid var(--surface-3);
  padding: 6px 10px;
  background: var(--surface-2);
  font-size: 13px;
}

.feed-list li.is-ok {
  border-left-color: var(--success);
}

.feed-list li.is-error {
  border-left-color: var(--error);
}

.feed-list li.is-error span {
  color: var(--error);
}

.feed-list code {
  overflow-wrap: anywhere;
}

.feed-list span {
  color: var(--muted-text);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(720px, calc(100vw - 24px));
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--error);
  color: var(--error);
}

/* ---------- Smaller screens ---------- */

/* Narrow landscape tablets: widen the Lower 3rd / Driver Info column so Driver Info keeps its
   presets beside the lines. */
@media (max-width: 1150px) {
  .board {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr) minmax(0, 1.25fr);
  }
}

@media (max-width: 900px) {
  .board {
    grid-template-columns: 1fr;
  }

  .stack > .tile {
    flex: none;
  }

  .brand h1,
  .connection {
    display: none;
  }

  .flag-columns {
    grid-template-columns: 1fr;
  }
}

/* Short screens: tighten vertical spacing so both tiles in each column still fit. */
@media (max-height: 900px) and (min-width: 901px) {
  :root {
    --touch: 44px;
    --gap: 8px;
  }

  .tile {
    gap: 8px;
    padding: 10px;
  }

  .tile-head {
    min-height: 34px;
  }

  .tile-head h2 {
    font-size: 26px;
  }

  .more-button {
    width: 36px;
    min-height: 36px;
  }

  .tile-body,
  .driver-side,
  .driver-fields {
    gap: 8px;
  }

  label {
    gap: 3px;
    font-size: 11px;
  }

  .action-toggle,
  .action-update,
  .flag-push {
    min-height: 46px;
  }

  .action-toggle {
    font-size: 18px;
  }

  .preset-button {
    min-height: 36px;
    font-size: 12px;
  }
}

/* ---------- MRP: data-source switching ---------- */

body[data-source="riivet"] .mrp-only,
body[data-source="mrp"] .riivet-only {
  display: none !important;
}

/* ---------- Four columns: the fourth holds Lineups ---------- */

.board {
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr);
}

/* Two columns scroll instead of squeezing: each stack takes the height its tiles need. */
@media (max-width: 1400px) and (min-width: 901px) {
  .board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: max-content;
  }

  .stack {
    min-height: auto;
  }

  .stack > .tile {
    flex: none;
  }
}

.lineup-options {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
}

/* ---------- Race strip ---------- */

.race-strip {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  border-bottom: 1px solid var(--border);
  padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  background: var(--surface-2);
}

.source-buttons {
  display: flex;
  gap: 6px;
}

.source-button {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--secondary-text);
  background: var(--surface);
  font-size: 14px;
  font-weight: 700;
}

.source-button.is-active {
  border-color: var(--brand-red);
  color: #fff;
  background: var(--brand-red);
}

.source-button.is-empty:not(.is-active) {
  opacity: 0.5;
}

.live-info {
  display: flex;
  flex: 1 1 320px;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.poll-state {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  color: var(--muted-text);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.poll-state span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted-text);
}

.poll-state.is-live {
  color: var(--success);
}

.poll-state.is-live span {
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 20%, transparent);
}

.poll-state.is-lost {
  color: var(--error);
}

.poll-state.is-lost span {
  background: var(--error);
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  to {
    opacity: 0.3;
  }
}

.live-event {
  overflow: hidden;
  font-family: "Bebas Neue Pro", Impact, sans-serif;
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 0.03em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.live-details {
  overflow: hidden;
  color: var(--secondary-text);
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.strip-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.strip-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.strip-controls select {
  width: auto;
  min-height: 40px;
  padding: 6px 10px;
  font-size: 14px;
}

.strip-controls .is-overridden,
.bar-button.is-overridden {
  border-color: var(--warning);
  color: var(--warning);
  box-shadow: inset 0 0 0 1px var(--warning);
}

.missing-section {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.missing-section h4 {
  font-size: 22px;
}

.missing-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.missing-list li {
  display: grid;
  grid-template-columns: 44px 90px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

/* ---------- Driver Info: lineup picker ---------- */

.driver-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
}

.driver-picker select {
  min-height: 40px;
  padding: 6px 8px;
  font-size: 14px;
}

/* ---------- Settings: MRP ---------- */

.segmented {
  display: flex;
  gap: 8px;
}

.segmented label {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-height: var(--touch);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.segmented label:has(input:checked) {
  border-color: var(--brand-red);
  box-shadow: inset 0 0 0 1px var(--brand-red);
}

.segmented input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand-red);
}

.mrp-settings {
  display: grid;
  gap: 12px;
}

.source-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.source-table th {
  padding: 0 4px 4px;
  color: var(--secondary-text);
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
}

.source-table th:first-child {
  width: 16%;
}

.source-table th:last-child {
  width: 18%;
}

.source-table td {
  padding: 3px 4px;
  vertical-align: top;
}

.source-table input {
  min-height: 40px;
  padding: 6px 8px;
}

.source-test {
  display: block;
  color: var(--muted-text);
  font-size: 12px;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.source-test.is-ok {
  color: var(--success);
}

.source-test.is-error {
  color: var(--error);
}

.quad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 10px;
}

.class-overrides summary {
  color: var(--secondary-text);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.class-overrides summary small {
  color: var(--muted-text);
  font-weight: 400;
  text-transform: none;
}

.class-overrides[open] summary {
  margin-bottom: 8px;
}

.class-override-rows {
  display: grid;
  gap: 6px;
}

.class-override-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.class-override-row input {
  min-height: 40px;
  padding: 6px 8px;
}

.results-list {
  display: grid;
  gap: 8px;
  max-height: 300px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.results-list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
}

.results-list li.is-empty {
  color: var(--muted-text);
}

.results-list li > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.results-list strong {
  flex: 1;
}

.results-list .is-final {
  color: var(--success);
  font-size: 12px;
}

.results-list .is-running {
  color: var(--warning);
  font-size: 12px;
}

.results-list p {
  margin: 4px 0 0;
  color: var(--secondary-text);
  font-size: 13px;
}

@media (max-width: 900px) {
  .race-strip {
    align-items: stretch;
  }

  .source-table,
  .source-table tbody,
  .source-table tr,
  .source-table td {
    display: block;
    width: 100%;
  }

  .source-table thead {
    display: none;
  }

  .source-table tr {
    margin-bottom: 10px;
  }

  .quad {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}


/* ---------- Tablets: touch, full screen, and a one-line race bar ---------- */

html {
  -webkit-text-size-adjust: 100%;
}

/* No rubber-band bounce or double-tap zoom while operating in full screen. */
body {
  overscroll-behavior: none;
}

button,
select,
input,
label,
a {
  touch-action: manipulation;
}

/* Launched from the home screen: keep the top bar clear of the iPad status bar. */
.topbar {
  height: calc(var(--topbar-height) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}

@media (min-width: 901px) {
  .race-strip {
    flex-wrap: nowrap;
  }

  .live-info {
    flex: 1 1 0;
    min-width: 0;
  }

  .strip-controls {
    flex: none;
    flex-wrap: nowrap;
  }
}

/* Tablet widths: drop the strip's secondary text so the controls stay on one line. */
@media (min-width: 901px) and (max-width: 1400px) {
  .live-details {
    display: none;
  }

  .strip-controls label {
    gap: 0;
    font-size: 0;
  }

  .source-button {
    padding: 6px 9px;
  }
}


/* Landscape tablets (every iPad is 1024-1366 wide): every column on one screen, no page scroll.
   A column that runs long scrolls on its own. */
@media (min-width: 1000px) and (max-width: 1400px) {
  .board {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-auto-rows: auto;
    overflow: hidden;
  }

  .stack {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* Portrait tablets: two columns, and the page scrolls. */
@media (min-width: 700px) and (max-width: 999px) {
  .board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: max-content;
    overflow: auto;
  }

  .stack {
    min-height: auto;
    overflow: visible;
  }

  .stack > .tile {
    flex: none;
  }
}

/* Short landscape screens (1024x768 iPads): tighter vertical spacing so every Push button stays on
   screen without scrolling. Controls stay at least 42px tall for fingers. */
@media (max-height: 800px) and (min-width: 1000px) {
  :root {
    --topbar-height: 50px;
    --touch: 42px;
  }

  .board {
    --preview-max: clamp(48px, 10vh, 110px);
  }

  .race-strip {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .tile {
    gap: 6px;
  }

  .tile-body {
    gap: 6px;
  }

  .action-toggle,
  .action-update {
    min-height: 42px;
  }
}

/* Top Hat auto in/out: the switch and what the automation is doing right now. */
.auto-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}

.auto-note {
  flex: 1 1 160px;
  min-width: 0;
  font-size: 13px;
}

/* Minimize hotlaps: Scorebug and Left Slab shrink to their name, status, and Push button. */
body.hotlaps-min .hotlaps-stack > .tile {
  flex: none;
}

body.hotlaps-min .hotlaps-stack :is(.preview, .tile-body, .dirty-pill, .more-button, [data-action="update"]) {
  display: none;
}

body.hotlaps-min .hotlaps-stack .tile-head {
  flex-wrap: wrap;
  min-height: 0;
}

body.hotlaps-min .hotlaps-stack .tile-head h2 {
  font-size: 22px;
}

body.hotlaps-min .hotlaps-stack .tile-actions {
  grid-template-columns: 1fr;
}

/* Four columns here (the CRUSA board has three); the shrunken first column gives its room to the rest. */
body.hotlaps-min .board {
  grid-template-columns: minmax(170px, 0.3fr) minmax(0, 1.3fr) minmax(0, 1.1fr) minmax(0, 1.1fr);
}

/* Two-column and phone layouts: the two small tiles sit side by side across the top. */
@media (max-width: 999px) {
  body.hotlaps-min .board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.hotlaps-min .hotlaps-stack {
    grid-column: 1 / -1;
    flex-direction: row;
  }

  body.hotlaps-min .hotlaps-stack > .tile {
    flex: 1 1 0;
  }
}

@media (max-width: 699px) {
  body.hotlaps-min .board {
    grid-template-columns: 1fr;
  }
}

#hotlaps-toggle[aria-pressed="true"] {
  border-color: var(--red-accent);
}

/* Top Hat auto-out delay: a compact seconds box beside the Auto in/out switch. */
.auto-delay {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}

.auto-delay input {
  width: 64px;
  min-height: 36px;
  padding: 4px 8px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* The brand doubles as the way back to the events list. */
a.brand {
  color: inherit;
  text-decoration: none;
}

a.brand:hover h1 {
  color: var(--red-accent);
}

.quiet-link {
  color: var(--text);
  background: var(--surface-3);
}

.signed-in-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  color: var(--secondary-text);
  font-size: 14px;
}

/* Companion & AV bridge: label, value, then Show / Copy. */
.key-rows {
  display: grid;
  gap: 8px;
}

.key-row {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  color: var(--secondary-text);
  font-size: 14px;
}

.key-row code {
  overflow-wrap: anywhere;
  user-select: all;
}

/* Copy always sits in the last column, so both rows line up. */
.key-row > button:last-child {
  grid-column: 4;
}


/* =====================================================================================
   Compact layout (2026-10-27), the same in MRP Graphics and CRUSA Graphics:
   one top bar with a menu, hot laps hidden into the bar, a visual logo picker, and
   Settings shortcuts. These rules come last so they win over the older layout rules above.
   ===================================================================================== */

/* ---------- One bar ---------- */

.command-bar {
  position: relative;
  z-index: 30;
  gap: 10px;
  --topbar-height: 58px;
}

.command-bar .brand {
  flex: none;
  gap: 10px;
  max-width: 300px;
}

.command-bar .brand-logo {
  width: 104px;
  height: 30px;
}

.command-bar .brand h1 {
  min-width: 0;
  font-size: 22px;
  text-overflow: ellipsis;
}

/* The race data sits in the bar now instead of a second strip. */
.command-bar .race-strip {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 0;
  padding: 0;
  background: none;
}

.command-bar .source-buttons {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 34vw;
  overflow-x: auto;
  scrollbar-width: none;
}

.command-bar .source-buttons::-webkit-scrollbar {
  display: none;
}

.command-bar .source-button {
  flex: none;
  min-height: 38px;
  padding: 4px 11px;
  font-size: 13px;
}

/* One source set up: it's a label, not a choice. */
.command-bar .source-button:only-child {
  pointer-events: none;
}

.command-bar .live-info {
  flex: 1 1 0;
  gap: 8px;
  min-width: 0;
}

.command-bar .live-event {
  min-width: 0;
  font-size: 22px;
}

.command-bar .topbar-actions {
  flex: none;
  gap: 6px;
}

.command-bar .connection {
  margin-right: 2px;
}

.command-bar .strip-controls {
  flex-wrap: nowrap;
  gap: 6px;
}

.command-bar .bar-button {
  min-height: 40px;
  padding: 6px 12px;
  white-space: nowrap;
}

.menu-button {
  position: relative;
  width: 46px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.menu-button[aria-expanded="true"] {
  box-shadow: inset 0 0 0 2px var(--brand-red);
}

/* A race-night override is set in the menu (transfers or order). */
.menu-button.has-override::after {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warning);
  content: "";
}

/* ---------- Menu ---------- */

.app-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: max(10px, env(safe-area-inset-right));
  display: grid;
  gap: 12px;
  width: min(320px, calc(100vw - 20px));
  max-height: calc(100dvh - var(--topbar-height) - 24px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgb(0 0 0 / 45%);
}

.app-menu[hidden] {
  display: none;
}

.menu-group {
  display: grid;
  gap: 6px;
}

.menu-group + .menu-group {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.menu-label {
  color: var(--muted-text);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.app-menu label {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.app-menu select {
  min-height: 42px;
  padding: 6px 10px;
  font-size: 15px;
}

.app-menu .is-overridden {
  border-color: var(--warning);
  color: var(--warning);
  box-shadow: inset 0 0 0 1px var(--warning);
}

.menu-item {
  justify-content: flex-start;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  color: var(--text);
  background: var(--surface-2);
  font-size: 15px;
  text-align: left;
}

/* All events is a link; it looks like the menu buttons around it. */
a.menu-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.menu-item:hover {
  background: var(--surface-3);
}

.menu-item[aria-pressed="true"] {
  border-color: var(--brand-red);
}

.compact-only {
  display: none;
}

/* ---------- Hot laps: off the board, into the bar ---------- */

.hotlaps-bar {
  display: none;
  flex: none;
  gap: 6px;
}

body.hotlaps-min .hotlaps-bar {
  display: flex;
}

body.hotlaps-min .hotlaps-stack {
  display: none;
}

.hotlap-chip {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  min-height: 42px;
  border: 1px solid var(--border);
  padding: 3px 11px;
  color: var(--text);
  background: var(--surface-2);
  line-height: 1.05;
  white-space: nowrap;
}

.hotlap-chip:hover {
  background: var(--surface-3);
}

.hotlap-chip b {
  font-family: "Bebas Neue Pro", Impact, sans-serif;
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.03em;
}

.hotlap-chip small {
  color: var(--muted-text);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hotlap-chip.is-on {
  border-color: var(--brand-red);
  color: #fff;
  background: var(--brand-red);
}

.hotlap-chip.is-on small {
  color: #fff;
}

/* The board without the hot laps column: CRUSA keeps two columns, MRP three. */
body.hotlaps-min .board {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
}

body.hotlaps-min .board:has(> div.stack:nth-of-type(4)) {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1fr);
}

/* ---------- Logo picker ---------- */

.logo-select-native {
  display: none !important;
}

.logo-pick {
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: var(--touch);
  border: 1px solid var(--border);
  padding: 4px 30px 4px 4px;
  color: var(--text);
  background: var(--background);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  text-align: left;
  text-transform: none;
  position: relative;
}

.logo-pick:hover {
  background: var(--surface-2);
}

.logo-pick::after {
  position: absolute;
  right: 10px;
  color: var(--muted-text);
  content: "▾";
}

.logo-pick img,
.logo-option img {
  flex: none;
  border-radius: 5px;
  background: #101012;
  object-fit: contain;
}

.logo-pick img {
  width: 58px;
  height: calc(var(--touch) - 10px);
}

.logo-pick img.is-blank,
.logo-option img.is-blank {
  background: repeating-linear-gradient(45deg, #1b1b1f 0 6px, #26262b 6px 12px);
}

.logo-pick span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logo-picker-sheet {
  width: min(900px, calc(100vw - 24px));
}

.logo-picker-sheet h3 {
  font-size: 26px;
}

.logo-picker-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.logo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  max-height: min(62dvh, 640px);
  margin: 0;
  overflow: auto;
  padding: 2px;
  list-style: none;
  overscroll-behavior: contain;
}

.logo-option {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 7px;
  color: var(--text);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.logo-option:hover {
  background: var(--surface-3);
}

.logo-option img {
  width: 100%;
  height: 66px;
}

.logo-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logo-option.is-current {
  border-color: var(--brand-red);
}

.logo-option.is-default span {
  color: var(--secondary-text);
  font-style: italic;
}

/* ---------- Settings shortcuts ---------- */

#settings .settings-head {
  flex-wrap: wrap;
  row-gap: 10px;
}

.settings-nav {
  display: flex;
  flex-basis: 100%;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.settings-nav::-webkit-scrollbar {
  display: none;
}

.settings-nav-link {
  flex: none;
  min-height: 36px;
  border: 1px solid var(--border);
  padding: 4px 12px;
  color: var(--text);
  background: var(--surface-2);
  font-size: 13px;
}

.settings-nav-link:hover {
  background: var(--surface-3);
}

.settings-section {
  scroll-margin-top: 120px;
}

/* ---------- Sizes ---------- */

/* Wide screens have room for the strip's details; tablets keep only the race name. */
@media (max-width: 1399px) {
  .command-bar .live-details {
    display: none;
  }
}

/* Narrow landscape and portrait tablets: the event name gives way to the race data. */
@media (max-width: 1199px) {
  .command-bar .brand h1 {
    display: none;
  }

  .command-bar .connection {
    font-size: 0;
    gap: 0;
  }
}

/* Portrait tablets: two columns, page scroll (also without hot laps). */
@media (max-width: 999px) {
  body.hotlaps-min .board,
  body.hotlaps-min .board:has(> div.stack:nth-of-type(4)) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .command-bar .source-buttons {
    max-width: 28vw;
  }

  .hotlap-chip small {
    display: none;
  }
}

/* Phones: one column; Race override and Pause move into the menu. */
@media (max-width: 699px) {
  .command-bar {
    gap: 6px;
    --topbar-height: 54px;
  }

  .command-bar .brand-logo {
    width: 56px;
  }

  .command-bar .strip-controls,
  .command-bar .connection,
  .command-bar .poll-state b {
    display: none;
  }

  .compact-only {
    display: flex;
  }

  .command-bar .live-event {
    font-size: 18px;
  }

  .command-bar .source-buttons {
    max-width: 30vw;
  }

  .command-bar .source-button {
    padding: 4px 8px;
  }

  .hotlap-chip {
    padding: 3px 8px;
  }

  .hotlap-chip b {
    font-size: 16px;
  }

  body.hotlaps-min .board,
  body.hotlaps-min .board:has(> div.stack:nth-of-type(4)) {
    grid-template-columns: 1fr;
  }

  .logo-grid {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  }

  .logo-picker-tools {
    grid-template-columns: 1fr;
  }
}

/* Portrait tablets and phones: Race override and Pause join the menu, so the race name keeps its room. */
@media (max-width: 999px) {
  .command-bar .strip-controls {
    display: none;
  }

  .compact-only {
    display: flex;
  }
}

/* Portrait tablets: tiles flow down two columns with no gaps (a grid lines up rows and leaves holes
   under the shorter column). */
@media (max-width: 999px) {
  .board,
  body.hotlaps-min .board,
  body.hotlaps-min .board:has(> div.stack:nth-of-type(4)) {
    display: block;
    columns: 2;
    column-gap: var(--gap);
    overflow: auto;
  }

  .board > .stack {
    display: contents;
  }

  .board .tile {
    margin-bottom: var(--gap);
    break-inside: avoid;
  }
}

/* ...and the page scrolls under a pinned top bar, so the columns grow down instead of sideways. */
@media (max-width: 999px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  .board,
  body.hotlaps-min .board,
  body.hotlaps-min .board:has(> div.stack:nth-of-type(4)) {
    flex: none;
    height: auto;
    overflow: visible;
  }

  .command-bar {
    position: sticky;
    top: 0;
  }
}

/* Phones: the same page scroll, one column; the logo leaves the bar ("All events" is in the menu). */
@media (max-width: 699px) {
  .board,
  body.hotlaps-min .board,
  body.hotlaps-min .board:has(> div.stack:nth-of-type(4)) {
    columns: 1;
  }

  .command-bar .brand {
    display: none;
  }

  .command-bar {
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }
}

.hotlap-chip .chip-short {
  display: none;
}

@media (max-width: 699px) {
  .hotlap-chip .chip-long {
    display: none;
  }

  .hotlap-chip .chip-short {
    display: inline;
  }
}

/* ---------- Layout editor: drag graphics on a full view of the output ---------- */

.layout-editor {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border: 0;
  padding: 0;
  color: var(--text);
  background: #0b0b0d;
}

.layout-editor[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.layout-editor::backdrop {
  background: #000;
}

.layout-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  border-bottom: 1px solid var(--border);
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: var(--surface);
}

.layout-bar h3 {
  font-size: 26px;
}

.layout-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.layout-tab {
  min-height: 38px;
  border: 1px solid var(--border);
  padding: 4px 12px;
  color: var(--text);
  background: var(--surface-2);
  font-size: 13px;
}

.layout-tab:hover {
  background: var(--surface-3);
}

.layout-tab[aria-selected="true"] {
  border-color: #ff9f1a;
  box-shadow: inset 0 0 0 1px #ff9f1a;
}

.layout-fields {
  display: flex;
  gap: 8px;
}

.layout-fields label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.layout-fields input {
  width: 82px;
  min-height: 38px;
  padding: 4px 8px;
}

.layout-nudge,
.layout-toggles,
.layout-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.layout-nudge button {
  min-width: 40px;
  min-height: 38px;
  padding: 0;
}

.layout-toggles .switch-field {
  min-height: 38px;
}

.layout-actions {
  margin-left: auto;
}

.layout-actions button {
  min-height: 40px;
  padding: 6px 14px;
}

.layout-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
}

/* The output at 1920x1080, scaled to fit; the overlay uses the same canvas pixels. */
.layout-canvas {
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  background: repeating-conic-gradient(#1c1c20 0% 25%, #141417 0% 50%) 0 0 / 32px 32px;
  box-shadow: 0 0 0 1px #3a3a40;
}

.layout-canvas iframe,
.layout-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  transform: scale(var(--layout-scale, 0.5));
  transform-origin: 0 0;
}

.layout-canvas iframe {
  /* The output page is light-scheme; a frame whose scheme differs from its page is painted opaque. */
  color-scheme: light;
  border: 0;
  background: transparent;
  pointer-events: none;
}

.layout-overlay {
  touch-action: none;
}

.layout-safe {
  position: absolute;
  left: 5%;
  top: 5%;
  right: 5%;
  bottom: 5%;
  border: 3px dashed rgb(255 214 0 / 75%);
  pointer-events: none;
}

.layout-safe span {
  position: absolute;
  top: 6px;
  left: 10px;
  color: rgb(255 214 0 / 90%);
  font: 700 22px Arial, sans-serif;
}

.layout-center {
  position: absolute;
  background: rgb(255 255 255 / 14%);
  pointer-events: none;
}

.layout-center-x {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
}

.layout-center-y {
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
}

.layout-guide {
  position: absolute;
  z-index: 3;
  background: #ff2bd6;
  box-shadow: 0 0 6px #ff2bd6;
  pointer-events: none;
}

.layout-guide-x {
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1px;
}

.layout-guide-y {
  left: 0;
  right: 0;
  height: 3px;
  margin-top: -1px;
}

.layout-box {
  position: absolute;
  z-index: 1;
  border: 3px dashed rgb(255 255 255 / 35%);
  cursor: pointer;
}

.layout-box span {
  position: absolute;
  bottom: 100%;
  left: -3px;
  padding: 2px 10px;
  border-radius: 6px 6px 0 0;
  color: #fff;
  background: rgb(255 255 255 / 25%);
  font: 700 24px Arial, sans-serif;
  white-space: nowrap;
}

.layout-box.is-hidden {
  display: none;
}

.layout-box.is-selected {
  z-index: 2;
  border: 4px solid #ff9f1a;
  background: rgb(255 159 26 / 8%);
  cursor: grab;
}

.layout-box.is-selected span {
  color: #111;
  background: #ff9f1a;
}

.layout-box.is-dragging {
  cursor: grabbing;
}

.layout-help {
  margin: 0;
  padding: 8px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  color: var(--muted-text);
  font-size: 13px;
}

.layout-open {
  justify-self: start;
}

@media (max-width: 999px) {
  .layout-actions {
    margin-left: 0;
  }

  .layout-help {
    display: none;
  }
}

/* ---------- MadSpeed TV additions ---------- */

/* Lit keys (Logan's button standard) for the Left Slab's live chips: raised when off, pressed in with a
   soft ring when on. */
:root {
  --lift-top: inset 0 1px 0 rgb(255 255 255 / 0.9);
  --lift-bottom: inset 0 -1px 0 rgb(16 20 27 / 0.06);
  --lift-contact: 0 1px 2px rgb(16 20 27 / 0.08);
  --lift-glow: 0 3px 8px -2px rgb(16 20 27 / 0.08);
}

:root[data-theme="dark"] {
  --lift-top: inset 0 1px 0 rgb(255 255 255 / 0.07);
  --lift-bottom: inset 0 -1px 0 rgb(0 0 0 / 0.35);
  --lift-contact: 0 1px 2px rgb(0 0 0 / 0.5);
  --lift-glow: 0 3px 8px -2px rgb(0 0 0 / 0.5);
}

.chip {
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  color: var(--text);
  background: linear-gradient(180deg, var(--surface-2), var(--surface-3));
  box-shadow: var(--lift-top), var(--lift-bottom), var(--lift-contact), var(--lift-glow);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.1;
  transition: box-shadow 150ms, transform 100ms, filter 150ms;
}

.chip:hover {
  background: linear-gradient(180deg, var(--surface-2), var(--surface-3));
  filter: brightness(1.05);
}

.chip:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: var(--lift-bottom), var(--lift-contact);
}

.chip.is-active {
  color: #111;
  border-color: #b98f00;
  background: linear-gradient(180deg, #ffe45c, #f5c400);
  box-shadow:
    inset 0 2px 3px rgb(0 0 0 / 0.25),
    0 0 0 3px color-mix(in srgb, #f5c400 30%, transparent);
}

.slab-split {
  display: grid;
  grid-template-columns: minmax(96px, 0.42fr) minmax(0, 1fr);
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
}

.slab-preview {
  max-height: 420px;
}

.slab-live {
  display: grid;
  align-content: start;
  gap: 10px;
}

.live-row {
  display: grid;
  gap: 5px;
}

.live-label {
  color: var(--secondary-text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.live-label small {
  margin-left: 4px;
  color: var(--warning);
  font-size: 10px;
}

.chip-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 6px;
}

.chip-grid {
  grid-auto-flow: row;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}

.rotation-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 12px;
}

.rotation-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.rotation-row input {
  width: 58px;
  min-height: 36px;
  padding: 4px 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#slab-auto-races {
  width: auto;
  min-height: 36px;
  padding: 4px 8px;
  font-size: 13px;
}

/* A narrow tile stacks the slab preview above its controls. */
@container (max-width: 420px) {
  .slab-split {
    grid-template-columns: 1fr;
  }

  .slab-preview {
    max-height: 220px;
  }
}

/* Three columns here (MRP has four): the hot laps column carries the Left Slab's live controls. */
@media (min-width: 1000px) {
  .board {
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* ---------- Colour fields and the colour picker sheet ---------- */

.color-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.color-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.color-label {
  color: var(--secondary-text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.color-swatch {
  justify-content: flex-start;
  gap: 8px;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  color: var(--text);
  background: linear-gradient(180deg, var(--surface-2), var(--surface-3));
  box-shadow: var(--lift-top), var(--lift-bottom), var(--lift-contact), var(--lift-glow);
  font-weight: 700;
}

.color-swatch:hover {
  background: linear-gradient(180deg, var(--surface-2), var(--surface-3));
  filter: brightness(1.05);
}

.color-swatch span {
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid rgb(0 0 0 / 0.35);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25);
}

.color-swatch code {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
}

.color-sheet {
  width: min(560px, calc(100vw - 24px));
}

.color-body {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.color-wheel-wrap {
  position: relative;
  aspect-ratio: 1;
  touch-action: none;
}

.color-wheel {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.35);
  cursor: crosshair;
}

.color-wheel-dot {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000, 0 2px 6px rgb(0 0 0 / 0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.color-side {
  display: grid;
  gap: 12px;
}

.color-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 40px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.color-side input[type="range"] {
  width: 100%;
  min-height: 32px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(90deg, #000, var(--color-full, #fff));
  accent-color: #fff;
}

.color-side input.is-invalid {
  border-color: var(--brand-red);
}

.color-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.color-tools .quiet-button {
  min-height: 38px;
  padding: 6px 10px;
  font-size: 13px;
}

/* The browser's own picker, opened by tapping "More…". */
.color-native {
  position: relative;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  cursor: pointer;
}

.color-native input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.color-chip {
  min-height: 34px;
  padding: 0;
  border: 1px solid rgb(0 0 0 / 0.35);
  border-radius: 8px;
  box-shadow: var(--lift-top), var(--lift-contact);
}

.color-chip:hover {
  filter: brightness(1.08);
}

@media (max-width: 560px) {
  .color-body {
    grid-template-columns: 1fr;
  }

  .color-wheel-wrap {
    width: min(240px, 100%);
    justify-self: center;
  }
}

/* Long, thin previews (Top Hat, Lower 3rd): the graphic fills the full width, and the "Preview" label sits
   in a strip under it instead of covering the logo box at its left end. */
.preview-wide {
  aspect-ratio: auto;
  max-height: none;
  padding-bottom: 20px;
}

.preview-wide iframe {
  position: relative;
  inset: auto;
  display: block;
  height: auto;
  aspect-ratio: var(--ratio);
}

.preview-wide .preview-tag {
  top: auto;
  bottom: 3px;
}
