@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;
}
