/* ==========================================================================
   F1 Pit Wall — Locked 800x480 5-inch Touchscreen Dashboard
   Supports Mercedes-AMG Petronas & McLaren Formula 1 Editions
   ========================================================================== */

:root {
  --bg-outer: #05070a;
  --bg-frame: #0b0f14;
  --bg-card: #131922;
  --bg-card-alt: #18202c;
  --bg-elevated: #1e2836;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text-main: #f3f6fa;
  --text-muted: #93a1b5;
  --text-dim: #64748b;

  /* Default Team: Mercedes-AMG Petronas */
  --team-primary: #00d2be;
  --team-secondary: #c8d1d8;
  --team-glow: rgba(0, 210, 190, 0.22);
  --team-tint: rgba(0, 210, 190, 0.12);
  --team-text-on-primary: #061414;

  /* F1 Semantic Colors */
  --f1-purple: #b84dff;
  --f1-green: #22c55e;
  --f1-yellow: #facc15;
  --f1-red: #ef4444;
  --f1-amber: #f59e0b;

  /* Tyre Compounds */
  --tyre-soft: #ef4444;
  --tyre-medium: #facc15;
  --tyre-hard: #f1f5f9;
  --tyre-inter: #22c55e;
  --tyre-wet: #3b82f6;
}

html[data-team="mclaren"] {
  --bg-frame: #0d0c10;
  --bg-card: #17151c;
  --bg-card-alt: #1e1b24;
  --bg-elevated: #27232f;
  --team-primary: #ff8000;
  --team-secondary: #47c7fc;
  --team-glow: rgba(255, 128, 0, 0.25);
  --team-tint: rgba(255, 128, 0, 0.14);
  --team-text-on-primary: #140a00;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-outer);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

/* Centers the locked 800x480 5" screen on desktop, fills 100% on an 800x480 display */
.viewport-stage {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #11161f 0%, #05070a 75%);
}

.pitwall-frame {
  width: 800px;
  height: 480px;
  background: var(--bg-frame);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 0 1px var(--border-strong), 0 20px 60px rgba(0, 0, 0, 0.85);
  transform-origin: center center;
}

/* Top bar subtle team racing stripe */
.pitwall-frame::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--team-primary), var(--team-secondary), var(--team-primary));
  z-index: 20;
}

/* ==========================================================================
   TOP STATUS BAR (48px)
   ========================================================================== */
.topbar {
  height: 48px;
  min-height: 48px;
  padding: 3px 10px 0;
  background: linear-gradient(180deg, #121822 0%, var(--bg-frame) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.team-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  text-align: left;
}
.team-badge:active {
  background: var(--bg-elevated);
}

.team-stripe {
  width: 5px;
  height: 28px;
  border-radius: 3px;
  background: var(--team-primary);
  box-shadow: 0 0 10px var(--team-glow);
}

.team-badge-text {
  display: flex;
  flex-direction: column;
  line-height: 1.08;
}

.team-name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.7px;
  color: var(--team-primary);
}

.team-sub {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  border: 1px solid var(--border);
}

.pill-live {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fca5a5;
}

.pill-demo {
  background: rgba(184, 77, 255, 0.18);
  border-color: rgba(184, 77, 255, 0.55);
  color: #e9d5ff;
}

.pill-prerace {
  background: var(--team-tint);
  border-color: var(--team-primary);
  color: var(--team-primary);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

.pill-flag.flag-green { background: rgba(34, 197, 94, 0.18); border-color: #22c55e; color: #86efac; }
.pill-flag.flag-yellow { background: rgba(250, 204, 21, 0.22); border-color: #facc15; color: #fef08a; }
.pill-flag.flag-sc { background: rgba(245, 158, 11, 0.28); border-color: #f59e0b; color: #fde68a; }
.pill-flag.flag-red { background: rgba(239, 68, 68, 0.3); border-color: #ef4444; color: #fecaca; }

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

.spoiler-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card-alt);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.spoiler-btn.active {
  background: var(--f1-amber);
  border-color: #fde68a;
  color: #1c1000;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.45);
}

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
  min-width: 48px;
  text-align: right;
}

/* ==========================================================================
   MAIN PAGE AREA (374px)
   ========================================================================== */
.page-container {
  height: 374px;
  min-height: 374px;
  padding: 10px 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* ==========================================================================
   BOTTOM TOUCH NAVIGATION DOCK (58px)
   ========================================================================== */
.nav-dock {
  height: 58px;
  min-height: 58px;
  background: #0d121a;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 5px 8px;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-btn:active {
  transform: scale(0.97);
}

.nav-btn.active {
  background: var(--team-tint);
  border-color: var(--team-primary);
  color: var(--team-primary);
  box-shadow: inset 0 0 12px var(--team-glow);
}

.nav-icon {
  font-size: 17px;
  line-height: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
}

/* ==========================================================================
   SHARED CARDS, GRIDS & TYPOGRAPHY
   ========================================================================== */
.hidden { display: none !important; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  position: relative;
  overflow: hidden;
}

.card-accent {
  border-color: rgba(255, 255, 255, 0.14);
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-alt) 100%);
}

.card-team {
  border-color: var(--team-primary);
  background: linear-gradient(135deg, var(--team-tint) 0%, var(--bg-card) 68%);
}

.section-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.grid-home-pre {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 9px;
  height: 100%;
}

.grid-home-live {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 9px;
  height: 100%;
}

.mono {
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   PRE-RACE COUNTDOWN & FUN FACTS
   ========================================================================== */
.gp-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.2px;
  line-height: 1.15;
  color: var(--text-main);
}

.gp-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.countdown-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.cd-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
}

.cd-val {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--team-primary);
  line-height: 1;
}

