/* Neon Overdrive - everything the page wears. */

:root {
  --pink: #ff2f7d;
  --pink-soft: #ff6fb0;
  --cyan: #26f0ff;
  --violet: #8a3bff;
  --ink: #08040f;
  --panel: rgba(18, 8, 32, 0.82);
  --panel-solid: #140a24;
  --line: rgba(255, 47, 125, 0.45);
  --font-display: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-display);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior: none; }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#view {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* the vignette, on the compositor rather than in the canvas */
#app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(125% 105% at 50% 55%, rgba(0,0,0,0) 40%, rgba(0,0,0,0.30) 72%, rgba(0,0,0,0.62) 100%);
  z-index: 4;
}

/* a whisper of CRT, drawn over everything the road throws up */
#app::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.045) 0 1px, rgba(0,0,0,0) 1px 3px);
  mix-blend-mode: overlay;
  z-index: 5;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------------ HUD */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  font-family: var(--font-mono);
}

.hud-top {
  position: absolute;
  top: calc(8px + var(--safe-t));
  left: 8px;
  right: 8px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.hud-cell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 9px 5px;
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  box-shadow: 0 0 14px rgba(255, 47, 125, 0.25), inset 0 0 12px rgba(138, 59, 255, 0.18);
}

.hud-cell .k {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--cyan);
  opacity: 0.85;
}

.hud-cell .v {
  font-size: clamp(13px, 3.6vw, 20px);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 0 10px rgba(255, 47, 125, 0.8);
}

.hud-cell .v.small { font-size: clamp(11px, 2.6vw, 14px); opacity: 0.85; }

.hud-cell.wide {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-cell.wide .k { font-size: 8px; }

.minimap-cell {
  margin-left: auto;
  padding: 4px;
}

#hud-map {
  display: block;
  width: 132px;
  height: 84px;
}

.speedo {
  position: absolute;
  left: 14px;
  bottom: calc(14px + var(--safe-b));
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px 8px;
  min-width: 132px;
  box-shadow: 0 0 18px rgba(255, 47, 125, 0.28);
}

.speedo .kph {
  font-size: clamp(26px, 8vw, 46px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 0 16px var(--pink), 0 0 30px var(--violet);
  font-variant-numeric: tabular-nums;
}

.speedo .unit {
  font-size: 9px;
  letter-spacing: 0.28em;
  color: var(--cyan);
}

.speedo .bar {
  margin-top: 5px;
  height: 5px;
  width: 100%;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
}

.speedo .bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--pink));
  box-shadow: 0 0 12px var(--pink);
}

.hint {
  position: absolute;
  right: 14px;
  bottom: calc(16px + var(--safe-b));
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.55);
  font-family: var(--font-mono);
  text-align: right;
}

.center-msg {
  position: absolute;
  left: 0; right: 0;
  top: 38%;
  text-align: center;
  font-size: clamp(48px, 18vw, 140px);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 0 22px var(--pink), 0 0 60px var(--violet);
  opacity: 0;
  transition: opacity 0.12s linear;
}

.center-msg.on { opacity: 1; }

.lap-flash {
  position: absolute;
  left: 0; right: 0;
  top: 18%;
  text-align: center;
  font-size: clamp(16px, 4.6vw, 30px);
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--cyan);
  text-shadow: 0 0 18px rgba(38, 240, 255, 0.9);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.lap-flash.on { opacity: 1; }

/* ------------------------------------------------------------ touch pads */

/* the thumb pads only exist where thumbs do: the class is added the moment
   the page is opened on a coarse pointer or the first touch lands */
#touch {
  position: absolute;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  display: none;
}

body.touch #touch { display: block; }

