:root {
  --ink: #e9f1ff;
  --muted: #9fb0cc;
  --panel: rgba(9, 13, 24, 0.82);
  --line: rgba(134, 217, 255, 0.28);
  --cy: #86d9ff;
  --pink: #ff7ab6;
  --good: #6dffa6;
  --bad: #ff5d7c;
  --gold: #ffe28a;
  --head: "Orbitron", "Segoe UI", system-ui, sans-serif;
  --body: "Exo 2", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #04060c; color: var(--ink); font-family: var(--body); overflow: hidden; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.ui, .touch, .pausebtn { z-index: 2; }
body.playing #cv { cursor: none; }

/* ---------- overlay screens */
.ui { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; 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)); overflow-y: auto; background: radial-gradient(ellipse at center, rgba(4,6,12,0.25), rgba(4,6,12,0.7)); }
.ui[hidden] { display: none; }
.panel { width: min(560px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px 28px; box-shadow: 0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); animation: rise 0.35s ease-out; }
.panel.wide { width: min(860px, 100%); }
.panel.small { width: min(420px, 100%); text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.kicker { font: 700 12px/1.2 var(--head); letter-spacing: 0.18em; color: var(--cy); margin-bottom: 6px; }
.kicker.good { color: var(--good); } .kicker.bad { color: var(--bad); }
h1, h2, h3 { font-family: var(--head); margin: 0 0 12px; letter-spacing: 0.04em; }
h2 { font-size: clamp(22px, 4vw, 30px); }
h2.big { font-size: clamp(34px, 7vw, 52px); color: var(--gold); }
h3 { font-size: 14px; color: var(--cy); margin-top: 16px; }
p { line-height: 1.5; margin: 0 0 10px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.good { color: var(--good); } .cy { color: var(--cy); }

/* title */
.title { text-align: center; width: min(500px, 100%); }
.logo { font-size: clamp(40px, 9vw, 68px); line-height: 0.95; margin: 4px 0 12px; font-weight: 900; display: flex; flex-direction: column; align-items: center; }
.logo span { background: linear-gradient(180deg, #ffffff, #9fdcff 60%, #4aa8ff); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 0 18px rgba(80,180,255,0.45)); }
.logo .b { background: linear-gradient(180deg, #ffe0ef, #ff8fc4 60%, #ff4f9a); -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 0 18px rgba(255,90,160,0.45)); letter-spacing: 0.12em; }
.tag { color: var(--muted); margin-bottom: 18px; }
.note { color: var(--muted); font-size: 13px; margin-top: 8px; }
.hint-rotate { display: none; color: var(--gold); font-size: 13px; }
@media (orientation: portrait) and (pointer: coarse) { .hint-rotate { display: block; } }

/* buttons */
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.menu.row button { flex: 1 1 160px; }
.menu.grid2 { display: grid; grid-template-columns: 1fr 1fr; }
button { font: 600 16px var(--body); color: var(--ink); background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.14); border-radius: 12px; padding: 12px 16px; cursor: pointer; transition: transform 0.08s, background 0.15s, border-color 0.15s; min-height: 46px; }
button:hover:not([disabled]) { background: rgba(134,217,255,0.12); border-color: rgba(134,217,255,0.5); }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button:active:not([disabled]) { transform: scale(0.98); }
button.primary { background: linear-gradient(180deg, #4cc3ff, #1f7fd6); border-color: #7fd6ff; color: #fff; font-weight: 700; box-shadow: 0 6px 22px rgba(40,150,255,0.35); }
button.primary:hover { background: linear-gradient(180deg, #6fd0ff, #2b8fe6); }
button.danger { border-color: rgba(255,93,124,0.5); color: #ffb3c2; }
button[disabled] { opacity: 0.4; cursor: not-allowed; }



/* tables */
.scores { width: 100%; border-collapse: collapse; font-size: 15px; margin-bottom: 10px; }
.scores th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px; }
.scores td { padding: 7px 4px; border-top: 1px solid rgba(255,255,255,0.07); }
.scores td:nth-child(3) { font-family: var(--head); color: var(--gold); }
.scores tr.me td { background: rgba(255,226,138,0.12); }

/* name entry */


/* how-to */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 22px; }
.cols p { font-size: 14px; }
kbd { display: inline-block; min-width: 24px; padding: 1px 6px; margin: 0 2px 2px 0; font: 700 12px var(--head); color: var(--ink); background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.2); border-bottom-width: 3px; border-radius: 6px; text-align: center; }

/* settings */
.slider { display: flex; align-items: center; gap: 12px; margin: 6px 0 10px; }
.slider input { flex: 1; accent-color: var(--cy); }

/* ---------- touch controls */

/* link to the web guide on the How to play screen */
.guidelink { text-align: center; margin: 14px 0 0; font-size: 15px; }
.guidelink a { color: #86d9ff; }

/* online high scores */
.tabs { display: flex; gap: 6px; margin: 4px 0 12px; }
.tabs button { flex: 1; padding: 9px 8px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--ink); font: 700 13px var(--head); letter-spacing: 0.06em; cursor: pointer; }
.tabs button.sel { border-color: var(--cy); color: var(--cy); background: rgba(80,220,255,0.1); }
.scores tr.gap td { text-align: center; color: var(--muted); border-top: 0; padding: 2px; }
.pilotbox { margin: 12px 0 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,0.25); text-align: left; }
.pilotbox p { margin: 0 0 6px; }
.pilotbox .code { font-family: var(--head); letter-spacing: 0.08em; color: var(--gold); }
.pilotbox .row { display: flex; gap: 8px; margin-top: 8px; }
.pilotbox input { flex: 1; min-width: 0; font: 600 14px var(--head); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); background: rgba(0,0,0,0.35); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; -webkit-user-select: text; user-select: text; }
.pilotbox button[type="submit"] { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--cy); background: rgba(80,220,255,0.12); color: var(--cy); font: 700 13px var(--head); cursor: pointer; }
.linkish { border: 0; background: none; padding: 0 2px; color: var(--cy); font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.online { margin: 12px 0; }
.online .ranks { font-weight: 700; margin: 0 0 4px; }
.online .ranks b { color: var(--gold); font-family: var(--head); }
.newbest { color: var(--gold); font-weight: 700; margin: 8px 0 0; }
.pname { margin: 10px 0 2px; text-align: left; }
.pname label { display: block; font-weight: 700; font-size: 13px; color: var(--gold); margin-bottom: 6px; }
.pname .row { display: flex; gap: 8px; }
.pname input { flex: 1; min-width: 0; font: 700 15px var(--head); letter-spacing: 0.04em; color: var(--ink); background: rgba(0,0,0,0.35); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; -webkit-user-select: text; user-select: text; }
.pname input:focus { outline: 2px solid var(--gold); }
.pname button[type="submit"] { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--gold); background: rgba(255,226,138,0.12); color: var(--gold); font: 700 13px var(--head); cursor: pointer; }
.nmsg { min-height: 16px; margin: 6px 0 0; }
.nmsg.bad { color: var(--bad); } .nmsg.good { color: var(--good); }

/* ---------- Crater Racer */
:root { --head: "Bungee", "Nunito", system-ui, sans-serif; --body: "Nunito", "Segoe UI", system-ui, sans-serif; --cy: #8fdcff; --gold: #ffd23f; --line: rgba(255, 210, 63, 0.3); --panel: rgba(14, 20, 48, 0.88); }
html, body { background: #3f9cff; }
h2 { font-family: var(--head); font-weight: 400; letter-spacing: 0.02em; font-size: clamp(22px, 4.4vw, 32px); }
h2.big { color: var(--gold); }
h3 { font-family: var(--body); font-weight: 900; }
.kicker { font-family: var(--body); font-weight: 900; }
button { font-weight: 800; }
button small { opacity: 0.75; font-weight: 700; font-size: 12px; margin-left: 4px; }
button.primary { background: linear-gradient(180deg, #ff8a3d, #e5491c); border-color: #ffc08a; color: #fff; box-shadow: 0 6px 22px rgba(240, 90, 30, 0.35); }
button.primary:hover { background: linear-gradient(180deg, #ff9d57, #ef5a2a); }
.ui { background: radial-gradient(ellipse at center, rgba(6, 14, 34, 0.15), rgba(4, 10, 26, 0.6)); }
.bad { color: var(--bad); } .gold { color: var(--gold); }
.title { width: min(520px, 100%); }
.logo { font-family: var(--head); font-weight: 400; font-size: clamp(42px, 10vw, 74px); line-height: 0.95; margin: 0 0 4px; letter-spacing: 0.02em; }
.logo span { background: linear-gradient(180deg, #fff, #ffe27a 55%, #ff9d2e); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 #b23a12) drop-shadow(0 0 16px rgba(255, 160, 40, 0.4)); }
.logo .b { background: linear-gradient(180deg, #fff, #8fe3ff 55%, #2d8cff); -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 4px 0 #13408a) drop-shadow(0 0 16px rgba(60, 160, 255, 0.4)); letter-spacing: 0.08em; }
.worktitle { font-size: 11px; color: var(--muted); margin: 0 0 8px; letter-spacing: 0.1em; text-transform: uppercase; }
.how-list { margin: 0; padding: 0; list-style: none; }
.how-list li { font-size: 14px; line-height: 1.45; margin: 0 0 8px; padding-left: 26px; position: relative; }
.how-list li i { position: absolute; left: 0; top: 0; font-style: normal; }
.instore { text-align: left; margin: 14px auto 0; max-width: 520px; font-size: 13px; color: var(--muted); }
.instore > b { display: block; text-align: center; color: var(--gold); font-size: 13px; margin-bottom: 4px; }
.store { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 2px 14px; }
.store li { font-size: 13px; line-height: 1.35; padding-left: 24px; position: relative; }
.store li i { position: absolute; left: 0; top: 0; font-style: normal; }
.store li b { color: #fff; }
.store li em { font-style: normal; color: var(--gold); font-weight: 800; white-space: nowrap; }
@media (max-height: 560px) { .instore { display: none; } .logo { font-size: 40px; } .tag { font-size: 13px; margin-bottom: 6px; } }

/* setup: racers, speed, tracks */
.racers { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin: 6px 0 12px; }
.racer { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; border-radius: 14px; border: 2px solid rgba(255,255,255,0.12); background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(0,0,0,0.2)); position: relative; overflow: hidden; }
.racer::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--kc); }
.racer .em { font-size: 34px; line-height: 1.1; }
.racer small { margin: 0; color: var(--muted); }
.racer.sel { border-color: var(--gold); background: linear-gradient(180deg, rgba(255,210,63,0.2), rgba(0,0,0,0.2)); box-shadow: 0 0 0 3px rgba(255,210,63,0.25); }
.diffs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-bottom: 4px; }
.diffs span { color: var(--muted); font-weight: 800; margin-right: 4px; }
.diffs button { min-height: 40px; padding: 8px 16px; border-radius: 999px; }
.diffs button.sel { border-color: var(--gold); background: rgba(255,210,63,0.18); color: var(--gold); }
.tracks { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin: 8px 0 6px; }
.trackcard { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 3px; padding: 14px; border-radius: 14px; min-height: 120px; }
.trackcard .em { font-size: 28px; }
.trackcard small { margin: 0; color: var(--ink); opacity: 0.8; font-weight: 600; }
.trackcard em { font-style: normal; color: var(--gold); font-size: 13px; margin-top: auto; }
.t-meadow { background: linear-gradient(160deg, rgba(98,184,78,0.45), rgba(20,40,30,0.6)); }
.t-shores { background: linear-gradient(160deg, rgba(34,178,214,0.45), rgba(243,216,156,0.25)); }
.t-frosty { background: linear-gradient(160deg, rgba(200,225,255,0.4), rgba(40,60,100,0.6)); }
.t-crater { background: linear-gradient(160deg, rgba(60,60,140,0.6), rgba(10,10,30,0.7)); }
.t-mesa { background: linear-gradient(160deg, rgba(207,133,80,0.55), rgba(60,30,20,0.65)); }
.t-city { background: linear-gradient(160deg, rgba(120,60,200,0.5), rgba(10,10,40,0.75)); }

/* results */
.results-panel { text-align: center; }
.results-panel .scores { text-align: left; }
.results td:nth-child(3) { font-family: var(--body); color: var(--ink); font-weight: 700; }
.results td:nth-child(4) { color: var(--gold); font-weight: 800; }
.scores td:nth-child(3) { font-family: var(--body); font-weight: 800; }
.cols2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 22px; text-align: left; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 8px; margin: 6px 0 10px; }
.pod { width: 96px; display: flex; flex-direction: column; align-items: center; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.14); border-radius: 12px 12px 4px 4px; padding: 8px 4px 0; }
.pod .em { font-size: 30px; } .pod small { color: var(--muted); }
.pod i { font-style: normal; font-family: var(--head); font-size: 22px; color: var(--gold); width: 100%; text-align: center; background: rgba(255,210,63,0.15); margin-top: 6px; border-radius: 0 0 4px 4px; }
.pod.p1 { order: 2; } .pod.p1 i { padding: 22px 0 10px; } .pod.p2 { order: 1; } .pod.p2 i { padding: 12px 0 6px; } .pod.p3 { order: 3; } .pod.p3 i { padding: 4px 0 2px; }
.pod.me { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255,210,63,0.35); }

/* the in-race display */
.hud { position: absolute; inset: 0; z-index: 2; pointer-events: none; font-family: var(--head); color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,0.45), 0 0 12px rgba(0,0,0,0.35); }
.hud[hidden] { display: none; }
.hud-l { position: absolute; left: max(14px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); }
.pos { font-size: clamp(40px, 7vw, 64px); line-height: 1; color: var(--gold); }
.pos[data-p="1"] { color: #ffe14d; } .pos[data-p="5"], .pos[data-p="6"] { color: #ff9b9b; }
.lap { font-size: clamp(16px, 2.6vw, 22px); margin-top: 4px; }
.flagc { font-size: clamp(18px, 3vw, 26px); margin-top: 6px; }
.flagc.done { color: #6dff8f; }
.flagc[hidden] { display: none; }
.trackcard.locked { opacity: 0.45; }
.trackcard .lvl { font: 900 12px var(--body); letter-spacing: 0.08em; color: var(--gold); }
.hud-r { position: absolute; right: max(64px, calc(env(safe-area-inset-right) + 60px)); top: max(10px, env(safe-area-inset-top)); text-align: right; }
.time { font-size: clamp(18px, 3vw, 26px); }
.best, .trk { font: 800 13px var(--body); opacity: 0.85; margin-top: 2px; }
.hud-c { position: absolute; left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; }
.itemslot { width: 72px; height: 72px; border-radius: 16px; background: rgba(10,16,40,0.55); border: 3px solid rgba(255,255,255,0.55); display: flex; align-items: center; justify-content: center; font-size: 40px; text-shadow: none; }
.itemslot.ready { border-color: var(--gold); box-shadow: 0 0 18px rgba(255,210,63,0.6); animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.07); } }
.itemname { font: 900 13px var(--body); margin-top: 4px; min-height: 16px; }
.mini { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); width: 150px; height: 150px; opacity: 0.92; }
body.touchui .mini { left: auto; right: max(10px, env(safe-area-inset-right)); top: max(96px, calc(env(safe-area-inset-top) + 92px)); bottom: auto; width: 110px; height: 110px; }
.msg { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-size: clamp(38px, 9vw, 92px); opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.2s cubic-bezier(.2,1.6,.4,1); }
.msg.show { opacity: 1; transform: none; }
.msg.count { color: #fff; } .msg.go { color: #6dff8f; } .msg.lap { color: #8fdcff; font-size: clamp(30px, 6vw, 60px); } .msg.fin { color: var(--gold); }
.msg.turbo { color: #ffb12b; font-size: clamp(22px, 4vw, 38px); top: 58%; }
.wrong { position: absolute; left: 0; right: 0; top: 22%; text-align: center; font-size: clamp(26px, 5vw, 48px); color: #ff5d7c; animation: blink 0.6s steps(2) infinite; }
.wrong[hidden] { display: none; }
/* the keys, along the bottom while racing on a computer */
.keys { position: absolute; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 14px; padding: 7px 14px; border-radius: 12px; background: rgba(10, 14, 36, 0.55); color: #dfe6ff; font: 600 13px/1.2 system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
.keys kbd { display: inline-block; min-width: 20px; padding: 2px 6px; margin-right: 4px; border-radius: 5px; background: #fff; color: #141a3a; font: 800 12px/1.2 system-ui, sans-serif; text-align: center; box-shadow: 0 2px 0 #9aa3c7; }
.keys .sk.on kbd { background: var(--gold); }
body.touchui .keys { display: none; }
@media (max-width: 640px) { .keys { display: none; } }
@keyframes blink { 50% { opacity: 0.25; } }

/* touch: steer bottom left, drift and item bottom right */
.touch { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.touch[hidden] { display: none; }
.tb { position: absolute; pointer-events: auto; touch-action: none; -webkit-touch-callout: none; min-height: 0; padding: 0; border-radius: 50%; color: #fff; font: 400 16px var(--head); background: rgba(8,14,36,0.5); border: 2px solid rgba(255,255,255,0.7); box-shadow: 0 4px 14px rgba(0,0,0,0.3); }
.tb.on { background: rgba(255,210,63,0.45); transform: scale(0.95); }
.steer { width: 96px; height: 96px; bottom: max(20px, env(safe-area-inset-bottom)); font-size: 34px; }
.steer.l { left: max(16px, env(safe-area-inset-left)); }
.steer.r { left: calc(max(16px, env(safe-area-inset-left)) + 112px); }
.drift { width: 112px; height: 112px; right: max(18px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); background: rgba(255,120,40,0.32); border-color: rgba(255,190,120,0.8); }
.item { width: 80px; height: 80px; right: calc(max(18px, env(safe-area-inset-right)) + 124px); bottom: max(40px, calc(env(safe-area-inset-bottom) + 20px)); font-size: 14px; }
.item.has { background: rgba(255,210,63,0.4); border-color: var(--gold); }
@media (max-height: 460px) { .steer { width: 80px; height: 80px; } .steer.r { left: calc(max(16px, env(safe-area-inset-left)) + 94px); } .drift { width: 96px; height: 96px; } .item { width: 68px; height: 68px; right: calc(max(18px, env(safe-area-inset-right)) + 106px); } .panel { padding: 16px 20px; } .itemslot { width: 58px; height: 58px; font-size: 32px; } }
.pausebtn { position: absolute; z-index: 3; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 44px; height: 36px; min-height: 0; padding: 0; font: 400 14px var(--head); background: rgba(0, 0, 0, 0.35); border-radius: 10px; opacity: 0.85; }
.pausebtn[hidden] { display: none; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 7px; vertical-align: 0; box-shadow: 0 0 0 2px rgba(255,255,255,0.25); }
.pickrow { display: grid; grid-template-columns: minmax(200px, 1fr) 1.4fr; gap: 12px; align-items: center; margin: 4px 0 10px; }
.pv { aspect-ratio: 4 / 3; border-radius: 16px; overflow: hidden; background: #141a3a; border: 1px solid var(--line); }
.carcv { width: 100%; height: 100%; display: block; }
.pickrow .racers { grid-template-columns: repeat(3, 1fr); margin: 0; }
.racer .em { font-size: 26px; }
@media (max-width: 620px) { .pickrow { grid-template-columns: 1fr; } .pv { aspect-ratio: 16 / 7; } }
@media (max-height: 520px) { .pv { aspect-ratio: 16 / 10; } .racer { padding: 6px 4px; } .racer .em { font-size: 20px; } }
