/* whipp.in — dark timing-screen */

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

:root {
  --bg: #0d0d11;
  --panel: #16161d;
  --panel-hover: #1b1b24;
  --border: #26262f;
  --text: #e6e6ee;
  --muted: #8b8b99;
  --purple: #a78bfa;
  --green: #34d399;
  --red: #f87171;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.t-purple { color: var(--purple); }
.t-green { color: var(--green); }
.t-red { color: var(--red); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---- top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--border);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.wordmark-accent { color: var(--purple); }

/* The mark: a D-shaped racing wheel (source of truth: brand/gen.js). */
.wordmark-icon { width: 22px; height: 22px; flex: none; }
.wordmark-icon .ring { stroke: var(--purple); }
.wordmark-icon .hub { fill: var(--purple); }
.wordmark-icon .hub-hole { fill: var(--bg); }
.wordmark-icon .stripe { fill: var(--text); }

.tabs { display: flex; gap: 4px; }

.tabs a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 14px;
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-bottom: 2px solid transparent;
}

.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--purple); }

/* ---- error bar ---- */

.error-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 20px 0;
  padding: 8px 12px;
  background: #2a1520;
  border: 1px solid #52222f;
  border-radius: 6px;
  color: var(--red);
  font-size: 13px;
}

.error-close {
  background: none;
  border: none;
  color: var(--red);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* ---- filter bar ---- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.filter-group { display: flex; align-items: center; gap: 8px; }

.filter-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

.sel,
.maxms-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 13px;
  font-family: var(--sans);
}

.sel:focus,
.maxms-input:focus { outline: 1px solid var(--purple); }

.sel-combo { max-width: 360px; font-family: var(--mono); font-size: 12px; }
.sel-lap { max-width: 320px; font-family: var(--mono); font-size: 12px; }
.maxms-input { width: 90px; font-family: var(--mono); }
.maxms-wrap { display: inline-flex; align-items: center; gap: 6px; }

.chips { display: flex; gap: 4px; }

.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}

.chip:hover { color: var(--text); }
.chip-active { color: var(--purple); border-color: var(--purple); }

.chk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  margin-right: 8px;
}

.chk input { accent-color: var(--purple); }
.chk:has(input:checked) { color: var(--text); }

/* ---- combo hero ----
   Track outline on the left, car render on the right, both straight from the
   game's content folders. Images are optional: the JS removes any that 404,
   and the text half stands on its own. */

.combo-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.hero-side {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.hero-side.hero-car { justify-content: flex-end; text-align: right; }

.hero-text { min-width: 0; }

.hero-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-meta {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The outline ships as a dark shape on transparency; invert it for the dark
   theme and dim it so it reads as a mark, not a picture. */
.hero-outline {
  height: 44px;
  width: auto;
  flex: none;
  filter: invert(1);
  opacity: 0.75;
}

.hero-render {
  height: 46px;
  width: auto;
  flex: none;
  border-radius: 4px;
}

.track-cell { display: inline-flex; align-items: center; gap: 8px; }

.track-thumb {
  height: 22px;
  width: auto;
  flex: none;
  filter: invert(1);
  opacity: 0.6;
}

/* ---- stats strip ---- */

.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
  padding: 12px 20px 0;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 0;
}

.tile-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 3px;
  white-space: nowrap;
}

.tile-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- main / panels / tables ---- */

main { padding: 12px 20px 40px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.section { margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tbl th {
  text-align: right;
  color: var(--muted);
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.tbl td {
  text-align: right;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.tbl th.left,
.tbl td.left { text-align: left; }

.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: var(--panel-hover); }

.pos { color: var(--muted); }
.driver { font-weight: 500; }

.lap-big { font-size: 17px; font-weight: 700; }
.lap-time { font-size: 14px; font-weight: 600; }
.row-invalid .lap-time { color: var(--muted); font-weight: 400; }

.cuts-bad { color: var(--red); }
.cfg-dot { color: var(--green); font-size: 9px; }

.badge {
  display: inline-block;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  letter-spacing: 1px;
  margin-right: 4px;
  font-family: var(--mono);
}

.row-link { cursor: pointer; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
  font-size: 14px;
}

/* ---- pager ---- */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 0;
}

.pager-info { color: var(--muted); font-size: 12px; }

.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 14px;
  font-size: 12px;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--purple); }
