:root {
  --fg: #d7dbe8;
  --dim: rgba(200, 206, 224, 0.5);
  --faint: rgba(200, 206, 224, 0.18);
  --accent: #e8c48a;
  --red: #c8453c;
  --font: "Helvetica Neue", "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #05060b; overflow: hidden; color: var(--fg); font-family: var(--font); font-weight: 300; user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
.hidden { display: none !important; }

/* ------------------------------------------------ screens */
#ui { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; justify-content: center; padding: 6vh 7vw; pointer-events: auto; }
.screen.active { display: flex; animation: fadein 0.6s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
#s-menu { background: linear-gradient(90deg, rgba(4, 5, 10, 0.82) 0%, rgba(4, 5, 10, 0.45) 34%, rgba(4, 5, 10, 0) 60%); }
#s-garage, #s-settings, #s-rally, #s-pause, #s-over, #s-finish { background: rgba(4, 5, 10, 0.72); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.title h1 { font-weight: 200; font-size: clamp(34px, 6.2vw, 92px); letter-spacing: 0.32em; margin: 0; line-height: 1; text-shadow: 0 0 30px rgba(160, 180, 255, 0.12); }
.title .tag, .tag { font-style: italic; color: var(--dim); letter-spacing: 0.16em; margin: 1.1em 0 0; font-size: clamp(13px, 1.3vw, 17px); }
h2 { font-weight: 200; letter-spacing: 0.4em; font-size: clamp(22px, 3vw, 38px); margin: 0 0 3vh; }
.menu, .list { display: flex; flex-direction: column; align-items: flex-start; gap: 0.2em; margin-top: 6vh; }
.list { margin-top: 1vh; }
.item { position: relative; letter-spacing: 0.32em; font-size: clamp(15px, 1.55vw, 21px); padding: 0.5em 0 0.5em 1.6em; color: var(--dim); transition: color 0.2s, padding 0.25s; text-align: left; }
.item::before { content: ''; position: absolute; left: 0; top: 50%; width: 0.8em; height: 1px; background: var(--fg); transform: scaleX(0); transform-origin: left; transition: transform 0.25s; }
.item.sel, .item:focus-visible { color: var(--fg); padding-left: 2em; outline: none; }
.item.sel::before { transform: scaleX(1); }
.item.small { font-size: clamp(12px, 1.1vw, 14px); margin-top: 1.4em; }
.foot { position: absolute; left: 7vw; bottom: 5vh; right: 7vw; font-size: 12px; letter-spacing: 0.22em; }
.foot > div { margin-top: 0.7em; }
.dim { color: var(--dim); letter-spacing: 0.2em; font-size: 12px; margin: 0.6em 0; }
.hint { color: rgba(200, 206, 224, 0.32); font-size: 11px; }
.hint.mob { display: none; }
body.touch .hint.desk { display: none; }
body.touch .hint.mob { display: block; }

/* settings */
.list.wide { align-items: stretch; width: min(620px, 86vw); }
.row { display: flex; align-items: center; gap: 1em; }
.row .lbl { flex: 1; }
.row .val { min-width: 8em; text-align: right; font-family: var(--mono); font-size: 0.8em; letter-spacing: 0.1em; color: var(--fg); }
.row input[type=range] { width: 9em; accent-color: #c9cede; height: 2px; }

/* garage */
.garage { display: flex; gap: 6vw; align-items: flex-start; }
.garage .item { display: flex; flex-direction: column; }
.garage .item small { font-size: 10px; letter-spacing: 0.2em; color: rgba(200, 206, 224, 0.35); margin-top: 0.3em; }
.garage .item.locked span { color: rgba(200, 206, 224, 0.28); }
.garage .item.chosen span { color: var(--accent); }
.preview { width: min(320px, 40vw); }
#garage-canvas { width: 100%; height: auto; image-rendering: pixelated; background: radial-gradient(circle at 50% 45%, rgba(130, 140, 180, 0.12), transparent 70%); }
#g-name { letter-spacing: 0.35em; margin: 1em 0 0.4em; font-size: 18px; }
#g-desc { color: var(--dim); font-size: 13px; line-height: 1.6; letter-spacing: 0.04em; min-height: 3.2em; }
.stat { display: flex; align-items: center; gap: 1em; font-size: 11px; letter-spacing: 0.25em; color: var(--dim); margin: 0.55em 0; }
.stat span { width: 7em; }
.stat i { flex: 1; height: 2px; background: var(--faint); position: relative; }
.stat i b { position: absolute; left: 0; top: 0; bottom: 0; background: var(--fg); }
.stat em { font-style: normal; color: var(--fg); font-family: var(--mono); }

/* rally */
.seed { letter-spacing: 0.3em; font-size: 13px; color: var(--dim); display: flex; align-items: center; gap: 1em; margin-bottom: 1em; }
#rally-seed { font-family: var(--mono); background: transparent; border: 0; border-bottom: 1px solid var(--faint); color: var(--fg); font-size: 18px; letter-spacing: 0.2em; width: 9em; padding: 0.3em 0.2em; user-select: text; -webkit-user-select: text; outline: none; }
#rally-seed::before { display: none; }
#rally-seed.sel { border-bottom-color: var(--fg); }

/* results */
.stats { display: grid; grid-template-columns: repeat(2, minmax(160px, 260px)); gap: 1.2em 3em; margin-top: 4vh; }
.stats div { display: flex; flex-direction: column; gap: 0.4em; }
.stats span { font-size: 11px; letter-spacing: 0.3em; color: var(--dim); }
.stats b { font-weight: 300; font-family: var(--mono); font-size: 20px; letter-spacing: 0.06em; }
.stats em { font-style: normal; font-size: 10px; letter-spacing: 0.2em; color: var(--accent); vertical-align: middle; margin-left: 0.5em; }
.unlock { margin-top: 3vh; color: var(--accent); letter-spacing: 0.25em; font-size: 12px; }
.bigtime { font-family: var(--mono); font-size: clamp(40px, 7vw, 84px); font-weight: 200; letter-spacing: 0.06em; margin: 2vh 0; }

/* ------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; pointer-events: none; font-family: var(--mono); color: rgba(220, 226, 240, 0.86); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6); }
#hud .u { font-size: 0.42em; letter-spacing: 0.2em; margin-left: 0.5em; color: var(--dim); }
#hud-tl { position: absolute; left: max(22px, env(safe-area-inset-left)); top: max(18px, env(safe-area-inset-top)); }
#hud-dist { font-size: 24px; font-weight: 300; letter-spacing: 0.04em; }
#hud-biome { font-family: var(--font); font-size: 10px; letter-spacing: 0.32em; color: var(--dim); margin-top: 0.4em; }
#hud-tc { position: absolute; left: 50%; top: max(18px, env(safe-area-inset-top)); transform: translateX(-50%); text-align: center; }
#hud-timer { font-size: 26px; letter-spacing: 0.06em; }
#hud-drift { opacity: 0; transition: opacity 0.25s; font-size: 22px; }
#hud-drift.on { opacity: 1; }
#hud-drift.fading { opacity: 0.45; }
#drift-mult { font-size: 13px; margin-left: 0.6em; color: var(--accent); }
#hud-toast { font-family: var(--font); font-size: 10px; letter-spacing: 0.3em; color: var(--dim); margin-top: 0.4em; line-height: 1.8; }
#hud-toast b { color: var(--fg); font-weight: 400; font-family: var(--mono); letter-spacing: 0.05em; }
#hud-biome-title { position: absolute; left: 0; right: 0; top: 24vh; text-align: center; font-family: var(--font); font-weight: 200; letter-spacing: 0.6em; font-size: clamp(14px, 1.6vw, 22px); opacity: 0; }
#hud-biome-title.show { animation: biome 5s ease forwards; }
@keyframes biome { 0% { opacity: 0; letter-spacing: 0.4em; } 20% { opacity: 0.85; } 70% { opacity: 0.7; } 100% { opacity: 0; letter-spacing: 0.75em; } }
#btn-pause { position: absolute; right: max(20px, env(safe-area-inset-right)); top: max(16px, env(safe-area-inset-top)); width: 34px; height: 34px; pointer-events: auto; display: flex; gap: 6px; align-items: center; justify-content: center; opacity: 0.55; }
#btn-pause i { display: block; width: 2px; height: 14px; background: var(--fg); }
#btn-pause:hover { opacity: 1; }
#hud-bl { position: absolute; left: max(22px, env(safe-area-inset-left)); bottom: max(20px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 10px; }
#hud-car { width: 16px; height: 28px; image-rendering: pixelated; opacity: 0.85; }
#hud-repair { font-family: var(--font); font-size: 10px; letter-spacing: 0.3em; color: var(--accent); }
#hud-br { position: absolute; right: max(24px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); text-align: right; }
#hud-speed { font-size: 40px; font-weight: 200; letter-spacing: 0.02em; line-height: 1; }
#hud-gear { font-size: 11px; color: var(--dim); letter-spacing: 0.3em; margin-top: 0.3em; }
#hud[data-mode=free] #hud-car { display: none; }
#fps { position: fixed; right: 8px; bottom: 4px; font: 10px var(--mono); color: rgba(200, 206, 224, 0.4); display: none; pointer-events: none; }

/* ------------------------------------------------ touch */
#touch { position: fixed; inset: 0; pointer-events: none; }
#touch .tz { position: absolute; top: 30%; bottom: 0; width: 50%; pointer-events: auto; display: flex; align-items: flex-end; padding: 0 0 18vh; }
#tz-left { left: 0; justify-content: flex-start; padding-left: 8vw !important; }
#tz-right { right: 0; justify-content: flex-end; padding-right: 8vw !important; }
#touch .tz span { color: rgba(220, 226, 240, 0.14); font-size: 22px; transition: color 0.1s; }
#touch .tz.on span { color: rgba(220, 226, 240, 0.5); }
#touch .tb { position: absolute; pointer-events: auto; border: 1px solid rgba(220, 226, 240, 0.18); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--font); font-size: 9px; letter-spacing: 0.2em; color: rgba(220, 226, 240, 0.45); background: rgba(10, 12, 20, 0.15); }
#touch .tb.on { background: rgba(220, 226, 240, 0.14); color: var(--fg); }
#tb-brake { width: 74px; height: 74px; left: 50%; transform: translateX(-50%); bottom: max(22px, env(safe-area-inset-bottom)); }
#tb-hand { width: 50px; height: 50px; left: 50%; transform: translateX(-50%); bottom: calc(max(22px, env(safe-area-inset-bottom)) + 88px); }
#tb-gas { width: 62px; height: 62px; right: 22px; bottom: calc(max(22px, env(safe-area-inset-bottom)) + 70px); display: none !important; }
#touch.manual #tb-gas { display: flex !important; }
body.touch #hud-br { bottom: auto; top: calc(max(16px, env(safe-area-inset-top)) + 44px); }
body.touch #hud-bl { bottom: auto; top: calc(max(18px, env(safe-area-inset-top)) + 58px); }

@media (orientation: portrait) {
  .screen { padding: 8vh 9vw; justify-content: flex-end; }
  #s-menu { background: linear-gradient(0deg, rgba(4, 5, 10, 0.88) 0%, rgba(4, 5, 10, 0.5) 45%, rgba(4, 5, 10, 0) 70%); padding-bottom: 20vh; }
  .title h1 { font-size: 11vw; letter-spacing: 0.25em; }
  .menu { margin-top: 4vh; }
  .foot { bottom: 3vh; }
  .garage { flex-direction: column-reverse; gap: 2vh; }
  .preview { width: 70vw; }
  #garage-canvas { max-height: 26vh; width: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 1em 1.5em; }
  #hud-dist { font-size: 20px; }
  #hud-speed { font-size: 30px; }
}
