:root {
  --ink: #f4f6fa;
  --dim: #aab3c2;
  --panel: rgba(12, 16, 24, 0.72);
  --line: rgba(255, 255, 255, 0.12);
  --ahead: #4aa8ff;
  --behind: #ff5a5a;
  --accent: #ffd24a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fc3ea; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  user-select: none;
}
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#top { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); text-align: center; }
#timer {
  font: 700 44px/1 "Consolas", "SF Mono", ui-monospace, monospace;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
  letter-spacing: 1px;
}
#cps { margin-top: 4px; font-size: 15px; color: var(--dim); text-shadow: 0 1px 3px #000; }
.split {
  margin-top: 6px; display: inline-block; min-width: 120px; padding: 3px 12px; border-radius: 4px;
  font: 700 22px/1.2 "Consolas", ui-monospace, monospace; background: var(--panel);
  opacity: 0; transition: opacity 0.25s;
}
.split.show { opacity: 1; }
.split.ahead { color: var(--ahead); }
.split.behind { color: var(--behind); }

#countdown {
  position: absolute; top: 38%; width: 100%; text-align: center;
  font: 800 72px/1 "Segoe UI", system-ui, sans-serif; text-shadow: 0 3px 10px rgba(0, 0, 0, 0.6);
}
#speed {
  position: absolute; bottom: 22px; left: 24px; display: flex; align-items: flex-end; gap: 10px;
  font: 700 42px/1 "Consolas", ui-monospace, monospace; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}
#speed small { font-size: 11px; margin-left: 5px; color: var(--dim); }
/* Four digits always: the unused leading ones are dim, so the box never stretches as the speed climbs. */
#speedZ { color: rgba(255, 255, 255, 0.28); }
#speedBox { white-space: nowrap; }
/* Gear: a big number beside the speed. Revs: a bar under it, the last fifth is the redline. */
#gear {
  min-width: 29px; height: 42px; display: flex; align-items: center; justify-content: center;
  font: 800 32px/1 "Segoe UI", system-ui, sans-serif; color: var(--accent); background: var(--panel); border-radius: 6px;
}
#gear.shift { color: var(--dim); }
#rpm { position: relative; width: 100%; height: 5px; margin-top: 4px; border-radius: 3px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
#rpmFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: #fff; }
#rpmFill.red { background: var(--behind); }
#rpmRed { position: absolute; right: 0; top: 0; bottom: 0; width: 18%; background: rgba(255, 70, 70, 0.28); }
/* Speedslide meter: the slide width against the ideal (centre tick); the band is where it pushes. */
#slide { position: relative; width: 100%; height: 4px; margin: 5px auto 0; border-radius: 3px; background: rgba(255, 255, 255, 0.15); opacity: 0; transition: opacity 0.3s ease; }
#slide.on { opacity: 1; }
#slide::after { content: ""; position: absolute; left: 50%; top: -2px; width: 2px; height: 10px; margin-left: -1px; background: rgba(255, 255, 255, 0.6); }
#slideZone { position: absolute; left: 25%; width: 50%; top: 0; bottom: 0; border-radius: 3px; background: rgba(255, 255, 255, 0.18); }
#slideMark { position: absolute; top: -3px; width: 6px; height: 12px; margin-left: -3px; border-radius: 2px; background: var(--dim); transition: background-color 0.2s ease; }
#slideMark.push { background: var(--accent); }
#debug {
  position: absolute; left: 12px; top: 12px; padding: 8px 10px; background: var(--panel);
  font: 12px/1.45 "Consolas", ui-monospace, monospace; white-space: pre; border-radius: 4px;
}

#replayTag {
  position: absolute; top: 118px; left: 50%; transform: translateX(-50%); padding: 3px 12px;
  background: var(--panel); border-radius: 4px; color: var(--accent); font-size: 14px; white-space: nowrap;
}
#inputs {
  position: absolute; bottom: 86px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px;
  align-items: center; font: 700 11px/1 "Consolas", ui-monospace, monospace;
}
#inputs span { padding: 4px 6px; border-radius: 3px; background: var(--panel); color: var(--dim); }
#inputs span.on { background: var(--ink); color: #111; }
#inputs .steer { position: relative; width: 160px; height: 10px; background: var(--panel); border-radius: 3px; overflow: hidden; }
#inSteer { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: var(--accent); }
#help .link { text-decoration: underline; cursor: pointer; }
/* The build, bottom right: physics version and map generator version (what a replay or a bug report ran on). */
#ver {
  position: fixed; right: 10px; bottom: 6px; z-index: 5; pointer-events: none;
  font: 11px "Consolas", ui-monospace, monospace; color: var(--dim); opacity: 0.7; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
