:root {
  --crag-slate: #0E1726;
  --crag-slate-deep: #080E18;
  --crag-panel: rgba(14, 23, 38, 0.90);
  --saddler-brass: #D97706;
  --saddler-gold: #F59E0B;
  --willow-moss: #84CC16;
  --highland-heather: #C084FC;
  --parchment: #FEF3C7;
  --parchment-muted: rgba(254, 243, 199, 0.72);
  --leather-border: rgba(217, 119, 6, 0.42);
  --danger-ember: #EF4444;
  --serif-stack: "Georgia", "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --sans-stack: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--crag-slate);
  color: var(--parchment);
  font-family: var(--sans-stack);
  font-variant-numeric: tabular-nums;
  touch-action: none;
}

.app-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--crag-slate);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

/* Top Telemetry Strip (Score-Safe & 320px Zero-Overflow) */
.top-hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  pointer-events: none;
}

.hud-cluster,
.hud-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
  min-width: 0;
}

.hud-pill {
  height: 34px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(14, 23, 38, 0.86);
  border: 1px solid var(--leather-border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  min-width: 0;
}

.hud-pill-gold {
  border-color: rgba(245, 158, 11, 0.55);
}

.hud-pill-heather {
  border-color: rgba(192, 132, 252, 0.45);
}

.hud-mini-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex-shrink: 0;
}

.hud-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--parchment-muted);
  white-space: nowrap;
}

.hud-val {
  font-size: 12px;
  font-weight: 800;
  color: var(--parchment);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  height: 34px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(14, 23, 38, 0.88);
  border: 1px solid rgba(254, 243, 199, 0.28);
  color: var(--parchment);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn-brass {
  background: linear-gradient(180deg, #D97706 0%, #9A3412 100%);
  border-color: #FEF3C7;
  color: #FEF3C7;
}

/* Stunt & Milepost Banner */
.stunt-banner {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px) scale(0.92);
  z-index: 9;
  max-width: calc(100vw - 24px);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(14, 23, 38, 0.92);
  border: 1.5px solid var(--saddler-gold);
  color: var(--parchment);
  font-family: var(--serif-stack);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.stunt-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* Bottom Cockpit Dashboard */
.cockpit-dock {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) 74px;
  align-items: stretch;
  gap: 6px;
  height: 92px;
}

.pedal-btn {
  position: relative;
  border-radius: 14px;
  border: 2px solid rgba(254, 243, 199, 0.32);
  padding: 4px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.65),
    inset 0 2px 2px rgba(255, 255, 255, 0.22);
  transition: transform 0.08s ease, filter 0.08s ease;
  overflow: hidden;
  min-width: 0;
}

