:root {
  --bg: #0f0f13;
  --surface: #1a1a21;
  --surface-2: #23232c;
  --border: #2e2e3a;
  --text: #f2f2f5;
  --text-dim: #9a9aa8;
  --red: #e10600;
  --gold: #ffd24d;
  --silver: #c0c0c8;
  --bronze: #cd8a55;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15, 15, 19, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
  flex-wrap: wrap;
}

.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 20px;
  background: none; border: none; color: var(--text);
  font-family: inherit; cursor: pointer;
  padding: 6px 10px; margin: -6px -10px;
  border-radius: 10px;
  transition: background 0.15s;
}
.logo:hover { background: var(--surface-2); }
.logo-mark {
  background: var(--red);
  padding: 2px 8px;
  border-radius: 6px;
  font-style: italic;
  letter-spacing: -1px;
}
.logo-home {
  font-size: 11px; font-weight: 700;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  margin-left: 2px;
  transition: color 0.15s, border-color 0.15s;
}
.logo:hover .logo-home { color: var(--text); border-color: var(--red); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--red); }

main { flex: 1; width: 100%; max-width: 1000px; margin: 0 auto; padding: 24px; }

.panel { display: none; }
.panel.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-title { font-size: 22px; margin-bottom: 16px; }

/* Hero / next race */
.hero {
  background: linear-gradient(135deg, var(--surface) 0%, #26161a 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 20px;
}
.hero-label {
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.hero-race { font-size: 28px; font-weight: 800; margin: 6px 0 2px; }
.hero-circuit { color: var(--text-dim); font-size: 15px; }
.countdown { display: flex; gap: 14px; margin-top: 20px; }
.count-unit {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 0;
  width: 80px;
  text-align: center;
}
.count-num { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.count-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.hero-sessions { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.session-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-dim);
}
.session-chip strong { color: var(--text); margin-right: 6px; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 720px) { .dash-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}
.card h2 { font-size: 15px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 14px; }

.mini-list { display: flex; flex-direction: column; gap: 10px; }
.mini-row { display: flex; align-items: center; gap: 12px; font-size: 15px; }
.mini-pos { width: 22px; color: var(--text-dim); font-weight: 700; font-variant-numeric: tabular-nums; }
.team-bar { width: 4px; height: 22px; border-radius: 2px; background: var(--text-dim); }
.mini-name { flex: 1; font-weight: 600; }
.mini-sub { color: var(--text-dim); font-size: 13px; }
.mini-pts { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Schedule */
.race-list { display: flex; flex-direction: column; gap: 10px; }
.race-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
}
.race-row.past { opacity: 0.55; }
.race-row.next { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.race-round {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 10px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.race-info { flex: 1; min-width: 0; }
.race-name { font-weight: 700; }
.race-loc { color: var(--text-dim); font-size: 13px; }
.race-date { text-align: right; font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.race-date strong { display: block; color: var(--text); font-size: 14px; }
.badge {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 999px;
}
.badge.next-badge { background: var(--red); color: #fff; }
.badge.done-badge { background: var(--surface-2); color: var(--text-dim); }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-dim); padding: 12px 16px; border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.pos { font-weight: 800; font-variant-numeric: tabular-nums; width: 40px; }
td.pts { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
td.num-right { text-align: right; font-variant-numeric: tabular-nums; }
th.num-right { text-align: right; }
.pos-1 { color: var(--gold); }
.pos-2 { color: var(--silver); }
.pos-3 { color: var(--bronze); }
.driver-cell { display: flex; align-items: center; gap: 10px; }
.dim { color: var(--text-dim); }

/* Live timing */
.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--red);
  margin-left: 4px;
  animation: pulse 1.2s ease-in-out infinite;
}
.live-dot.hidden { display: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.live-header { margin-bottom: 16px; }
.live-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.live-badge {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  padding: 4px 10px; border-radius: 999px;
}
.live-badge.on { background: var(--red); color: #fff; }
.live-badge.off { background: var(--surface-2); color: var(--text-dim); }
.flag-chip {
  font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2);
}
.flag-green { color: #52e252; }
.flag-yellow { color: var(--gold); }
.flag-red { color: var(--red); }

.tyre {
  display: inline-block;
  width: 22px; height: 22px; line-height: 20px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
  text-align: center;
  font-size: 10px; font-weight: 800;
}
.tyre-soft { border-color: var(--red); color: var(--red); }
.tyre-medium { border-color: var(--gold); color: var(--gold); }
.tyre-hard { border-color: #e8e8ee; color: #e8e8ee; }
.tyre-intermediate { border-color: #52e252; color: #52e252; }
.tyre-wet { border-color: #64c4ff; color: #64c4ff; }

.status-chip {
  font-size: 10px; font-weight: 800; letter-spacing: 1px;
  padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim);
}
.status-chip.pit { background: var(--gold); color: #000; }
.status-chip.out { background: var(--red); color: #fff; }

.row-retired td { opacity: 0.45; }
.live-note { margin-top: 14px; font-size: 12px; color: var(--text-dim); }

.error-box {
  background: var(--surface);
  border: 1px solid var(--red);
  border-radius: 12px;
  padding: 16px;
  color: var(--text-dim);
}

/* Welcome */
.welcome-hero { text-align: center; padding: 40px 16px 36px; }
.welcome-flag { font-size: 52px; margin-bottom: 8px; }
.welcome-hero h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
.welcome-sub {
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1.6;
  max-width: 560px;
  margin: 12px auto 24px;
}
.cta {
  background: var(--red);
  color: #fff;
  border: none;
  font-size: 16px;
  font-weight: 700;
  padding: 13px 26px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}
.cta:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(225, 6, 0, 0.35); }

.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 640px) { .feature-grid { grid-template-columns: 1fr; } }
.feature {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.feature:hover { border-color: var(--red); transform: translateY(-2px); }
.feature-icon { font-size: 26px; margin-bottom: 10px; }
.feature h3 { font-size: 16px; margin-bottom: 6px; }
.feature p { font-size: 14px; color: var(--text-dim); line-height: 1.55; }

/* Modal */
.clickable { cursor: pointer; }
.clickable:hover .race-name, tr.clickable:hover strong, .mini-row.clickable:hover .mini-name { text-decoration: underline; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(480px, calc(100vw - 32px));
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute; top: 10px; right: 12px;
  background: rgba(0,0,0,0.4);
  border: none; color: var(--text);
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 16px; cursor: pointer;
  z-index: 2;
}
.modal-close:hover { background: var(--red); }

.modal-hero {
  display: flex; align-items: flex-end; gap: 16px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-radius: 16px 16px 0 0;
}
.modal-headshot {
  width: 110px; height: 110px;
  object-fit: cover; object-position: top;
  border-radius: 12px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.modal-trackimg {
  width: 100%; max-height: 220px;
  object-fit: contain;
  background: #fff;
  border-radius: 16px 16px 0 0;
  display: block;
}
.modal-title { font-size: 22px; font-weight: 800; line-height: 1.15; }
.modal-sub { color: var(--text-dim); font-size: 14px; margin-top: 4px; }
.modal-body { padding: 16px 20px 20px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.stat-num { font-size: 18px; font-weight: 800; }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }

.modal-bio { font-size: 14px; line-height: 1.55; color: var(--text); }
.modal-link { display: inline-block; margin-top: 12px; font-size: 13px; color: var(--text-dim); }
.modal-sessions { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.modal-session { display: flex; justify-content: space-between; font-size: 14px; background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.modal-session .dim { font-variant-numeric: tabular-nums; }

footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 20px;
  border-top: 1px solid var(--border);
}
footer a { color: var(--text-dim); }