#board {
  position: fixed; right: 12px; top: 44px; width: 250px; max-height: calc(100% - 110px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
  font-size: 13px;
}
#board header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
#board .title { font-weight: 700; text-transform: uppercase; letter-spacing: 1px; font-size: 12px; color: var(--accent); }
#mapDate { color: var(--dim); font-family: "Consolas", ui-monospace, monospace; }
#boardList, #lbList { list-style: none; margin: 0; padding: 0; }
#boardList li, #boardMe .row, #lbList li, #lbMe .row {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 6px; padding: 3px 0;
  border-bottom: 1px solid var(--line);
}
#boardList li.me, #lbList li.me { color: var(--accent); }
#boardList li:not(.empty):not(.noreplay), #lbList li:not(.empty):not(.noreplay) { cursor: pointer; }
#boardList li:not(.empty):not(.noreplay):hover, #lbList li:not(.empty):not(.noreplay):hover { background: rgba(255, 255, 255, 0.06); }
#boardList .rk, #boardMe .rk, #lbList .rk, #lbMe .rk { color: var(--dim); }
#boardList .nm, #lbList .nm { display: flex; align-items: center; gap: 5px; min-width: 0; }
#boardList .nm .tx, #lbList .nm .tx { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
/* Replay kept on the server: a pixel-art outline of a video-play badge. */
.play { display: inline-block; flex: none; width: 14px; height: 10px; vertical-align: middle; image-rendering: pixelated;
  background: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2010'%20shape-rendering='crispEdges'%3E%3Cpath%20fill='%23c8ccd2'%20d='M2%200h1v1h-1zM3%200h1v1h-1zM4%200h1v1h-1zM5%200h1v1h-1zM6%200h1v1h-1zM7%200h1v1h-1zM8%200h1v1h-1zM9%200h1v1h-1zM10%200h1v1h-1zM11%200h1v1h-1zM1%201h1v1h-1zM12%201h1v1h-1zM0%202h1v1h-1zM5%202h1v1h-1zM6%202h1v1h-1zM13%202h1v1h-1zM0%203h1v1h-1zM5%203h1v1h-1zM7%203h1v1h-1zM13%203h1v1h-1zM0%204h1v1h-1zM5%204h1v1h-1zM8%204h1v1h-1zM13%204h1v1h-1zM0%205h1v1h-1zM5%205h1v1h-1zM8%205h1v1h-1zM13%205h1v1h-1zM0%206h1v1h-1zM5%206h1v1h-1zM7%206h1v1h-1zM13%206h1v1h-1zM0%207h1v1h-1zM5%207h1v1h-1zM6%207h1v1h-1zM13%207h1v1h-1zM1%208h1v1h-1zM12%208h1v1h-1zM2%209h1v1h-1zM3%209h1v1h-1zM4%209h1v1h-1zM5%209h1v1h-1zM6%209h1v1h-1zM7%209h1v1h-1zM8%209h1v1h-1zM9%209h1v1h-1zM10%209h1v1h-1zM11%209h1v1h-1z'/%3E%3C/svg%3E") center / 100% 100% no-repeat; }
#boardList .tm, #boardMe .tm, #lbList .tm, #lbMe .tm { font-family: "Consolas", ui-monospace, monospace; }
#boardList .empty, #lbList .empty { display: block; color: var(--dim); border: 0; }
#boardMe, #lbMe { margin-top: 6px; color: var(--accent); }
#driver { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--dim); }
#driver button, .panel button {
  font: inherit; color: var(--ink); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 10px; cursor: pointer;
}
#driver button:hover, .panel button:hover { background: rgba(255, 255, 255, 0.16); }

#help {
  position: fixed; left: 12px; bottom: 12px; max-width: calc(100% - 300px); font-size: 12px; color: var(--ink);
  background: var(--panel); padding: 6px 10px; border-radius: 4px; opacity: 0.85;
}