.btn:disabled { color: var(--muted); opacity: 0.5; cursor: default; }

/* ---- session detail ---- */

.detail-head { padding: 14px 16px; }

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
}

.back-link:hover { color: var(--purple); }

.detail-title {
  font-size: 16px;
  font-weight: 600;
  margin: 8px 0 6px;
}

.detail-title .type {
  color: var(--purple);
  font-family: var(--mono);
  letter-spacing: 1px;
  font-size: 13px;
  margin-right: 10px;
}

.detail-meta {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.panel-title {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 10px 16px 0;
}

.cond-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  padding: 10px 16px 14px;
}

.cond-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 2px;
  white-space: nowrap;
}

.cond-value { font-size: 13px; }

.cond-empty { padding: 10px 16px 14px; font-size: 13px; }

/* ---- analyse affordance on lap-time cells ---- */

.analyse-link { cursor: pointer; }
.analyse-link:hover { text-decoration: underline dotted; text-underline-offset: 3px; }

/* ---- uPlot dark overrides (canvas colours are set in the chart opts) ---- */

.uplot {
  font-family: var(--mono);
  font-size: 11px;
  width: 100%;
  color: var(--muted);
}

.u-legend { display: none; }
.u-hz .u-cursor-x, .u-vt .u-cursor-y { border-right-color: var(--muted); }
.u-hz .u-cursor-y, .u-vt .u-cursor-x { border-bottom-color: var(--muted); }
.u-select { background: rgba(167, 139, 250, 0.12); }

/* ---- chart panels ---- */

.panel-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.panel-sub { font-size: 11px; padding: 10px 16px 0 0; }
.panel-body { padding: 10px 16px 14px; }
.chart-box { width: 100%; min-width: 0; }

.chart-empty {
  text-align: center;
  padding: 28px 0;
  font-size: 13px;
}

.chart-readout {
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: none;
}

.legend-dashed {
  height: 0;
  width: 14px;
  border-radius: 0;
  border-top: 1px dashed var(--muted);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

/* ---- analysis headline ---- */

.headline {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  padding: 14px 16px;
}

.hl-card { min-width: 0; }

.hl-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.hl-time { font-size: 26px; font-weight: 700; line-height: 1.1; }
.hl-sub { font-size: 12px; margin: 4px 0 8px; }

.hl-rows { display: grid; gap: 3px; }
.hl-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.hl-key { color: var(--muted); text-transform: uppercase; letter-spacing: 1px; font-size: 10px; white-space: nowrap; }
.hl-val { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hl-delta {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: 180px;
  padding: 0 16px;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.hl-sec {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hl-sectors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 12px;
  margin-top: 8px;
  font-size: 12px;
}

/* ---- micro-sector strips ---- */

.strip-wrap { min-width: 0; }

.ms-strip {
  display: flex;
  gap: 1px;
  height: 28px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
}

.ms-cell { flex: 1 1 0; min-width: 0; cursor: crosshair; }
.ms-cell.ms-hot { box-shadow: inset 0 0 0 2px var(--text); }

.strip-scale {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  margin-top: 4px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ---- track map ---- */

.map-body { min-width: 0; }

.map-wrap {
  position: relative;
  width: 100%;
  max-height: 70vh;
  margin: 0 auto;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
}

.map-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.map-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-wrap-auto { max-height: none; }

.map-svg-auto {
  position: static;
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
}

/* ---- live ---- */

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  margin-left: 6px;
  vertical-align: middle;
  flex: none;
}

.tabs a .live-dot { display: none; }
.tabs a .live-dot.on { display: inline-block; }

.live-dot.on {
  background: var(--green);
  animation: live-pulse 1.6s ease-out infinite;
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot.on { animation: none; }
}

.live-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 10px 16px;
}

.live-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  min-width: 120px;
}

.live-head .live-dot { margin-left: 0; }

.live-status { white-space: nowrap; }

.live-pill {
  border: 1px solid #52222f;
  background: #2a1520;
  color: var(--red);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
}

.live-head-mid {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  min-width: 0;
}

.live-head-mid .type {
  color: var(--purple);
  font-family: var(--mono);
  letter-spacing: 1px;
  font-size: 13px;
  text-transform: uppercase;
  white-space: nowrap;
}

.live-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.live-countdown {
  font-size: 22px;
  font-weight: 700;
  min-width: 80px;
  text-align: right;
}

.live-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.live-left { min-width: 0; }

.live-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.live-idle { grid-column: 1 / -1; }

.live-card {
  padding: 12px 14px;
  border-top: 3px solid var(--border);
  min-width: 0;
}

.lc-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  min-width: 0;
}

