/* Dark only. The panel is four equal sectors that fill the window and never scroll; Ajustes opens over it. */

:root {
  --bg: #07090d;
  --card: #10151d;
  --text: #eef2f8;
  --muted: #6f7a8c;
  --grid: #1c2230;
  --track: #2b3547;
  --accent: #4cc2ff;
  --ghost: #b794f6;
  --good: #3ddc84;
  --warn: #ffb020;
  --bad: #ff5d5d;
  --bar: clamp(38px, 4.6vh, 52px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

body { display: flex; flex-direction: column; }

[hidden] { display: none !important; }

/* ------------------------------------------------------------ Header */

.bar {
  flex: none;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  border-bottom: 1px solid var(--grid);
}

.brand { font-size: 13px; letter-spacing: 0.22em; color: var(--muted); }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 14px;
  font-weight: 600;
}
.tab.active { background: var(--card); color: var(--text); }

.chips { display: flex; gap: 6px; margin-left: auto; overflow: hidden; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--chip, var(--muted));
  background: color-mix(in srgb, var(--chip, var(--muted)) 16%, transparent);
}
.chip::before {
  content: '';
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.5em;
  border-radius: 50%;
  background: currentColor;
}
.chip.good { --chip: var(--good); }
.chip.warn { --chip: var(--warn); }
.chip.bad { --chip: var(--bad); }

.icon {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 20px;
  line-height: 1;
}
.icon:hover, .tab:hover { color: var(--text); }

.banner {
  flex: none;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  background: var(--warn);
  color: #1a1200;
}
.banner.error { background: var(--bad); color: #fff; }

/* ------------------------------------------------------------ Views */

.views { position: relative; flex: 1; min-height: 0; }

.panel {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas: 'data map' 'secondary video';
  gap: 2px;
  background: var(--grid);
}

@media (orientation: portrait) {
  .panel {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 1fr);
    grid-template-areas: 'data' 'map' 'secondary' 'video';
  }
}

.quad {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  container-type: size;
}
.data { grid-area: data; }
.map { grid-area: map; }
.secondary { grid-area: secondary; }
.video { grid-area: video; }

/* Sizes inside a sector follow the sector (cqh, cqw), so each reads the same on a phone and on a big screen. */

.data {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 2cqh 3cqw;
  padding: 3cqh 3cqw;
  align-items: center;
}

.speed { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
#speed {
  font-size: min(46cqh, 23cqw);
  line-height: 0.88;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.unit { font-size: max(11px, min(6cqh, 3cqw)); letter-spacing: 0.12em; color: var(--muted); }

.lap { display: flex; flex-direction: column; gap: 1.5cqh; min-width: 0; }
#lapNow {
  font-size: min(17cqh, 9cqw);
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.delta {
  font-size: min(15cqh, 8cqw);
  line-height: 1;
  min-height: 1em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }

.stats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3cqw; }
.stats div, .forces div { display: flex; flex-direction: column; min-width: 0; }
.stats b { font-size: max(15px, min(10cqh, 5cqw)); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stats span, .forces span {
  font-size: max(10px, min(4cqh, 2cqw));
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

#speed.stale { color: var(--warn); }
#speed.old { color: var(--bad); }

.map > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* The close-up that follows the car. It sits over the circuit and can be dragged anywhere inside its sector. */
.zoom {
  position: absolute;
  left: 0;
  top: 0;
  width: min(32cqw, 48cqh);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--grid);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.zoom.dragging { cursor: grabbing; border-color: var(--accent); }
.zoom canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

.video video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }

.secondary {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 1cqh;
  padding: 1.5cqh 1.5cqw;
}
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5cqw; min-height: 0; }
.chart { position: relative; min-width: 0; min-height: 0; }
.chart canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.below { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3cqw; align-items: end; }
.forces { display: flex; gap: 2.5cqw; }
.forces b { font-size: max(16px, min(8cqh, 4cqw)); font-variant-numeric: tabular-nums; line-height: 1.1; }

#lapTable { width: 100%; border-collapse: collapse; font-size: max(12px, min(4.6cqh, 2.3cqw)); font-variant-numeric: tabular-nums; }
#lapTable td { padding: 0.15em 0.5em; text-align: right; white-space: nowrap; }
#lapTable td:first-child { text-align: left; color: var(--muted); }
#lapTable tr.best td { color: var(--good); font-weight: 700; }

td.good { color: var(--good); }
td.bad { color: var(--bad); }
td.warn { color: var(--warn); }

/* ------------------------------------------------------------ Ajustes */

.settings {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: auto;
  padding: 16px;
  background: var(--bg);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  max-width: 1400px;
  margin: 0 auto;
}
.card { display: grid; gap: 12px; align-content: start; min-width: 0; padding: 16px 18px; border-radius: 14px; background: var(--card); }
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0; font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
label.delay b { color: var(--text); font-variant-numeric: tabular-nums; }
input[type='text'], input[type='password'] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--grid);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
}
input[type='range'] { width: 100%; }
input[type='radio'], input[type='checkbox'] { accent-color: var(--accent); }

.row { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  font: inherit;
  cursor: pointer;
}
.card button {
  background: var(--accent);
  color: #04121c;
  border: 0;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 16px;
  font-weight: 700;
}
.card button.secondary { background: transparent; color: var(--muted); border: 1px solid var(--grid); }

.note { margin: 0; color: var(--muted); font-size: 13px; }
.note a { color: var(--accent); }

.card table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.card th, .card td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); }
.card th { color: var(--muted); font-weight: 600; font-size: 13px; }
.card tr.best td { color: var(--good); font-weight: 700; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 18px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .brand, .chip.opt { display: none; }
  .bar { gap: 8px; padding: 0 8px; }
  .settings { padding: 10px; }
}
