/* ============================================================
   Lap Times — dark "pit-wall" timing board.
   Deliberately single-look (dark). Self-contained, no CDN.
   Chart colors validated via the dataviz palette validator
   against the chart surface (#131a22, dark).
   ============================================================ */

:root {
  --plane:          #0b0f14;   /* page background */
  --surface-1:      #131a22;   /* cards + chart surface (validated) */
  --surface-2:      #1a222c;   /* row hover / insets */
  --text-primary:   #f4f6f8;
  --text-secondary: #aeb6c0;
  --muted:          #7a828c;
  --grid:           #232c37;
  --baseline:       #313b47;
  --border:         rgba(255,255,255,0.08);
  --series-1:       #3987e5;   /* best-lap bars */
  --series-2:       #199e70;   /* reserve: 2nd rider / reference */
  --good:           #0ca30c;   /* status: personal best / improving */
  --live:           #d03b3b;   /* status: live session */
  --warning:        #fab219;

  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --wrap: 980px;
  --radius: 12px;
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--plane);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* --- Top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: rgba(11,15,20,0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand .flag { font-size: 1.25rem; }
.brand h1 {
  font-size: 1.05rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}
.search { display: flex; gap: 0.4rem; }
.search input {
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 8px; padding: 0.45rem 0.7rem; font: inherit; width: min(52vw, 260px);
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: 2px solid var(--series-1); outline-offset: 0; }
.search button {
  background: var(--series-1); color: #061018; border: 0; border-radius: 8px;
  padding: 0.45rem 0.9rem; font: inherit; font-weight: 700; cursor: pointer;
}
.search button:hover { filter: brightness(1.08); }

/* --- Layout --- */
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 1.25rem; }
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.15rem; margin-bottom: 1.1rem;
}
.card-title {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-secondary); font-weight: 700; margin-bottom: 0.85rem;
}
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 0.75rem; }
.hint code { font-family: var(--mono); color: var(--text-secondary); }

/* --- Rider hero --- */
.hero {
  display: grid; grid-template-columns: auto 1fr; gap: 1rem 1.25rem; align-items: center;
  background: linear-gradient(180deg, #16202b, var(--surface-1));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.15rem 1.25rem; margin-bottom: 1.1rem;
}
.hero-num {
  font-family: var(--mono); font-weight: 700; font-size: 2rem; line-height: 1;
  color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 0.5rem 0.7rem; min-width: 3.2rem; text-align: center;
}
.hero-id h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.01em; }
.hero-id .sub { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.15rem; }
.hero-stats {
  grid-column: 1 / -1; display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.6rem;
}
.stat {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.6rem 0.75rem;
}
.stat .k { color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat .v { font-family: var(--mono); font-size: 1.15rem; font-weight: 700; margin-top: 0.15rem; }
.stat .v.hl { color: var(--series-1); }

/* --- Live banner --- */
.live {
  border: 1px solid rgba(208,59,59,0.5);
  background: linear-gradient(180deg, rgba(208,59,59,0.14), var(--surface-1));
  border-radius: var(--radius); padding: 1.05rem 1.15rem; margin-bottom: 1.1rem;
}
.live-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--live);
  box-shadow: 0 0 0 0 rgba(208,59,59,0.7); animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(208,59,59,0.6); }
  70% { box-shadow: 0 0 0 8px rgba(208,59,59,0); }
  100% { box-shadow: 0 0 0 0 rgba(208,59,59,0); }
}
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.live-tag { font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem; color: var(--live); }
.live-head .ev { color: var(--text-secondary); font-size: 0.9rem; }
.live-toggle {
  margin-left: auto; display: flex; align-items: center; gap: 0.45rem;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 8px; padding: 0.35rem 0.7rem; font: inherit; font-size: 0.82rem; cursor: pointer;
}
.live-toggle[aria-pressed="true"] { border-color: var(--good); color: var(--good); }
.live-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.6rem;
  margin-top: 0.9rem;
}
.big { font-family: var(--mono); font-weight: 700; }
.live .stat .v.last { color: var(--text-primary); }
.pos-pill {
  display: inline-block; font-family: var(--mono); font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.05rem 0.4rem;
}

/* --- Events table --- */
.table-scroll { overflow-x: auto; }
table.events { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.events th, table.events td {
  text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
table.events th {
  color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700;
}
table.events th.num, table.events td.num { text-align: right; }
table.events tbody tr { cursor: pointer; }
table.events tbody tr:hover { background: var(--surface-2); }
table.events tr.is-live td { box-shadow: inset 3px 0 0 var(--live); }
table.events td.c-best { font-weight: 700; }
.badge {
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  border-radius: 5px; padding: 0.05rem 0.35rem; margin-left: 0.35rem; vertical-align: middle;
}
.badge.pb { background: rgba(12,163,12,0.16); color: var(--good); border: 1px solid rgba(12,163,12,0.4); }
.badge.live { background: rgba(208,59,59,0.16); color: var(--live); border: 1px solid rgba(208,59,59,0.45); }
.badge.cap { background: rgba(57,135,229,0.16); color: var(--series-1); border: 1px solid rgba(57,135,229,0.4); }
.muted-cell { color: var(--muted); }

/* Expanded lap detail row */
tr.detail-row > td { padding: 0; background: var(--plane); }
.lap-panel { padding: 0.85rem 0.9rem; }
.lap-panel .lp-head { color: var(--text-secondary); font-size: 0.8rem; margin-bottom: 0.6rem; }
.lap-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 0.3rem; }
.lap {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 7px;
  padding: 0.3rem 0.55rem;
}
.lap .li { color: var(--muted); font-size: 0.72rem; font-family: var(--mono); }
.lap .lt { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.lap.best { border-color: rgba(12,163,12,0.5); }
.lap.best .lt { color: var(--good); }
.lap.out .lt { color: var(--muted); font-weight: 400; }

/* --- Trend chart --- */
.trend-chart { width: 100%; overflow-x: auto; }
.trend-chart svg { display: block; width: 100%; height: auto; }
.trend-chart .bar { fill: var(--series-1); }
.trend-chart .bar.pb { fill: var(--series-1); }
.trend-chart .gridline { stroke: var(--grid); stroke-width: 1; }
.trend-chart .axis { stroke: var(--baseline); stroke-width: 1; }
.trend-chart .lbl { fill: var(--muted); font: 10px var(--sans); }
.trend-chart .val { fill: var(--text-secondary); font: 10px var(--mono); }
.trend-chart .star { fill: var(--good); font: 10px var(--sans); }

/* --- Status / footer --- */
.status { color: var(--muted); font-size: 0.9rem; padding: 0.5rem 0.2rem; }
.status.err { color: var(--warning); }
.foot { max-width: var(--wrap); margin: 0.5rem auto 2rem; padding: 0 1.25rem; color: var(--muted); font-size: 0.78rem; }
.foot a { color: var(--text-secondary); }

@media (max-width: 560px) {
  .hero { grid-template-columns: auto 1fr; }
  .hero-id h2 { font-size: 1.25rem; }
  .brand h1 { font-size: 0.95rem; }
}