.overlay { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; }
.overlay .panel {
  pointer-events: auto; min-width: 300px; text-align: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 18px 26px;
}
.overlay .label { text-transform: uppercase; letter-spacing: 2px; color: var(--accent); font-size: 13px; font-weight: 700; }
.overlay .big { font: 700 52px/1.15 "Consolas", ui-monospace, monospace; margin: 6px 0; }
.overlay .hint { margin-top: 12px; color: var(--dim); font-size: 13px; }
#finPb.ahead { color: var(--ahead); }
#finPb.behind { color: var(--behind); }
#finRank { margin-top: 6px; font-size: 18px; }
#nameDlg { background: rgba(0, 0, 0, 0.35); pointer-events: auto; }
#nameInput {
  width: 100%; margin-top: 10px; padding: 8px 10px; font: 18px "Segoe UI", system-ui, sans-serif;
  color: var(--ink); background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 4px;
}
.panel .row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.err { color: var(--behind); min-height: 1.2em; font-size: 13px; margin-top: 4px; }
.fine { color: var(--dim); font-size: 11px; max-width: 280px; margin: 12px auto 0; }

#replayTag {
  position: absolute; top: 118px; left: 50%; transform: translateX(-50%); padding: 3px 12px;
  background: var(--panel); border-radius: 4px; color: var(--accent); font-size: 14px; white-space: nowrap;
}
#inputs {
  position: absolute; bottom: 86px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px;
  align-items: center; font: 700 11px/1 "Consolas", ui-monospace, monospace;
}
#inputs span { padding: 4px 6px; border-radius: 3px; background: var(--panel); color: var(--dim); }
#inputs span.on { background: var(--ink); color: #111; }
#inputs .steer { position: relative; width: 160px; height: 10px; background: var(--panel); border-radius: 3px; overflow: hidden; }
#inSteer { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: var(--accent); }
#help .link { text-decoration: underline; cursor: pointer; }
@media (max-width: 700px) {
  #board { width: 190px; font-size: 12px; }
  #help { display: none; }
  #timer { font-size: 32px; }
  #speed { font-size: 40px; }
}

/* The button picked with the keyboard or a gamepad in a menu (menunav.js). */
.overlay .kbsel { outline: 2px solid var(--accent); outline-offset: 2px; background: rgba(255, 255, 255, 0.16); }

/* Pause menu: a column of full-width buttons, each showing its key. */
#pause .panel, #finish .panel { pointer-events: auto; min-width: 300px; }
#pause .menu, #finish .menu { display: flex; flex-direction: column; gap: 8px; }
#pause .big, #finish .big { font-size: 34px; }
#finish .menu > div:not(.label):not(.big) { text-align: center; }
#pause button, #finish button { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 15px; text-align: left; }
#pause button:disabled, #finish button:disabled { opacity: 0.4; cursor: default; }
#pause kbd, #finish kbd { font: 12px "Consolas", ui-monospace, monospace; color: var(--dim); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 4px; padding: 1px 6px; }

/* World / region tabs on the side board and the full leaderboard. */
.tabs { display: flex; gap: 4px; margin: 0 0 6px; flex-wrap: wrap; }
.tabs button { flex: 1; padding: 3px 6px; font-size: 11px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent; color: var(--dim); cursor: pointer; white-space: nowrap; }
.tabs button.on { background: rgba(255, 255, 255, 0.14); color: inherit; }
#lb .panel { pointer-events: auto; width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto; text-align: left; }
#lb .label { text-align: center; }
#lb .tabs { margin: 10px 0; }
#lb .tabs button { font-size: 12px; padding: 5px 8px; }
#lb .tabs button:last-child { flex-basis: 100%; } /* History: its own full row, not a stray label under the regions */
#lbList li { font-size: 14px; }

/* Paint dialog: panel list and colour presets on the left, the car in view. */
#paint { place-items: center start; padding-left: 20px; }
#paint .panel { pointer-events: auto; width: 270px; text-align: left; }
#paint .label { text-align: center; }
#paintParts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 10px 0 6px; }
#paintParts button { display: flex; align-items: center; gap: 6px; padding: 4px 6px; font-size: 11px; text-align: left; white-space: nowrap; overflow: hidden; }
#paintParts button.on { background: rgba(255, 255, 255, 0.22); outline: 1px solid var(--accent); }
#paintParts .dot, #paintSwatches button { border: 1px solid rgba(255, 255, 255, 0.35); }
#paintParts .dot { flex: none; width: 11px; height: 11px; border-radius: 3px; }
#paintSwatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 4px 0 12px; }
#paintSwatches button { height: 28px; padding: 0; border-radius: 5px; }
#paintSwatches button.on { outline: 2px solid var(--accent); outline-offset: 1px; }
#paintPicked { margin: 2px 0; text-align: left; }
#paint .row button kbd { margin-left: 8px; }

