/* F1 Pool design system ---------------------------------------------------
   F1-inspired: Titillium Web, F1 red, carbon nav, team-colour accents.
   Use tokens (var(--...)) everywhere so dark mode just works. */

:root {
  --f1-red: #e10600;
  --f1-red-dark: #b80500;
  --ink: #15151e;
  --carbon: #1f1f27;
  --carbon-2: #2a2a35;
  --bg: #f4f2ef;
  --surface: #ffffff;
  --surface-2: #f8f7f5;
  --text: #15151e;
  --muted: #67676f;
  --line: #e4e1dc;
  --line-strong: #cfcbc4;
  --hit: #0f9d58;
  --hit-bg: #e3f6ec;
  --miss: #9a9aa2;
  --neg: #d93025;
  --neg-bg: #fde8e7;
  --gold: #d4a017;
  --silver: #9ea3a8;
  --bronze: #b0703c;
  --warn: #b26a00;
  --warn-bg: #fff4e0;
  --info-bg: #e8f0fe;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(21, 21, 30, .06), 0 4px 16px rgba(21, 21, 30, .06);
  --font: "Titillium Web", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f14; --surface: #1a1a22; --surface-2: #22222c; --text: #f2f2f5; --muted: #a2a2ad;
    --line: #2e2e3a; --line-strong: #3d3d4b; --hit-bg: #0f2e1f; --neg-bg: #3a1513; --warn-bg: #33250d;
    --info-bg: #17223a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f14; --surface: #1a1a22; --surface-2: #22222c; --text: #f2f2f5; --muted: #a2a2ad;
  --line: #2e2e3a; --line-strong: #3d3d4b; --hit-bg: #0f2e1f; --neg-bg: #3a1513; --warn-bg: #33250d;
  --info-bg: #17223a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 16px; line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column;
}
a { color: inherit; text-decoration-color: var(--f1-red); text-underline-offset: 3px; }
a:hover { color: var(--f1-red); }
img { max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.15; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 900; text-transform: uppercase; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.upper { text-transform: uppercase; letter-spacing: .04em; }
.display { font-weight: 900; font-style: italic; text-transform: uppercase; letter-spacing: -.01em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* --- Layout -------------------------------------------------------------- */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 24px; padding-bottom: 48px; flex: 1; }
.stack > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 28px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.span-2 { grid-column: span 2; }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } .span-2 { grid-column: auto; } }

