:root {
  --ink: #e8f4ff;
  --glow: #59c8ff;
  --deep: #04102e;
  --panel: rgba(6, 22, 60, 0.55);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--deep); }
body { font-family: "Chakra Petch", system-ui, sans-serif; font-style: italic; color: var(--ink); touch-action: none; user-select: none; -webkit-user-select: none; }
canvas { display: block; }
.glow { text-shadow: 0 0 12px rgba(89, 200, 255, 0.8), 0 0 2px #fff; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#top { position: absolute; top: 16px; left: 0; right: 0; text-align: center; }
#timer { font-size: 40px; font-weight: 700; letter-spacing: 1px; }
#lap { font-size: 16px; font-weight: 600; letter-spacing: 3px; opacity: 0.85; }
#pos { font-size: 26px; font-weight: 700; letter-spacing: 2px; margin-top: 2px; }
#speedBox { position: absolute; right: 20px; bottom: 20px; text-align: right; }
#kmh { font-size: 48px; font-weight: 700; line-height: 1; }
#speedBox small { display: block; font-size: 14px; letter-spacing: 3px; opacity: 0.8; }
#boostBar { width: 140px; height: 6px; border-radius: 3px; background: rgba(89, 200, 255, 0.2); margin-top: 8px; margin-left: auto; overflow: hidden; }
#boostFill { height: 100%; width: 0; background: var(--glow); box-shadow: 0 0 10px var(--glow); }
#mute { position: absolute; top: 16px; right: 16px; pointer-events: auto; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(89, 200, 255, 0.5); background: var(--panel); color: var(--ink); cursor: pointer; display: grid; place-items: center; }
#mute svg { width: 22px; height: 22px; }

#center { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); font-size: 120px; font-weight: 700; pointer-events: none; opacity: 0; }
#center.show { animation: punch 0.9s ease-out; }
#center.small { font-size: 48px; letter-spacing: 4px; }
@keyframes punch { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } }

#touch { position: fixed; left: 16px; right: 16px; bottom: 16px; display: none; justify-content: space-between; pointer-events: none; }
@media (pointer: coarse) { #touch { display: flex; } #speedBox { bottom: 110px; } }
#touch .grp { display: flex; gap: 12px; }
#touch button { pointer-events: auto; width: 76px; height: 76px; border-radius: 20px; border: 1px solid rgba(89, 200, 255, 0.6); background: var(--panel); color: var(--ink); font: inherit; font-size: 28px; }
#touch button.on { background: rgba(89, 200, 255, 0.45); }

/* ---------- screens ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(4, 16, 46, 0.25), rgba(2, 6, 20, 0.8)); }
.overlay.hidden { display: none; }
.card { text-align: center; max-width: 460px; width: 100%; max-height: calc(100vh - 32px); overflow-y: auto; }
.card h1 { font-size: clamp(48px, 13vw, 88px); line-height: 0.9; margin: 0 0 16px; letter-spacing: 2px; }
.card h2 { font-size: 44px; margin: 0 0 8px; }
.card p { font-size: 17px; line-height: 1.45; margin: 8px 0; opacity: 0.9; font-style: normal; }
.keys { opacity: 0.7; font-size: 15px; }
.big { font-size: 56px; font-weight: 700; margin: 4px 0; }
.laps { font-style: normal; opacity: 0.85; font-size: 16px; line-height: 1.6; }
.place { font-size: 30px; font-weight: 700; letter-spacing: 3px; }
.place.win { color: #ffe08a; text-shadow: 0 0 14px rgba(255, 210, 90, 0.9), 0 0 2px #fff; }
button.go { margin-top: 20px; pointer-events: auto; cursor: pointer; font: inherit; font-size: 26px; font-weight: 700; letter-spacing: 3px; color: var(--ink); background: rgba(89, 200, 255, 0.12); border: 2px solid var(--glow); padding: 12px 48px; transform: skewX(-12deg); box-shadow: 0 0 24px rgba(89, 200, 255, 0.5), inset 0 0 18px rgba(89, 200, 255, 0.35); }
button.go:hover { background: rgba(89, 200, 255, 0.28); }
button.go.alt { font-size: 18px; padding: 8px 24px; margin-top: 0; }
button.link { margin-top: 14px; border: 0; background: none; font: inherit; font-size: 16px; color: var(--ink); opacity: 0.75; text-decoration: underline; cursor: pointer; }
.links { display: flex; justify-content: center; gap: 18px; }

/* menu */
.modes { display: flex; flex-wrap: wrap; gap: 0 18px; justify-content: center; }
.modes button.go { font-size: 22px; padding: 10px 28px; }
.versus { margin-top: 22px; padding-top: 12px; border-top: 1px solid rgba(89, 200, 255, 0.3); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.field { font: inherit; font-style: normal; font-size: 18px; font-weight: 700; text-align: center; color: var(--ink); background: rgba(6, 22, 60, 0.7); border: 1px solid rgba(89, 200, 255, 0.6); padding: 8px 12px; width: 200px; user-select: text; -webkit-user-select: text; }
.join { display: flex; gap: 8px; }
.join .field { width: 110px; letter-spacing: 4px; }

/* track selection */
.card.wide { max-width: 900px; }
.tracks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-top: 12px; }
.trackCard { cursor: pointer; font: inherit; color: var(--ink); text-align: left; background: rgba(6, 22, 60, 0.6); border: 1px solid var(--c, var(--glow)); padding: 8px; box-shadow: 0 0 14px color-mix(in srgb, var(--c, var(--glow)) 35%, transparent); transition: transform 0.08s; }
.trackCard:hover { transform: translateY(-2px); background: rgba(6, 22, 60, 0.85); }
.trackCard canvas { width: 100%; height: 110px; display: block; }
.trackCard .name { font-size: 18px; font-weight: 700; letter-spacing: 1px; margin-top: 6px; }
.trackCard .meta { font-size: 13px; font-style: normal; opacity: 0.75; display: flex; justify-content: space-between; gap: 6px; }

/* lobby */
.code { font-size: 56px; font-weight: 700; letter-spacing: 8px; }
#qr:not(:empty) { width: 200px; height: 200px; margin: 10px auto; padding: 8px; background: #fff; }
#qr svg { width: 100%; height: 100%; display: block; }
.card p.url { font-size: 13px; word-break: break-all; opacity: 0.7; margin: 0; }

/* scores */
.card.scores { text-align: left; }
.card.scores h2, .card.scores .center { text-align: center; }
.card.scores h3 { margin: 16px 0 6px; letter-spacing: 2px; font-size: 18px; }
.card.scores h4 { margin: 10px 0 4px; font-size: 15px; letter-spacing: 1px; opacity: 0.85; }
.card.scores ol, .card.scores ul { margin: 0; padding-left: 24px; font-style: normal; }
.card.scores ul { list-style: none; padding-left: 0; }
.card.scores li { display: flex; gap: 8px; padding: 2px 0; }
.card.scores li span { margin-left: auto; opacity: 0.6; }

/* taunts: buttons for the winner, a reaction raining over the loser's screen */
.taunts { margin-top: 10px; }
.taunts.hidden { display: none; }
#tauntButtons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
#tauntButtons button { border: 1px solid rgba(89, 200, 255, 0.6); background: rgba(6, 22, 60, 0.7); font-size: 28px; line-height: 1; padding: 8px 10px; cursor: pointer; }
#tauntButtons button:disabled { opacity: 0.4; cursor: default; }
#tauntLayer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
#tauntLayer .rise { position: absolute; bottom: -12vh; font-size: var(--s); font-style: normal; animation: rise var(--d) cubic-bezier(0.2, 0.7, 0.4, 1) var(--delay) forwards; opacity: 0; }
@keyframes rise { 0% { opacity: 0; transform: translate(0, 0) rotate(0deg) scale(0.6); } 10% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), -115vh) rotate(var(--r)) scale(1.1); } }
#tauntLayer .shout { position: absolute; left: 50%; top: 42%; text-align: center; transform: translate(-50%, -50%); animation: shout 2.6s ease-out forwards; }
#tauntLayer .shout .emo { font-size: 110px; line-height: 1; margin: 0; font-style: normal; }
#tauntLayer .shout .words { font-size: 52px; font-weight: 700; width: max-content; max-width: 90vw; line-height: 1.1; text-shadow: 0 0 14px rgba(89, 200, 255, 0.9), 0 0 2px #fff; }
@keyframes shout { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2) rotate(-12deg); } 14% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(4deg); } 24% { transform: translate(-50%, -50%) scale(1) rotate(-2deg); } 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); } }
#tauntLayer .sent { position: absolute; left: 50%; bottom: 30%; font-size: 64px; font-style: normal; animation: sent 1.2s ease-out forwards; }
@keyframes sent { 0% { opacity: 0; transform: translate(-50%, 0) scale(0.5); } 20% { opacity: 1; transform: translate(-50%, -20px) scale(1.2); } 100% { opacity: 0; transform: translate(-50%, -160px) scale(1); } }