/* History: a minimap, the day's top times and a replay link per past day. */
#lbHistory.hidden, #lbList.hidden { display: none; }
#lbHistory .day { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.1); }
#lbHistory canvas { width: 150px; height: 110px; flex: none; background: #1a1e24; border-radius: 6px; }
#lbHistory .info { flex: 1; min-width: 0; font-size: 12px; }
#lbHistory .info b { color: var(--accent); }
#lbHistory ol { list-style: none; margin: 4px 0 0; padding: 0; }
#lbHistory li { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 1px 0; }
#lbHistory li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lbHistory li .tm, #lbHistory .archive .tm { font-family: "Consolas", ui-monospace, monospace; }
#lbHistory .play { margin-left: 5px; }
#lbHistory .archive { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.1); font-size: 12px; }
#lbHistory .archive > div:not(.label) { display: grid; grid-template-columns: 82px 1fr auto; gap: 6px; padding: 1px 0; color: var(--dim); }
#lbHistory .empty { color: var(--dim); padding: 8px 0; }

/* Start menu: the logo on a white band, today's map beside the top 5 and the menu. */
#start { background: rgba(6, 9, 14, 0.45); pointer-events: auto; }
#start .panel.start { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; padding: 0; text-align: left; }
#start .logo { background: #fff; border-radius: 8px 8px 0 0; padding: 14px 24px 10px; text-align: center; }
#start .logo img { width: min(420px, 100%); height: auto; display: inline-block; }
#start .startBody { display: flex; gap: 18px; padding: 16px 20px 20px; }
#start .mapCol { flex: 1.2; min-width: 0; }
#start .sideCol { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#startMap { display: block; width: 100%; aspect-ratio: 640 / 460; margin-top: 8px; background: #1a1e24; border-radius: 6px; }
#startStats { margin-top: 8px; text-align: left; }
#startTop { list-style: none; margin: 8px 0 0; padding: 0; min-height: 6.5em; }
#startTop li { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; padding: 3px 0; font-size: 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
#startTop li.noreplay { cursor: default; }
#startTop li.me { color: var(--accent); }
#startTop .rk { color: var(--dim); }
#startTop .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#startTop .tm { font-family: "Consolas", ui-monospace, monospace; }
#startTop .empty { display: block; color: var(--dim); border: 0; cursor: default; }
#startMe { margin-top: 6px; color: var(--accent); font-size: 13px; }
#startMe .row { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; }
#start .menu { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding-top: 14px; }
#start button { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 15px; text-align: left; }
#start button.go { background: #e30613; border-color: #e30613; color: #fff; font-weight: 700; font-size: 17px; }
#start button.go:hover { background: #ff1f2c; }
#start kbd { font: 12px "Consolas", ui-monospace, monospace; color: var(--dim); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 4px; padding: 1px 6px; }
#start button.go kbd { color: #fff; border-color: rgba(255, 255, 255, 0.5); }
@media (max-width: 640px) {
  #start .startBody { flex-direction: column; }
}
/* The start menu stands alone: no HUD, side board or key help behind it. */
body.atStart #hud, body.atStart #board, body.atStart #help { display: none; }

