/* =========================================================================
 * Rally Legends — UI styles (voxel / Minecraft look).
 * Hard pixel edges only: no border-radius, no skew, no blur, no soft shadows.
 * All text is drawn as pixel-font canvases by menu.js / hud.js (sized from the
 * CSS font-size of the element, coloured from its CSS colour).
 * Everything sizes in rem; the HUD sets the root font-size from the window size.
 * ========================================================================= */
:root {
  --yellow: #ffd23c; --yellow-d: #c99a00; --blue: #3d6fe0; --red: #ff5555; --green: #55ff55;
  --ink: #ffffff; --dim: #c4c4c4;
  --font: "Courier New", Menlo, Consolas, "Liberation Mono", monospace;
  --display: var(--font);
  --px: 4px;                      /* bevel width */
  --tex-stone: none; --tex-dirt: none; --tex-planks: none; --tex-grass: none;   /* set by Menu from RALLY.PixelUI */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; background: #000; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); font-family: var(--font); font-weight: 700; text-transform: uppercase; user-select: none; -webkit-user-select: none; }
body { background: #000; }
canvas.px, img.px { image-rendering: pixelated; }
.pxt { display: inline-block; vertical-align: top; }
#app { position: fixed; inset: 0; overflow: hidden; }
#viewport, #viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; font-weight: inherit; color: inherit; text-transform: inherit; }

/* ----------------------------------------------------- menu background */
.menu-bg { position: absolute; inset: 0; background: #4a86d0; overflow: hidden; }
.menu-bg .menu-bg-cv { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
body.has-scene .menu-bg { display: none; }

/* ------------------------------------------------------------- screens */
.ui { position: absolute; inset: 0; z-index: 20; }
.screen { --st: 4.5vh; --sl: 6vw; --sr: 6vw; position: absolute; inset: 0; display: flex; flex-direction: column; padding: var(--st) var(--sr) 3.5vh var(--sl); overflow-y: auto; animation: fadein .3s steps(3, end); }
.screen::-webkit-scrollbar { width: 1rem; }
.screen::-webkit-scrollbar-track { background: #111; }
.screen::-webkit-scrollbar-thumb { background: #8b8b8b; border: 4px solid; border-color: #d0d0d0 #444 #444 #d0d0d0; }
/* menu screens over the menu backdrop / 3D scene: darkened dirt (hard overlay, no blur) */
.screen-stages, .screen-settings, .screen-controls, .screen-champIntro, .screen-cars {
  background: var(--tex-dirt) #5a4026; background-size: 64px 64px; image-rendering: pixelated; box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, .66);
}
.screen-pause { background: rgba(0, 0, 0, .62); align-items: center; justify-content: center; }
.screen-results, .screen-champion { background: rgba(0, 0, 0, .74); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.head h2 { margin: 0; font: 900 2.6rem/1 var(--font); color: #fff; }
.head h2::after { content: ""; display: block; width: 8rem; height: .5rem; margin-top: .8rem; background: var(--yellow); box-shadow: 0 0 0 3px #000; }
.head p { margin: 1rem 0 0; color: var(--dim); font-size: 1.2rem; max-width: 52rem; }
.head.center { text-align: center; } .head.center h2::after { margin-left: auto; margin-right: auto; }
.row-foot { display: flex; gap: 1.2rem; margin-top: auto; padding-top: 1.8rem; flex-wrap: wrap; }
/* navigation bar: the screen's buttons (back, reset, retry…) sit at the top like on a web page and stay there while the content scrolls under them */
.row-foot.nav-top { position: sticky; top: calc(-1 * var(--st)); z-index: 3; margin: calc(-1 * var(--st)) calc(-1 * var(--sr)) 1.4rem calc(-1 * var(--sl)); padding: .8rem var(--sr) .8rem var(--sl); background: rgba(0, 0, 0, .86); border-bottom: 3px solid #000; }
.foot { margin-top: auto; display: flex; gap: 2rem; color: var(--dim); font-size: 1rem; }
.foot .ver { margin-left: auto; opacity: .75; }
.tip { color: var(--dim); max-width: 60rem; margin: 1.4rem 0 0; font-size: 1.1rem; }

/* ---------------------------------------------------------------- logo */
.logo { margin: 1vh 0 3vh; }
.logo-top { display: flex; align-items: center; gap: .5rem; color: var(--yellow); font-size: 1.1rem; }
.logo-top i { width: .8rem; height: .8rem; background: var(--yellow); display: inline-block; box-shadow: 0 0 0 2px #000; }
.logo-top i:nth-child(2) { background: #ff9a3c; } .logo-top i:nth-child(3) { background: #ff5555; }
.logo-main { display: flex; flex-direction: column; margin-top: .9rem; gap: .5rem; }
.logo-main .l2 { margin-left: .4rem; }
.logo-sub { margin: 1.2rem 0 0 .3rem; color: #fff; font-size: 1.05rem; }

/* ------------------------------------------------------------- buttons */
.menu-col { display: flex; flex-direction: column; gap: 1rem; width: 30rem; max-width: 90vw; }
.btn { position: relative; appearance: none; cursor: pointer; text-align: center; padding: .85rem 1.4rem; font: 800 1.3rem var(--font); color: #fff;
  background: #7c7c7c var(--tex-stone); background-size: 64px 64px; image-rendering: pixelated;
  border: var(--px) solid; border-color: #d8d8d8 #3a3a3a #3a3a3a #d8d8d8; box-shadow: 0 0 0 3px #000; }
.btn > span { display: block; }
.btn.big { font-size: 1.45rem; padding: 1rem 1.4rem; }
.btn.primary { background-color: #4caf3a; background-image: var(--tex-planks); background-blend-mode: multiply; border-color: #b9f08c #1f5a16 #1f5a16 #b9f08c; }
.btn.ghost { background-color: #6a6a6a; background-blend-mode: multiply; }
.btn.focus, .btn:hover { background-color: #3d6fe0; background-blend-mode: multiply; border-color: #fff #fff #fff #fff; }
.btn.primary.focus, .btn.primary:hover { background-color: #6bff4c; }
.btn.disabled { opacity: .45; pointer-events: none; }
/* main menu: the two settings surfaced on it sit under the navigation as their own small block */
.quick { margin-top: .6rem; padding-top: 1rem; border-top: 3px solid rgba(0, 0, 0, .55); display: flex; flex-direction: column; gap: .6rem; }
.quick-label { font-size: .95rem; color: var(--dim); text-shadow: 2px 2px 0 #000; }
.quick-row { display: flex; gap: .8rem; }
.quick-row .btn { flex: 1 1 0; min-width: 0; font-size: 1.05rem; padding: .6rem .6rem; background-color: #6a6a6a; background-blend-mode: multiply; }
.quick-row .btn > span { overflow: hidden; }

/* stage variant toggles (stage select) */
.var-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1.2rem; }
.var-row .var-btn { font-size: 1rem; padding: .55rem 1rem; }

/* --------------------------------------------------------------- cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); gap: 1.6rem; margin-top: 1.8rem; padding: .6rem .6rem 1rem .4rem; }
.card { appearance: none; text-align: left; padding: 0; cursor: pointer; overflow: hidden; color: #fff; font: inherit;
  background: #866043 var(--tex-dirt); background-size: 48px 48px; image-rendering: pixelated;
  border: var(--px) solid; border-color: #b58a63 #3a281a #3a281a #b58a63; box-shadow: 0 0 0 3px #000; }
.card.focus, .card:hover { border-color: #fff; box-shadow: 0 0 0 3px #000, 0 0 0 7px #3d6fe0; }
.thumb { position: relative; aspect-ratio: 2 / 1; overflow: hidden; border-bottom: 3px solid #000; background: #000; }
.thumb img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.thumb .flag { position: absolute; left: .7rem; top: .7rem; width: 2rem; height: 1.3rem; border: 3px solid #000; }
.thumb .num { position: absolute; right: .7rem; top: .5rem; font: 900 1.3rem var(--font); color: #fff; }
.cbody { position: relative; padding: 1.1rem 1rem 1rem; }
.cbody::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 12px; background: var(--tex-grass) 0 0 / 48px 48px repeat-x; image-rendering: pixelated; border-bottom: 3px solid #000; }
.cname { font: 900 1.35rem var(--font); color: #fff; margin-top: .5rem; }
.ccountry { color: #ffe9b0; font-size: 1rem; margin-top: .3rem; }
.chips { display: flex; gap: .45rem; flex-wrap: wrap; margin: .8rem 0; }
.chip { font-size: 1rem; font-weight: 800; padding: .25rem .6rem; background: #444; border: 3px solid #000; color: #fff; display: inline-block; }
.chip.s0 { background: #4a4d55; } .chip.s1 { background: #8d7756; } .chip.s2 { background: #7d98b3; } .chip.s3 { background: #5b4632; } .chip.s4 { background: #5f9dc4; } .chip.s5 { background: #55702f; }
.cstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; border-top: 3px solid #000; padding-top: .7rem; }
.cstats small { display: block; color: #e0cdb0; font-size: .85rem; } .cstats b { display: block; font: 800 1.05rem var(--font); margin-top: .2rem; }
.gold { color: var(--yellow); }

/* -------------------------------------------------------------- panels */
.panel { background: #9a9a9a var(--tex-stone); background-size: 64px 64px; background-blend-mode: multiply; image-rendering: pixelated;
  border: var(--px) solid; border-color: #8e8e8e #1a1a1a #1a1a1a #8e8e8e; box-shadow: 0 0 0 3px #000; padding: 1.2rem 1.5rem; margin-top: 1.8rem; }
.panel h3 { margin: .5rem 0 .6rem; font: 800 1.15rem var(--font); color: var(--yellow); }
.champ-list { max-width: 58rem; }
.champ-row { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) 11rem 8rem 6rem; align-items: center; gap: .8rem; padding: .6rem 0; border-bottom: 3px solid rgba(0, 0, 0, .55); font-size: 1.2rem; }
.champ-row b { font: 900 1.2rem var(--font); color: var(--yellow); } .champ-row em { color: var(--dim); font-style: normal; } .champ-row small { color: var(--dim); text-align: right; font-size: 1.1rem; }

/* ------------------------------------------------------------ settings */
.settings { max-width: 56rem; }
.set-group { --acc: #b8791a; padding: 0 1.5rem .8rem; margin-top: 1.3rem; }
.set-group:first-child { margin-top: 1.8rem; }
.set-group.g-lang { --acc: #5b6b82; } .set-group.g-audio { --acc: #2f5fd0; } .set-group.g-drive { --acc: #2f8f3a; } .set-group.g-gfx { --acc: #8a4fc4; } .set-group.g-rec { --acc: #b03a3a; }
.set-group h3 { display: flex; align-items: center; gap: .8rem; margin: 0 -1.5rem .7rem; padding: .55rem 1.5rem; color: #fff; background: var(--acc); border-bottom: 3px solid #000;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .35), inset 0 -3px 0 rgba(0, 0, 0, .35); }
.set-group h3 i { font-style: normal; background: #141414; color: #fff; padding: .2rem .45rem; border: 3px solid; border-color: #000 #6a6a6a #6a6a6a #000; }
.set-row { display: grid; grid-template-columns: minmax(0, 1fr) 22rem; align-items: center; gap: 1rem; padding: .4rem .9rem; margin: .15rem -.9rem; border: 3px solid transparent; cursor: pointer; }
.set-row.focus { background: #1f3f9f; border-color: #fff; }
.set-label { font-size: 1.2rem; font-weight: 800; } .set-label small { display: block; color: var(--dim); font-weight: 700; font-size: 1rem; margin-top: .2rem; }
.slider { position: relative; height: 2.3rem; background: #141414; border: 3px solid; border-color: #000 #6a6a6a #6a6a6a #000; overflow: hidden; cursor: ew-resize; }
.slider .fill { position: absolute; left: 0; top: 0; bottom: 0; background: #3ddc5c; box-shadow: inset 0 3px 0 #9dffb0, inset 0 -3px 0 #1f8f38; }
.slider .val { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1rem; color: #fff; }
.select { display: flex; align-items: center; justify-content: space-between; height: 2.3rem; background: #141414; border: 3px solid; border-color: #000 #6a6a6a #6a6a6a #000; }
.select .val { flex: 1; text-align: center; font-weight: 800; font-size: 1.05rem; color: var(--yellow); cursor: pointer; }
.select .arr { appearance: none; border: 3px solid; border-color: #d0d0d0 #3a3a3a #3a3a3a #d0d0d0; background: #7c7c7c var(--tex-stone); background-size: 48px 48px; color: #fff; font-size: 1.6rem; font-weight: 900; width: 2.6rem; height: 100%; cursor: pointer; padding: 0; }
.select .arr:hover { background-color: #3d6fe0; background-blend-mode: multiply; border-color: #fff; }
/* text input styled like .select (online nick; js/game/menu.js _textRow / results nick form). Text nodes only are pixelised, so the input keeps the system monospace font. */
input.select.text { display: block; width: 100%; box-sizing: border-box; padding: 0 .7rem; font: 800 1.05rem var(--font); color: var(--yellow); text-transform: none; text-align: center; letter-spacing: .04em; outline: none; user-select: text; -webkit-user-select: text; caret-color: var(--yellow); }
input.select.text::placeholder { color: #6a6a6a; text-transform: uppercase; }
input.select.text:focus, input.select.text.focus { border-color: #fff; background: #1f3f9f; }
/* online ranking panel on the results screen (.online-slot is reserved for the full leaderboard) */
.online-panel .online-line { font-size: 1.15rem; min-height: 1.6rem; } .online-panel .online-line b { color: var(--yellow); }
.online-panel .nick-form { display: flex; gap: .6rem; align-items: stretch; margin-top: .6rem; } .online-panel .nick-form input { flex: 1; min-width: 0; height: auto; }
.online-panel .nick-form .btn { padding: .3rem 1rem; font-size: 1.05rem; }
.online-panel .nick-ask { color: var(--dim); font-size: 1.05rem; }

.ctl-wrap { display: flex; gap: 1.5rem; flex-wrap: wrap; } .ctl { min-width: 24rem; flex: 1; }
.ctl-row { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 3px solid rgba(0, 0, 0, .5); font-size: 1.15rem; gap: 1rem; }
kbd { font: 800 1rem var(--font); background: #8b8b8b var(--tex-stone); background-size: 48px 48px; color: #fff; border: 3px solid; border-color: #e0e0e0 #2a2a2a #2a2a2a #e0e0e0; box-shadow: 0 0 0 2px #000; padding: .3rem .7rem; }

/* ------------------------------------------------------------- results */
.res-lines span, .ctl-row span, .set-label { min-width: 0; }
.res-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1.8rem; align-items: start; }
.res-main { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.5rem; }
.res-pos small, .res-time small { display: block; color: var(--dim); font-size: 1rem; }
.res-pos b { display: flex; align-items: flex-start; font: 900 4rem/1.1 var(--font); color: var(--ink); } .res-pos.podium b { color: var(--yellow); }
.res-pos sup { font-size: 1.6rem; vertical-align: top; } .res-pos em { color: var(--dim); font-style: normal; font-size: 1.1rem; }
.res-time b { display: block; font: 900 3.2rem/1.1 var(--font); }
.badge { display: inline-block; margin-top: .5rem; font: 800 1.1rem var(--font); background: var(--yellow); color: #3a2a00; border: 3px solid #000; padding: .25rem .7rem; animation: pulse 1s steps(2, end) infinite; }
@keyframes pulse { 50% { background: #fff; } }
.res-lines { grid-column: 1 / -1; }
.res-lines > div { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 3px solid rgba(0, 0, 0, .5); font-size: 1.15rem; gap: 1rem; }
.res-lines span { color: var(--dim); } .res-lines i { font-style: normal; font-weight: 800; margin-left: .5rem; }
.good { color: var(--green) !important; } .bad { color: var(--red) !important; }
.res-right .panel:first-child { margin-top: 1.4rem; } .res-right .panel { margin-top: 1rem; padding: 1rem 1.3rem; }
.screen-results .res-grid .res-main { margin-top: 1.4rem; }
.screen-pause .head { margin-bottom: 2rem; }
.board .brow { display: grid; grid-template-columns: 2.4rem minmax(0, 1fr) 6.5rem 5.5rem; gap: .6rem; padding: .28rem .5rem; font-size: 1.1rem; border-bottom: 3px solid rgba(0, 0, 0, .45); }
.board.wide .brow { grid-template-columns: 2.4rem minmax(0, 1fr) 8rem 6.5rem 6rem; font-size: 1.2rem; }
.brow i { font: 900 1.1rem var(--font); color: var(--dim); font-style: normal; } .brow em { color: var(--dim); font-style: normal; text-align: right; } .brow u { text-decoration: none; color: var(--yellow); font-weight: 800; text-align: right; }
.brow.me { background: #1f3f9f; border: 3px solid #fff; font-weight: 800; }
.cond .word { color: var(--ink); margin-left: .8rem; }
.cgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem; }
.cbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .25rem .5rem; font-size: 1rem; margin: .5rem 0 .7rem; } .cbar span { color: var(--dim); }
.cbar b { display: block; grid-row: 2; grid-column: 1 / -1; height: .8rem; background: #141414; border: 3px solid #000; overflow: hidden; } .cbar b i { display: block; height: 100%; } .cbar em { grid-row: 1; grid-column: 2; font-style: normal; text-align: right; }

/* ------------------------------------------------------------- loading */
.loading { position: absolute; inset: 0; z-index: 40; background: #2a1d10 var(--tex-dirt); background-size: 64px 64px; image-rendering: pixelated; box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; }
.load-inner { width: min(40rem, 88vw); text-align: center; }
.load-thumb { aspect-ratio: 2 / 1; overflow: hidden; border: var(--px) solid; border-color: #d8d8d8 #3a3a3a #3a3a3a #d8d8d8; box-shadow: 0 0 0 3px #000; background: #000; } .load-thumb img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.load-title { font: 900 2.6rem var(--font); margin-top: 1.6rem; } .load-sub { color: var(--yellow); margin-top: .5rem; font-size: 1.1rem; }
.load-bar { height: 1.6rem; background: #141414; margin: 1.8rem 0 .8rem; border: 3px solid; border-color: #000 #6a6a6a #6a6a6a #000; box-shadow: 0 0 0 3px #000; overflow: hidden; }
.load-bar i { display: block; height: 100%; width: 5%; background: repeating-linear-gradient(90deg, #3ddc5c 0 16px, #1c1c1c 16px 20px); transition: width .4s steps(8, end); }
.load-text { color: #fff; font-size: 1.1rem; min-height: 1.6rem; } .load-tip { color: var(--dim); margin-top: 1.4rem; font-size: 1.1rem; }

/* ---------------------------------------------------------------- toasts */
.toasts { position: absolute; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; }
.toast { background: #202020; border: 3px solid #000; border-left: .6rem solid var(--blue); padding: .6rem 1rem; font-size: 1rem; max-width: 80vw; animation: fadein .25s steps(3, end); transition: opacity .4s steps(4, end); }
.toast.error { border-left-color: var(--red); color: #ffb4ae; } .toast.out { opacity: 0; }

/* ================================================================== HUD */
.hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; font-family: var(--font); }
.hud > div { position: absolute; }
.hud canvas.px { display: inline-block; }
.hud-tl { left: 1.6rem; top: 1.3rem; display: flex; flex-direction: column; align-items: flex-start; gap: .5rem; }
.hud-stage { display: flex; align-items: center; gap: .7rem; background: rgba(0, 0, 0, .7); border: 3px solid #000; padding: .35rem .7rem; }
.hud-stage-flag { width: 1.8rem; height: 1.2rem; border: 3px solid #000; flex: none; }
.hud-time { background: rgba(0, 0, 0, .55); border: 3px solid #000; border-left: .5rem solid var(--yellow); padding: .35rem 1rem .35rem .8rem; display: inline-block; }
.hud-time-val { display: block; }
.hud-pen { background: rgba(0, 0, 0, .55); border: 3px solid #000; padding: .25rem .7rem; }
.hud-delta { background: rgba(0, 0, 0, .78); border: 3px solid #000; border-left: .5rem solid #fff; padding: .3rem .9rem; animation: fadein .3s steps(3, end); }
.hud-ghost { background: rgba(0, 0, 0, .55); border: 3px solid #000; border-left: .5rem solid #7fc4ff; padding: .2rem .7rem; }
.hud-ghost.good { border-left-color: var(--green); } .hud-ghost.bad { border-left-color: var(--red); }
.hud-delta.good { border-left-color: var(--green); } .hud-delta.bad { border-left-color: var(--red); }

.hud-tc { left: 50%; top: 1.2rem; transform: translateX(-50%); width: min(26rem, 28vw); }
.hud-progress { position: relative; height: 1rem; background: #222; border: 3px solid #000; margin-top: .4rem; }
.hud-prog-fill { position: absolute; left: 0; top: 0; bottom: 0; background: #3ddc5c; box-shadow: inset 0 3px 0 #9dffb0; }
.hud-prog-marks i { position: absolute; top: -.4rem; width: 3px; height: 1.4rem; background: #fff; transform: translateX(-50%); box-shadow: 0 0 0 2px #000; }
.hud-prog-marks i.done { background: var(--green); }
.hud-prog-car { position: absolute; top: 50%; width: 1.2rem; height: 1.2rem; background: var(--yellow); border: 3px solid #000; transform: translate(-50%, -50%); }
.hud-prog-l, .hud-prog-r { position: absolute; top: 1.35rem; } .hud-prog-l { left: 0; } .hud-prog-r { right: 0; }

/* next pace note: one big card, top centre under the progress bar */
.hud-tr { left: 50%; top: 4.2rem; width: auto; }
.hud-notes { display: flex; flex-direction: column; gap: .5rem; --ns: 4.4rem; }
.note { display: grid; grid-template-columns: var(--ns) auto auto; align-items: center; gap: 1rem; background: rgba(0, 0, 0, .62); border: 3px solid #000; padding: .5rem 1.2rem .5rem .5rem; position: relative; white-space: nowrap; }
.note canvas { grid-row: 1; grid-column: 1; }
.note-sev { position: absolute; left: .5rem; top: calc(var(--ns) - 1.2rem); }
.note-mods { margin-top: .3rem; }
.note.active { border-color: var(--yellow); background: rgba(40, 30, 0, .8); }
.note.note-1 { opacity: .9; } .note.note-2 { opacity: .75; }

.hud-bl { left: 1.6rem; bottom: 1.4rem; display: flex; flex-direction: column; gap: .7rem; }
.hud-cond { display: flex; gap: .9rem; align-items: center; background: rgba(0, 0, 0, .55); border: 3px solid #000; padding: .5rem .9rem .5rem .6rem; }
.hud-car { display: block; flex: none; }
.hud-lbl { margin-bottom: .35rem; }
.hud-cond-bars { display: grid; grid-template-columns: auto 5.5rem; align-items: center; gap: .6rem .6rem; }
.cb { display: contents; }
.cb b { display: block; height: .7rem; background: #141414; border: 2px solid #000; overflow: hidden; } .cb b i { display: block; height: 100%; width: 100%; background: #3ddc5c; transition: width .3s steps(5, end); }
.hud-surface { background: rgba(0, 0, 0, .55); border: 3px solid #000; padding: .5rem 1rem; display: grid; grid-template-columns: auto 1fr; column-gap: .8rem; align-items: center; }
.hud-surf-dots { grid-row: 1 / 3; display: grid; grid-template-columns: repeat(2, .8rem); gap: .25rem; }
.hud-surf-dots i { display: block; width: .8rem; height: 1rem; border: 2px solid #000; outline: 1px solid rgba(255, 255, 255, .35); }
.hud-surf-sub { margin-top: .2rem; }

.hud-br { right: 1.2rem; bottom: 1rem; width: 19rem; height: 19rem; }
/* in-race overlay scaled down so it covers less of the view (menus keep full size) */
.hud-tl { transform: scale(.72); transform-origin: top left; }
.hud-tr { transform: translateX(-50%) scale(.7); transform-origin: top center; }
.hud-bl { transform: scale(.72); transform-origin: bottom left; }
.hud-br { transform: scale(.72); transform-origin: bottom right; }
.hud-tc { transform: translateX(-50%) scale(.8); transform-origin: top center; }
.hud-gauge { width: 100%; height: 100%; display: block; }
.hud-shift { position: absolute; left: 50%; top: -1.9rem; transform: translateX(-50%); display: flex; gap: .3rem; }
.hud-shift i { display: block; width: 1.2rem; height: 1.2rem; background: #2a2a2a; border: 3px solid #000; }
.hud-shift i.g { background: #3ddc5c; } .hud-shift i.y { background: #ffd23c; } .hud-shift i.r { background: #ff3a30; }
.hud-shift i.f { background: #fff; }

.hud-center { left: 0; right: 0; top: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.hud-countdown { opacity: 0; margin-top: -12vh; }
.hud-countdown.show { animation: cd 1s steps(10, end) forwards; } .hud-countdown.go { animation-duration: 1.2s; }
@keyframes cd { 0% { opacity: 0; transform: scale(1.5); } 15% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: scale(1); } }
.hud-wrong { position: absolute; top: 22vh; background: #c82020; border: 4px solid #000; padding: .5rem 2.4rem; animation: blink .6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.hud-fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; }
.hud-msgs { position: absolute; top: 12vh; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.hud-msg { padding: .35rem 1.6rem; background: rgba(0, 0, 0, .78); border: 3px solid #000; border-bottom: .4rem solid #fff; animation: msg 2.4s steps(12, end) forwards; }
.hud-msg.good { border-bottom-color: var(--green); } .hud-msg.bad { border-bottom-color: var(--red); } .hud-msg.warn { border-bottom-color: var(--yellow); }
@keyframes msg { 0% { opacity: 0; } 10% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
.hud-fps { right: 1.5rem; bottom: 21.5rem; background: rgba(0, 0, 0, .7); border: 3px solid #000; padding: .2rem .5rem; }
.hud-hint { left: 50%; bottom: 1.2rem; transform: translateX(-50%); opacity: 0; background: rgba(0, 0, 0, .55); padding: .3rem .8rem; border: 3px solid #000; transition: opacity .4s steps(4, end); }
.hud-hint.show { opacity: 1; }

@media (max-width: 900px) {
  .res-grid { grid-template-columns: 1fr; } .set-row { grid-template-columns: minmax(0, 1fr) 14rem; }
  .hud-tc { display: none; } .hud-tr { top: 1rem; }
}
.set-label small.diff-blurb { color: var(--yellow); max-width: 30rem; margin-top: .2rem; }

/* =============================================================== TOUCH / MOBILE */
:root { --pad: clamp(68px, 24vh, 118px); --tsafe-l: env(safe-area-inset-left, 0px); --tsafe-r: env(safe-area-inset-right, 0px); --tsafe-t: env(safe-area-inset-top, 0px); --tsafe-b: env(safe-area-inset-bottom, 0px); }
html, body { overscroll-behavior: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%; touch-action: manipulation; }
#viewport, #touch, .hud { touch-action: none; }
.screen { touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.slider { touch-action: none; }

/* on-screen pads: hard-edged, semi-transparent stone blocks */
.touch { position: absolute; inset: 0; z-index: 12; pointer-events: none; touch-action: none; -webkit-user-select: none; user-select: none; }
.tpad { position: absolute; pointer-events: auto; touch-action: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: rgba(20, 20, 20, .38); border: 4px solid; border-color: rgba(255, 255, 255, .55) rgba(0, 0, 0, .65) rgba(0, 0, 0, .65) rgba(255, 255, 255, .55);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .55); }
.tpad::before { content: ""; position: absolute; inset: -10px; }   /* generous hit area */
.tpad .ti, .tpad .tt { pointer-events: none; display: block; line-height: 0; }
.tpad canvas { display: block; image-rendering: pixelated; }
.tpad.on { background: rgba(255, 210, 60, .55); border-color: #fff8c0 #7a5a00 #7a5a00 #fff8c0; transform: translateY(3px); }
.tp-throttle { background: rgba(40, 150, 60, .34); } .tp-throttle.on { background: rgba(85, 255, 85, .5); border-color: #d8ffd0 #1f6a1f #1f6a1f #d8ffd0; }
.tp-brake { background: rgba(170, 40, 40, .34); } .tp-brake.on { background: rgba(255, 85, 85, .52); border-color: #ffd0d0 #7a1a1a #7a1a1a #ffd0d0; }
.tp-handbrake { background: rgba(200, 120, 20, .34); } .tp-handbrake.on { background: rgba(255, 176, 60, .55); }
.tp-throttle.auto { opacity: .6; }
/* left cluster: steering */
.tp-left, .tp-right { bottom: calc(var(--tsafe-b) + 12px); width: var(--pad); height: calc(var(--pad) * 1.2); }
.tp-left { left: calc(var(--tsafe-l) + 14px); }
.tp-right { left: calc(var(--tsafe-l) + 14px + var(--pad) + 12px); }
/* right cluster: pedals (+ handbrake above) */
.tp-throttle { right: calc(var(--tsafe-r) + 14px); bottom: calc(var(--tsafe-b) + 12px); width: var(--pad); height: calc(var(--pad) * 1.5); }
.tp-brake { right: calc(var(--tsafe-r) + 14px + var(--pad) + 12px); bottom: calc(var(--tsafe-b) + 12px); width: var(--pad); height: calc(var(--pad) * 1.2); }
.tp-handbrake { right: calc(var(--tsafe-r) + 14px); bottom: calc(var(--tsafe-b) + 12px + var(--pad) * 1.5 + 14px); width: calc(var(--pad) * 2 + 12px); height: calc(var(--pad) * .5); flex-direction: row; }
.touch.tilt .tp-left, .touch.tilt .tp-right { display: none; }
/* top icon buttons */
.ttop { position: absolute; top: calc(var(--tsafe-t) + 8px); left: 50%; transform: translateX(-50%); display: flex; gap: 12px; pointer-events: none; }
.tbtn { pointer-events: auto; touch-action: none; position: relative; width: 52px; height: 48px; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 20, 20, .5); border: 4px solid; border-color: rgba(255, 255, 255, .55) rgba(0, 0, 0, .65) rgba(0, 0, 0, .65) rgba(255, 255, 255, .55); box-shadow: 0 0 0 3px rgba(0, 0, 0, .55); }
.tbtn::before { content: ""; position: absolute; inset: -6px; }
.tbtn .ti { line-height: 0; pointer-events: none; } .tbtn canvas { display: block; image-rendering: pixelated; }
.tbtn.on { background: rgba(255, 210, 60, .6); }

/* portrait blocker (phones) */
.rotate { position: fixed; inset: 0; z-index: 300; display: none; align-items: center; justify-content: center; text-align: center; background: #14110d var(--tex-dirt); background-size: 64px 64px; image-rendering: pixelated; box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, .78); touch-action: none; }
/* (portrait is playable: the overlay stays hidden) */
.rot-box { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 24px; }
.rot-ic { animation: rotphone 2s steps(6, end) infinite; line-height: 0; } .rot-ic canvas { display: block; }
@keyframes rotphone { 0%, 30% { transform: rotate(0); } 70%, 100% { transform: rotate(-90deg); } }
.rot-t, .rot-s { line-height: 0; } .rot-t canvas, .rot-s canvas { display: inline-block; }

/* ---- compact HUD (phones / short windows) ---- */
body.hud-small .hud-tl { transform: scale(.6); top: calc(var(--tsafe-t) + .5rem); left: calc(var(--tsafe-l) + .8rem); }
body.hud-small .hud-tr { transform: translateX(-50%) scale(.6); top: calc(var(--tsafe-t) + .5rem); }
body.hud-small.touch-on .hud-tr { top: calc(var(--tsafe-t) + 62px); }  /* below the camera/reset/pause buttons */
body.hud-small .hud-bl { transform: scale(.6); left: calc(var(--tsafe-l) + .8rem); bottom: calc(var(--tsafe-b) + .6rem); }
body.hud-small .hud-br { transform: scale(.6); right: calc(var(--tsafe-r) + .8rem); bottom: calc(var(--tsafe-b) + .6rem); }
body.hud-small .hud-tc { display: none; }
body.hud-small .hud-cond { display: none; }
body.hud-small .note-2 { display: none !important; }
body.hud-small .hud-notes { gap: .3rem; }
body.hud-small .hud-msgs { top: 16vh; } body.hud-small .hud-wrong { top: 28vh; }
/* touch overlay on: gauge moves to the bottom centre, surface info sits above the steering pads */
body.touch-on .hud-br { right: auto; left: 50%; transform: translateX(-50%) scale(.6); transform-origin: bottom center; bottom: calc(var(--tsafe-b) + .5rem); }
body.touch-on .hud-bl { bottom: calc(var(--tsafe-b) + var(--pad) * 1.2 + 26px); }
body.touch-on.touch-tilt .hud-bl { bottom: calc(var(--tsafe-b) + .6rem); }
body.touch-on .hud-fps { right: auto; left: calc(var(--tsafe-l) + 1rem); top: auto; bottom: calc(var(--tsafe-b) + var(--pad) * 1.2 + 70px); }
body.touch-on .hud-hint { display: none; }

/* ---- portrait phones: pads in both bottom corners, gauge above them, notes across the top ---- */
body.portrait { --pad: 68px; }
body.portrait .tp-left, body.portrait .tp-right { height: calc(var(--pad) * 1.35); }
body.portrait .tp-throttle { height: calc(var(--pad) * 1.6); }
body.portrait .tp-brake { height: calc(var(--pad) * 1.35); }
body.portrait .tp-handbrake { width: calc(var(--pad) * 2 + 12px); height: calc(var(--pad) * .55); bottom: calc(var(--tsafe-b) + 12px + var(--pad) * 1.6 + 12px); }
body.portrait .ttop { top: calc(var(--tsafe-t) + 6px); gap: 10px; }
body.portrait .tbtn { width: 44px; height: 42px; }
body.portrait.touch-on .hud-br { bottom: calc(var(--tsafe-b) + var(--pad) * 1.6 + 30px); transform: translateX(-50%) scale(.55); }
body.portrait .hud-tl { top: calc(var(--tsafe-t) + 56px); left: calc(var(--tsafe-l) + .5rem); transform: scale(.55); }
body.portrait .hud-tr { top: calc(var(--tsafe-t) + 56px); transform: translateX(-50%) scale(.6); }
body.portrait.touch-on .hud-bl { left: 50%; transform: translateX(-50%) scale(.55); transform-origin: bottom center; bottom: calc(var(--tsafe-b) + var(--pad) * 1.6 + 30px + 7.5rem); }
body.portrait .hud-msgs { top: 30vh; } body.portrait .hud-wrong { top: 40vh; }
body.portrait .hud-countdown { top: 34vh; }

/* ---- menus on touch screens ---- */
body.is-touch .btn, body.is-mobile .btn { min-height: 52px; display: flex; align-items: center; justify-content: center; }
body.is-touch .menu-col { gap: 1.1rem; }
body.is-touch .set-row, body.is-mobile .set-row { min-height: 56px; }
body.is-touch .select, body.is-mobile .select { height: max(2.3rem, 46px); }
body.is-touch .select .arr, body.is-mobile .select .arr { min-width: 48px; width: 48px; }
body.is-touch .slider, body.is-mobile .slider { height: max(2.3rem, 46px); }
body.is-touch .card, body.is-mobile .card { min-height: 44px; }
body.is-touch .tilt-btn { margin: .6rem 0; width: 100%; }
@media (max-height: 520px) {
  .screen { --st: 3vh; --sl: calc(4vw + var(--tsafe-l)); --sr: calc(4vw + var(--tsafe-r)); padding-bottom: 3vh; }
  .head h2 { font-size: 2rem; } .head p { margin-top: .5rem; }
  .logo { margin: 0 0 1.5vh; }
  .set-row { grid-template-columns: minmax(0, 1fr) 20rem; }
  .select .arr { flex: none; } .select .val { min-width: 0; overflow: hidden; }
  .panel { margin-top: 1rem; }
  .menu-col { gap: .8rem; width: 26rem; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1.2rem; margin-top: 1rem; }
  .ctl { min-width: 18rem; }
}

/* main menu has six big buttons (incl. the quick difficulty switch and the car screen): tighten on short screens */
@media (max-height: 780px) { .menu-col { gap: .55rem; } .menu-col .btn.big { padding: .65rem 1.4rem; } }

/* ---- share screen (js/game/menu.js _share): the result card and where to send it ---- */
/* results: the run in one narrow column (time, classification, records); the share card large beside it, car
 * condition under the card */
.screen-results .head h2 { font-size: 2.2rem; } .screen-results .head p { margin-top: .5rem; }
.screen-results .res-grid { grid-template-columns: minmax(0, .8fr) minmax(0, 1.25fr); gap: 1.4rem; }
.screen-results .panel { margin-top: 1rem; }
.screen-results .res-grid .res-main { margin-top: 1rem; gap: .5rem 1.2rem; }
.screen-results .res-left .panel { padding: .8rem 1.1rem; }
.screen-results .res-pos b { font-size: 2.8rem; } .screen-results .res-time b { font-size: 2.3rem; }
.screen-results .badge { font-size: .95rem; padding: .15rem .5rem; margin-top: .3rem; }
.screen-results .res-lines > div { padding: .22rem 0; font-size: 1rem; }
.screen-results .board h3, .screen-results .cond h3, .share-panel h3 { margin: .1rem 0 .4rem; font-size: 1.05rem; }
.screen-results .board .brow { font-size: 1rem; padding: .16rem .5rem; grid-template-columns: 2rem minmax(0, 1fr) 6rem 5rem; }
.screen-results .res-right .panel:first-child { margin-top: 1rem; }
.share-panel { padding: .8rem 1.1rem 1rem; }
.share-card { display: block; width: 100%; height: auto; border: 3px solid #000; }
.share-row { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin-top: .9rem; }
.share-row .btn { font-size: 1.05rem; padding: .55rem 1rem; }
.share-hint { display: block; margin-top: .6rem; color: var(--dim); font-size: .9rem; }
.res-rcol .panel { padding: .8rem 1.1rem; }
.res-rcol .cgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.res-rcol .cbar { margin: .2rem 0 .35rem; }
.res-rcol .setup-line { text-align: left; padding: .5rem 0 0; }
@media (max-width: 900px) { .screen-results .res-grid { grid-template-columns: 1fr; } }
/* ---- medals (js/game/medals.js): pixel icons scaled by whole pixels (11 x 12 native), tally, results row ---- */
.medal-ic { width: 22px; height: 24px; vertical-align: middle; margin-right: .4rem; image-rendering: pixelated; }
.medal-ic.big { width: 44px; height: 48px; }
.cstats b .medal-ic { margin-top: -4px; }
.medal-tally { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .45rem; font-size: 1rem; color: #fff; }
.medal-tally b { color: var(--yellow); margin-right: .5rem; } .medal-tally span { margin-right: .7rem; }
.head .medal-tally { margin-top: .9rem; }
.screen-main .medal-tally { margin: -1vh 0 .3rem; }
.screen-results .res-left .res-medal { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .7rem; padding: .5rem 1.1rem; margin-top: .6rem; }
.res-medal b { font-size: 1.2rem; } .res-medal b.none { color: var(--dim); }
.res-medal b.bronze { color: #b87333; } .res-medal b.silver { color: #c0c8d0; } .res-medal b.gold { color: #ffd23c; } .res-medal b.platinum { color: #8fd0ff; }
.res-medal em { font-style: normal; color: var(--dim); font-size: .95rem; margin-left: auto; }
.res-medal .mth { display: inline-flex; align-items: center; font-size: .95rem; }
.select .val.locked { color: #8a8a8a; }
/* ---- car setup panel (js/game/menu.js _cars) ---- */
.setup-btn { margin-left: auto; }
/* ---- car screen (js/game/menu.js _cars): roster cards + setup of the selected car ---- */
.car-cards { max-width: 76rem; }
.car-cards .cstats { grid-template-columns: 1fr; gap: .35rem; margin-top: .7rem; }
.car-cards .cstats > div { display: flex; justify-content: space-between; align-items: center; gap: .6rem; } .car-cards .cstats b { margin-top: 0; }
.car-cards .cblurb { margin-top: .7rem; color: #f1e6d2; font-size: .9rem; min-height: 4.6rem; }
.card.sel { border-color: #b9f08c #1f5a16 #1f5a16 #b9f08c; box-shadow: 0 0 0 3px #000, 0 0 0 7px #3ddc5c; }
.card.sel.focus, .card.sel:hover { border-color: #fff; box-shadow: 0 0 0 3px #000, 0 0 0 7px #3ddc5c, 0 0 0 11px #3d6fe0; }
.thumb .tag { position: absolute; left: .6rem; top: .6rem; padding: .25rem .5rem; font-size: .9rem; color: #fff; background: #2f8f3a; border: 3px solid #000; }
.setup-panel .set-label small, .setup-panel .set-hint { display: block; font-size: .8rem; opacity: .75; margin-top: .3rem; }
.setup-panel .ends { margin-top: .3rem; display: flex; justify-content: space-between; max-width: 18rem; gap: 1rem; font-size: .8rem; opacity: .7; font-style: normal; }
.setup-panel .ends em { font-style: normal; }
.notch .blocks { flex: 1; display: flex; gap: .35rem; justify-content: center; align-items: center; padding: 0 .5rem; }
.notch .blk { flex: 1; height: 1.2rem; background: #2a2a2a; border: 3px solid; border-color: #000 #555 #555 #000; cursor: pointer; }
.notch .blk.mid { background: #3a3a3a; }
.notch .blk.on { background: #3ddc5c; border-color: #9dffb0 #1f8f38 #1f8f38 #9dffb0; }
.notch .blk.cur { background: var(--yellow); border-color: #fff #a08000 #a08000 #fff; }
.setup-line { text-align: center; padding: .4rem .8rem; color: var(--yellow); }
