:root {
  --ink: #1a1420; --paper: #fff6e6; --red: #e4553f; --gold: #ffd93b; --teal: #2de2ff;
  --purple: #8d3bd8; --green: #3faf4a; --panel: rgba(26, 20, 32, 0.86);
  --font-h: 'Lilita One', 'Arial Black', system-ui, sans-serif;
  --font-b: 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e0b14; color: var(--paper); font-family: var(--font-b); user-select: none; -webkit-user-select: none; touch-action: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hide { display: none !important; }

/* ---------------------------------------------------------------- menus */
#ui { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#ui > .screen { pointer-events: auto; width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; padding: 22px 24px; border-radius: 22px;
  background: var(--panel); border: 3px solid rgba(255, 255, 255, 0.12); box-shadow: 0 16px 60px rgba(0, 0, 0, 0.5); backdrop-filter: blur(6px); }
#ui.bg { background: radial-gradient(ellipse at 50% 30%, #3a2a66 0%, #1a1230 55%, #0e0b14 100%); }
h1, h2, h3 { font-family: var(--font-h); font-weight: 400; margin: 0 0 10px; letter-spacing: 0.5px; }
h1 { font-size: clamp(44px, 9vw, 92px); line-height: 0.95; text-align: center; color: var(--gold);
  text-shadow: 0 4px 0 var(--red), 0 8px 0 var(--ink), 0 10px 24px rgba(0, 0, 0, 0.6); transform: rotate(-3deg); }
