:root {
  --bg: #05070b;
  --bg-accent: #11161d;
  --panel: rgba(16, 22, 29, 0.92);
  --panel-strong: #0c1117;
  --panel-soft: #141b23;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f6f7fb;
  --muted: #97a3b3;
  --accent: #e10600;
  --accent-soft: rgba(225, 6, 0, 0.18);
  --green: #1ecb81;
  --yellow: #e8c547;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.hidden {
  display: none !important;
}

button {
  font-family: inherit;
  cursor: pointer;
}

a {
  color: var(--text);
}

select {
  font-family: inherit;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.76rem;
}

/* ---------------------------------------------------------------------
   Rotate-to-landscape prompt — phones only (coarse pointer); a resized
   desktop browser window never triggers it. "Continue in portrait" is
   remembered per-device via localStorage (see bindRotatePrompt in app.js).
--------------------------------------------------------------------- */
.rotate-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  text-align: center;
  padding: 24px;
}

.rotate-prompt-icon {
  font-size: 2.4rem;
  color: var(--muted);
  animation: rotate-hint 1.6s ease-in-out infinite;
}

.rotate-prompt p {
  color: var(--muted);
  max-width: 260px;
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (pointer: coarse) and (max-width: 900px) {
  .rotate-prompt { display: flex; }
  .app-shell { display: none; }
}

body.m-force-portrait .rotate-prompt { display: none !important; }
body.m-force-portrait .app-shell { display: block !important; }

/* ---------------------------------------------------------------------
   Auth gate
--------------------------------------------------------------------- */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-gate-backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top, rgba(225, 6, 0, 0.14), var(--bg) 65%);
}

.auth-gate-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: var(--shadow);
}

.auth-gate-card h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.auth-gate-card p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.primary-btn, .secondary-btn {
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  padding: 9px 14px;
  font-size: 0.82rem;
  font-weight: 600;
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.secondary-btn {
  background: var(--panel-soft);
  color: var(--text);
}

/* Only the auth-gate sign-in button (alone in its card) wants to fill the
   width — everything else sizes to its own content. */
.auth-gate-card .primary-btn {
  width: 100%;
}

.compact-btn {
  padding: 6px 10px;
  font-size: 0.7rem;
}

.auth-gate-status {
  margin-top: 10px;
  font-size: 0.74rem;
  color: var(--muted);
}

.session-ended-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 36px 8px 12px;
  background: #241d06;
  border-bottom: 1px solid rgba(232, 197, 71, 0.4);
  box-shadow: var(--shadow);
}

.session-ended-banner-text {
  color: var(--yellow);
  font-size: 0.72rem;
  font-weight: 600;
}

.session-ended-banner-close {
  position: absolute;
  top: 4px;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--yellow);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}