.pad {
  position: absolute;
  bottom: calc(10px + var(--safe-b));
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.pad.left { left: 10px; }
.pad.right { right: 10px; flex-direction: row-reverse; }

.tbtn {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  background: rgba(20, 8, 36, 0.55);
  border: 2px solid rgba(38, 240, 255, 0.55);
  box-shadow: 0 0 18px rgba(38, 240, 255, 0.22), inset 0 0 22px rgba(255, 47, 125, 0.18);
  backdrop-filter: blur(3px);
  border-radius: 50%;
  width: 82px;
  height: 82px;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.tbtn.gas, .tbtn.brake {
  border-radius: 22px;
  width: 92px;
  height: 82px;
  font-size: 15px;
  border-color: rgba(255, 47, 125, 0.6);
  box-shadow: 0 0 18px rgba(255, 47, 125, 0.25), inset 0 0 22px rgba(38, 240, 255, 0.15);
}

.tbtn.gas { border-color: rgba(38, 240, 255, 0.7); }

.tbtn.active {
  background: rgba(255, 47, 125, 0.4);
  border-color: #fff;
  transform: translateY(1px);
}

.pausetop {
  position: absolute;
  top: calc(8px + var(--safe-t));
  right: calc(8px + 140px);
  width: 40px;
  height: 40px;
  font-size: 15px;
  border-radius: 12px;
  opacity: 0.75;
}

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

.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(138, 59, 255, 0.22), rgba(0, 0, 0, 0) 60%),
    rgba(6, 2, 12, 0.66);
  backdrop-filter: blur(2px);
  -webkit-overflow-scrolling: touch;
}

.card {
  width: 100%;
  max-width: 620px;
  flex: 0 0 auto;
  background: linear-gradient(180deg, #180b2c 0%, #0d0619 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 0 40px rgba(255, 47, 125, 0.22), 0 0 90px rgba(138, 59, 255, 0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card.narrow { max-width: 380px; }

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 47, 125, 0.28);
  background: linear-gradient(90deg, rgba(255, 47, 125, 0.16), rgba(38, 240, 255, 0.08));
}

.card-head h2 {
  margin: 0;
  font-size: clamp(16px, 4.4vw, 22px);
  letter-spacing: 0.22em;
  text-shadow: 0 0 14px var(--pink);
}

.card-head .place {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 800;
  color: var(--cyan);
  text-shadow: 0 0 16px var(--cyan);
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* hero --------------------------------------------------------------- */

.hero {
  position: relative;
  height: clamp(96px, 22vh, 176px);
  flex: 0 0 auto;
  overflow: hidden;
  background: #12052a;
}

.hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 42%;
  display: block;
}

.hero-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(12, 4, 26, 0.15) 0%, rgba(12, 4, 26, 0.35) 45%, rgba(13, 6, 25, 0.98) 100%);
}

.hero-text {
  position: absolute;
  left: 0; right: 0;
  bottom: 4px;
  text-align: center;
}

.hero-text h1 {
  margin: 0;
  /* 13 wide capitals plus the gap between the two words: the size has to keep
     the whole title inside the card at the narrow end */
  font-size: clamp(19px, 7.1vw, 46px);
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 0 10px #fff, 0 0 24px var(--pink), 0 0 48px var(--violet);
}

.hero-text h1 span {
  color: var(--cyan);
  text-shadow: 0 0 10px #fff, 0 0 26px var(--cyan), 0 0 52px var(--violet);
  margin-left: 0.28em;
}

.hero-text .tagline {
  margin: 2px 0 8px;
  font-family: var(--font-mono);
  font-size: clamp(8px, 2.3vw, 11px);
  letter-spacing: 0.26em;
  color: rgba(255, 255, 255, 0.72);
}

/* rows --------------------------------------------------------------- */

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.035);
  color: #fff;
  text-align: left;
  font-family: inherit;
}

.row.selectable { cursor: pointer; }

.row.selectable:hover { background: rgba(255, 47, 125, 0.12); }

.rowtext {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.rowk {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--cyan);
}