h1 small { display: block; font-size: 0.32em; color: var(--paper); text-shadow: 0 3px 0 var(--ink); transform: rotate(2deg); margin-top: 8px; }
h2 { font-size: 34px; color: var(--gold); text-shadow: 0 3px 0 var(--ink); }
.sub { opacity: 0.8; font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.col { display: flex; flex-direction: column; gap: 10px; }
.center { justify-content: center; text-align: center; }
.grid { display: grid; gap: 10px; }
.btn { font-family: var(--font-h); font-size: 22px; color: var(--ink); background: var(--gold); border: 0; border-radius: 14px; padding: 12px 20px; cursor: pointer;
  box-shadow: 0 5px 0 #b8901c, 0 8px 14px rgba(0, 0, 0, 0.35); transition: transform 0.08s; outline: none; }
.btn:hover, .btn.focus { transform: translateY(-2px) scale(1.03); box-shadow: 0 7px 0 #b8901c, 0 0 0 4px #fff, 0 10px 20px rgba(0, 0, 0, 0.4); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b8901c; }
.btn.red { background: var(--red); color: #fff; box-shadow: 0 5px 0 #8f2a1c, 0 8px 14px rgba(0, 0, 0, 0.35); }
.btn.teal { background: var(--teal); box-shadow: 0 5px 0 #1386a0, 0 8px 14px rgba(0, 0, 0, 0.35); }
.btn.purple { background: var(--purple); color: #fff; box-shadow: 0 5px 0 #521f84, 0 8px 14px rgba(0, 0, 0, 0.35); }
.btn.ghost { background: transparent; color: var(--paper); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35); }
.btn.small { font-size: 16px; padding: 8px 14px; }
.btn.sel { background: #fff; box-shadow: 0 5px 0 #aaa, 0 0 0 4px var(--red); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.big-menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 18px; }
.big-menu .btn { font-size: 26px; padding: 18px; text-align: left; }
.big-menu .btn span { display: block; font-family: var(--font-b); font-size: 13px; font-weight: 800; opacity: 0.75; margin-top: 4px; }
input[type=text] { font-family: var(--font-h); font-size: 22px; padding: 10px 14px; border-radius: 12px; border: 3px solid var(--gold); background: #fff; color: var(--ink); width: 220px; }
.back { float: right; }

/* character select */
.chars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 14px 0; }
@media (max-width: 640px) { .chars { grid-template-columns: repeat(4, 1fr); } }
.char { position: relative; border-radius: 14px; padding: 6px; cursor: pointer; text-align: center; background: rgba(255, 255, 255, 0.08); border: 3px solid transparent; outline: none; }
.char img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.char .nm { font-family: var(--font-h); font-size: 15px; }
.char .tg { font-size: 11px; opacity: 0.7; }
.char.focus, .char:hover { border-color: #fff; transform: scale(1.04); }
.char.taken::after { content: attr(data-p); position: absolute; top: 4px; right: 6px; font-family: var(--font-h); background: var(--red); color: #fff; border-radius: 8px; padding: 0 6px; }
.char .side { position: absolute; top: 4px; left: 6px; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: var(--green); color: #fff; }
.char .side.villain { background: var(--purple); }
.char .side.ally { background: #1386a0; }
.stats { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; font-weight: 800; font-size: 13px; max-width: 360px; }
.bar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.15); overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--red)); }

/* tracks */
.tracks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 12px; }
.tcard { border-radius: 14px; padding: 12px; background: rgba(255, 255, 255, 0.08); cursor: pointer; border: 3px solid transparent; outline: none; }
.tcard b { font-family: var(--font-h); font-weight: 400; font-size: 20px; display: block; }
.tcard small { opacity: 0.75; }
.tcard.focus, .tcard:hover { border-color: #fff; background: rgba(255, 255, 255, 0.16); }
.tcard .best { color: var(--gold); font-weight: 800; font-size: 12px; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }

/* results */
table.res { width: 100%; border-collapse: collapse; font-size: 18px; margin: 10px 0; }
table.res td { padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
table.res tr.me td { background: rgba(255, 217, 59, 0.18); }
table.res td.pl { font-family: var(--font-h); font-size: 24px; width: 60px; color: var(--gold); }
table.res img { width: 36px; height: 36px; vertical-align: middle; margin-right: 8px; }
.trophy { font-size: 90px; text-align: center; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.4)); }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; font-family: var(--font-h); }
.hudp { position: absolute; overflow: hidden; }
.hudp .itembox { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: 84px; height: 84px; border-radius: 16px; background: rgba(26, 20, 32, 0.55);
  border: 4px solid rgba(255, 255, 255, 0.85); display: flex; align-items: center; justify-content: center; font-size: 48px; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4); }
.hudp .itembox b { position: absolute; bottom: -2px; right: 4px; font-size: 18px; color: #fff; text-shadow: 0 2px 0 #000; }
.hudp .itembox.rolling { border-color: var(--gold); animation: pulse 0.15s infinite alternate; }
@keyframes pulse { to { transform: translateX(-50%) scale(1.06); } }
.hudp .place { position: absolute; right: 22px; bottom: 16px; font-size: 76px; line-height: 1; text-shadow: 0 5px 0 var(--ink), 0 0 20px rgba(0, 0, 0, 0.4); -webkit-text-stroke: 2px var(--ink); }
.hudp .lap { position: absolute; left: 20px; top: 18px; font-size: 30px; color: #fff; text-shadow: 0 3px 0 var(--ink); }
.hudp .lap b { color: var(--gold); font-weight: 400; font-size: 38px; }
.hudp .time { position: absolute; right: 20px; top: 18px; font-size: 30px; color: #fff; text-shadow: 0 3px 0 var(--ink); font-variant-numeric: tabular-nums; }
.hudp .bstat { position: absolute; left: 20px; bottom: 18px; font-size: 36px; color: #fff; text-shadow: 0 3px 0 var(--ink); }
.hudp .bstat .hold { color: var(--gold); font-size: 20px; }
.hudp .pname { position: absolute; left: 20px; bottom: 16px; font-size: 18px; opacity: 0.85; text-shadow: 0 2px 0 var(--ink); }
.hudp .msg { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-size: 46px; color: #fff; text-shadow: 0 4px 0 var(--ink); opacity: 0; transform: scale(0.6); transition: 0.18s; }
.hudp .msg.show { opacity: 1; transform: scale(1); }
.hudp .msg.gold { color: var(--gold); }
.hudp .msg.warn { color: #6fd6ff; }
.hudp .wrong { position: absolute; left: 0; right: 0; top: 22%; text-align: center; font-size: 40px; color: var(--red); text-shadow: 0 3px 0 #fff; opacity: 0; }
.hudp .wrong.show { opacity: 1; animation: blink 0.5s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }
.hudp.small .itembox { width: 60px; height: 60px; font-size: 34px; top: 8px; }
.hudp.small .place { font-size: 48px; }
.hudp.small .lap, .hudp.small .time { font-size: 20px; }
.hudp.small .lap b { font-size: 24px; }
.hudp.small .msg { font-size: 30px; }
.hudp.small .pname { bottom: auto; top: 44px; left: 20px; }
.minimap { position: absolute; right: 14px; bottom: 110px; width: 190px; height: 190px; opacity: 0.92; }
.minimap.center { left: 50%; top: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%); width: 150px; height: 150px; opacity: 0.8; }
.banner { position: absolute; left: 0; right: 0; top: 16%; text-align: center; font-size: clamp(28px, 5vw, 54px); color: #fff; text-shadow: 0 4px 0 var(--ink); opacity: 0; transition: 0.25s; }
.banner.show { opacity: 1; }
.banner.gold { color: var(--gold); }
.banner.title { color: var(--gold); font-size: clamp(34px, 6vw, 70px); }
.countdown { position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-size: 150px; color: var(--gold); text-shadow: 0 8px 0 var(--red), 0 14px 0 var(--ink); opacity: 0; transform: scale(2); transition: 0.15s; }
.countdown.show { opacity: 1; transform: scale(1); }
.countdown.go { color: #7fff6a; text-shadow: 0 8px 0 #1f8a2a, 0 14px 0 var(--ink); }
.flash { position: absolute; inset: 0; opacity: 0; }
.flash.on { animation: flash 0.5s; }
@keyframes flash { 0% { opacity: 0.8; } 100% { opacity: 0; } }

/* pause */
.pause-title { text-align: center; }

/* loading */
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; background: rgba(14, 11, 20, 0.85); font-family: var(--font-h); font-size: 26px; z-index: 5; }
.spin { width: 64px; height: 64px; border-radius: 50%; border: 8px solid rgba(255, 255, 255, 0.2); border-top-color: var(--gold); animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* touch */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
#touch .tz { position: absolute; pointer-events: auto; width: 84px; height: 84px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); border: 3px solid rgba(255, 255, 255, 0.5);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-h); font-size: 20px; color: #fff; }
#tSteer { position: absolute; left: 0; bottom: 0; width: 46vw; height: 55vh; pointer-events: auto; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 40px; }
#tSteer span { position: absolute; bottom: 12px; font-family: var(--font-b); font-size: 11px; opacity: 0.5; }
#tKnob { width: 76px; height: 76px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); border: 3px solid rgba(255, 255, 255, 0.55); transition: transform 0.05s; }
#tSteer.on #tKnob, #touch .tz.on { background: rgba(255, 217, 59, 0.45); }
#tHop { right: 18px; bottom: 30px; width: 100px !important; height: 100px !important; }
#tItem { right: 130px; bottom: 60px; } #tBrake { right: 40px; bottom: 150px; width: 64px !important; height: 64px !important; }

/* wide screens: menus on the left, the 3D racer turntable on the right */
@media (min-width: 1000px) {
  #ui { justify-content: flex-start; padding-left: 4vw; }
  #ui > .screen { width: min(660px, 56vw); }
}
#ui > .screen.clear { background: transparent; border: 0; box-shadow: none; backdrop-filter: none; }

.fps { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); font: 700 12px var(--font-b); color: #fff; background: rgba(0,0,0,0.45); padding: 2px 8px; border-radius: 8px; }
.hudp .itembox img { width: 82%; height: 82%; object-fit: contain; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.4)); }
.hudp .bstat .coins { font-size: 30px; display: inline-flex; align-items: center; gap: 2px; }
.hudp .bstat .coins img { width: 40px; height: 40px; }
.hudp.small .bstat .coins { font-size: 20px; } .hudp.small .bstat .coins img { width: 26px; height: 26px; }
.char.locked { opacity: 0.55; filter: grayscale(0.7); }
.char .lockpic { font-size: 54px; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.char .side.boss { background: #ff7a1f; }
.parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tcard.part { padding: 8px; text-align: center; }
.tcard.part b { font-size: 14px; }
.tcard.part .picon { width: 64px; height: 64px; margin: 0 auto; display: flex; align-items: center; justify-content: center; font-size: 40px; object-fit: contain; }
.tcard.part.sel { border-color: var(--gold); background: rgba(255, 217, 59, 0.16); }
.tcard.part.locked { opacity: 0.6; }