/* Broadcast banner, maintenance bar, spectator strip, map ratings. */
#banner {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20; max-width: min(640px, 92vw);
  display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 14px; border-radius: 6px;
  background: rgba(12, 16, 24, 0.86); border: 1px solid var(--accent); color: var(--ink); font-size: 14px;
}
#banner button { pointer-events: auto; background: none; border: 0; color: var(--dim); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
#maint {
  position: fixed; top: 0; left: 0; right: 0; z-index: 19; padding: 5px 12px; text-align: center; font-size: 13px;
  background: #7a4b00; color: #fff3d6;
}
body.atStart #banner { top: 62px; }
#spec {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 18; padding: 6px 14px; border-radius: 6px;
  background: var(--panel); color: var(--accent); font: 600 14px/1.4 "Consolas", ui-monospace, monospace; white-space: nowrap;
}
#wrongWay { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); z-index: 12; padding: 6px 22px; border-radius: 6px; background: rgba(150, 20, 28, 0.82); color: #fff; font: 800 28px/1.2 system-ui, sans-serif; letter-spacing: 3px; text-transform: uppercase; pointer-events: none; }
#specExit { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 19; padding: 6px 12px; border-radius: 6px; border: 0; background: var(--panel); color: var(--accent); font: 600 14px/1.4 "Consolas", ui-monospace, monospace; cursor: pointer; }
#specExit:hover { background: #26324a; }
#specMap { position: fixed; right: 14px; bottom: 14px; z-index: 19; width: 260px; height: 260px; border-radius: 8px; background: rgba(12, 17, 26, 0.82); cursor: crosshair; }
#bug { z-index: 40; background: rgba(0, 0, 0, 0.5); }
#bug:not(.hidden) { pointer-events: auto; }
#bug .panel { pointer-events: auto; background: #151b27; width: min(460px, 92vw); }
#bugText { width: 100%; box-sizing: border-box; margin: 10px 0 6px; padding: 8px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(0, 0, 0, 0.35); color: var(--ink, #fff); font: 14px/1.4 system-ui, sans-serif; resize: vertical; }
#bug .check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--dim); }
#bug .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.stars { display: inline-flex; gap: 2px; align-items: center; }
.stars button { background: none; border: 0; padding: 0 1px; font-size: 20px; line-height: 1; color: rgba(255, 255, 255, 0.28); cursor: pointer; }
.stars button.on { color: var(--accent); }
.stars button:hover { color: #fff; }
.rate { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; }
.rate small { color: var(--dim); }
#finRate { margin-top: 8px; display: flex; align-items: center; gap: 8px; justify-content: center; }
#finRate .hint { margin: 0; }

#consent {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 40; width: min(760px, 94vw);
  display: flex; align-items: center; gap: 16px; padding: 12px 16px; border-radius: 8px;
  background: rgba(12, 16, 24, 0.94); border: 1px solid var(--accent); color: var(--ink); font-size: 13px; line-height: 1.45;
}
#consent.hidden { display: none; }
#consent .cBtns { display: flex; flex-direction: column; gap: 8px; flex: none; }
#consent button { pointer-events: auto; cursor: pointer; padding: 7px 18px; border-radius: 5px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); color: var(--ink); font: inherit; font-weight: 600; }
#consent button.go { background: var(--accent); color: #1a1a1a; border-color: var(--accent); }
@media (max-width: 560px) { #consent { flex-direction: column; align-items: stretch; } #consent .cBtns { flex-direction: row; } #consent .cBtns button { flex: 1; } }

/* --- touch controls (touch.js) and small screens --- */
:root { --tr: clamp(56px, 9vw, 96px); } /* the steering stick's travel, as in touch.js */
#touch { position: fixed; inset: 0; z-index: 5; pointer-events: none; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
#touch > * { pointer-events: auto; touch-action: none; }
#tLook { position: absolute; inset: 0; }
#tStickZone { position: absolute; left: 0; bottom: 0; width: 42%; height: 62%; }
#tBase {
  position: absolute; left: max(84px, 15vh); top: calc(100% - max(84px, 15vh)); width: calc(var(--tr) * 2); height: calc(var(--tr) * 2);
  transform: translate(-50%, -50%); border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); background: rgba(12, 16, 24, 0.25);
  pointer-events: none; transition: opacity 0.2s; opacity: 0.7;
}
#tBase.on { opacity: 1; border-color: rgba(255, 255, 255, 0.7); }
#tKnob { position: absolute; left: 50%; top: 50%; width: 44%; height: 44%; margin: -22% 0 0 -22%; border-radius: 50%; background: rgba(255, 255, 255, 0.55); }
#touch button {
  position: absolute; border: 2px solid rgba(255, 255, 255, 0.55); border-radius: 14px; background: rgba(12, 16, 24, 0.45); color: #fff;
  font: 800 15px/1 "Segoe UI", system-ui, sans-serif; letter-spacing: 1px; padding: 0; -webkit-tap-highlight-color: transparent;
}
#touch button.on { background: rgba(255, 255, 255, 0.38); }
#tGas { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); width: clamp(110px, 22vw, 190px); height: clamp(100px, 40vh, 170px); background: rgba(60, 190, 100, 0.38); font-size: 20px; }
#tBrake { right: calc(max(16px, env(safe-area-inset-right)) + clamp(110px, 22vw, 190px) + 14px); bottom: max(16px, env(safe-area-inset-bottom)); width: clamp(84px, 16vw, 140px); height: clamp(80px, 28vh, 120px); background: rgba(230, 70, 70, 0.38); }
#tPause, #tCam, #tResp, #tTilt { top: max(10px, env(safe-area-inset-top)); height: 46px; }
#tPause { right: max(10px, env(safe-area-inset-right)); width: 46px; font-size: 18px; }
#tCam { right: calc(max(10px, env(safe-area-inset-right)) + 56px); width: 62px; font-size: 12px; }
#tResp { right: calc(max(10px, env(safe-area-inset-right)) + 128px); width: 92px; font-size: 11px; }
#tTilt { right: calc(max(10px, env(safe-area-inset-right)) + 230px); width: 56px; font-size: 11px; }
#tTilt.on { outline: 2px solid var(--accent); }
#tStickZone.off { pointer-events: none; opacity: 0.25; }
#touch.watch > :not(#tPause):not(#tLook) { display: none; }
body.touch #board, body.touch #help { display: none; }
body.touch #speed { left: 50%; transform: translateX(-50%); bottom: 10px; font-size: clamp(26px, 7vh, 42px); }
#tRotate { position: fixed; inset: 0; z-index: 9; display: grid; place-items: center; background: rgba(8, 12, 20, 0.86); text-align: center; font-size: 18px; line-height: 1.6; padding: 24px; }
#tRotate button { margin-top: 14px; padding: 10px 18px; font-size: 16px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.1); color: inherit; }
#sFull.hidden { display: none; }