.rowv {
  font-size: clamp(14px, 3.8vw, 18px);
  font-weight: 800;
  letter-spacing: 0.1em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rowsub {
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rowmap {
  width: 132px;
  height: 76px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(38, 240, 255, 0.28);
}

.chev { color: var(--pink); font-size: 20px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.chip {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
}

.chip.on {
  border-color: var(--pink);
  color: #fff;
  background: rgba(255, 47, 125, 0.28);
  box-shadow: 0 0 14px rgba(255, 47, 125, 0.4);
}

.toggles { flex-direction: column; gap: 8px; align-items: stretch; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  background: none;
  border: none;
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.sw {
  width: 42px;
  height: 24px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  position: relative;
  flex: 0 0 auto;
  transition: background 0.15s ease;
}

.sw::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  transition: transform 0.15s ease, background 0.15s ease;
}

.toggle[aria-pressed="true"] .sw { background: rgba(38, 240, 255, 0.35); border-color: var(--cyan); }
.toggle[aria-pressed="true"] .sw::after { transform: translateX(18px); background: #fff; box-shadow: 0 0 10px var(--cyan); }

button.big {
  font-family: inherit;
  font-size: clamp(15px, 4.2vw, 19px);
  font-weight: 900;
  letter-spacing: 0.2em;
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--pink);
  background: linear-gradient(180deg, rgba(255, 47, 125, 0.95), rgba(150, 20, 90, 0.95));
  color: #fff;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 22px rgba(255, 47, 125, 0.45);
  cursor: pointer;
  width: 100%;
}

button.big:active { transform: translateY(1px); }

button.ghost {
  font-family: inherit;
  font-size: clamp(12px, 3.4vw, 15px);
  font-weight: 800;
  letter-spacing: 0.16em;
  padding: 11px 14px;
  border-radius: 11px;
  border: 1px solid rgba(38, 240, 255, 0.5);
  background: rgba(38, 240, 255, 0.08);
  color: #fff;
  cursor: pointer;
}

button.ghost:active { transform: translateY(1px); }

.fine {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.45);
  text-align: center;
}

.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
/* stacked, the buttons must size to their text: the row bases below are widths,
   and a flex-basis on the main axis of a column is a height */
.buttons.col { flex-direction: column; }
.buttons.col > button { flex: 0 0 auto; }
.buttons .big { flex: 1 1 160px; }
.buttons .ghost { flex: 1 1 100px; }

/* track grid --------------------------------------------------------- */

.track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 9px;
}

.track-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 9px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.035);
  color: #fff;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.track-card.on {
  border-color: var(--pink);
  background: rgba(255, 47, 125, 0.16);
  box-shadow: 0 0 18px rgba(255, 47, 125, 0.3);
}

.track-card .tname { font-size: 14px; font-weight: 800; letter-spacing: 0.1em; }
.track-card .tblurb { font-family: var(--font-mono); font-size: 9px; color: rgba(255,255,255,0.55); line-height: 1.35; }
.track-card .tmeta { font-family: var(--font-mono); font-size: 9px; color: var(--cyan); letter-spacing: 0.08em; }
.track-card canvas { width: 100%; height: 66px; border-radius: 7px; background: rgba(0, 0, 0, 0.4); display: block; }

/* results ------------------------------------------------------------ */

.res-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.stat {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.035);
}

.stat .k {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--cyan);
}