.lc-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  align-self: center;
}

.lc-driver {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lc-car {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lc-timer {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 1px;
}

.lc-delta-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
}

.lc-delta {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}

.lc-delta-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lc-small {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  font-size: 12px;
  margin-top: 2px;
}

.lc-sectors {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.lc-sec {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 6px;
  text-align: center;
  min-width: 0;
}

.lc-sec-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.lc-sec-val { font-size: 14px; font-weight: 600; }
.lc-ghost { opacity: 0.45; }

.lc-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 10px;
  font-size: 11px;
}

.lc-kv { display: inline-flex; gap: 5px; align-items: baseline; }
.lc-kv-label { text-transform: uppercase; letter-spacing: 1px; font-size: 9px; }
.lc-kv-val { color: var(--text); }

.live-feed { min-width: 0; }

.feed-list {
  max-height: 75vh;
  overflow-y: auto;
  padding: 4px 0 6px;
}

.feed-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 5px 16px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.feed-row:last-child { border-bottom: none; }
.feed-time { flex: none; font-size: 11px; }
.feed-text { min-width: 0; overflow-wrap: anywhere; }

.feed-pb {
  border-left: 3px solid var(--purple);
  background: rgba(167, 139, 250, 0.08);
}

.feed-pb .feed-text { color: var(--purple); font-weight: 600; }
.feed-chat .feed-text { font-style: italic; }
.feed-session .feed-text { color: var(--muted); }
.feed-empty { padding: 14px 16px; font-size: 12px; }

.lm-car text { pointer-events: none; user-select: none; }

@media (max-width: 900px) {
  .live-grid { grid-template-columns: 1fr; }
}

/* ---- small screens ---- */

@media (max-width: 720px) {
  .topbar { justify-content: center; }
  /* Six tabs are ~529px; a phone gives the nav ~335px. Wrapping puts them on
     two centred rows (Live/Leaderboard/Laps, then Sessions/Analysis/Trends)
     with everything reachable — a scrolling strip would hide the last tabs
     behind a gesture with nothing to hint at it. */
  .tabs { flex-wrap: wrap; justify-content: center; row-gap: 2px; }
  .filter-bar { gap: 8px 12px; }
  /* Selects are sized by their longest option and would otherwise push the
     page a few px wide; let them shrink to the bar instead. */
  .filter-group { max-width: 100%; }
  .sel { min-width: 0; }
  .sel-combo, .sel-lap { max-width: 100%; }
  main, .stats-strip, .combo-hero { padding-left: 10px; padding-right: 10px; }
  /* Side by side, both names ellipsise on a phone; stacked, each gets the
     full width. row-reverse keeps the picture leading on both rows. */
  .combo-hero { flex-direction: column; align-items: stretch; gap: 10px; }
  .hero-side.hero-car { flex-direction: row-reverse; justify-content: flex-end; text-align: left; }
  .hero-outline, .hero-render { height: 34px; }
  .error-bar { margin-left: 10px; margin-right: 10px; }
  .headline { grid-template-columns: 1fr; }
  .hl-delta { border-left: none; border-right: none; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 10px 0; }
  .lc-timer { font-size: 30px; }
}
