:root {
  --asphalt: #090c0f;
  --panel: #0f141a;
  --raised: #151d25;
  --line: #1f2932;
  --line-soft: #17202880;
  --ink: #e9eff5;
  --mute: #6d7e8d;
  --dim: #43525e;
  --purple: #b24bf3;
  --green: #3dd65e;
  --amber: #ffd02e;
  --red: #ff4b3e;
  --blue: #3d9bff;
  --dock: calc(3.9rem + env(safe-area-inset-bottom));
  --gut: 1rem;
}

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--asphalt);
  color: var(--ink);
  font-family: "Spline Sans Mono", ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: "Archivo", system-ui, sans-serif;
  font-variation-settings: "wdth" 116;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
  text-transform: uppercase;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.eyebrow {
  margin: 0;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

.empty, .hint {
  margin: 0;
  padding: 1.4rem var(--gut);
  color: var(--dim);
  font-size: 11px;
  text-align: center;
}

.empty.is-hidden, .hint.is-hidden { display: none; }

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  padding: calc(env(safe-area-inset-top) + 0.7rem) var(--gut) 0.7rem;
  background: color-mix(in srgb, var(--asphalt) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.bar-id { min-width: 0; }

.bar-id h1 {
  font-size: 1.05rem;
  line-height: 1.15;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-live {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mute);
}

.bar-live .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.bar-live[data-state="live"] { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.bar-live[data-state="live"] .dot { background: var(--green); animation: pulse 2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.2; } }

main {
  padding-bottom: var(--dock);
}

.screen { display: none; }
.screen.is-active { display: block; }

.lights {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  padding: 1rem var(--gut) 0.7rem;
  max-width: 22rem;
  margin: 0 auto;
}

.lights i {
  aspect-ratio: 1;
  border-radius: 50%;
  background: #14191e;
  border: 1px solid #1c242c;
  box-shadow: inset 0 2px 6px #00000090;
  transition: background 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.lights[data-state="armed"] i,
.lights[data-state="red"] i {
  background: radial-gradient(circle at 38% 32%, #ff8478, var(--red) 62%, #7a1108);
  border-color: #ff6a5c;
  box-shadow: 0 0 14px #ff4b3e70, inset 0 1px 3px #ffffff40;
}

.lights[data-state="caution"] i {
  background: radial-gradient(circle at 38% 32%, #ffe58a, var(--amber) 62%, #7a5c00);
  border-color: #ffd85c;
  box-shadow: 0 0 12px #ffd02e60, inset 0 1px 3px #ffffff40;
  animation: blink 0.9s steps(1) infinite;
}

.lights[data-state="caution"] i:nth-child(even) { animation-delay: 0.45s; }

@keyframes blink { 50% { opacity: 0.25; box-shadow: none; } }

.lights[data-state="go"] i {
  background: #0d1216;
  border-color: color-mix(in srgb, var(--green) 45%, #1c242c);
  box-shadow: 0 0 10px #3dd65e28;
}

.lights[data-state="chequered"] i {
  background:
    repeating-conic-gradient(var(--ink) 0 25%, #0d1216 0 50%) 0 0 / 50% 50%;
  border-color: var(--mute);
}

.lights-note {
  margin: 0;
  padding: 0 var(--gut) 0.9rem;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--dim);
  min-height: 1.4em;
}

.lights-note.is-hot { color: var(--amber); }
.lights-note.is-stop { color: var(--red); }

.map-wrap {
  position: relative;
  margin: 0 var(--gut);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(160deg, var(--panel), var(--asphalt));
  overflow: hidden;
  aspect-ratio: 1 / 1.05;
}

#map { display: block; width: 100%; height: 100%; touch-action: manipulation; }

.map-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 2rem;
  text-align: center;
  font-size: 11px;
  color: var(--dim);
  background: var(--asphalt);
}

.map-empty.is-hidden { display: none; }

.strip {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.9rem var(--gut);
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.strip::-webkit-scrollbar { display: none; }

.pill {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem 0.4rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 11px;
  scroll-snap-align: start;
  transition: border-color 0.15s ease;
}

.pill i {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--team, var(--dim));
  flex: none;
}

.pill b { font-family: "Archivo", sans-serif; font-variation-settings: "wdth" 108; font-weight: 700; }
.pill span { color: var(--dim); font-size: 10px; }
.pill.is-on { border-color: var(--ink); background: var(--raised); }

.cond {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 0 0 1.4rem;
  background: var(--line);
  border-block: 1px solid var(--line);
}

.cond > div { background: var(--asphalt); padding: 0.8rem 0.6rem; text-align: center; }
.cond dt { font-size: 8.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.cond dd { margin: 0.3rem 0 0; font-size: 13px; }

.tower { list-style: none; margin: 0; padding: 0; }

.row {
  position: relative;
  display: grid;
  grid-template-columns: 1.7rem 1fr auto auto;
  gap: 0.6rem;
  align-items: center;
  width: 100%;
  padding: 0.62rem var(--gut);
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  isolation: isolate;
  min-height: 3rem;
}

.row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--trail, 0%);
  background: linear-gradient(90deg, color-mix(in srgb, var(--team, #4a5a68) 15%, transparent), transparent);
  z-index: -1;
  transition: width 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.row:active { background: var(--panel); }

.row .pos {
  font-family: "Archivo", sans-serif;
  font-variation-settings: "wdth" 110;
  font-weight: 700;
  font-size: 1rem;
  color: var(--mute);
}

.row.is-lead .pos { color: var(--ink); }

.who { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.who .tag { width: 3px; height: 1.5rem; border-radius: 2px; background: var(--team, #4a5a68); flex: none; }
.who .acr { font-family: "Archivo", sans-serif; font-variation-settings: "wdth" 110; font-weight: 700; }
.who .tyre {
  display: grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  border: 1.5px solid var(--dim);
  border-radius: 50%;
  font-size: 8px;
  font-weight: 700;
  flex: none;
}

.who .tyre[data-c="SOFT"] { border-color: var(--red); }
.who .tyre[data-c="MEDIUM"] { border-color: var(--amber); }
.who .tyre[data-c="HARD"] { border-color: var(--ink); }
.who .tyre[data-c="INTERMEDIATE"] { border-color: var(--green); }
.who .tyre[data-c="WET"] { border-color: var(--blue); }

.times { text-align: right; }
.times .lap { font-size: 12.5px; }
.times .lap.is-purple { color: var(--purple); }
.times .lap.is-green { color: var(--green); }
.times .gap { display: block; font-size: 10.5px; color: var(--dim); margin-top: 0.1rem; }

.sec { display: flex; flex-direction: column; gap: 2px; width: 0.5rem; }
.sec i { height: 5px; border-radius: 1px; background: var(--line); }
.sec i[data-s="green"] { background: var(--green); }
.sec i[data-s="purple"] { background: var(--purple); }
.sec i[data-s="yellow"] { background: var(--amber); }

.row.is-out { opacity: 0.4; }

.feed-title {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--dim);
  padding: 1.6rem var(--gut) 0.7rem;
}

.feed { list-style: none; margin: 0; padding: 0 0 1.5rem; }

.msg {
  display: grid;
  grid-template-columns: 3.6rem 1fr;
  gap: 0.7rem;
  padding: 0.6rem var(--gut);
  border-bottom: 1px solid var(--line-soft);
  align-items: baseline;
}

.msg time { color: var(--dim); font-size: 10.5px; }
.msg p { margin: 0; font-size: 11.5px; }
.msg[data-flag="RED"] p { color: var(--red); }
.msg[data-flag="YELLOW"] p, .msg[data-flag="DOUBLE YELLOW"] p { color: var(--amber); }
.msg[data-flag="GREEN"] p { color: var(--green); }
.msg[data-flag="CHEQUERED"] p { color: var(--ink); }

.next { padding: 1.5rem var(--gut) 1.3rem; border-bottom: 1px solid var(--line); }
.next h2 { font-size: 1.5rem; margin-top: 0.35rem; line-height: 1.05; }
.next-where { margin: 0.4rem 0 0; color: var(--mute); font-size: 11px; }

.cd { display: flex; gap: 1.6rem; margin-top: 1.2rem; }
.cd div { display: flex; align-items: baseline; gap: 0.25rem; }
.cd strong {
  font-family: "Archivo", sans-serif;
  font-variation-settings: "wdth" 105;
  font-weight: 800;
  font-size: 1.7rem;
  line-height: 1;
}
.cd span { font-size: 10px; color: var(--dim); }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  margin: 1rem var(--gut);
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.seg button {
  padding: 0.55rem 0.3rem;
  border-radius: 7px;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  transition: background 0.15s ease, color 0.15s ease;
}

.seg button[aria-selected="true"] { background: var(--raised); color: var(--ink); }

.stand, .cal { list-style: none; margin: 0; padding: 0 0 1.5rem; display: none; }
.stand.is-active, .cal.is-active { display: block; }

.stand li {
  position: relative;
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.7rem var(--gut);
  border-bottom: 1px solid var(--line-soft);
  isolation: isolate;
}

.stand li::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--share, 0%);
  background: color-mix(in srgb, var(--team, #4a5a68) 16%, transparent);
  z-index: -1;
  transition: width 0.7s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.stand .rank { color: var(--dim); font-size: 11px; }
.stand .name { font-family: "Archivo", sans-serif; font-variation-settings: "wdth" 108; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stand .name small { display: block; font-family: "Spline Sans Mono", monospace; font-weight: 400; font-size: 10px; color: var(--dim); }
.stand .pts { font-size: 13px; }

.cal li {
  display: grid;
  grid-template-columns: 1.8rem 1fr auto;
  gap: 0.7rem;
  align-items: baseline;
  padding: 0.7rem var(--gut);
  border-bottom: 1px solid var(--line-soft);
}

.cal .rnd { color: var(--dim); font-size: 10.5px; }
.cal .gp { font-family: "Archivo", sans-serif; font-variation-settings: "wdth" 108; font-weight: 600; font-size: 13px; }
.cal .gp small { display: block; font-family: "Spline Sans Mono", monospace; font-weight: 400; font-size: 10px; color: var(--dim); }
.cal .when { color: var(--mute); font-size: 11px; }
.cal li.is-past { opacity: 0.35; }
.cal li.is-next { background: var(--panel); }

.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet[hidden] { display: none; }

.sheet-back {
  position: absolute;
  inset: 0;
  background: #000000aa;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.2s ease;
}

@keyframes fade { from { opacity: 0; } }

.sheet-card {
  position: absolute;
  inset: auto 0 0;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 0.5rem var(--gut) calc(env(safe-area-inset-bottom) + 1.5rem);
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  animation: rise 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes rise { from { transform: translateY(100%); } }

.sheet-grip {
  display: block;
  width: 2.6rem;
  height: 4px;
  margin: 0.5rem auto 1rem;
  border-radius: 999px;
  background: var(--line);
}

.sheet-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1.4rem; }

.sheet-num {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 10px;
  background: var(--team, var(--raised));
  color: #fff;
  font-family: "Archivo", sans-serif;
  font-variation-settings: "wdth" 108;
  font-weight: 800;
  flex: none;
}

.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head h3 { font-size: 1.05rem; }
.sheet-head p { margin: 0.15rem 0 0; font-size: 10.5px; color: var(--dim); }

.sheet-pos {
  font-family: "Archivo", sans-serif;
  font-variation-settings: "wdth" 108;
  font-weight: 800;
  font-size: 1.6rem;
  color: var(--mute);
}

.dial { margin-bottom: 1.2rem; }
.dial-label { font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); }
.dial strong {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin: 0.4rem 0 0.7rem;
  font-family: "Archivo", sans-serif;
  font-variation-settings: "wdth" 108;
  font-weight: 800;
  font-size: 3rem;
  line-height: 1;
}
.dial strong em { font-family: "Spline Sans Mono", monospace; font-style: normal; font-size: 11px; font-weight: 400; color: var(--dim); }

.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width 0.2s linear; }
.bar-thr i { background: var(--green); }
.bar-brk i { background: var(--red); }

.pedals { display: grid; gap: 0.9rem; margin-bottom: 1.3rem; }
.pedal { display: grid; grid-template-columns: 4.6rem 1fr 2.4rem; gap: 0.7rem; align-items: center; }
.pedal span { font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.pedal b { font-size: 12px; text-align: right; font-weight: 400; }

.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.chip { background: var(--panel); padding: 0.75rem 0.5rem; text-align: center; }
.chip span { display: block; font-size: 8.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.chip b { display: block; margin-top: 0.3rem; font-size: 13px; font-weight: 500; }
.chip.is-open b { color: var(--green); }

.dock {
  position: fixed;
  inset: auto 0 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--asphalt) 92%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}

.dock button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.6rem 0 0.55rem;
  color: var(--dim);
  transition: color 0.15s ease;
}

.dock svg { width: 22px; height: 22px; fill: currentColor; }
.dock span { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; }
.dock button[aria-selected="true"] { color: var(--ink); }
.dock button:active { opacity: 0.6; }

@media (min-width: 640px) {
  :root { --gut: 1.4rem; }
  main { max-width: 30rem; margin: 0 auto; }
  .dock { max-width: 30rem; margin: 0 auto; border-inline: 1px solid var(--line); }
  .sheet-card { max-width: 30rem; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