/* Short screens (a phone on its side): everything smaller, menus scroll instead of running off. */
@media (max-height: 520px) {
  #timer { font-size: 30px; }
  #top { top: 6px; }
  #cps { font-size: 12px; margin-top: 2px; }
  #countdown { font-size: 48px; top: 30%; }
  .overlay .panel { max-height: calc(100vh - 12px); overflow-y: auto; padding: 10px 16px; }
  .overlay .big { font-size: 34px; margin: 2px 0; }
  #pause .big, #finish .big { font-size: 26px; }
  #pause button, #finish button { padding: 6px 12px; font-size: 14px; }
  #pause .menu, #finish .menu { gap: 5px; }
  /* The start menu on a phone on its side: a slim logo, a smaller map, the buttons in two columns. */
  #start .panel.start { max-height: calc(100vh - 8px); }
  #start .logo { padding: 4px 12px; }
  #start .logo img { width: auto; height: min(15vh, 70px); max-width: 100%; }
  #start .startBody { padding: 8px 14px 10px; gap: 12px; }
  #startMap { max-height: 38vh; width: auto; max-width: 100%; margin-top: 4px; }
  #startStats { margin-top: 4px; font-size: 11px; }
  #startTop { min-height: 0; margin-top: 4px; }
  #startTop li { font-size: 12px; padding: 1px 0; }
  #start .menu { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding-top: 6px; }
  #start button { padding: 6px 10px; font-size: 13px; }
  #start button.go { grid-column: 1 / -1; font-size: 15px; }
}
@media (max-width: 700px) and (orientation: portrait) {
  #touch #tGas { width: 38vw; height: 22vh; }
  #touch #tBrake { right: calc(max(16px, env(safe-area-inset-right)) + 38vw + 12px); width: 22vw; height: 16vh; }
  #tBase { left: calc(var(--tr) + 12px); top: calc(100% - var(--tr) - 14px); }
  #tResp { right: auto; left: max(10px, env(safe-area-inset-left)); }
  body.touch #speed { bottom: 26vh; }
}

/* Controls dialog: opaque, over the menu behind it. */
#controls { background: rgba(0, 0, 0, 0.55); pointer-events: auto; }
#controls .panel { width: min(480px, calc(100vw - 24px)); background: rgba(12, 16, 24, 0.97); }
#controls label { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
#controls label input { flex: 1; max-width: 55%; }
#controls .row { flex-wrap: wrap; }
#controls .fine { max-width: none; text-align: left; }