.cd-lbl {
  font-size: 9px;
  font-weight: 800;
  color: var(--text-muted);
  margin-top: 3px;
  letter-spacing: 0.7px;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.stat-chip {
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
}

.stat-chip-lbl {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.stat-chip-val {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 2px;
}

.trivia-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
}

.trivia-text {
  font-size: 13.5px;
  line-height: 1.38;
  color: var(--text-main);
  font-weight: 500;
}

.trivia-hint {
  font-size: 10px;
  font-weight: 700;
  color: var(--team-primary);
  text-align: right;
  margin-top: 6px;
}

/* ==========================================================================
   TYRE BADGES & SECTOR PILLS
   ========================================================================== */
.tyre-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 900;
  border: 2.5px solid currentColor;
  background: #0a0c10;
  flex-shrink: 0;
}

.tyre-SOFT { color: var(--tyre-soft); }
.tyre-MEDIUM { color: var(--tyre-medium); }
.tyre-HARD { color: var(--tyre-hard); }
.tyre-INTERMEDIATE { color: var(--tyre-inter); }
.tyre-WET { color: var(--tyre-wet); }
.tyre-UNKNOWN { color: var(--text-muted); }

.sector-dots {
  display: inline-flex;
  gap: 3px;
}

.sector-dot {
  width: 14px;
  height: 7px;
  border-radius: 2px;
  background: #2c3645;
}
.sector-dot.purple { background: var(--f1-purple); }
.sector-dot.green { background: var(--f1-green); }
.sector-dot.yellow { background: var(--f1-yellow); }

/* ==========================================================================
   TIMING TOWER PAGE
   ========================================================================== */
.tower-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.seg-group {
  display: flex;
  gap: 5px;
}

.touch-btn {
  height: 36px;
  padding: 0 13px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card-alt);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.touch-btn:active { transform: scale(0.97); }

.touch-btn.active,
.touch-btn.primary {
  background: var(--team-primary);
  border-color: var(--team-primary);
  color: var(--team-text-on-primary);
}

.timing-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 4px;
}

.timing-table th {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  text-align: left;
  padding: 0 8px 2px;
}

.timing-row td {
  background: var(--bg-card);
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 700;
  vertical-align: middle;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.timing-row td:first-child {
  border-left: 1px solid var(--border);
  border-radius: 7px 0 0 7px;
}

.timing-row td:last-child {
  border-right: 1px solid var(--border);
  border-radius: 0 7px 7px 0;
}

.timing-row.my-team td {
  background: var(--team-tint);
  border-color: var(--team-primary);
}

.pos-cell {
  width: 38px;
  font-size: 15px !important;
  font-weight: 900 !important;
  text-align: center;
}

.driver-cell {
  display: flex;
  align-items: center;
  gap: 7px;
}

.color-bar {
  width: 4px;
  height: 20px;
  border-radius: 2px;
  flex-shrink: 0;
}

.pit-tag {
  display: inline-block;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--f1-amber);
  color: #1c1000;
  font-size: 10px;
  font-weight: 900;
  margin-left: 5px;
}

.fl-tag {
  color: var(--f1-purple);
}

/* ==========================================================================
   TEAM GARAGE SPOTLIGHT PAGE
   ========================================================================== */
.garage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  height: 100%;
}

.driver-hero-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.driver-hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.driver-big-pos {
  font-size: 38px;
  font-weight: 900;
  line-height: 0.95;
  color: var(--team-primary);
  font-variant-numeric: tabular-nums;
}

.driver-big-name {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.3px;
}

.driver-num-pill {
  font-size: 12px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--team-primary);
  border: 1px solid var(--team-primary);
}

.driver-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.metric-box {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
}

.metric-lbl {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.metric-val {
  font-size: 14px;
  font-weight: 800;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.stint-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.stint-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px 2px 4px;
  font-size: 11px;
  font-weight: 700;
}

/* ==========================================================================
   WEATHER & RACE CONTROL PAGE
   ========================================================================== */
.track-grid {
  display: grid;
  grid-template-columns: 0.95fr 1.25fr;
  gap: 10px;
  height: 100%;
}

.weather-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.rc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  max-height: 295px;
  padding-right: 2px;
}