/* ---------------------------------------------------------------------
   Shell / header
--------------------------------------------------------------------- */
.app-shell {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 10px 0;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.mobile-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.mobile-title h1 {
  margin: 0;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-title .accent {
  color: var(--accent);
}

.mobile-title .subtitle {
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-auth {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mobile-auth .compact-btn {
  padding: 6px 9px;
  font-size: 0.7rem;
}

.mobile-user-label {
  font-size: 0.64rem;
  color: var(--muted);
  max-width: 84px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-pulse {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.66rem;
  color: var(--muted);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}

.live-dot.is-live {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(30, 203, 129, 0.6);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(30, 203, 129, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(30, 203, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(30, 203, 129, 0); }
}

.session-title {
  margin: 5px 0 0;
  font-size: 0.82rem;
}

/* ---------------------------------------------------------------------
   Cards / banners
--------------------------------------------------------------------- */
.mobile-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 10px;
  margin-bottom: 8px;
}

.session-picker-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.session-picker-row:last-child {
  margin-bottom: 0;
}

.session-picker-row .picker-select {
  flex: 1;
  min-width: 0;
}

.session-picker-row .compact-btn {
  flex-shrink: 0;
}

#m-live-btn {
  padding: 6px 8px;
  font-size: 0.66rem;
}

/* ---------------------------------------------------------------------
   Info strip — track status + weather + latest race control message,
   condensed into a single row above the leaderboard so the table gets
   the space instead of three stacked cards.
--------------------------------------------------------------------- */
.info-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.66rem;
}

.info-strip-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  flex-shrink: 0;
  padding-right: 8px;
  border-right: 1px solid var(--line);
}

.info-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.info-strip[data-status="green"] .info-dot { background: var(--green); }
.info-strip[data-status="yellow"] .info-dot,
.info-strip[data-status="vsc"] .info-dot { background: var(--yellow); }
.info-strip[data-status="sc"] .info-dot { background: #f0a63b; }
.info-strip[data-status="red"] .info-dot { background: var(--accent); }
.info-strip[data-status="chequered"] .info-dot { background: var(--text); }

.track-status-yellow-sectors {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: -3px 0 8px;
}

.track-status-yellow-chip {
  font-size: 0.58rem;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(232, 197, 71, 0.16);
  color: var(--yellow);
}

.track-status-yellow-chip.is-double {
  background: var(--accent-soft);
  color: var(--accent);
}

.info-strip-weather {
  display: flex;
  gap: 7px;
  flex-shrink: 0;
  color: var(--muted);
  white-space: nowrap;
}

.info-strip-weather strong {
  color: var(--text);
  font-weight: 700;
}

/* ---------------------------------------------------------------------
   Race Control — 2-row compact preview, tap a row to expand its full
   message inline (no modal; there isn't room for desktop's filter bar +
   full history on a phone). Tone colours mirror src/styles.css's
   race-control-tone-* palette.
--------------------------------------------------------------------- */
.race-control-card {
  padding: 8px 8px 6px;
}

.race-control-card h2 {
  margin: 0 0 6px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.rc-rows {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rc-empty {
  color: var(--muted);
  font-size: 0.7rem;
  padding: 6px 2px;
}

.rc-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 5px 8px;
  cursor: pointer;
}

.rc-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.rc-row-title {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rc-row-time {
  font-size: 0.58rem;
  color: var(--muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.rc-row-message {
  font-size: 0.72rem;
  color: var(--text);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rc-row.is-expanded .rc-row-message {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

.rc-row[class*="rc-tone-"] {
  border-color: var(--rc-tone-border);
  background: var(--rc-tone-bg);
  box-shadow: inset 3px 0 0 var(--rc-tone-accent);
}

.rc-row[class*="rc-tone-"] .rc-row-title,
.rc-row[class*="rc-tone-"] .rc-row-message {
  color: var(--rc-tone-text);
}

.rc-tone-orange {
  --rc-tone-accent: #fb923c;
  --rc-tone-border: rgba(251, 146, 60, 0.46);
  --rc-tone-bg: rgba(251, 146, 60, 0.12);
  --rc-tone-text: #fdba74;
}

.rc-tone-yellow {
  --rc-tone-accent: #facc15;
  --rc-tone-border: rgba(250, 204, 21, 0.48);
  --rc-tone-bg: rgba(250, 204, 21, 0.12);
  --rc-tone-text: #fde047;
}

.rc-tone-blue {
  --rc-tone-accent: #38bdf8;
  --rc-tone-border: rgba(56, 189, 248, 0.5);
  --rc-tone-bg: rgba(56, 189, 248, 0.13);
  --rc-tone-text: #7dd3fc;
}

.rc-tone-red {
  --rc-tone-accent: #ef4444;
  --rc-tone-border: rgba(239, 68, 68, 0.5);
  --rc-tone-bg: rgba(239, 68, 68, 0.13);
  --rc-tone-text: #fca5a5;
}

.rc-tone-stewards {
  --rc-tone-accent: #ff1f2d;
  --rc-tone-border: rgba(255, 31, 45, 0.62);
  --rc-tone-bg: rgba(255, 31, 45, 0.15);
  --rc-tone-text: #ff4d57;
}

.rc-tone-stewards .rc-row-title,
.rc-tone-stewards .rc-row-message {
  font-weight: 800;
}

.rc-tone-green {
  --rc-tone-accent: #22c55e;
  --rc-tone-border: rgba(34, 197, 94, 0.46);
  --rc-tone-bg: rgba(34, 197, 94, 0.12);
  --rc-tone-text: #86efac;
}

.rc-tone-session-status {
  --rc-tone-accent: #ffffff;
  --rc-tone-border: rgba(255, 255, 255, 0.76);
  --rc-tone-bg: #ffffff;
  --rc-tone-text: #0f172a;
}

.rc-tone-session-status .rc-row-time {
  color: #334155;
}

.free-tier-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.68rem;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
}

.free-tier-banner button {
  flex-shrink: 0;
}

@media (orientation: landscape) {
  .app-shell { max-width: 920px; }
}

.leaderboard-card h2 {
  margin: 0 0 6px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.rc-empty, .leaderboard-empty {
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
  padding: 10px 0;
}

/* ---------------------------------------------------------------------
   Leaderboard
--------------------------------------------------------------------- */
.leaderboard-card {
  padding: 8px 6px 4px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}

.leaderboard-table th {
  text-align: left;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 3px 4px;
}

.leaderboard-table td {
  padding: 5px 4px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
  padding-left: 5px;
}

.lb-pos {
  width: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.lb-driver {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.lb-team-bar {
  width: 4px;
  align-self: stretch;
  min-height: 20px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Rows carry an inline background tint (same team colour as the accent bar,
   low alpha — see teamRowTint in app.js) so a team is recognisable at a
   glance while scrolling, not just from the thin bar on close inspection. */
.leaderboard-table tr {
  transition: background 0.15s ease;
}

.lb-driver-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.lb-driver-num {
  color: var(--muted);
  font-size: 0.6rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-gap {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.lb-gap .lb-interval {
  display: block;
  color: var(--muted);
  font-size: 0.58rem;
}

.lb-lap {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.lb-tyre {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.tyre-badge {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: 800;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.tyre-badge.soft { background: #e10600; color: #fff; }
.tyre-badge.medium { background: #e8c547; color: #1a1a1a; }
.tyre-badge.hard { background: #f4f4f4; color: #1a1a1a; }
.tyre-badge.intermediate { background: #1ecb81; color: #05070b; }
.tyre-badge.wet { background: #1e8fe1; color: #fff; }
.tyre-badge.unknown { background: var(--panel-soft); color: var(--muted); }

.lb-tyre-age {
  font-size: 0.58rem;
  color: var(--muted);
}

.lb-pit {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------
   Window tabs — switch between Leaderboard / Tyres / Race Plot / Position.
   Race Plot and Position stay hidden outside race sessions (see
   updateWindowTabAvailability in app.js).
--------------------------------------------------------------------- */
.window-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  overflow-x: auto;
}

.window-tab {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 9px;
  padding: 7px 6px;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.window-tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.mobile-window.hidden {
  display: none;
}

.tyres-card h2,
.plot-card h2 {
  margin: 0 0 6px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* ---------------------------------------------------------------------
   Tyres window — every stint per driver, oldest to current.
--------------------------------------------------------------------- */
.tyres-card {
  padding: 8px 6px 4px;
}

.tyres-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 5px;
  border-top: 1px solid var(--line);
}

.tyres-row:first-child {
  border-top: none;
}

.tyres-row-pos {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  width: 14px;
  flex-shrink: 0;
  text-align: right;
}

.tyres-row-name {
  font-size: 0.68rem;
  font-weight: 600;
  width: 78px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tyres-chips {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  padding-bottom: 1px;
}

.tyres-chip,
.tyres-chip-empty {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px 5px;
}

.tyres-chip-empty {
  color: var(--muted);
  font-size: 0.64rem;
}

.tyres-chip.is-current {
  border-color: var(--line-strong);
  background: var(--panel-strong);
}

.tyres-chip-laps {
  font-size: 0.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tyre-new-used-badge {
  font-size: 0.52rem;
  font-weight: 800;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tyre-new-used-badge.is-new {
  background: rgba(30, 203, 129, 0.22);
  color: var(--green);
}

.tyre-new-used-badge.is-used {
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
}

/* ---------------------------------------------------------------------
   Race Plot / Driver Position — wide charts, meant to be viewed in
   landscape (same rotate-prompt as the rest of the app nudges toward it).
--------------------------------------------------------------------- */
.plot-card {
  padding: 8px 8px 10px;
}

.plot-canvas-wrap {
  position: relative;
  width: 100%;
  height: 62vw;
  max-height: 420px;
  min-height: 220px;
}

@media (orientation: landscape) {
  .plot-canvas-wrap {
    height: 46vw;
    max-height: 480px;
  }
}

.plot-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
  padding: 0 20px;
}

/* ---------------------------------------------------------------------
   Footer
--------------------------------------------------------------------- */
.mobile-footer {
  text-align: center;
  padding: 14px 0 4px;
}

.mobile-footer a {
  font-size: 0.68rem;
  color: var(--muted);
  text-decoration: underline;
}

.mobile-footer-links {
  margin: 6px 0 0;
}

.mobile-footer-links a {
  text-decoration: none;
}

.mobile-footer-note {
  margin: 6px 0 0;
  font-size: 0.6rem;
  color: var(--muted);
  opacity: 0.8;
  padding: 0 12px;
}

.status-line {
  text-align: center;
  font-size: 0.62rem;
  color: var(--muted);
  padding: 4px 0 8px;
}
