: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;
  padding-right: 8px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

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

.info-strip-rc {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.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: 3px;
  align-self: stretch;
  min-height: 16px;
  border-radius: 2px;
  flex-shrink: 0;
}

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

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

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

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