:root {
  color-scheme: dark;
  --bg: #090909;
  --panel: #151515;
  --panel-strong: #1f1d1a;
  --line: #33312d;
  --text: #f3efe7;
  --muted: #a8a29a;
  --accent-red: #ff4d4d;
  --accent-yellow: #f6d32d;
  --accent-green: #33d17a;
  --accent-blue: #62a0ea;
  --shadow: 0 20px 80px rgb(0 0 0 / 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101010;
  color: var(--text);
}

button {
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

button:hover,
select:hover,
input:focus {
  border-color: var(--accent-yellow);
}

button:active {
  transform: translateY(1px);
}

select,
input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  width: 100%;
  height: 100%;
}

.control-rail {
  display: flex;
  min-width: 0;
  height: 100%;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
  box-shadow: var(--shadow);
  z-index: 2;
}

.brand-block,
.panel-section {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.brand-block {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
}

.brand-block h1,
.brand-block p {
  margin: 0;
}

.brand-block h1 {
  margin-top: 4px;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  line-height: 1.05;
}

.eyebrow,
.field-label,
.section-title,
.hud span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-pill,
.mono-readout {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--accent-yellow);
  font-size: 0.72rem;
  white-space: nowrap;
}

.status-pill.ready {
  color: var(--accent-green);
}

.status-pill.error {
  color: var(--accent-red);
}

.panel-section {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.section-title,
.split-row,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title {
  min-height: 28px;
}

.icon-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.route-meta {
  display: grid;
  gap: 2px;
  border-left: 3px solid var(--accent-red);
  padding-left: 10px;
}

.route-meta strong {
  font-size: 0.92rem;
}

.route-meta span,
.toggle-row span,
.time-grid small,
.hud small {
  color: var(--muted);
  font-size: 0.86rem;
}

.button-row,
.search-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.search-row button {
  min-width: 76px;
}

.runner-search-results {
  display: grid;
  gap: 8px;
}

.runner-search-option {
  display: grid;
  height: auto;
  min-height: 52px;
  justify-items: start;
  gap: 3px;
  padding: 9px 10px;
  text-align: left;
}

.runner-search-option strong,
.runner-search-option span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.runner-search-option span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.toggle-row {
  justify-content: flex-start;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent-yellow);
}

.time-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.time-grid span {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  padding: 10px;
}

.time-grid strong {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92rem;
}

.leaderboard-section {
  min-height: 180px;
}

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

.leader-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  padding: 10px;
}

.leader-row.is-selected {
  border-color: var(--accent-yellow);
}

.leader-rank {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 999px;
  background: #26231d;
  color: var(--accent-yellow);
  font-weight: 800;
}

.leader-main {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.leader-main strong,
.leader-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-main span,
.leader-time {
  color: var(--muted);
  font-size: 0.78rem;
}

.leader-time {
  text-align: right;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 14px;
  text-align: center;
}

.race-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgb(255 255 255 / 0.035) 1px, transparent 1px),
    #050505;
  background-size: 48px 48px;
}

.deck-map {
  position: absolute;
  inset: 0;
}

.hud,
.floating-runner-button,
.floating-controls-button,
.map-credit,
.toast {
  position: absolute;
  z-index: 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(16 16 16 / 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.hud {
  display: grid;
  gap: 3px;
  min-width: min(240px, calc(100vw - 40px));
  padding: 12px 14px;
}

.hud strong {
  overflow-wrap: anywhere;
  font-size: clamp(1rem, 2vw, 1.4rem);
}

.hud small {
  display: block;
}

.map-credit {
  left: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 0.68rem;
}

.credit-compact {
  display: none;
}

.hud-primary {
  top: 18px;
  left: 18px;
}

.hud-secondary {
  right: 18px;
  bottom: 18px;
}

.floating-runner-button {
  right: 18px;
  top: 18px;
  min-height: 44px;
  border-color: rgb(246 211 45 / 0.65);
  background: rgb(246 211 45 / 0.16);
  color: var(--text);
  z-index: 4;
}

.floating-controls-button {
  display: none;
}

.toast {
  right: 18px;
  top: 74px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.62);
  padding: 18px;
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  display: grid;
  width: min(420px, 100%);
  max-height: min(680px, calc(100vh - 36px));
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  overflow: auto;
  padding: 16px;
}

.runner-detail-panel {
  width: min(520px, 100%);
}

.runner-detail-content {
  display: grid;
  gap: 12px;
}

.runner-detail-hero {
  display: grid;
  gap: 3px;
  border-left: 4px solid var(--accent-yellow);
  padding-left: 10px;
}

.runner-detail-hero strong {
  font-size: 1.05rem;
}

.runner-detail-hero span {
  color: var(--muted);
  font-size: 0.86rem;
}

.runner-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.runner-detail-grid div,
.runner-split-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  padding: 9px 10px;
}

.runner-detail-grid dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.runner-detail-grid dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

.runner-splits {
  display: grid;
  gap: 6px;
}

.runner-split-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
}

.runner-split-row span {
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(56vh, 1fr) auto;
    min-height: 100%;
  }

  .control-rail {
    order: 2;
    height: auto;
    max-height: none;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .race-stage {
    order: 1;
    min-height: 56vh;
  }

  .hud-primary,
  .toast {
    left: 12px;
    right: 12px;
    top: 12px;
  }

  .hud-primary {
    padding-right: 148px;
  }

  .hud-secondary {
    right: 12px;
    bottom: 30px;
  }

  .floating-runner-button {
    top: 21px;
    right: 18px;
    min-height: 44px;
  }

  .map-credit {
    left: 6px;
    bottom: 4px;
    max-width: max-content;
    padding: 2px 5px;
    background: rgb(16 16 16 / 0.58);
    box-shadow: none;
    font-size: 0.52rem;
    line-height: 1.2;
    pointer-events: none;
  }

  .credit-full {
    display: none;
  }

  .credit-compact {
    display: inline;
  }

  .app-shell.is-controls-collapsed {
    grid-template-rows: minmax(100svh, 1fr) 0;
    min-height: 100svh;
  }

  .app-shell.is-controls-collapsed .control-rail {
    display: none;
  }

  .app-shell.is-controls-collapsed .race-stage {
    min-height: 100svh;
  }

  .app-shell.is-controls-collapsed .hud-secondary {
    bottom: 58px;
  }

  .app-shell.is-controls-collapsed .floating-controls-button {
    display: block;
    right: 12px;
    bottom: 8px;
    min-height: 38px;
    padding: 0 12px;
    color: var(--text);
    font-size: 0.78rem;
    z-index: 4;
  }

  .runner-detail-grid {
    grid-template-columns: 1fr;
  }
}
