/* Revvy Racers - bright, toy-like UI */
:root {
  --red: #ff4f6d; --yellow: #ffd23f; --blue: #3a86ff; --green: #38d16a; --purple: #b15cff;
  --ink: #1d1b3a; --panel: rgba(255, 255, 255, 0.94);
  --font: "Trebuchet MS", "Arial Rounded MT Bold", "Nunito", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3a86ff; font-family: var(--font); color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#game, #hud, #touch { touch-action: none; }
.screen { touch-action: pan-y; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 900;
  color: #fff; background: linear-gradient(160deg, #3a86ff, #b15cff); z-index: 50; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20;
  background: radial-gradient(ellipse at center, rgba(20, 10, 60, 0.05), rgba(20, 10, 60, 0.45)); overflow-y: auto; }
#screen-pause { background: rgba(20, 10, 60, 0.55); }
.panel { background: var(--panel); border-radius: 28px; padding: 26px 30px; box-shadow: 0 10px 0 rgba(0, 0, 0, 0.18), 0 18px 40px rgba(0, 0, 0, 0.25);
  border: 5px solid #fff; max-width: 460px; width: 100%; text-align: center; margin: auto; }
.panel.wide { max-width: 980px; }
h1 { font-size: clamp(44px, 9vw, 84px); margin: 4px 0 6px; line-height: 0.95; letter-spacing: 1px; color: var(--yellow);
  text-shadow: 0 4px 0 #ff7b00, 0 8px 0 var(--red), 0 12px 18px rgba(0, 0, 0, 0.3); -webkit-text-stroke: 2px #ff7b00; transform: rotate(-3deg); }
h2 { font-size: 34px; margin: 0 0 14px; color: var(--blue); text-shadow: 0 3px 0 #bcd6ff; }
h3 { margin: 12px 0 6px; color: var(--red); }
.tagline { margin: 10px 0 18px; font-weight: 700; color: #5a5880; }
.hint { font-size: 13px; color: #7a7898; margin: 14px 0 0; }

/* ---------- title screen: the attract race fills the screen; no panel, just a big logo and chunky buttons ---------- */
#screen-title { background: radial-gradient(ellipse at center, rgba(20, 10, 60, 0) 35%, rgba(20, 10, 60, 0.4)); padding: 0; overflow: hidden; }
.title-wrap { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); text-align: center; }
.title-logo { display: flex; flex-direction: column; align-items: center; }
#title-name { font-size: clamp(64px, 13vw, 210px); margin: 0; line-height: 0.9; letter-spacing: 2px; -webkit-text-stroke: 4px #ff7b00;
  text-shadow: 0 6px 0 #ff7b00, 0 12px 0 var(--red), 0 18px 0 #a01d3a, 0 24px 30px rgba(0, 0, 0, 0.45); transform: rotate(-4deg); }
#title-name span { display: inline-block; }
#title-name span + span { color: #fff; -webkit-text-stroke-color: var(--blue); text-shadow: 0 6px 0 var(--blue), 0 12px 0 #1f5fcc, 0 18px 0 #143f8a, 0 24px 30px rgba(0, 0, 0, 0.45); }
.title-logo .tagline { margin: clamp(22px, 4vh, 44px) 0 0; font-size: clamp(17px, 2.4vw, 30px); font-weight: 900; color: #fff;
  text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink), 0 4px 0 var(--ink), 0 6px 14px rgba(0, 0, 0, 0.5); max-width: 22em; }
.title-menu { display: flex; flex-direction: column; align-items: center; gap: clamp(14px, 2.4vh, 26px); width: min(560px, 88vw); }
.title-menu button { width: 100%; border: 5px solid #fff; border-radius: 28px; padding: clamp(12px, 2vh, 22px) 24px; font-size: clamp(26px, 3.6vw, 44px);
  font-weight: 900; color: #fff; background: var(--blue); box-shadow: 0 9px 0 #1f5fcc, 0 16px 26px rgba(0, 0, 0, 0.35); letter-spacing: 1px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); transition: transform 0.08s; }
.title-menu button.big { font-size: clamp(38px, 6vw, 72px); background: var(--red); box-shadow: 0 10px 0 #c42848, 0 18px 30px rgba(0, 0, 0, 0.35); padding: clamp(14px, 2.6vh, 28px) 24px; }
.title-menu button:hover, .title-menu button:focus-visible { transform: translateY(-3px) scale(1.03); outline: none; filter: brightness(1.08); }
.title-menu button:active { transform: translateY(6px); box-shadow: 0 3px 0 #1f5fcc; }
.title-menu .hint { color: #fff; font-size: clamp(14px, 1.8vw, 20px); font-weight: 700; margin: 0;
  text-shadow: -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink), 1px 1px 0 var(--ink), 0 3px 8px rgba(0, 0, 0, 0.5); }
body.touch .title-menu .hint { display: none; }
/* wide screens: logo on the left, buttons on the right */
@media (min-aspect-ratio: 4/3) {
  .title-wrap { flex-direction: row; justify-content: space-evenly; gap: 4vw; padding-left: max(5vw, env(safe-area-inset-left)); padding-right: max(5vw, env(safe-area-inset-right)); }
  .title-logo { flex: 1 1 58%; }
  .title-menu { flex: 0 1 32%; width: auto; min-width: 280px; max-width: 520px; }
  #title-name { font-size: clamp(64px, 12.5vw, 250px); }
  #title-name span { display: block; }
}
/* portrait phones: two-line logo, buttons fill the width */
@media (max-aspect-ratio: 3/4) {
  #title-name { font-size: clamp(64px, 21vw, 180px); }
  #title-name span { display: block; }
  .title-menu { width: min(520px, 90vw); }
  .title-menu button.big { font-size: clamp(40px, 11vw, 72px); }
  .title-menu button { font-size: clamp(26px, 7vw, 44px); }
}
/* landscape phones: keep everything on one screen */
@media (max-height: 500px) and (min-aspect-ratio: 4/3) {
  #title-name { font-size: clamp(48px, 21vh, 120px); -webkit-text-stroke-width: 3px; }
  .title-logo .tagline { font-size: 16px; margin-top: 16px; }
  .title-menu { gap: 10px; }
  .title-menu button { font-size: 22px; padding: 8px 18px; border-width: 4px; border-radius: 20px; }
  .title-menu button.big { font-size: 34px; padding: 10px 18px; }
  .title-menu .hint { display: none; }
}
.menu { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.menu.row { flex-direction: row; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.menu button, .seg button { border: none; border-radius: 18px; padding: 12px 26px; font-size: 20px; font-weight: 900; color: #fff;
  background: var(--blue); box-shadow: 0 6px 0 #1f5fcc; min-width: 200px; transition: transform 0.08s; }
.menu button:hover, .menu button:focus-visible { transform: translateY(-2px) scale(1.03); outline: none; filter: brightness(1.08); }
.menu button:active { transform: translateY(4px); box-shadow: 0 2px 0 #1f5fcc; }
.menu button.big { background: var(--red); box-shadow: 0 6px 0 #c42848; font-size: 28px; padding: 14px 40px; }
.menu.row button { min-width: 150px; }

/* track select */
#track-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
@media (min-width: 860px) { #track-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; } }
.track-card { border: none; border-radius: 22px; padding: 12px; color: #fff; text-align: left; box-shadow: 0 7px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.1s; display: flex; flex-direction: column; gap: 4px; }
.track-card:hover, .track-card:focus-visible { transform: translateY(-4px) rotate(-1deg); outline: 4px solid #fff; }
.track-card canvas { width: 100%; height: auto; background: rgba(255, 255, 255, 0.2); border-radius: 14px; }
.track-name { font-size: 21px; font-weight: 900; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); margin-top: 4px; }
.track-theme { font-size: 13px; font-weight: 700; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.5px; }
.track-blurb { font-size: 14px; line-height: 1.3; }
.track-stars { font-size: 13px; font-weight: 700; margin-top: auto; color: #fff7c2; }
.theme-beach { background: linear-gradient(160deg, #2fb5ff, #ffb84d); }
.theme-toyroom { background: linear-gradient(160deg, #ff4f6d, #ffd23f); }
.theme-jungle { background: linear-gradient(160deg, #2f9e44, #9c8f63); }
.theme-space { background: linear-gradient(160deg, #24124f, #ff4fd8); }
.theme-golf { background: linear-gradient(160deg, #38b24d, #f3d99c); }

/* settings */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.setting-label { font-weight: 900; font-size: 18px; }
.seg { display: flex; gap: 6px; }
.seg button { min-width: 0; padding: 8px 14px; font-size: 15px; background: #c9d3ea; color: var(--ink); box-shadow: 0 4px 0 #9aa6c4; border-radius: 12px; }
.seg button.on { background: var(--green); color: #fff; box-shadow: 0 4px 0 #23964a; }

/* help */
.help { text-align: left; }
.help h2 { text-align: center; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.help ul { margin: 0; padding-left: 20px; line-height: 1.45; }
#item-list { list-style: none; padding: 0; }
#item-list li { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 14px; }
.mini-icon { width: 34px; height: 34px; flex: none; background: #eef2ff; border-radius: 10px; }
@media (max-width: 700px) { .help-cols { grid-template-columns: 1fr; } }

/* results */
#results { width: 100%; border-collapse: separate; border-spacing: 0 5px; font-size: 18px; }
#results th { font-size: 13px; text-transform: uppercase; color: #7a7898; }
#results td { background: #eef2ff; padding: 7px 10px; font-weight: 700; }
#results td:first-child { border-radius: 12px 0 0 12px; font-weight: 900; }
#results td:last-child { border-radius: 0 12px 12px 0; }
#results tr.me td { background: var(--yellow); }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 50%; margin-right: 8px; vertical-align: -2px; border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; font-weight: 900; color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
#hud-pos { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: 18px; font-size: 92px; line-height: 1; -webkit-text-stroke: 3px var(--ink); }
#hud-pos #pos-suf { font-size: 42px; vertical-align: top; margin-left: 2px; }
#hud-pos.p1 { color: var(--yellow); }
#hud-pos.p2 { color: #e6ecff; }
#hud-pos.p3 { color: #ffb36b; }
#hud-pos.p4 { color: #ffffff; }
#hud-lap { position: absolute; left: max(18px, env(safe-area-inset-left)); top: 14px; font-size: 34px; -webkit-text-stroke: 1.5px var(--ink); }
#hud-time { position: absolute; left: max(18px, env(safe-area-inset-left)); top: 54px; font-size: 22px; -webkit-text-stroke: 1px var(--ink); font-variant-numeric: tabular-nums; }
#hud-item { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: 92px; height: 92px; border-radius: 26px;
  background: rgba(255, 255, 255, 0.78); border: 5px solid #fff; box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2), inset 0 0 0 4px var(--blue); }
#hud-item.rolling { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2), inset 0 0 0 4px var(--yellow); }
#item-canvas { width: 82px; height: 82px; }
#item-count { position: absolute; right: -6px; bottom: -8px; font-size: 24px; color: var(--yellow); -webkit-text-stroke: 1px var(--ink); }
#item-name { position: absolute; left: 50%; top: 96px; transform: translateX(-50%); white-space: nowrap; font-size: 15px; }
/* item key prompt: a chunky keycap badge beside the item slot (keyboard) or a mini Item button (touch) */
#item-key { position: absolute; left: 100%; top: 50%; margin-left: 12px; transform: translateY(-50%); min-width: 40px; height: 40px;
  padding: 0 6px; border-radius: 10px; background: linear-gradient(#ffffff, #dfe3f0); color: var(--ink); font-size: 22px; line-height: 34px;
  text-align: center; border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink); -webkit-text-stroke: 0; opacity: 0.55; transition: opacity 0.15s; }
#hud-item.ready #item-key { opacity: 1; animation: keypulse 0.9s ease-in-out infinite; }
body.touch #item-key { font-size: 14px; border-radius: 50%; width: 46px; height: 46px; line-height: 40px; padding: 0;
  background: rgba(177, 92, 255, 0.85); color: #fff; border-color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); }
@keyframes keypulse { 0%, 100% { transform: translateY(-50%) scale(1); } 50% { transform: translateY(-58%) scale(1.08); } }
#zap-flash { position: absolute; inset: 0; background: radial-gradient(circle, rgba(255, 230, 255, 0) 40%, rgba(155, 92, 255, 0.55)); opacity: 0;
  transition: opacity 0.4s; pointer-events: none; }
#zap-flash.show { opacity: 1; transition: none; }
#minimap { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: 12px; width: 170px; height: 170px; opacity: 0.95; }
#hud-msg { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%) scale(0.6); font-size: 64px; opacity: 0;
  transition: opacity 0.15s, transform 0.15s; white-space: nowrap; -webkit-text-stroke: 3px var(--ink); color: #fff; }
#hud-msg.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#hud-msg.count { font-size: 140px; color: var(--yellow); }
#hud-msg.go { font-size: 120px; color: var(--green); }
#hud-msg.good { color: var(--yellow); }
#hud-msg.bad { color: var(--red); }
#btn-pause { position: absolute; right: max(14px, env(safe-area-inset-right)); top: 12px; width: 52px; height: 52px; border-radius: 16px;
  border: 4px solid #fff; background: rgba(29, 27, 58, 0.55); color: #fff; font-size: 18px; pointer-events: auto; }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
#touch button { pointer-events: auto; border: 4px solid rgba(255, 255, 255, 0.9); background: rgba(29, 27, 58, 0.35); color: #fff;
  font-weight: 900; border-radius: 50%; font-size: 18px; touch-action: none; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
#touch button.down { background: rgba(255, 210, 63, 0.75); transform: scale(0.95); }
.tc-left { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: 20px; display: flex; gap: 14px; }
.tc-left button { width: 92px; height: 92px; font-size: 34px !important; }
.tc-right { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: 16px; width: 230px; height: 220px; }
.tc-right button { position: absolute; width: 78px; height: 78px; }
.tc-accel { right: 0; bottom: 0; width: 96px !important; height: 96px !important; background: rgba(56, 209, 106, 0.55) !important; }
.tc-brake { right: 108px; bottom: 0; background: rgba(255, 79, 109, 0.45) !important; }
.tc-drift { right: 20px; bottom: 108px; background: rgba(58, 134, 255, 0.5) !important; }
.tc-item { right: 120px; bottom: 96px; background: rgba(177, 92, 255, 0.5) !important; }
#touch.auto-accel .tc-accel { display: none; }
#touch.auto-accel .tc-brake { right: 0; }
body.touch #minimap { display: none; }
body.touch #hud-pos { bottom: auto; top: 70px; font-size: 64px; }
body.touch #hud-pos #pos-suf { font-size: 30px; }

@media (max-width: 640px), (max-height: 480px) {
  #hud-pos { font-size: 64px; }
  #hud-pos #pos-suf { font-size: 30px; }
  #minimap { width: 120px; height: 120px; }
  #hud-msg { font-size: 44px; }
  #hud-msg.count, #hud-msg.go { font-size: 90px; }
  .panel { padding: 18px; }
}

@media (max-height: 500px) {
  h1 { font-size: 46px; }
  h2 { font-size: 24px; margin: 0 0 8px; }
  .panel { padding: 12px 16px; border-radius: 20px; }
  #track-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
  .track-card { padding: 8px; border-radius: 16px; }
  .track-card canvas { height: 64px; object-fit: contain; }
  .track-name { font-size: 16px; }
  .track-blurb { display: none; }
  .menu.row { margin-top: 10px; }
  .menu button { padding: 8px 18px; font-size: 17px; min-width: 150px; }
  .menu button.big { font-size: 22px; padding: 10px 26px; }
  #results { font-size: 14px; border-spacing: 0 3px; }
  #results td { padding: 3px 8px; }
  .tagline { margin: 4px 0 8px; }
}

/* character select */
#screen-character { align-items: flex-end; background: none; }
.char-panel { padding: 16px 22px; margin: auto auto 0; }
.char-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.char-head h2 { margin: 0 0 6px; font-size: 28px; }
.char-info { margin: 0 0 8px; font-weight: 700; color: #5a5880; text-align: right; flex: 1; min-width: 240px; }
#char-name { font-size: 24px; font-weight: 900; color: var(--red); }
#char-species { font-weight: 900; color: var(--ink); margin-right: 6px; }
#char-grid { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 8px; }
.char-btn { border: 4px solid #fff; border-radius: 18px; background: #eef2ff; padding: 4px 2px 6px; display: flex; flex-direction: column;
  align-items: center; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.15); transition: transform 0.08s; color: var(--ink); }
.char-btn canvas { width: 100%; max-width: 88px; aspect-ratio: 1; border-radius: 12px; }
.char-btn-name { font-weight: 900; font-size: 15px; margin-top: 3px; }
.char-btn-species { font-size: 11px; font-weight: 700; color: #7a7898; }
.char-btn:hover, .char-btn:focus-visible { transform: translateY(-3px); outline: none; }
.char-btn.selected { border-color: var(--kart, #3a86ff); background: #fff; transform: translateY(-4px) scale(1.04); box-shadow: 0 6px 0 var(--kart, #3a86ff); }
#results .species { font-size: 12px; color: #7a7898; margin-left: 6px; font-weight: 700; }
@media (max-width: 760px) { #char-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } .char-info { text-align: left; } }
@media (max-height: 500px) {
  .char-panel { padding: 8px 12px; }
  .char-head h2 { font-size: 20px; }
  .char-btn canvas { max-width: 42px; }
  .char-btn { padding: 2px 1px 3px; border-width: 3px; border-radius: 12px; }
  .char-btn-name { font-size: 12px; }
  .char-btn-species, #char-blurb { display: none; }
  .char-head h2 { font-size: 18px; margin: 0 0 4px; }
  #char-name { font-size: 18px; }
  .char-info { margin: 0 0 4px; }
}

/* ---------- v4: coins, stats, shop, race setup, chaos ---------- */
.coin-ico { display: inline-block; width: 0.95em; height: 0.95em; border-radius: 50%; vertical-align: -0.12em; margin-right: 0.3em;
  background: radial-gradient(circle at 35% 30%, #fff6c2 0 18%, #ffd23f 22% 62%, #e09a00 66%); box-shadow: inset 0 0 0 0.09em #b87400; }
.coin-badge { display: inline-flex; align-items: center; font-weight: 900; font-size: 22px; color: var(--ink); background: #fff7d6;
  border-radius: 999px; padding: 6px 16px; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15); white-space: nowrap; }
.title-coins { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); font-size: clamp(20px, 2.6vw, 32px); z-index: 2; }
#hud-coins { position: absolute; left: max(18px, env(safe-area-inset-left)); top: 84px; font-size: 24px; -webkit-text-stroke: 1px var(--ink); color: #ffe066; }
#hud-banner { position: absolute; left: 50%; top: 118px; transform: translate(-50%, -20px) scale(0.8); padding: 10px 28px; border-radius: 999px;
  background: linear-gradient(90deg, #ff4f6d, #b15cff, #3ad7ff); color: #fff; font-size: 34px; border: 4px solid #fff; opacity: 0;
  transition: opacity 0.2s, transform 0.2s; white-space: nowrap; box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2); }
#hud-banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* stats bars */
.stat-bars { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px 12px; }
.stat-row { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.stat-label { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.4px; color: #5a5880; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-bar { display: flex; gap: 3px; }
.stat-bar .pip { flex: 1; height: 12px; border-radius: 4px; background: #dfe5f5; }
.stat-0 .pip.on { background: #ff4f6d; } .stat-1 .pip.on { background: #ff9f1c; } .stat-2 .pip.on { background: #38d16a; }
.stat-3 .pip.on { background: #3a86ff; } .stat-4 .pip.on { background: #b15cff; }
.stat-bars.small .pip { height: 9px; }
.stat-bars.small .stat-label { font-size: 10px; }
.char-mid { display: flex; align-items: center; gap: 16px; margin: 0 0 10px; }
.char-mid .stat-bars { flex: 1; }
#char-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.char-btn { position: relative; }
.char-lock { display: none; position: absolute; inset: 0; border-radius: 14px; background: rgba(29, 27, 58, 0.45); flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; color: #fff; font-weight: 900; font-size: 15px; }
.char-btn.locked .char-lock { display: flex; }
.char-btn.locked canvas { filter: saturate(0.4); }
.padlock { position: relative; width: 22px; height: 16px; margin-top: 10px; background: #ffd23f; border-radius: 4px; box-shadow: 0 2px 0 #b87400; }
.padlock::before { content: ''; position: absolute; left: 4px; top: -11px; width: 10px; height: 10px; border: 3px solid #ffd23f; border-bottom: none; border-radius: 9px 9px 0 0; }
.char-price::before { content: ''; display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; background: #ffd23f; margin-right: 3px; vertical-align: -0.05em; }
#btn-char-next.locked { background: #ff9f1c; box-shadow: 0 6px 0 #c47400; }
#btn-char-next:disabled { background: #9aa0b8; box-shadow: 0 6px 0 #6c7290; cursor: default; transform: none; }

/* race setup: difficulty */
.setup-panel { max-height: calc(100vh - 24px); overflow-y: auto; }
.setup-sub { margin: 10px 0 8px; color: var(--blue); }
.diff-wrap { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.diff-row { display: flex; gap: 10px; flex-wrap: wrap; }
.diff-btn { border: 4px solid #fff; border-radius: 18px; padding: 8px 18px; color: #fff; font-weight: 900; display: flex; flex-direction: column;
  align-items: center; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18); opacity: 0.7; transition: transform 0.08s; }
.diff-btn .diff-name { font-size: 24px; }
.diff-btn .diff-pay { font-size: 12px; opacity: 0.95; }
.diff-btn.on { opacity: 1; transform: translateY(-3px) scale(1.06); outline: 4px solid var(--ink); }
.diff-btn:hover, .diff-btn:focus-visible { opacity: 1; outline: 4px solid #fff7c2; }
.diff-chill { background: #38d16a; } .diff-risky { background: #3a86ff; } .diff-mad { background: #ff7b00; }
.diff-chaos { background: linear-gradient(135deg, #ff4f6d, #b15cff, #3ad7ff); }
.diff-blurb { margin: 0; font-weight: 700; color: #5a5880; flex: 1; min-width: 200px; }
#track-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
@media (min-width: 860px) { #track-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; } }
.track-card canvas { max-height: 90px; object-fit: contain; }
.track-name { font-size: 18px; }
.track-blurb { font-size: 12px; }
.theme-candy { background: linear-gradient(160deg, #ff6fb5, #ffd1a3); }
.theme-frost { background: linear-gradient(160deg, #3a86ff, #bfe9ff); }
.theme-reef { background: linear-gradient(160deg, #0fa3b1, #ffcf6e); }
.theme-neon { background: linear-gradient(160deg, #2a1660, #ff2fb0); }
.theme-spooky { background: linear-gradient(160deg, #3b1d5e, #ff8c1a); }
.theme-volcano { background: linear-gradient(160deg, #c2240f, #ffb703); }
.theme-sky { background: linear-gradient(160deg, #5aa8ff, #ff9fd8); }
.theme-desert { background: linear-gradient(160deg, #d9822b, #f5c96a); }
.theme-kitchen { background: linear-gradient(160deg, #e2463a, #4ac0b8); }
.theme-factory { background: linear-gradient(160deg, #3c4a5e, #f2a91b); }

/* shop */
.shop-panel { max-height: calc(100vh - 24px); overflow-y: auto; }
.shop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.shop-head h2 { margin: 0; }
.shop-hint { margin: 6px 0 12px; }
#shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.shop-card { display: grid; grid-template-columns: 96px 1fr; grid-template-rows: 1fr auto; gap: 8px 12px; background: #eef2ff; border-radius: 20px;
  padding: 10px; border: 4px solid #fff; box-shadow: 0 5px 0 var(--kart, #3a86ff); }
.shop-card canvas { width: 96px; height: 96px; border-radius: 14px; grid-row: span 2; }
.shop-name { font-weight: 900; font-size: 18px; color: var(--ink); }
.shop-blurb { font-size: 13px; color: #5a5880; margin: 2px 0 6px; }
.shop-card .stat-bars { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px 6px; }
.shop-buy { grid-column: 2; border: none; border-radius: 14px; padding: 9px 14px; font-size: 17px; font-weight: 900; color: #fff; background: var(--green);
  box-shadow: 0 4px 0 #23964a; }
.shop-buy:disabled { background: #9aa0b8; box-shadow: 0 4px 0 #6c7290; cursor: default; }
.shop-card.owned .shop-buy { background: #3a86ff; box-shadow: 0 4px 0 #1f5fcc; }

/* results coins */
.results-coins { margin: -6px 0 10px; }
.rc-total { font-size: 28px; font-weight: 900; color: #c47400; }
.rc-detail { font-size: 14px; font-weight: 700; color: #5a5880; }

@media (max-width: 760px) {
  #char-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .stat-label { font-size: 10px; }
  .char-mid { gap: 8px; }
  .char-mid .coin-badge { font-size: 16px; padding: 4px 10px; }
  .diff-btn { padding: 6px 12px; } .diff-btn .diff-name { font-size: 19px; }
  #hud-banner { font-size: 22px; top: 150px; }
}
@media (max-height: 500px) {
  .char-mid { margin: 0 0 4px; }
  .stat-bar .pip { height: 7px; }
  .stat-label { font-size: 9px; }
  #char-grid { grid-template-columns: repeat(15, minmax(0, 1fr)); gap: 4px; }
  .char-lock { font-size: 11px; } .padlock { transform: scale(0.7); margin-top: 4px; }
  .diff-btn { padding: 4px 10px; } .diff-btn .diff-name { font-size: 16px; } .diff-btn .diff-pay { display: none; }
  .diff-blurb { font-size: 12px; }
  .setup-sub { margin: 4px 0; font-size: 15px; }
  #track-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
  .track-card canvas { height: 44px; }
  .track-name { font-size: 13px; } .track-theme, .track-stars { font-size: 10px; }
  #hud-coins { top: 74px; font-size: 18px; }
  #hud-banner { top: 70px; font-size: 20px; }
}
@media (max-aspect-ratio: 3/4) {
  .char-panel { width: 100%; }
  .stat-bars { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px 6px; }
}
body.touch #hud-coins { top: 84px; }

/* ---------- v5: title modes, Grand Prix, Time Trial, Coin Rush, Garage, Stickers ---------- */
.title-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(10px, 1.8vh, 18px); width: 100%; }
.title-menu .title-grid button { font-size: clamp(19px, 2.3vw, 30px); padding: clamp(9px, 1.5vh, 16px) 12px; border-radius: 22px; border-width: 4px; }
.title-menu button.mode-gp { background: #ffb000; box-shadow: 0 8px 0 #c47f00, 0 14px 22px rgba(0, 0, 0, 0.3); }
.title-menu button.mode-tt { background: #22c3e6; box-shadow: 0 8px 0 #1488a3, 0 14px 22px rgba(0, 0, 0, 0.3); }
.title-menu button.mode-rush { background: #38d16a; box-shadow: 0 8px 0 #22924a, 0 14px 22px rgba(0, 0, 0, 0.3); }
.title-menu button.mode-garage { background: #b15cff; box-shadow: 0 8px 0 #7a32c4, 0 14px 22px rgba(0, 0, 0, 0.3); }
.title-menu button.mode-stickers { background: #ff5cc8; box-shadow: 0 8px 0 #c42f93, 0 14px 22px rgba(0, 0, 0, 0.3); }
.title-menu button.small { font-size: clamp(16px, 1.8vw, 22px); padding: 6px 18px; width: auto; border-width: 3px; border-radius: 999px; background: #1d1b3a; box-shadow: 0 5px 0 #000; }
.title-daily { position: absolute; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); z-index: 2; border: 4px solid #fff;
  border-radius: 999px; background: #ff9f1c; color: #fff; font-weight: 900; font-size: clamp(15px, 1.7vw, 21px); padding: 6px 16px 6px 10px;
  box-shadow: 0 5px 0 #c46a00, 0 8px 16px rgba(0, 0, 0, 0.3); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); display: inline-flex; align-items: center; gap: 8px; }
.td-sun { width: 1.3em; height: 1.3em; border-radius: 50%; background: radial-gradient(circle, #fff6b0 0 35%, #ffd23f 40% 60%, transparent 62%),
  repeating-conic-gradient(#ffd23f 0 12deg, transparent 12deg 30deg); }
@media (max-height: 500px) and (min-aspect-ratio: 4/3) {
  .title-menu .title-grid button { font-size: 17px; padding: 5px 8px; border-width: 3px; border-radius: 16px; }
  .title-grid { gap: 8px; }
  .title-menu button.small { font-size: 14px; padding: 4px 12px; }
  .title-menu .hint { display: none; }
}
@media (max-aspect-ratio: 3/4) { .title-menu .title-grid button { font-size: clamp(18px, 5vw, 30px); } }

/* setup hints */
#setup-hint { margin: -6px 0 10px; font-size: 15px; font-weight: 700; color: #22924a; }
.setup-panel > .hint { font-size: 15px; font-weight: 700; margin: -4px 0 12px; color: #5a5880; }

/* Grand Prix cups */
#cup-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
@media (max-width: 760px) { #cup-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cup-card { border: 4px solid #fff; border-radius: 22px; padding: 12px 10px; background: var(--cup, #3a86ff); color: #fff; text-align: left;
  box-shadow: 0 7px 0 rgba(0, 0, 0, 0.2); transition: transform 0.08s; display: flex; flex-direction: column; gap: 6px; position: relative; }
.cup-card:hover:not(:disabled), .cup-card:focus-visible { transform: translateY(-4px) rotate(-1deg); outline: 4px solid #fff; }
.cup-card.locked { filter: grayscale(0.85) brightness(0.9); cursor: not-allowed; }
.cup-name { font-size: 22px; font-weight: 900; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.cup-tracks { margin: 0; padding-left: 20px; font-weight: 800; font-size: 14px; line-height: 1.35; }
.cup-trophies { display: flex; gap: 3px; justify-content: space-between; background: rgba(255, 255, 255, 0.92); border-radius: 14px; padding: 4px; }
.cup-t { display: flex; flex-direction: column; align-items: center; font-size: 10px; font-weight: 900; color: #7a7898; flex: 1; }
.cup-t.got { color: var(--ink); }
.cup-t canvas { width: 34px; height: 34px; }
.cup-t:not(.got) canvas { opacity: 0.35; }
.cup-lock { font-size: 12px; font-weight: 900; background: rgba(0, 0, 0, 0.35); border-radius: 10px; padding: 4px 6px; }

/* standings + trophy */
#standings { width: 100%; border-collapse: separate; border-spacing: 0 4px; font-size: 17px; }
#standings th { font-size: 13px; text-transform: uppercase; color: #7a7898; }
#standings td { background: #eef2ff; padding: 6px 10px; font-weight: 700; }
#standings td:first-child { border-radius: 12px 0 0 12px; font-weight: 900; }
#standings td:last-child { border-radius: 0 12px 12px 0; font-weight: 900; color: var(--blue); font-size: 20px; }
#standings tr.me td { background: var(--yellow); }
#standings .species { font-size: 12px; color: #7a7898; margin-left: 6px; font-weight: 700; }
#standings .swatch, .podium .swatch, #rush-board .swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; border: 2px solid #fff; }
#screen-standings .panel { max-height: calc(100vh - 32px); overflow-y: auto; }
.trophy-panel { max-width: 520px; }
#trophy-canvas { width: min(180px, 26vh); height: min(180px, 26vh); display: block; margin: -10px auto 0; }
#screen-trophy .panel { max-height: calc(100vh - 32px); overflow-y: auto; padding-top: 16px; padding-bottom: 16px; }
#trophy-title { font-size: 36px; color: var(--red); margin: 0 0 4px; }
.podium { list-style: none; padding: 0; margin: 6px auto 10px; display: flex; flex-direction: column; gap: 5px; max-width: 380px; }
.podium li { display: flex; align-items: center; gap: 6px; background: #eef2ff; border-radius: 12px; padding: 6px 12px; font-weight: 800; }
.podium li.me { background: var(--yellow); }
.pod-place { font-weight: 900; width: 2.6em; text-align: left; }
.pod-name { flex: 1; text-align: left; }
.pts { font-weight: 900; color: var(--blue); }

/* results extras: medals, dailies, stickers */
.results-extra { margin: 0 0 10px; font-weight: 800; color: #5a5880; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.rx-line { background: #eef8ff; border-radius: 999px; padding: 4px 14px; }
.rx-stickers { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-top: 4px; }
.rx-label { font-weight: 900; color: #ff5cc8; font-size: 18px; }
.rx-sticker { display: flex; flex-direction: column; align-items: center; font-size: 12px; font-weight: 900; color: var(--ink); animation: pop 0.5s ease-out; }
.rx-sticker canvas { width: 56px; height: 56px; }
@keyframes pop { 0% { transform: scale(0.2) rotate(-30deg); } 70% { transform: scale(1.15) rotate(6deg); } 100% { transform: scale(1); } }

/* Time Trial */
.tt-opts { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 10px; }
#tt-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 860px) { #tt-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px) { #tt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tt-card { position: relative; padding: 10px; }
.tt-card canvas { max-height: 70px; }
.tt-card canvas.tt-medal { position: absolute; top: 4px; right: 4px; width: 40px; height: 40px; background: none; }
.tt-best { font-weight: 900; font-size: 15px; }
.tt-targets { font-size: 11px; font-weight: 800; opacity: 0.92; }
.tt-has-ghost { font-size: 11px; font-weight: 900; background: rgba(255, 255, 255, 0.3); border-radius: 8px; padding: 1px 6px; display: inline-block; margin-top: 3px; }

/* Garage */
#screen-garage { align-items: flex-end; background: none; }
.garage-head { align-items: center; }
.garage-racer { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 20px; color: var(--red); flex: 1; justify-content: center; }
.garage-racer button, .seg button.small { border: 3px solid #fff; border-radius: 999px; background: var(--blue); color: #fff; font-weight: 900; padding: 4px 12px; box-shadow: 0 3px 0 #1f5fcc; }
.garage-opts { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 6px 0 10px; }
#garage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; max-height: 32vh; overflow-y: auto; padding: 4px; }
.gar-card { background: #eef2ff; border-radius: 16px; padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 3px; border: 3px solid transparent; cursor: pointer; }
.gar-card canvas { width: 84px; height: 63px; }
.gar-card.on { border-color: var(--green); background: #e6fff0; }
.gar-name { font-size: 13px; font-weight: 900; text-align: center; line-height: 1.1; min-height: 2.2em; display: flex; align-items: center; }
.gar-btn { border: none; border-radius: 999px; padding: 4px 10px; font-weight: 900; font-size: 13px; color: #fff; background: var(--red); box-shadow: 0 3px 0 #c42848; width: 100%; }
.gar-card.owned .gar-btn { background: var(--blue); box-shadow: 0 3px 0 #1f5fcc; }
.gar-card.on .gar-btn { background: var(--green); box-shadow: 0 3px 0 #22924a; }
.gar-btn:disabled { opacity: 0.75; cursor: default; }
.gar-card:not(.owned) .gar-btn:disabled { background: #a7a5bf; box-shadow: 0 3px 0 #7a7898; }
@media (max-height: 500px) { #garage-grid { max-height: 28vh; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); } .gar-card canvas { width: 60px; height: 45px; } .garage-opts { margin: 2px 0 4px; } }

/* Sticker book + dailies */
.stickers-panel { max-height: calc(100vh - 32px); overflow-y: auto; }
.sticker-count { font-size: 22px; font-weight: 900; color: #ff5cc8; }
#sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.stk { background: #f5f3ff; border-radius: 16px; padding: 6px; display: flex; flex-direction: column; align-items: center; }
.stk canvas { width: 72px; height: 72px; }
.stk-name { font-weight: 900; font-size: 13px; }
.stk-how { font-size: 11px; font-weight: 700; color: #7a7898; text-align: center; line-height: 1.15; }
.stk:not(.got) .stk-name { color: #a7a5bf; }
.daily-list { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 6px; }
.daily-list li { display: grid; grid-template-columns: 1fr 120px 64px 50px; align-items: center; gap: 10px; background: #fff4e0; border-radius: 14px; padding: 8px 12px; font-weight: 800; text-align: left; }
.daily-list li.done { background: #e6fff0; }
.dl-bar { height: 12px; background: #fff; border-radius: 999px; overflow: hidden; box-shadow: inset 0 0 0 2px #ffd9a0; }
.dl-fill { display: block; height: 100%; background: linear-gradient(90deg, #ff9f1c, #ffd23f); border-radius: 999px; }
.daily-list li.done .dl-fill { background: var(--green); }
.dl-prog { font-size: 13px; color: #5a5880; }
.dl-reward { font-weight: 900; color: #c47f00; }
@media (max-width: 560px) { .daily-list li { grid-template-columns: 1fr 52px 40px; } .dl-bar { grid-column: 1 / -1; grid-row: 2; } }

/* HUD: Coin Rush timer + leaderboard, Time Trial targets */
#hud.mode-rush #hud-lap, #hud.mode-tt #hud-pos, #hud.mode-tt #hud-coins { display: none; }
#hud-rush { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(84px, calc(env(safe-area-inset-right) + 70px)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none; }
#rush-timer { font-size: 44px; font-weight: 900; color: #fff; -webkit-text-stroke: 2px var(--ink); text-shadow: 0 4px 0 var(--ink); background: #38d16a; border: 4px solid #fff; border-radius: 999px; padding: 0 22px; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25); }
#rush-timer.low { background: var(--red); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
#rush-board { list-style: none; margin: 0; padding: 4px 8px; background: rgba(29, 27, 58, 0.55); border-radius: 14px; min-width: 190px; }
#rush-board li { display: flex; align-items: center; color: #fff; font-weight: 900; font-size: 15px; padding: 1px 2px; }
#rush-board li.me { color: var(--yellow); }
.rb-pos { width: 1.4em; } .rb-name { flex: 1; } .rb-coins { min-width: 2.2em; text-align: right; }
#hud-tt { position: absolute; top: 88px; left: max(18px, env(safe-area-inset-left)); color: #fff; font-weight: 900; font-size: 15px;
  text-shadow: -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink), 1px 1px 0 var(--ink); display: flex; flex-direction: column; gap: 2px; }
@media (max-width: 640px), (max-height: 480px) { #rush-timer { font-size: 30px; padding: 0 14px; } #rush-board li { font-size: 12px; } #rush-board { min-width: 150px; } }
body.touch #hud.mode-rush #hud-pos { display: none; }
#screen-results .panel { max-height: calc(100vh - 32px); overflow-y: auto; padding-bottom: 0; }
#screen-results .menu.row { position: sticky; bottom: 0; background: linear-gradient(rgba(255, 255, 255, 0), #fff 30%); padding: 14px 0 16px; margin-top: 4px; }
