/* ============================================================================================
   Turbo Kart Rally — UI styles (canvas, overlay layering, menus, HUD, results)
   ============================================================================================ */
:root {
  --display: 'Lilita One', 'Arial Black', Impact, sans-serif;
  --body: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --ink: #14122b;
  --gold: #ffd23f;
  --orange: #ff8a1f;
  --red: #ff4757;
  --blue: #2f8bff;
  --cyan: #3de0ff;
  --panel: rgba(16, 20, 48, 0.72);
  --panel-solid: #161a3a;
  --outline: 0 3px 0 var(--ink), 0 -2px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink), 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink);
  --ui-scale: 1;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #0b1020; color: #fff;
  font-family: var(--body);
  user-select: none; -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}
#game-root { position: fixed; inset: 0; overflow: hidden; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#ui-root { position: absolute; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
#ui-root.no-world { background: radial-gradient(ellipse at 50% 120%, #ff9a3c 0%, #ff4f7b 30%, #5b3cc4 62%, #1a1e5a 100%); }
#ui-root.no-world::before {
  content: ''; position: absolute; inset: -50%;
  background: repeating-linear-gradient(115deg, rgba(255,255,255,0.05) 0 40px, transparent 40px 110px);
  animation: stripes 6s linear infinite;
}
@keyframes stripes { to { transform: translateX(220px); } }

button { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- generic buttons */
.btn {
  pointer-events: auto; cursor: pointer;
  font-family: var(--display); font-size: 26px; letter-spacing: 1px;
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.35);
  padding: 12px 28px; min-width: 200px;
  border: 3px solid rgba(255,255,255,0.9); border-radius: 16px;
  background: linear-gradient(180deg, #4a5bd8 0%, #2c35a0 100%);
  box-shadow: 0 6px 0 #161b5c, 0 10px 20px rgba(0,0,0,0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s, filter 0.15s;
}
.btn.primary { background: linear-gradient(180deg, #ffcf3a 0%, #ff8a1f 100%); color: #fff; box-shadow: 0 6px 0 #b24a00, 0 10px 20px rgba(0,0,0,0.35); }
.btn:hover, .btn.focus { transform: translateY(-3px) scale(1.04); filter: brightness(1.12); }
.btn.focus { outline: 4px solid #fff; outline-offset: 3px; animation: focusGlow 1s ease-in-out infinite alternate; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #161b5c; }
@keyframes focusGlow { from { box-shadow: 0 6px 0 rgba(0,0,0,0.45), 0 0 0 rgba(255,210,63,0); } to { box-shadow: 0 6px 0 rgba(0,0,0,0.45), 0 0 26px rgba(255,210,63,0.85); } }

.kc {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 6px; margin-right: 4px;
  font-family: var(--display); font-size: 14px; color: var(--ink);
  background: linear-gradient(180deg, #fff, #d9dcf0); border-radius: 6px;
  box-shadow: 0 3px 0 #8a8fb5;
}
.kc.wide { min-width: 52px; }

/* ---------------------------------------------------------------- screens */
.screen {
  position: absolute; inset: 0; opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}
.screen.active { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 0.35s ease; }

/* ---- loading */
.loading-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at center, rgba(26,30,90,0.85), rgba(8,10,28,0.96)); }
.spinner { width: 64px; height: 64px; border-radius: 50%; border: 8px solid rgba(255,255,255,0.18); border-top-color: var(--gold); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-family: var(--display); font-size: 30px; letter-spacing: 3px; text-shadow: var(--outline); }

/* ---- title */
.title-screen { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.title-vignette {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(0,0,0,0) 30%, rgba(8,8,30,0.55) 100%),
    linear-gradient(180deg, rgba(20,18,60,0.35) 0%, rgba(0,0,0,0) 40%, rgba(10,8,30,0.6) 100%);
}
.logo {
  position: relative; z-index: 0; margin-top: 11vh; text-align: center;
  transform: rotate(-4deg) skewX(-8deg);
  animation: logoIn 1s cubic-bezier(.2,1.6,.4,1) both, logoFloat 4s ease-in-out 1s infinite;
}
@keyframes logoIn { from { transform: rotate(-4deg) skewX(-8deg) scale(0.3) translateY(-80px); opacity: 0; } to { transform: rotate(-4deg) skewX(-8deg) scale(1); opacity: 1; } }
@keyframes logoFloat { 0%,100% { transform: rotate(-4deg) skewX(-8deg) translateY(0); } 50% { transform: rotate(-3deg) skewX(-8deg) translateY(-10px); } }
.logo-line {
  position: relative; font-family: var(--display); line-height: 0.92; letter-spacing: 2px;
  color: transparent; -webkit-background-clip: text; background-clip: text;
  -webkit-text-stroke: 3px rgba(255,255,255,0.95);
  paint-order: stroke fill;
}
.logo-line::before {
  content: attr(data-text); position: absolute; left: 0; top: 0; z-index: -1;
  -webkit-text-stroke: 14px var(--ink);
  color: var(--ink);
}
.logo-line.l1 {
  font-size: clamp(72px, 15vw, 210px);
  background-image: linear-gradient(180deg, #fff6a8 0%, #ffd23f 35%, #ff9d1f 60%, #ff5a1f 100%);
}
.logo-line.l1::before {
  text-shadow: 0 4px 0 #b3260a, 0 8px 0 #9a1f08, 0 12px 0 #801906, 0 16px 0 #661304, 0 22px 24px rgba(0,0,0,0.6);
}
.logo-line.l2 {
  font-size: clamp(40px, 7.6vw, 108px); margin-top: 4px;
  background-image: linear-gradient(180deg, #e8fcff 0%, #7ee8ff 40%, #2f8bff 75%, #3b3fd8 100%);
}
.logo-line.l2::before {
  text-shadow: 0 3px 0 #1d2a8a, 0 6px 0 #18237a, 0 9px 0 #121a63, 0 14px 18px rgba(0,0,0,0.6);
}
.logo-swoosh {
  position: absolute; left: -8%; right: -8%; top: 52%; height: 22%; z-index: -2;
  background: linear-gradient(90deg, rgba(255,71,87,0) 0%, rgba(255,71,87,0.95) 20%, rgba(255,138,31,0.95) 80%, rgba(255,138,31,0) 100%);
  transform: skewX(-20deg); border-radius: 8px;
  box-shadow: 0 0 30px rgba(255,120,40,0.6);
}
.press-start {
  position: absolute; bottom: 17vh; font-family: var(--display); font-size: clamp(20px, 2.6vw, 34px);
  letter-spacing: 2px; text-shadow: var(--outline), 0 0 20px rgba(255,210,63,0.6);
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.97); } }
.title-foot { position: absolute; bottom: 18px; left: 0; right: 0; display: flex; gap: 10px; justify-content: center; align-items: center;
  font-weight: 700; font-size: 14px; opacity: 0.85; text-shadow: 0 1px 2px #000; }
.title-foot span:first-child { margin-right: 24px; }

/* ---- character select */
.select-screen {
  display: flex; flex-direction: column; padding: 22px 28px 16px;
  background: linear-gradient(90deg, rgba(12,14,44,0.82) 0%, rgba(12,14,44,0.45) 34%, rgba(12,14,44,0) 44%, rgba(12,14,44,0) 58%, rgba(12,14,44,0.55) 68%, rgba(12,14,44,0.85) 100%);
}
.sel-header { display: flex; align-items: center; justify-content: space-between; }
.sel-title {
  font-family: var(--display); font-size: clamp(30px, 3.6vw, 52px); letter-spacing: 2px;
  background: linear-gradient(180deg, #fff 0%, #ffe27a 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 var(--ink)) drop-shadow(0 0 1px var(--ink));
  transform: skewX(-6deg);
}
.sel-back { font-family: var(--display); font-size: 18px; padding: 8px 16px; border-radius: 12px; background: rgba(0,0,0,0.35); cursor: pointer; }
.sel-back:hover { background: rgba(255,255,255,0.15); }
.sel-body { flex: 1; display: flex; justify-content: space-between; align-items: stretch; gap: 24px; min-height: 0; margin-top: 14px; }
.sel-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr);
  gap: 12px; width: min(520px, 42vw); align-content: start;
}
.card {
  position: relative; cursor: pointer; display: grid; grid-template-columns: 64px 1fr; grid-template-rows: auto 1fr;
  column-gap: 10px; padding: 9px 10px 9px 9px; border-radius: 16px;
  background: linear-gradient(135deg, rgba(40,46,110,0.92), rgba(22,26,66,0.92));
  border: 3px solid rgba(255,255,255,0.18);
  box-shadow: inset 6px 0 0 var(--kc), 0 6px 14px rgba(0,0,0,0.35);
  transition: transform 0.16s cubic-bezier(.3,1.6,.5,1), border-color 0.15s, box-shadow 0.15s, background 0.2s;
  animation: cardIn 0.45s cubic-bezier(.2,1.4,.4,1) both;
}
.card:nth-child(1) { animation-delay: 0.02s; } .card:nth-child(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.10s; } .card:nth-child(4) { animation-delay: 0.14s; }
.card:nth-child(5) { animation-delay: 0.18s; } .card:nth-child(6) { animation-delay: 0.22s; }
.card:nth-child(7) { animation-delay: 0.26s; } .card:nth-child(8) { animation-delay: 0.30s; }
@keyframes cardIn { from { opacity: 0; transform: translateX(-40px) scale(0.9); } to { opacity: 1; transform: none; } }
.card.selected { background: linear-gradient(135deg, color-mix(in srgb, var(--kc) 55%, #1c2160), rgba(22,26,66,0.95)); border-color: #fff; transform: scale(1.03); }
.card.focus { border-color: var(--gold); box-shadow: inset 6px 0 0 var(--kc), 0 0 0 3px rgba(255,210,63,0.5), 0 0 24px rgba(255,210,63,0.55); }
.card.picked { animation: picked 0.4s ease; }
@keyframes picked { 40% { transform: scale(1.12); } 100% { transform: scale(1.03); } }
.card-portrait {
  grid-row: 1 / span 2; width: 64px; height: 64px; border-radius: 14px; overflow: hidden; align-self: center;
  background: radial-gradient(circle at 40% 35%, color-mix(in srgb, var(--kc) 60%, #fff), var(--kc));
  border: 3px solid #fff; display: flex; align-items: center; justify-content: center;
}
.card-portrait img { width: 100%; height: 100%; object-fit: cover; }
.card-portrait .initial, .pv-initial { font-family: var(--display); font-size: 36px; text-shadow: var(--outline); }
.card-name { font-family: var(--display); font-size: 22px; line-height: 1.1; text-shadow: 0 2px 0 var(--ink); }
.card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; align-content: center; min-width: 0; }
.st { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 9px; font-weight: 900; letter-spacing: 0.5px; opacity: 0.9; }
.bar { display: flex; gap: 1.5px; }
.bar i { display: block; flex: none; width: 6px; height: 7px; border-radius: 2px; background: rgba(255,255,255,0.18); }
.bar i.on { background: linear-gradient(180deg, #fff27a, #ffb21f); box-shadow: 0 0 4px rgba(255,200,40,0.6); }
.st.big { font-size: 13px; margin: 3px 0; }
.st.big .bar { gap: 4px; }
.st.big .bar i { width: 22px; height: 11px; border-radius: 3px; }

.sel-side { width: min(380px, 34vw); display: flex; flex-direction: column; gap: 14px; }
.preview {
  padding: 16px; border-radius: 20px; background: var(--panel); border: 3px solid rgba(255,255,255,0.22);
  backdrop-filter: blur(6px); display: flex; flex-direction: column; align-items: center; gap: 10px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}
.pv-portrait {
  width: 124px; height: 124px; border-radius: 50%; overflow: hidden; border: 5px solid #fff;
  background: radial-gradient(circle at 40% 35%, color-mix(in srgb, var(--kc, #888) 55%, #fff), var(--kc, #888));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 5px var(--kc, #888), 0 10px 20px rgba(0,0,0,0.4);
}
.pv-portrait.pop { animation: pvPop 0.35s cubic-bezier(.3,1.8,.5,1); }
@keyframes pvPop { from { transform: scale(0.7) rotate(-8deg); } to { transform: none; } }
.pv-portrait img { width: 100%; height: 100%; object-fit: cover; }
.pv-info { width: 100%; }
.pv-name { font-family: var(--display); font-size: 40px; text-align: center; line-height: 1; text-shadow: 0 4px 0 var(--ink); }
.pv-kart { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 900; font-size: 12px; opacity: 0.85; margin: 6px 0 8px; letter-spacing: 1px; }
.swatch { width: 34px; height: 16px; border-radius: 5px; border: 2px solid #fff; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: grid; grid-template-columns: 70px 28px 1fr 28px; align-items: center; gap: 4px;
  padding: 10px 12px; border-radius: 14px; background: var(--panel); border: 3px solid rgba(255,255,255,0.18);
  cursor: pointer; transition: all 0.15s;
}
.opt.focus { border-color: var(--gold); background: rgba(60,50,20,0.8); box-shadow: 0 0 20px rgba(255,210,63,0.35); }
.opt-lbl { font-family: var(--display); font-size: 16px; opacity: 0.8; }
.opt-val { font-family: var(--display); font-size: 21px; text-align: center; white-space: nowrap; }
.opt-val.bump { animation: bump 0.25s ease; }
@keyframes bump { 50% { transform: scale(1.18); color: var(--gold); } }
.opt-arrow { font-size: 18px; text-align: center; color: var(--gold); cursor: pointer; transition: transform 0.1s; }
.opt-arrow:hover { transform: scale(1.3); }
.race-btn { font-size: 34px; padding: 14px; margin-top: 4px; }

.controls-help {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; margin-top: 12px;
  padding: 10px 14px; border-radius: 14px; background: rgba(0,0,0,0.42); font-weight: 800; font-size: 13px;
}
.ctl { display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.ctl .kc:last-of-type { margin-right: 8px; }

/* ---- pause */
.pause-screen { display: flex; align-items: center; justify-content: center; background: rgba(8,10,30,0.55); backdrop-filter: blur(5px); }
.pause-panel {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 26px 34px 22px; border-radius: 26px; background: linear-gradient(180deg, rgba(40,46,120,0.95), rgba(20,22,60,0.95));
  border: 4px solid #fff; box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  transform: scale(0.9); transition: transform 0.25s cubic-bezier(.3,1.6,.5,1);
}
.pause-screen.active .pause-panel { transform: none; }
.pause-title { font-family: var(--display); font-size: 58px; letter-spacing: 3px; color: var(--gold); text-shadow: 0 5px 0 var(--ink); margin-bottom: 4px; }
.pause-panel .btn { width: 300px; }
.controls-help.compact { max-width: 440px; font-size: 12px; margin-top: 8px; }

/* ---- intro card */
.intro-card {
  position: absolute; left: 0; bottom: 14vh; padding: 16px 60px 16px 40px; opacity: 0;
  background: linear-gradient(90deg, rgba(255,71,87,0.95), rgba(255,138,31,0.9) 80%, rgba(255,138,31,0));
  clip-path: polygon(0 0, 100% 0, 94% 100%, 0 100%);
  transform: translateX(-110%);
}
.intro-card.show { animation: introCard 4s cubic-bezier(.2,1,.3,1) forwards; }
@keyframes introCard {
  0% { transform: translateX(-110%); opacity: 1; }
  12%, 85% { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(-10%); opacity: 0; }
}
.ic-sub { font-family: var(--display); font-size: 20px; letter-spacing: 2px; opacity: 0.95; }
.ic-name { font-family: var(--display); font-size: clamp(36px, 5vw, 64px); line-height: 1; text-shadow: 0 4px 0 rgba(0,0,0,0.35); }
.ic-skip { font-weight: 900; font-size: 12px; letter-spacing: 2px; opacity: 0.8; margin-top: 6px; }

/* ================================================================ HUD */
.hud { position: absolute; inset: 0; pointer-events: none; font-family: var(--display); color: #fff; }
.hud.shake { animation: shake 0.45s ease; }
@keyframes shake { 15% { transform: translate(-7px, 3px); } 30% { transform: translate(6px, -4px); } 50% { transform: translate(-4px, 2px); } 70% { transform: translate(3px, -1px); } }

.hud-tl { position: absolute; top: 18px; left: 24px; }
.hud-lap { display: flex; align-items: baseline; gap: 6px; text-shadow: var(--outline); transform-origin: left center; }
.hud-lap .lbl { font-size: 26px; color: #bfe6ff; }
.hud-lap .val { font-size: 60px; line-height: 1; }
.hud-lap .of { font-size: 34px; opacity: 0.9; }
.hud-lap.final .val { color: var(--gold); }
.hud-lap.pulse { animation: lapPulse 0.6s ease; }
@keyframes lapPulse { 30% { transform: scale(1.3); color: var(--gold); } }
.hud-timer {
  font-family: var(--body); font-weight: 900; font-size: 28px; font-variant-numeric: tabular-nums; letter-spacing: 1px;
  text-shadow: var(--outline); margin-top: 2px;
}
.hud-splits { margin-top: 4px; font-family: var(--body); font-weight: 900; font-size: 15px; font-variant-numeric: tabular-nums; }
.split { text-shadow: 0 2px 0 var(--ink), 0 0 3px var(--ink); opacity: 0.92; animation: splitIn 0.35s ease both; }
.split span { display: inline-block; width: 28px; color: #9fd3ff; }
.split.best { color: #8dff9a; }
@keyframes splitIn { from { opacity: 0; transform: translateX(-20px); } }
.hud-lappop {
  position: absolute; top: 120px; left: 24px; font-family: var(--body); font-weight: 900; font-size: 26px; color: var(--gold);
  text-shadow: var(--outline); opacity: 0;
}
.hud-lappop.show { animation: lapPop 2.2s ease forwards; }
@keyframes lapPop { 0% { opacity: 0; transform: translateY(10px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* item slot */
.hud-item { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; }
.item-slot {
  position: relative; width: 112px; height: 112px; border-radius: 28px;
  background: radial-gradient(circle at 50% 35%, rgba(90,110,220,0.85), rgba(20,24,70,0.88));
  border: 5px solid #fff;
  box-shadow: 0 0 0 4px var(--ink), 0 8px 18px rgba(0,0,0,0.45), inset 0 -8px 16px rgba(0,0,0,0.35), inset 0 6px 10px rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
}
.item-slot::after { content: ''; position: absolute; inset: 6px; border-radius: 20px; border: 2px dashed rgba(255,255,255,0.18); }
.item-slot.filled { animation: slotGlow 1.4s ease-in-out infinite alternate; }
@keyframes slotGlow { to { box-shadow: 0 0 0 4px var(--ink), 0 0 26px rgba(255,220,90,0.75), inset 0 -8px 16px rgba(0,0,0,0.35); } }
.item-slot.spinning .item-img { animation: rouletteJitter 0.14s linear infinite; filter: blur(0.6px) brightness(1.1); }
@keyframes rouletteJitter { 0% { transform: translateY(-10px) scale(0.9); } 100% { transform: translateY(10px) scale(0.9); } }
.item-slot.got { animation: gotPop 0.4s cubic-bezier(.3,1.8,.5,1); }
@keyframes gotPop { 0% { transform: scale(0.7); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
.item-img { width: 84px; height: 84px; image-rendering: auto; filter: drop-shadow(0 4px 2px rgba(0,0,0,0.4)); }
.item-count {
  position: absolute; right: -14px; bottom: -12px; font-size: 32px; color: var(--gold); text-shadow: var(--outline);
}
.item-hint { margin-top: 6px; font-family: var(--body); font-weight: 900; font-size: 11px; letter-spacing: 1px; padding: 2px 8px; border-radius: 8px; background: rgba(0,0,0,0.45); transition: opacity 0.2s; opacity: 0; }

/* standings */
.hud-standings { position: absolute; right: 18px; top: 18px; display: flex; flex-direction: column; gap: 3px; }
.st-row {
  display: flex; align-items: center; gap: 7px; height: 25px; padding: 0 12px 0 6px; border-radius: 13px;
  background: rgba(10,12,40,0.55); font-family: var(--body); font-weight: 900; font-size: 13px;
  transition: background 0.2s, transform 0.2s;
}
.st-row.me { background: linear-gradient(90deg, rgba(255,210,63,0.95), rgba(255,138,31,0.9)); color: var(--ink); transform: translateX(-8px); }
.st-pos { width: 16px; text-align: center; font-family: var(--display); font-size: 15px; }
.st-chip { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; }
.st-name { min-width: 56px; }

/* minimap */
.hud-minimap {
  position: absolute; left: 16px; bottom: 16px; width: clamp(150px, 24vmin, 240px); height: clamp(150px, 24vmin, 240px);
  border-radius: 24px; background: radial-gradient(circle, rgba(10,14,40,0.45), rgba(10,14,40,0.2) 70%, rgba(10,14,40,0));
}
.hud-minimap canvas { width: 100%; height: 100%; display: block; }

/* speedo + place */
.hud-br { position: absolute; right: 22px; bottom: 10px; display: flex; align-items: flex-end; gap: 6px; }
.hud-speedo { position: relative; width: clamp(120px, 17vmin, 160px); height: clamp(120px, 17vmin, 160px); margin-bottom: 18px; border-radius: 50%; transition: filter 0.2s; }
.hud-speedo.boost { filter: drop-shadow(0 0 14px rgba(255,160,40,0.9)); }
.hud-speedo canvas { width: 100%; height: 100%; }
.speed-val { position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-size: clamp(30px, 4.4vmin, 42px); line-height: 1; text-shadow: var(--outline); }
.speed-unit { position: absolute; left: 0; right: 0; top: 64%; text-align: center; font-family: var(--body); font-weight: 900; font-size: 12px; opacity: 0.85; text-shadow: 0 1px 2px #000; }
.drift-pill {
  position: absolute; left: 50%; bottom: -14px; transform: translateX(-50%) scale(0.6); opacity: 0;
  padding: 3px 12px; border-radius: 10px; font-size: 15px; letter-spacing: 1px; background: #d8dbe8; color: var(--ink);
  border: 2px solid #fff; transition: transform 0.15s cubic-bezier(.3,1.8,.5,1), opacity 0.15s;
}
.drift-pill.show { opacity: 1; transform: translateX(-50%) scale(1); }
.drift-pill.lvl1 { background: #3aa0ff; color: #fff; box-shadow: 0 0 14px #3aa0ff; }
.drift-pill.lvl2 { background: #ff8a1f; color: #fff; box-shadow: 0 0 16px #ff8a1f; }
.drift-pill.lvl3 { background: #b34dff; color: #fff; box-shadow: 0 0 20px #d07bff; animation: ultra 0.25s linear infinite alternate; }
@keyframes ultra { to { filter: brightness(1.35); } }
.hud-place { --pc: #fff; display: flex; align-items: flex-start; line-height: 0.85; color: var(--pc); transform-origin: 70% 80%; }
.hud-place .num {
  font-size: clamp(90px, 16vmin, 150px);
  -webkit-text-stroke: 9px var(--ink); paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--ink), 0 10px 20px rgba(0,0,0,0.4);
}
.hud-place .suf {
  font-size: clamp(34px, 6vmin, 56px); margin-top: 6px;
  -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink);
}
.hud-place.bump { animation: placeBump 0.45s cubic-bezier(.3,1.8,.5,1); }
@keyframes placeBump { 0% { transform: scale(1.45) rotate(-6deg); } 100% { transform: none; } }

/* countdown */
.hud-countdown {
  position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: clamp(120px, 26vmin, 260px); line-height: 1;
  -webkit-text-stroke: 12px var(--ink); paint-order: stroke fill; text-shadow: 0 12px 0 var(--ink), 0 0 60px rgba(255,255,255,0.4);
  opacity: 0; pointer-events: none;
}
.hud-countdown.show { animation: cdPop 0.95s cubic-bezier(.2,1.6,.4,1) forwards; }
.hud-countdown.n3 { color: #ff4757; } .hud-countdown.n2 { color: #ffa21f; } .hud-countdown.n1 { color: #ffe23f; }
.hud-countdown.go { color: #4dff7c; animation: goPop 1.1s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes cdPop { 0% { opacity: 0; transform: scale(2.6); } 25% { opacity: 1; transform: scale(1); } 75% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(0.6); } }
@keyframes goPop { 0% { opacity: 0; transform: scale(0.3) rotate(-10deg); } 25% { opacity: 1; transform: scale(1.15) rotate(3deg); } 70% { opacity: 1; transform: scale(1.1); } 100% { opacity: 0; transform: scale(2.2); } }

/* banners */
.hud-banner {
  position: absolute; left: 0; right: 0; top: 24%; text-align: center; font-size: clamp(56px, 10vmin, 110px);
  color: var(--gold); -webkit-text-stroke: 9px var(--ink); paint-order: stroke fill; text-shadow: 0 8px 0 var(--ink);
  opacity: 0; font-style: italic;
}
.hud-banner.show { animation: bannerSweep 2.8s cubic-bezier(.2,.9,.3,1) forwards; }
.hud-banner.final { background: linear-gradient(90deg, rgba(255,71,87,0), rgba(255,71,87,0.85) 20%, rgba(255,71,87,0.85) 80%, rgba(255,71,87,0)); padding: 10px 0; }
@keyframes bannerSweep {
  0% { opacity: 1; transform: translateX(100vw) skewX(-12deg); }
  15% { transform: translateX(-2vw) skewX(-12deg); }
  22%, 78% { opacity: 1; transform: translateX(0) skewX(-8deg); }
  100% { opacity: 0; transform: translateX(-100vw) skewX(-12deg); }
}
.hud-wrongway {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); display: none; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 34px 12px; border-radius: 20px; background: rgba(200,20,40,0.88); border: 5px solid #fff;
  box-shadow: 0 0 0 5px var(--ink), 0 0 40px rgba(255,40,60,0.7);
}
.hud-wrongway.show { display: flex; animation: wwBlink 0.6s steps(2, jump-none) infinite; }
@keyframes wwBlink { 50% { opacity: 0.45; } }
.ww-text { font-size: clamp(40px, 7vmin, 64px); text-shadow: 0 4px 0 var(--ink); letter-spacing: 2px; }
.ww-arrow { width: 0; height: 0; border-left: 30px solid transparent; border-right: 30px solid transparent; border-bottom: 34px solid #fff; transform: rotate(180deg); animation: wwArrow 0.6s ease-in-out infinite alternate; }
@keyframes wwArrow { to { transform: rotate(180deg) translateY(-6px); } }

.hud-flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(circle, #fffde0 0%, #fff27a 60%, #ffd23f 100%); z-index: 5; }
.hud-flash.flash { animation: flash 0.75s ease-out; }
.hud-flash.flash-soft { animation: flashSoft 0.5s ease-out; }
@keyframes flash { 0% { opacity: 0.95; } 15% { opacity: 0.4; } 25% { opacity: 0.85; } 100% { opacity: 0; } }
@keyframes flashSoft { 0% { opacity: 0.45; } 100% { opacity: 0; } }

.hud-finish { position: absolute; left: 0; right: 0; top: 20%; text-align: center; opacity: 0; }
.hud-finish.show { animation: finishIn 0.7s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes finishIn { from { opacity: 0; transform: scale(3) rotate(8deg); } to { opacity: 1; transform: none; } }
.fin-title {
  display: inline-block; font-size: clamp(80px, 15vmin, 160px); font-style: italic; padding: 0 40px;
  color: #fff; -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; text-shadow: 0 10px 0 var(--ink);
  background:
    repeating-conic-gradient(rgba(0,0,0,0.85) 0 25%, rgba(255,255,255,0.85) 0 50%) 0 0 / 40px 40px;
  border: 6px solid #fff; border-radius: 20px; box-shadow: 0 0 0 6px var(--ink), 0 20px 40px rgba(0,0,0,0.45);
  transform: skewX(-8deg);
}
.fin-place { font-size: clamp(60px, 11vmin, 120px); margin-top: 18px; -webkit-text-stroke: 8px var(--ink); paint-order: stroke fill; text-shadow: 0 8px 0 var(--ink); }
.fin-place small { font-size: 0.45em; vertical-align: top; }

/* toast */
.toast { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 8px 20px; border-radius: 20px; background: rgba(0,0,0,0.7);
  font-family: var(--display); font-size: 18px; letter-spacing: 1px; opacity: 0; z-index: 20; }
.toast.show { animation: toast 1.6s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 20px); } 15%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ================================================================ results */
.results {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: auto; z-index: 10;
  background: radial-gradient(ellipse at center, rgba(20,24,70,0.55), rgba(6,8,24,0.85));
  opacity: 0; transition: opacity 0.4s ease;
}
.results.show { opacity: 1; }
.res-panel {
  width: min(780px, 94vw); max-height: 94vh; display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 20px 24px 22px; border-radius: 28px; background: linear-gradient(180deg, rgba(44,52,140,0.96), rgba(18,20,58,0.96));
  border: 5px solid #fff; box-shadow: 0 0 0 5px var(--ink), 0 30px 60px rgba(0,0,0,0.55);
  transform: translateY(40px) scale(0.92); transition: transform 0.5s cubic-bezier(.2,1.5,.4,1);
}
.results.show .res-panel { transform: none; }
.res-title { text-align: center; font-family: var(--display); font-size: clamp(40px, 7vmin, 66px); line-height: 1; color: var(--gold); text-shadow: 0 5px 0 var(--ink); transform: skewX(-8deg); }
.res-sub { text-align: center; font-weight: 900; font-size: 13px; letter-spacing: 2px; opacity: 0.8; margin-bottom: 4px; }
.res-table { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; min-height: 0; }
.res-row {
  display: grid; grid-template-columns: 70px 50px 1fr auto 110px; align-items: center; gap: 12px;
  padding: 4px 14px 4px 8px; border-radius: 14px; background: rgba(255,255,255,0.08);
  animation: rowIn 0.45s cubic-bezier(.2,1.4,.4,1) both; animation-delay: var(--d);
}
@keyframes rowIn { from { opacity: 0; transform: translateX(60px); } to { opacity: 1; transform: none; } }
.res-row.me { background: linear-gradient(90deg, rgba(255,210,63,0.95), rgba(255,138,31,0.92)); color: var(--ink); box-shadow: 0 0 20px rgba(255,190,50,0.5); }
.res-row.me .res-place { -webkit-text-stroke: 5px var(--ink); }
.res-place { font-family: var(--display); font-size: 36px; line-height: 1; text-align: center; -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; }
.res-place small { font-size: 0.45em; vertical-align: top; }
.res-portrait { width: 46px; height: 46px; border-radius: 12px; overflow: hidden; border: 3px solid #fff; background: var(--kc); display: flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 24px; }
.res-portrait img { width: 100%; height: 100%; object-fit: cover; }
.res-name { font-family: var(--display); font-size: 24px; }
.res-name em { font-style: normal; font-size: 12px; padding: 2px 7px; border-radius: 6px; background: var(--ink); color: var(--gold); vertical-align: middle; margin-left: 6px; }
.res-best { font-weight: 900; font-size: 12px; opacity: 0.75; font-variant-numeric: tabular-nums; }
.res-time { font-weight: 900; font-size: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.res-buttons { display: flex; justify-content: center; gap: 18px; margin-top: 12px; flex-wrap: wrap; }

/* ================================================================ responsive */
@media (max-width: 900px) {
  .select-screen { padding: 14px; overflow-y: auto; background: rgba(12,14,44,0.78); }
  .sel-body { flex-direction: column; }
  .sel-grid { width: 100%; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: auto; }
  .card { grid-template-columns: 1fr; text-align: center; }
  .card-portrait { grid-row: auto; margin: 0 auto 4px; width: 52px; height: 52px; }
  .card-stats { display: none; }
  .sel-side { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .preview { flex: 1 1 260px; }
  .opts { flex: 1 1 260px; }
  .controls-help { display: none; }
  .hud-standings { display: none; }
  .item-slot { width: 88px; height: 88px; border-radius: 22px; }
  .item-img { width: 64px; height: 64px; }
  .hud-lap .val { font-size: 44px; }
  .hud-timer { font-size: 22px; }
  .res-row { grid-template-columns: 54px 40px 1fr 90px; }
  .res-best { display: none; }
  .res-name { font-size: 18px; }
  .btn { min-width: 150px; font-size: 20px; }
}
@media (max-height: 640px) {
  .controls-help { display: none; }
  .pv-portrait { width: 84px; height: 84px; }
  .pv-name { font-size: 30px; }
  .card { padding: 5px; }
  .res-row { padding: 2px 10px 2px 6px; }
  .res-place { font-size: 28px; }
  .res-portrait { width: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .logo, .press-start, .btn.focus, .item-slot.filled { animation: none !important; }
}