/* The in-game minimap (N toggles it): the whole track, you in white and the ghost in blue. */
#mini { position: absolute; top: 14px; left: 14px; width: 150px; height: 150px; border-radius: 8px; background: var(--panel); opacity: 0.88; }
body.touch #mini, body.atStart #mini { display: none; }
@media (max-height: 520px) { #mini { width: 96px; height: 96px; top: 8px; left: 8px; } }

/* A driver's name in a board is a button that opens their records. */
button.who, #start button.who, #lb button.who, #profile button.who, #board button.who {
  all: unset; box-sizing: border-box; cursor: pointer; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px dotted transparent;
}
button.who:hover, button.who:focus-visible { border-bottom-color: currentColor; }
#profile { background: rgba(0, 0, 0, 0.5); pointer-events: auto; }
#profile .panel { width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow-y: auto; text-align: left; background: rgba(12, 16, 24, 0.97); }
#profile .label { text-align: center; font-size: 15px; }
#profile .hint { text-align: center; }
#profList { list-style: none; margin: 8px 0 0; padding: 0; }
#profList li { display: grid; grid-template-columns: 1fr auto auto 28px; gap: 10px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
#profList .tm { font-family: "Consolas", ui-monospace, monospace; }
#profList .pl { color: var(--dim); }
#profList li.win .pl { color: var(--accent); }
#profList .pbtn { all: unset; cursor: pointer; display: inline-flex; padding: 3px 6px; border-radius: 4px; }
#profList .pbtn:hover, #profList .pbtn:focus-visible { background: rgba(255, 255, 255, 0.14); }

/* Painting on a touch screen: only the look layer, clear of the paint panel on the left. */
#touch.lookonly > :not(#tLook) { display: none; }
#touch.lookonly #tLook { left: 300px; }

/* the map rotation's clock and the chat */
#mapClock {
  position: fixed; top: 8px; right: 10px; z-index: 6; padding: 3px 9px; border-radius: 12px; cursor: pointer;
  font: 12px "Consolas", ui-monospace, monospace; color: var(--dim); background: rgba(8, 10, 16, 0.55); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
#mapClock.hidden { display: none; }
#voteCard { position: fixed; left: 12px; top: 50%; transform: translateY(-50%); z-index: 8; width: 190px; padding: 10px 12px; border-radius: 8px; background: rgba(8, 10, 16, 0.78); color: #fff; font: 13px system-ui, sans-serif; text-align: center; }
#voteCard.hidden { display: none; }
#voteCard .tally { margin: 4px 0 8px; color: var(--dim); font-size: 12px; }
#voteCard .btns { display: flex; gap: 10px; justify-content: center; }
#voteCard button { width: 64px; height: 44px; border-radius: 6px; border: 2px solid transparent; font-size: 24px; line-height: 1; color: #fff; cursor: pointer; }
#voteCard .yes { background: #1f8f3d; }
#voteCard .no { background: #c0392b; }
#voteCard button.picked { border-color: #fff; }
#chat { position: fixed; left: 12px; bottom: 150px; z-index: 7; width: min(380px, calc(100vw - 24px)); pointer-events: none; font: 13px system-ui, sans-serif; }
#chat.open { pointer-events: auto; }
#chatLog { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; justify-content: flex-end; max-height: 32vh; overflow: hidden; }
#chatLog li { padding: 1px 6px; color: #fff; text-shadow: 0 1px 2px #000; background: rgba(8, 10, 16, 0.45); margin-top: 1px; border-radius: 3px; transition: opacity 0.6s; overflow-wrap: anywhere; }
#chatLog li b { color: #ffd54a; margin-right: 6px; font-weight: 600; }
#chatLog li.old { opacity: 0; height: 0; padding: 0; margin: 0; overflow: hidden; }
#chatInput { width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: rgba(8, 10, 16, 0.85); color: #fff; font: inherit; }
#chatInput.hidden, #chatNote.hidden { display: none; }
#chatNote { margin-top: 4px; padding: 3px 6px; color: #ffb4b4; background: rgba(8, 10, 16, 0.7); border-radius: 3px; }

/* Ghost pick on a leaderboard row */
.gbtn { margin-right: 8px; padding: 0 6px; font-size: 10px; line-height: 16px; border-radius: 3px; opacity: 0.6; }
li:hover .gbtn, .gbtn:focus-visible { opacity: 1; }