/* --- Top nav -------------------------------------------------------------- */
.topbar { background: var(--ink); color: #fff; border-top: 4px solid var(--f1-red); position: sticky; top: 0; z-index: 50; }
.topbar .container { display: flex; align-items: center; gap: 20px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; font-weight: 900;
  font-style: italic; font-size: 1.3rem; text-transform: uppercase; letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { color: #fff; }
.brand-mark { display: inline-flex; gap: 3px; transform: skewX(-20deg); }
.brand-mark i { display: block; width: 6px; height: 20px; background: var(--f1-red); }
.brand-mark i:nth-child(2) { opacity: .7; } .brand-mark i:nth-child(3) { opacity: .4; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a { color: #d6d6dd; text-decoration: none; font-weight: 600; padding: 8px 12px; border-radius: var(--radius-sm);
  text-transform: uppercase; font-size: .85rem; letter-spacing: .05em; }
.nav a:hover { color: #fff; background: var(--carbon-2); }
.nav a.active { color: #fff; box-shadow: inset 0 -3px 0 var(--f1-red); border-radius: 0; }
.nav-user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--f1-red); color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex: none; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; padding: 8px; cursor: pointer; }
.nav-toggle svg { width: 26px; height: 26px; }
@media (max-width: 860px) {
  .nav-toggle { display: block; margin-left: auto; }
  .nav { display: none; position: absolute; top: 64px; left: 0; right: 0; background: var(--ink); flex-direction: column;
    padding: 8px 16px 16px; border-bottom: 3px solid var(--f1-red); }
  .nav.open { display: flex; }
  .nav a { padding: 12px; }
  .nav a.active { box-shadow: inset 3px 0 0 var(--f1-red); }
  .nav-user .user-name { display: none; }
}
.dropdown { position: relative; }
.dropdown > button { background: none; border: 0; padding: 0; cursor: pointer; display: flex; align-items: center; gap: 8px; color: #fff; font: inherit; }
.dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 10px); background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 190px; padding: 6px; z-index: 60; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button { display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: var(--radius-sm);
  text-decoration: none; background: none; border: 0; font: inherit; color: inherit; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); color: var(--text); }

/* --- Footer ----------------------------------------------------------------- */
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; padding: 20px 0; }

/* --- Cards -------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; position: relative; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; text-transform: uppercase; font-size: 1rem; letter-spacing: .05em; }
.card.flush .card-head { padding: 14px 18px 0; }
.card.accent { border-top: 3px solid var(--f1-red); }
.card.corner::after { content: ""; position: absolute; top: -1px; right: -1px; width: 28px; height: 28px;
  border-top: 3px solid var(--f1-red); border-right: 3px solid var(--f1-red); border-top-right-radius: var(--radius); }

/* Race hero (dark banner with diagonal red speed lines) */
.hero { background: linear-gradient(110deg, var(--ink) 0%, var(--carbon) 60%, #2b0c0c 100%); color: #fff; border-radius: var(--radius);
  padding: 22px; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.hero::before { content: ""; position: absolute; right: -60px; top: 0; bottom: 0; width: 260px;
  background: repeating-linear-gradient(110deg, transparent 0 18px, rgba(225, 6, 0, .55) 18px 26px); opacity: .55;
  mask-image: linear-gradient(90deg, transparent, #000 60%); -webkit-mask-image: linear-gradient(90deg, transparent, #000 60%); }
.hero > * { position: relative; }
.hero .eyebrow { color: #ff8f8a; }
.hero h1, .hero h2 { color: #fff; }
.hero .muted { color: #b9b9c4; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; font-weight: 700; color: var(--f1-red); }

/* --- Stat tiles ------------------------------------------------------------------ */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); font-weight: 700; }
.stat .value { font-size: 2rem; font-weight: 900; font-style: italic; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .85rem; color: var(--muted); }
.hero .stat { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); }
.hero .stat .label, .hero .stat .sub { color: #b9b9c4; }

/* --- Buttons & forms ------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 2px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 18px; font: inherit; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; font-size: .85rem;
  cursor: pointer; text-decoration: none; background: var(--f1-red); color: #fff; transition: background .15s, transform .05s; }
.btn:hover { background: var(--f1-red-dark); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--ink); color: #fff; }
.btn.secondary:hover { background: var(--carbon-2); }
.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--text); }
.btn.ghost:hover { border-color: var(--text); }
.btn.danger { background: transparent; border-color: var(--neg); color: var(--neg); }
.btn.danger:hover { background: var(--neg); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: .75rem; }
.btn.block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }
.hero .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 9px 11px; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--f1-red); box-shadow: 0 0 0 3px rgba(225, 6, 0, .15); }
textarea { min-height: 100px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--f1-red); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.help { font-size: .82rem; color: var(--muted); }

/* --- Flash / alerts ------------------------------------------------------------- */
.flash { border-radius: var(--radius-sm); padding: 12px 14px; border-left: 4px solid var(--hit); background: var(--hit-bg); margin-bottom: 16px; }
.flash.error { border-color: var(--neg); background: var(--neg-bg); }
.flash.info { border-color: #4a7dff; background: var(--info-bg); }
.flash.warn { border-color: var(--warn); background: var(--warn-bg); }

/* --- Tables ------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  font-weight: 700; padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.me { background: rgba(225, 6, 0, .06); }
.table tr.me td:first-child { box-shadow: inset 3px 0 0 var(--f1-red); }
.table .num { text-align: right; }
.table.compact td, .table.compact th { padding: 6px 8px; }
.table td.sticky, .table th.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }

/* --- Pills, badges, positions -------------------------------------------------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.red { background: var(--f1-red); color: #fff; border-color: var(--f1-red); }
.pill.green { background: var(--hit-bg); color: var(--hit); border-color: transparent; }
.pill.amber { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill.sprint { background: #ffd400; color: #15151e; border-color: #ffd400; }
.pos { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 28px; padding: 0 6px;
  font-weight: 900; font-style: italic; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); }
.pos.p1 { background: var(--gold); color: #1a1300; border-color: var(--gold); }
.pos.p2 { background: var(--silver); color: #111; border-color: var(--silver); }
.pos.p3 { background: var(--bronze); color: #fff; border-color: var(--bronze); }
.move { font-size: .78rem; font-weight: 700; }
.move.up { color: var(--hit); } .move.down { color: var(--neg); } .move.same { color: var(--muted); }
.pts { font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; }
.pts.big { font-size: 1.4rem; }
.pts.neg { color: var(--neg); }
.hit { background: var(--hit-bg); color: var(--hit); font-weight: 700; }
.miss { color: var(--miss); }
.neg { color: var(--neg); }

/* Team stripe: put style="--team: #hex" on the element */
.team-stripe { border-left: 4px solid var(--team, var(--line-strong)); padding-left: 10px; }
.team-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--team, var(--line-strong)); flex: none; }
.team-logo { height: 22px; width: auto; vertical-align: middle; }
.team-logo.lg { height: 40px; }

/* Driver chip: headshot on team colour + name */
.driver { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.driver .face { width: 32px; height: 32px; border-radius: 50%; background: var(--team, var(--surface-2)); overflow: hidden; flex: none;
  display: inline-flex; align-items: flex-end; justify-content: center; color: #fff; font-weight: 700; font-size: .7rem; }
.driver .face img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.driver .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.driver .name b { text-transform: uppercase; }
.driver.lg .face { width: 56px; height: 56px; }
.driver.sm .face { width: 24px; height: 24px; }

/* Pick slots (pick form + read-only pick cards) */
.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .slots { grid-template-columns: minmax(0, 1fr); } }
.slot { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2);
  border-left: 4px solid var(--team, var(--line-strong)); min-width: 0; }
.slot .slot-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted);
  display: flex; justify-content: space-between; }
.slot select { margin-top: 6px; }
.slot.hit { border-left-color: var(--hit); background: var(--hit-bg); }
.slot-group-title { font-weight: 900; font-style: italic; text-transform: uppercase; margin: 18px 0 8px; display: flex; align-items: center; gap: 10px; }
.slot-group-title::after { content: ""; flex: 1; height: 2px; background: var(--line); }

/* Countdown */
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; }
.lock-box { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); }
.lock-box.urgent { background: var(--warn-bg); border-color: transparent; }
.lock-box.locked { background: var(--surface-2); color: var(--muted); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; font-weight: 700; text-transform: uppercase; font-size: .8rem; letter-spacing: .06em;
  color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active, .tabs a:hover { color: var(--text); border-bottom-color: var(--f1-red); }

/* Charts */
.chart-box { position: relative; height: 320px; }
.chart-box.sm { height: 200px; }
.chart-box.lg { height: 420px; }
.spark { display: block; }

/* Heatmap cells */
.heat { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; border-radius: 4px; min-width: 34px; }

/* Empty states */
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* Auth pages */
.auth-wrap { max-width: 420px; margin: 6vh auto; }
.auth-wrap .card { padding: 28px; }

/* Utility spacing */
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.gap-sm { gap: 6px; }
.w-100 { width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
