:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5d6470;
  --line: #e1e4ea;
  --accent: #c8102e;
  --gold: #b8860b;
  --gold-band: rgba(184, 134, 11, 0.16);
  --wr: #2557d6;
  --good: #2e9e5b;
  --warn: #d88a00;
  --bad: #d7263d;
  --you: #d7263d;
  --you-light: #f2a0aa;
  --line-ref: #8a919c;
  --ref-light: #c9cdd4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1a1d23;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #2c3038;
    --accent: #ff4d5e;
    --gold: #e0b44c;
    --gold-band: rgba(224, 180, 76, 0.18);
    --wr: #7aa2ff;
    --good: #3fb370;
    --warn: #e5a12a;
    --bad: #ef4b5f;
    --you: #ff5468;
    --you-light: #ffb8c1;
    --line-ref: #8a919c;
    --ref-light: #d6dae0;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
header { background: var(--card); border-bottom: 1px solid var(--line); padding: 20px 0 0; }
h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
h1::before { content: ""; display: inline-block; width: 6px; height: 1.1em; background: var(--accent);
  margin-right: 10px; vertical-align: -0.15em; border-radius: 2px; }
.sub { margin: 4px 0 12px; color: var(--muted); }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav a { padding: 10px 12px; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent;
  white-space: nowrap; }
nav a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
main { padding: 20px 16px 40px; }
.muted { color: var(--muted); }
a { color: var(--wr); }

.event { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px;
  margin-bottom: 18px; }
.event h2 { margin: 0; font-size: 1.2rem; }
.event .meta { color: var(--muted); margin: 2px 0 14px; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); margin-left: 6px; vertical-align: 2px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .value { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .note { font-size: 0.8rem; color: var(--muted); }
.stat.key { border-color: var(--gold); }
.stat.key .value { color: var(--gold); }
.progress { height: 6px; background: var(--line); border-radius: 3px; margin: 0 0 14px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); }
.chart { margin-top: 14px; }
.chart svg { width: 100%; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; }

.table-scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
td { min-width: 6em; }
td.num, th.num, td.date { white-space: nowrap; min-width: 0; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; background: var(--card); }
.table-scroll thead th { position: sticky; top: 0; } /* only column headings of the long scrolling tables */
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
input[type=search] { width: 100%; max-width: 420px; padding: 9px 12px; margin-bottom: 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; }
.prose { max-width: 720px; }
.prose h2 { font-size: 1.1rem; margin-top: 1.6em; }
footer { padding: 0 16px 30px; font-size: 0.85rem; }

/* event card additions */
.event-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.official { white-space: nowrap; font-size: 0.85rem; padding-top: 4px; }
.top-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-bottom: 12px; }
@media (max-width: 640px) {
  .top-grid { grid-template-columns: minmax(0, 1fr); }
  .event-head { flex-direction: column; gap: 2px; }
  .official { padding-top: 0; }
}
.headline { border: 2px solid var(--gold); border-radius: 10px; padding: 12px 14px; background: var(--gold-band); }
.headline .label { font-size: 0.8rem; color: var(--muted); }
.headline .big { font-size: 2rem; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1.2; }
.checker { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; height: 100%; }
.checker label { font-size: 0.8rem; color: var(--muted); display: block; margin-bottom: 6px; }
.checker .row { display: flex; gap: 8px; }
.checker input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-variant-numeric: tabular-nums; }
.checker button, .more { padding: 8px 14px; border-radius: 8px; border: 0; background: var(--accent); color: #fff;
  font: inherit; font-weight: 600; cursor: pointer; }
.checker .result { margin-top: 8px; font-size: 0.9rem; }
.checker .result div + div { margin-top: 2px; }
table.targets { width: auto; min-width: min(100%, 520px); margin: 4px 0 2px; }
table.targets th, table.targets td { padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); }
table.targets td.strong { font-weight: 650; }
.medal::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px;
  vertical-align: -1px; }