.stat .v {
  font-family: var(--font-mono);
  font-size: clamp(13px, 3.6vw, 17px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat.best .v { color: #ffe27a; text-shadow: 0 0 12px rgba(255, 226, 122, 0.7); }

.res-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.res-col h3 {
  margin: 0 0 5px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--cyan);
}

ol.laps, ol.standings {
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-mono);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

ol.laps li, ol.standings li {
  display: flex;
  gap: 8px;
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

ol.laps li.me, ol.standings li.me {
  background: rgba(255, 47, 125, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 47, 125, 0.5);
}

ol.laps li span:first-child, ol.standings li span:first-child { color: var(--cyan); }
ol.laps li span:last-child, ol.standings li span:last-child { margin-left: auto; }

/* ---------------------------------------------------- layout for touch */

body.touch .hint { display: none; }

body.touch .speedo {
  top: calc(58px + var(--safe-t));
  bottom: auto;
  left: 10px;
  padding: 4px 9px 6px;
  min-width: 104px;
}

body.touch .speedo .kph { font-size: clamp(22px, 7vw, 34px); }
body.touch .speedo .unit { font-size: 8px; }

body.touch .minimap-cell { padding: 3px; }
body.touch #hud-map { width: 96px; height: 62px; }

/* clear of the minimap cell, which is 106px wide at the right edge */
body.touch .pausetop { right: calc(8px + 114px); }

/* narrow screens: trim the HUD rather than let it overlap */
@media (max-width: 560px) {
  .hud-cell.wide .k:last-of-type, .hud-cell.wide .v.small { display: none; }
  #hud-map { width: 104px; height: 66px; }
  .speedo { min-width: 108px; }
  /* a phone cannot fit a label and three chips side by side without cutting
     the label off, so the chips drop to their own line */
  .row.wraprow { flex-wrap: wrap; }
  .row.wraprow .rowtext { flex: 1 1 100%; }
  .row.wraprow .chips { justify-content: flex-start; }
  /* a phone has no room for a third box in the top row: the pause button
     sits under the map instead, on the same edge */
  body.touch .pausetop { right: 8px; top: calc(88px + var(--safe-t)); }
}

@media (max-width: 400px) {
  .hud-cell { padding: 3px 6px 4px; }
  .hud-cell .v { font-size: 13px; }
  #hud-map { width: 84px; height: 54px; }
  .rowmap { width: 92px; height: 58px; }
}

/* a laptop window is wide but not tall: everything still has to fit without
   the bottom of the card running off the screen */
@media (max-height: 700px) {
  .hero { height: clamp(64px, 17vh, 128px); }
  .card-body { padding: 10px 12px 12px; gap: 7px; }
  .row { padding: 6px 9px; }
  .rowsub { display: none; }
  .rowmap { height: 60px; }
  .chip { padding: 5px 8px; }
  button.big { padding: 11px 14px; }
  .track-card canvas { height: 54px; }
}

/* short screens: the card gets out of its own way */
@media (max-height: 470px) {
  .hero { height: clamp(70px, 18vh, 110px); }
  .card-body { padding: 10px 12px 12px; gap: 7px; }
  .row { padding: 6px 9px; }
  .rowsub { display: none; }
  .speedo .kph { font-size: 26px; }
}

@media (max-height: 400px) {
  .hero { display: none; }
}

/* a phone held sideways is the shortest screen this page ever meets: the title
   card has to land inside it whole, with nothing clipped top or bottom */
@media (max-height: 430px) {
  .screen { padding: 8px; }
  .card-body { padding: 8px 10px 10px; gap: 5px; }
  .row { padding: 4px 8px; }
  .rowmap { height: 52px; }
  .rowv { font-size: 14px; }
  .chip { padding: 4px 7px; }
  .toggle { padding: 4px 4px; }
  .sw { width: 38px; height: 22px; }
  .sw::after { width: 16px; height: 16px; }
  .toggle[aria-pressed="true"] .sw::after { transform: translateX(16px); }
  button.big { padding: 9px 12px; font-size: 15px; }
  .fine { font-size: 9px; }
  .card-head { padding: 8px 12px; }
  .track-card { padding: 7px; gap: 3px; }
  .track-card canvas { height: 46px; }
  .track-card .tblurb { display: none; }
  /* six stats on one row, which is a whole row of height saved */
  .res-stats { grid-template-columns: repeat(auto-fit, minmax(86px, 1fr)); gap: 6px; }
  .stat { padding: 5px 7px; }
  .res-cols { gap: 8px; }
  .res-col h3 { margin-bottom: 3px; }
  ol.laps li, ol.standings li { padding: 3px 6px; font-size: 11px; }
}

@media (min-width: 900px) {
  .screen { padding: 24px; }
}