.rc-item {
  background: rgba(0, 0, 0, 0.28);
  border-left: 3px solid var(--team-primary);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12px;
  line-height: 1.3;
}

.rc-item.flag-YELLOW { border-left-color: var(--f1-yellow); }
.rc-item.flag-RED { border-left-color: var(--f1-red); }
.rc-item.flag-GREEN { border-left-color: var(--f1-green); }

.rc-meta {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 2px;
}

/* ==========================================================================
   SPOILER SHIELD OVERLAY CARD
   ========================================================================== */
.spoiler-shield {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  background: linear-gradient(145deg, rgba(245, 158, 11, 0.14) 0%, var(--bg-card) 65%);
  border: 1.5px solid var(--f1-amber);
  border-radius: 12px;
  padding: 18px 28px;
}

.spoiler-shield-icon {
  font-size: 40px;
  line-height: 1;
}

.spoiler-shield-title {
  font-size: 22px;
  font-weight: 900;
  color: #fde68a;
  letter-spacing: 0.5px;
}

.spoiler-shield-desc {
  font-size: 13.5px;
  color: var(--text-muted);
  max-width: 520px;
  line-height: 1.45;
}

/* ==========================================================================
   SETTINGS PAGE
   ========================================================================== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  height: 100%;
}

.theme-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-main);
  cursor: pointer;
  margin-bottom: 7px;
  text-align: left;
}

.theme-choice.selected {
  border-color: var(--team-primary);
  background: var(--team-tint);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }

.setting-title { font-size: 13px; font-weight: 800; }
.setting-sub { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; }

.url-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--team-primary);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  margin-top: 4px;
  word-break: break-all;
}

/* ==========================================================================
   MOBILE RESPONSIVE MODE (Phones & Portrait Tablets)
   Keeps locked 800x480 on 5-inch landscape displays & desktop,
   switches to native full-screen scrollable mobile UI on phones.
   ========================================================================== */
html.is-mobile,
html.is-mobile body {
  overflow: hidden;
  height: 100dvh;
}

html.is-mobile .viewport-stage {
  width: 100%;
  height: 100dvh;
  display: block;
  background: var(--bg-frame);
}

html.is-mobile .pitwall-frame {
  width: 100%;
  height: 100dvh;
  transform: none !important;
  box-shadow: none;
  padding-top: env(safe-area-inset-top, 0px);
}

html.is-mobile .topbar {
  height: auto;
  min-height: 52px;
  padding: 8px 10px 6px;
  flex-wrap: wrap;
  gap: 6px;
}

html.is-mobile .team-sub {
  display: none;
}

html.is-mobile .team-name {
  font-size: 13px;
}

html.is-mobile .clock {
  display: none;
}

html.is-mobile .pill {
  padding: 4px 8px;
  font-size: 10px;
}

html.is-mobile .spoiler-btn {
  height: 34px;
  padding: 0 9px;
  font-size: 10.5px;
}

html.is-mobile .page-container {
  flex: 1;
  height: auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 14px;
  gap: 10px;
}

html.is-mobile .grid-home-pre,
html.is-mobile .grid-home-live,
html.is-mobile .garage-grid,
html.is-mobile .track-grid,
html.is-mobile .settings-grid {
  grid-template-columns: 1fr;
  grid-template-rows: auto;
  height: auto;
}

html.is-mobile .grid-2 {
  grid-template-columns: 1fr 1fr;
}

html.is-mobile .driver-metrics {
  grid-template-columns: repeat(2, 1fr);
}

html.is-mobile .rc-list {
  max-height: 260px;
}

html.is-mobile .tower-controls {
  flex-wrap: wrap;
}

html.is-mobile .seg-group {
  flex-wrap: wrap;
}

html.is-mobile .touch-btn {
  height: 40px;
  padding: 0 11px;
  font-size: 12px;
}

html.is-mobile .timing-table th:nth-child(4),
html.is-mobile .timing-table td:nth-child(4),
html.is-mobile .timing-table th:nth-child(6),
html.is-mobile .timing-table td:nth-child(6) {
  display: none;
}

html.is-mobile .timing-row td {
  padding: 8px 6px;
  font-size: 12.5px;
}

html.is-mobile .nav-dock {
  height: auto;
  min-height: 62px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  gap: 3px;
}

html.is-mobile .nav-btn {
  padding: 6px 2px;
}

html.is-mobile .nav-icon {
  font-size: 18px;
}

html.is-mobile .nav-label {
  font-size: 9.5px;
}

html.is-mobile .spoiler-shield {
  padding: 24px 16px;
  min-height: 280px;
}