.medal.gold::before { background: #d4a017; }
.medal.silver::before { background: #a8b0ba; }
.medal.bronze::before { background: #b87333; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 6px 0 14px; }
.chart .grid { stroke: var(--line); stroke-dasharray: 2 4; }
.chart .now { stroke: var(--muted); stroke-dasharray: 3 3; opacity: 0.6; }
.chart .gold-day { fill: none; stroke: var(--wr); stroke-width: 2.2; }
.chart .pred { fill: none; stroke: var(--gold); stroke-width: 2; stroke-dasharray: 5 4; }
.chart .band { fill: var(--gold-band); }
.chart .endbar line { stroke: var(--gold); stroke-width: 2; }
.chart .endbar circle { fill: var(--gold); }
.legend .k-day { background: var(--wr); }
.legend .k-pred { background: var(--gold); }
figure.chart { margin: 14px 0 0; }

/* past events and scorecard */
h2.section { font-size: 1.1rem; margin: 6px 0 10px; }
h2.section + * { margin-bottom: 22px; }
.sub-car { font-size: 0.8rem; color: var(--muted); }
.more { display: block; margin: 14px auto 0; }
.ok { color: #2e9e5b; }
.miss { color: var(--accent); }
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 10px 12px; border-bottom: 1px solid var(--line); display: grid;
    grid-template-columns: 1fr auto; gap: 2px 12px; }
  table.stack td { border: 0; padding: 0; min-width: 0; text-align: left; }
  table.stack td.track { grid-column: 1 / -1; font-weight: 600; order: -1; }
  table.stack td.num { text-align: left; }
  table.stack td.num::before { content: attr(data-label) ": "; color: var(--muted); font-size: 0.8rem; }
  table.stack td.date { color: var(--muted); font-size: 0.85rem; }
}
.chart .pred-dot { fill: var(--gold); }
.chart .grid.zero { stroke: var(--muted); stroke-dasharray: none; opacity: 0.5; }
.chart text.offscale { font-size: 10px; }

/* past event page */
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; }
.event h3 { font-size: 1rem; margin: 18px 0 0; }
.chart .wr-dot { fill: var(--wr); }
td.track a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
td.track a:hover { color: var(--wr); }
table.compact td { min-width: 0; }
table.compact td.name { white-space: nowrap; width: 100%; }
@media (max-width: 640px) {
  table.compact { font-size: 0.9rem; }
  table.compact th, table.compact td { padding: 8px 5px; }
  table.compact td.name { white-space: normal; }
}

/* lap comparison */
.coach { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.coach h3 { margin: 0 0 4px; font-size: 1rem; }
.coach-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.button-link { display: inline-block; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  color: var(--text); text-decoration: none; font-size: 0.9rem; cursor: pointer; background: var(--bg); }
.button-link.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.coach-summary { margin: 14px 0 8px; }
.rec-panel { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.rec-status { margin: 0 0 6px; font-weight: 600; }
.rec-status.miss { font-weight: 400; }
.rec-laps { margin: 0 0 6px; padding-left: 20px; }
.rec-laps:empty { display: none; }
.rec-save { margin: 10px 0 0; }
.rec-ip { margin-top: 10px; }
.rec-ip summary { cursor: pointer; color: var(--muted); }
.rec-ip-form { display: flex; gap: 8px; flex-wrap: wrap; }
.rec-ip-form input { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; width: 11em;
  background: var(--bg); color: var(--text); }
.coach-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 760px) { .coach-grid { grid-template-columns: minmax(0, 1fr); } }
.trackmap { width: 100%; height: auto; max-height: 480px; display: block; }
.trackmap path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.trackmap .base { stroke: var(--line); }
.trackmap .hit { stroke: transparent; cursor: pointer; }
.trackmap .zone { cursor: pointer; outline: none; }
.trackmap .seg.good { stroke: var(--good); }
.trackmap .seg.warn { stroke: var(--warn); }
.trackmap .seg.bad { stroke: var(--bad); }
.trackmap .zone.selected .seg, .trackmap .zone:focus .seg { filter: drop-shadow(0 0 3px var(--text)); }
.trackmap .label { cursor: pointer; }
.trackmap .label circle { fill: var(--card); stroke-width: 0; }
.trackmap .label circle.good { fill: var(--good); }
.trackmap .label circle.warn { fill: var(--warn); }
.trackmap .label circle.bad { fill: var(--bad); }
.trackmap .label.selected circle { stroke: var(--text); stroke-width: 2px; vector-effect: non-scaling-stroke; }
.trackmap .label text { fill: #fff; text-anchor: middle; font-weight: 700; font-family: inherit; }
.trackmap .sf { stroke: var(--text); }
.trackmap .arrow { fill: var(--muted); }
.legend .k { width: 12px; height: 12px; border-radius: 3px; }
.legend .k.good { background: var(--good); } .legend .k.warn { background: var(--warn); } .legend .k.bad { background: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 0; border-radius: 8px; padding: 4px 8px; color: #fff; font: inherit; font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; line-height: 1.2; min-width: 52px; }
.chip small { font-weight: 500; font-size: 0.72rem; }
.chip.good { background: var(--good); } .chip.warn { background: var(--warn); } .chip.bad { background: var(--bad); }
.chip.selected { outline: 2px solid var(--text); outline-offset: 1px; }
.corner-detail { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.corner-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 1.05rem; }
.pill { color: #fff; border-radius: 999px; padding: 1px 9px; font-size: 0.85rem; font-weight: 700; }
.pill.good { background: var(--good); } .pill.warn { background: var(--warn); } .pill.bad { background: var(--bad); }
table.corner-table { font-size: 0.88rem; }
table.corner-table th, table.corner-table td { padding: 5px 6px; min-width: 0; }
table.corner-table tbody th { font-weight: 500; color: var(--muted); }
.tips { margin: 4px 0 12px; padding-left: 18px; font-size: 0.92rem; }
.tips li + li { margin-top: 6px; }
.trackmap.has-selection .zone:not(.selected) .seg { opacity: 0.45; }
table.corner-table thead th:first-child { font-weight: 500; }
@media (max-width: 640px) { table.corner-table { font-size: 0.82rem; } }
.trackmap .seg { stroke-linecap: butt; }

/* corner details: prev/next on all screens, a bottom sheet on phones */
.sheet-nav { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 4px; }
.nav-btn { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; padding: 4px 10px;
  font: inherit; font-size: 0.85rem; cursor: pointer; }
.nav-btn.close { display: none; }
.trackmap { cursor: pointer; }
@media (max-width: 760px) {
  .corner-detail { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; max-height: 52vh; overflow: hidden;
    display: flex; flex-direction: column; background: var(--card); border-radius: 14px 14px 0 0; border-width: 1px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25); padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    transform: translateY(105%); transition: transform 0.22s ease; }
  .corner-detail.open { transform: none; }
  .corner-detail .detail-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .sheet-nav { justify-content: space-between; }
  .sheet-nav .nav-btn { padding: 8px 14px; font-size: 0.95rem; }
  .nav-btn.close { display: inline-block; order: 3; margin-left: auto; }
  .sheet-nav .nav-btn[data-step="1"] { order: 2; }
  body.sheet-open { padding-bottom: 52vh; }
}

/* pedal chart in the corner details */
.pedal-chart { margin: 4px 0 12px; }
.pedal-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.pedal-chart path { fill: none; stroke-linejoin: round; }
.pc-ref { stroke: var(--muted); stroke-width: 1.2; opacity: 0.8; }
.pc-me { stroke-width: 2; }
.pc-me.brake { stroke: var(--bad); }
.pc-me.throttle { stroke: var(--good); }
.pc-me.gap { stroke: var(--text); }
.pc-axis { stroke: var(--line); }
.pc-grid { stroke: var(--line); stroke-dasharray: 2 3; }
.pc-tickline { stroke: var(--muted); }
.pc-title { fill: var(--text); font-size: 9.5px; font-weight: 600; }
.pc-tick { fill: var(--muted); font-size: 8.5px; font-variant-numeric: tabular-nums; }
.pc-gapval { font-weight: 700; }
.pc-mark { stroke: var(--muted); stroke-dasharray: 2 3; }
.pc-mark.anchor { stroke: var(--text); opacity: 0.6; }
.pc-marktext { fill: var(--muted); font-size: 8.5px; }
.pc-lift { fill: var(--warn); opacity: 0.16; }
.pc-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.pc-legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; }
.pc-legend .k-me { background: linear-gradient(90deg, var(--bad) 50%, var(--good) 50%); height: 4px; }
.pc-legend .k-ref { background: var(--muted); }
.pc-legend .k-lift { background: var(--warn); opacity: 0.5; height: 10px; width: 10px; border-radius: 2px; }
.trackmap .lift { stroke: var(--text); stroke-linecap: round; }

/* corner close-up: both racing lines to scale, thickness = pedals */
.corner-lines { margin: 4px 0 10px; }
.corner-lines svg { width: 100%; height: auto; display: block; max-height: 360px; }
.corner-lines path { fill: none; stroke-linecap: round; }
.cl-ref { stroke: var(--line-ref); }
.cl-me { stroke: var(--you); }
.cl-me-line { opacity: 0.82; } /* faded as one, so the pieces don't show where they overlap */
.cl-dot { stroke-width: 2; }
.cl-dot.me.brake { fill: var(--you); stroke: var(--card); }
.cl-dot.me.slow { fill: none; stroke: var(--you); }
.cl-dot.me.gas { fill: var(--you-light); stroke: var(--card); }
.cl-dot.ref.brake { fill: var(--line-ref); stroke: var(--card); }
.cl-dot.ref.slow { fill: none; stroke: var(--line-ref); }
.cl-dot.ref.gas { fill: var(--ref-light); stroke: var(--card); }
.cl-arrow { fill: var(--muted); stroke: none; }
.cl-scale { stroke: var(--muted); stroke-width: 2; }
.cl-scaletext { fill: var(--muted); font-size: 9px; }
.pc-legend .k-line { height: 4px; }
.pc-legend .k-line.me { background: var(--you); } .pc-legend .k-line.ref { background: var(--line-ref); }
.corner-lines { position: relative; }
.cl-toggle { position: absolute; top: 0; right: 0; z-index: 1; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: 0.8rem; cursor: pointer; }
.cl-toggle:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.corner-lines.hide-mine .cl-me-line, .corner-lines.hide-mine .cl-dot.me { display: none; }
/* close-up legend: a small grid of you / the reference against each dot */
table.cl-legend { width: auto; margin: 6px 0 2px; font-size: 0.78rem; color: var(--muted); }
table.cl-legend th, table.cl-legend td { padding: 2px 10px 2px 0; border: 0; min-width: 0; text-align: center;
  font-weight: 500; position: static; background: none; }
table.cl-legend tbody th { text-align: left; color: var(--text); white-space: nowrap; }
.cl-legend .k-line { display: inline-block; width: 14px; height: 4px; vertical-align: middle; margin-right: 5px; }
.cl-legend .k-line.me { background: var(--you); } .cl-legend .k-line.ref { background: var(--line-ref); }
.cl-legend .k-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; box-sizing: border-box; vertical-align: middle; }
.cl-legend .k-dot.brake.me { background: var(--you); } .cl-legend .k-dot.brake.ref { background: var(--line-ref); }
.cl-legend .k-dot.slow.me { border: 2px solid var(--you); } .cl-legend .k-dot.slow.ref { border: 2px solid var(--line-ref); }
.cl-legend .k-dot.gas.me { background: var(--you-light); } .cl-legend .k-dot.gas.ref { background: var(--ref-light); }

/* Super License tab */
.license-intro { margin-top: 0; max-width: 760px; }
.license-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.license-id { font-weight: 800; font-size: 1.05rem; color: #fff; background: var(--accent); border-radius: 8px; padding: 6px 9px;
  min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
.license-head h2 { margin: 0; font-size: 1.1rem; }
.license-head .meta { margin: 0; }
.license-medals { display: flex; flex-wrap: wrap; gap: 6px 18px; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.license-medals b, .medal-result b.medal { font-weight: 600; }
.license-test .coach { margin-top: 10px; padding-top: 10px; }
.medal-result { margin-left: 4px; }