.pedal-brake {
  background: linear-gradient(180deg, #475569 0%, #1E293B 55%, #0F172A 100%);
  border-color: rgba(192, 132, 252, 0.5);
}

.pedal-drive {
  background: linear-gradient(180deg, #F59E0B 0%, #D97706 55%, #78350F 100%);
  border-color: #FEF3C7;
}

.pedal-btn.pressed,
.pedal-btn:active {
  transform: translateY(3px) scale(0.97);
  filter: brightness(1.12);
}

.pedal-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: rgba(254, 243, 199, 0.85);
  white-space: nowrap;
}

.pedal-main {
  font-family: var(--serif-stack);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #FEF3C7;
  white-space: nowrap;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.pedal-rivets {
  width: 56%;
  height: 4px;
  border-radius: 999px;
  background: repeating-linear-gradient(
    90deg,
    rgba(254, 243, 199, 0.65) 0px,
    rgba(254, 243, 199, 0.65) 4px,
    transparent 4px,
    transparent 10px
  );
  margin-top: 2px;
}

.instrument-cluster {
  background: rgba(14, 23, 38, 0.92);
  border: 1.5px solid var(--leather-border);
  border-radius: 14px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(254, 243, 199, 0.14);
  backdrop-filter: blur(10px);
  min-width: 0;
}

.dials-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
}

.dial-box {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.inclinometer-svg {
  width: 34px;
  height: 22px;
  flex-shrink: 0;
}

.dial-readout {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dial-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--parchment-muted);
  white-space: nowrap;
}

.dial-value {
  font-size: 11px;
  font-weight: 800;
  color: var(--parchment);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Steam-Goad Turbo Button inside Cockpit */
.turbo-btn {
  height: 30px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1.5px solid var(--saddler-gold);
  background: linear-gradient(180deg, #D97706 0%, #78350F 100%);
  color: #FEF3C7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(245, 158, 11, 0.35);
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.turbo-btn.ready {
  border-color: #BEF264;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.75);
}

.turbo-btn.cooling {
  opacity: 0.55;
  border-color: rgba(254, 243, 199, 0.25);
}

.turbo-icon {
  width: 15px;
  height: 15px;
  object-fit: contain;
  flex-shrink: 0;
}

.turbo-text {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.oil-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.oil-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
}

.oil-title {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 800;
  color: var(--parchment);
  white-space: nowrap;
}

.oil-mini-icon {
  width: 12px;
  height: 12px;
  object-fit: contain;
  flex-shrink: 0;
}

.oil-post {
  font-size: 10px;
  font-weight: 800;
  color: var(--highland-heather);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.oil-pct {
  font-size: 10px;
  font-weight: 800;
  color: var(--saddler-gold);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.oil-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  border: 1px solid rgba(217, 119, 6, 0.35);
}

.oil-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #D97706 0%, #F59E0B 60%, #84CC16 100%);
  transition: width 0.12s linear;
}

.oil-fill.low {
  background: linear-gradient(90deg, #DC2626 0%, #F59E0B 100%);
}

/* Editorial Sheet (Grounded in Doji iOS Leaderboard) */
.editorial-sheet {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(8, 14, 24, 0.70);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.editorial-sheet.visible {
  opacity: 1;
  pointer-events: auto;
}

.sheet-card {
  width: 100%;
  max-width: 430px;
  max-height: 94vh;
  background: linear-gradient(180deg, #152136 0%, #0E1726 100%);
  border: 1.5px solid rgba(217, 119, 6, 0.55);
  border-radius: 22px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.78);
  overflow: hidden;
}

.sheet-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

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

.brand-titles {
  min-width: 0;
  flex: 1;
}

.brand-crest {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(254, 243, 199, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.45);
  padding: 2px;
  flex-shrink: 0;
}

.eyebrow-tag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--highland-heather);
  white-space: nowrap;
}

.editorial-serif-title {
  font-family: var(--serif-stack);
  font-size: 18px;
  font-weight: 700;
  color: var(--parchment);
  line-height: 1.15;
  white-space: nowrap;
}

.treasury-chip {
  height: 32px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(217, 119, 6, 0.18);
  border: 1px solid var(--saddler-gold);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.treasury-icon {
  width: 15px;
  height: 15px;
  object-fit: contain;
  flex-shrink: 0;
}

.treasury-val {
  font-size: 12px;
  font-weight: 800;
  color: var(--parchment);
  font-variant-numeric: tabular-nums;
}

.run-summary-banner {
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(192, 132, 252, 0.14);
  border: 1px solid rgba(192, 132, 252, 0.4);
  color: var(--parchment);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
}

.hidden {
  display: none !important;
}

/* Editorial Tabs */
.editorial-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(8, 14, 24, 0.65);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid rgba(254, 243, 199, 0.12);
}

.ed-tab {
  height: 34px;
  padding: 0 8px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--parchment-muted);
  font-family: var(--serif-stack);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ed-tab.active {
  background: rgba(217, 119, 6, 0.28);
  color: var(--parchment);
  border: 1px solid rgba(245, 158, 11, 0.55);
}

/* Numbered Editorial Rows */
.editorial-list {
  overflow-y: auto;
  max-height: 290px;
  padding-right: 2px;
}

.numbered-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ed-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border-radius: 12px;
  background: rgba(254, 243, 199, 0.05);
  border: 1px solid rgba(254, 243, 199, 0.12);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.ed-row.selected-row {
  background: rgba(132, 204, 22, 0.12);
  border-color: var(--willow-moss);
}

.ed-rank {
  font-family: var(--serif-stack);
  font-size: 12px;
  font-weight: 700;
  color: var(--saddler-gold);
  text-align: center;
}

.ed-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ed-name {
  font-family: var(--serif-stack);
  font-size: 13px;
  font-weight: 700;
  color: var(--parchment);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ed-meta {
  font-size: 11px;
  color: var(--parchment-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ed-action-btn {
  height: 30px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--saddler-gold);
  background: linear-gradient(180deg, #D97706 0%, #9A3412 100%);
  color: var(--parchment);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.ed-action-btn:disabled {
  opacity: 0.48;
  cursor: default;
  border-color: rgba(254, 243, 199, 0.22);
  background: rgba(255, 255, 255, 0.08);
}

.ed-action-btn.active-pass {
  background: linear-gradient(180deg, #65A30D 0%, #3F6212 100%);
  border-color: #BEF264;
}

/* Floating Dark Pill Callout (Doji iOS Grounding) */
.floating-pill-row {
  display: flex;
  justify-content: center;
}

.floating-dark-pill {
  height: 30px;
  max-width: 100%;
  padding: 0 12px;
  border-radius: 999px;
  background: #080E18;
  border: 1px solid rgba(192, 132, 252, 0.5);
  color: var(--parchment);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--willow-moss);
  box-shadow: 0 0 8px var(--willow-moss);
  flex-shrink: 0;
}

.sheet-footer-dock {
  display: flex;
}

.launch-btn {
  width: 100%;
  height: 42px;
  border-radius: 12px;
  border: 1.5px solid #FEF3C7;
  background: linear-gradient(180deg, #F59E0B 0%, #D97706 55%, #9A3412 100%);
  color: #FEF3C7;
  font-family: var(--serif-stack);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.05em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(217, 119, 6, 0.4);
  transition: transform 0.1s ease;
}

.launch-btn:active {
  transform: scale(0.98);
}

@media (max-width: 365px) {
  .hide-xs {
    display: none !important;
  }
  .top-hud {
    left: 6px;
    right: 6px;
    gap: 3px;
  }
  .hud-pill {
    padding: 0 6px;
    gap: 3px;
  }
  .hud-label {
    font-size: 9.5px;
  }
  .hud-val {
    font-size: 10.5px;
  }
  .icon-btn {
    padding: 0 7px;
    font-size: 10px;
  }
  .cockpit-dock {
    left: 6px;
    right: 6px;
    grid-template-columns: 62px minmax(0, 1fr) 62px;
    gap: 4px;
    height: 84px;
  }
  .pedal-tag {
    font-size: 8.5px;
  }
  .pedal-main {
    font-size: 12px;
  }
  .inclinometer-svg {
    display: none;
  }
  .instrument-cluster {
    padding: 5px 6px;
  }
}

@media (max-height: 640px) {
  .editorial-list {
    max-height: 215px;
  }
}
