:root {
  color-scheme: dark;
  font-family: "Bahnschrift", "Arial Narrow", system-ui, sans-serif;
  color: #fcf2e2;
  background: #202927;
  font-synthesis: none;
  --amber: #ffb45e;
  --ink: #182322;
  --line: #e9dfa342;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid #fff; outline-offset: 4px; }
kbd { font: inherit; font-weight: 700; }
#game { position: relative; width: 100%; height: 100dvh; overflow: hidden; isolation: isolate; }
canvas, .screen-shade { position: absolute; inset: 0; width: 100%; height: 100%; }
#course-labels, .screen-shade { pointer-events: none; }
.screen-shade { background: linear-gradient(180deg,#12222080,transparent 24%,transparent 73%,#15211c7a); }
[data-phase="ready"] .screen-shade { background: linear-gradient(90deg,#142320ef,#1423209c 35%,transparent 72%),linear-gradient(180deg,#12222080,transparent 20%); }
.top {
  position: absolute; inset: max(17px,env(safe-area-inset-top)) max(22px,env(safe-area-inset-right)) auto max(22px,env(safe-area-inset-left));
  height: 59px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 850; text-transform: uppercase; letter-spacing: .105em; line-height: 1.05; text-shadow: 0 2px 5px #182322; }
.brand i { width: 29px; height: 28px; background: var(--amber); clip-path: polygon(0 89%,31% 26%,43% 49%,63% 4%,100% 89%,67% 89%,61% 70%,46% 89%); }
.timing { position: relative; min-width: 218px; padding: 8px 16px 13px; display: flex; justify-content: space-between; gap: 18px; background: #182624e8; border: 1px solid var(--line); border-radius: 9px; line-height: 1; }
.timing span, .drive-status span { display: block; font-size: 11px; font-weight: 800; letter-spacing: .13em; color: #e0caad; }
.timing output { display: block; margin-top: 5px; font-size: 21px; font-variant-numeric: tabular-nums; font-weight: 750; min-width: 76px; }
.progress { position: absolute; inset: auto 11px 5px; height: 2px; background: #ffffff24; overflow: hidden; }
.progress i { display: block; width: 100%; height: 100%; background: var(--amber); transform: scaleX(0); transform-origin: left; }
.settings { display: flex; gap: 7px; justify-self: end; }
.settings button, .restart { min-height: 40px; padding: 0 11px; background: #182624e5; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; font-weight: 750; }
.settings button[aria-pressed="false"] { color: #d4c1a9; text-decoration: line-through; }
.panel { position: absolute; }
.intro { left: max(5.8vw,env(safe-area-inset-left)); top: 50%; transform: translateY(-46%); width: min(525px,52vw); }
.mode { margin: 0 0 .66rem; color: var(--amber); font-size: .8rem; font-weight: 850; letter-spacing: .24em; }
h1, h2 { font-weight: 950; letter-spacing: -.055em; text-transform: uppercase; margin: 0; line-height: .86; text-shadow: 0 3px 17px #19232267; }
h1 { font-size: clamp(3rem,8.9vw,8.5rem); transform: scaleX(.91); transform-origin: left; }
h1 span { color: var(--amber); }
.description, .touch-guide { margin: 1.25rem 0; max-width: 31ch; font-size: clamp(1rem,1.5vw,1.25rem); line-height: 1.4; color: #f2e4d1; }
.primary { background: var(--amber); color: #222723; border: 1px solid #ffd5a4; border-radius: 6px; padding: .65rem 1.2rem; min-height: 48px; font-size: 1.04rem; font-weight: 850; box-shadow: 0 4px 0 #7b4f2f; }
.primary:hover { background: #ffd095; }
.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #7b4f2f; }
.primary:disabled { opacity: .6; cursor: default; }
.keyboard-guide { margin-top: 1.15rem; display: flex; gap: .5rem 1rem; flex-wrap: wrap; max-width: 360px; font-size: .83rem; color: #f5e8d6; }
.keyboard-guide kbd, .restart kbd, .primary kbd { display: inline-block; min-width: 1.35em; text-align: center; padding: .11em .25em; margin-right: 3px; border: 1px solid currentColor; border-radius: 4px; font-size: .86em; }
.touch-guide { display: none; }
.drive-status { position: absolute; left: max(23px,env(safe-area-inset-left)); bottom: max(20px,env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 22px; text-shadow: 0 2px 5px #211b15; }
.drive-status output { display: block; font-variant-numeric: tabular-nums; font-size: clamp(1.65rem,3.5vw,3.4rem); font-weight: 900; line-height: .9; }
.drive-status span { margin-top: 5px; }
.drive-status .clean output { font-size: 1.45rem; color: var(--amber); }
.restart { position: absolute; right: max(22px,env(safe-area-inset-right)); bottom: max(20px,env(safe-area-inset-bottom)); }
[data-phase="ready"] :is(.drive-status,.restart), [data-phase="finished"] :is(.drive-status,.restart) { display: none; }
.feedback { position: absolute; top: max(78px,calc(env(safe-area-inset-top) + 65px)); left: 50%; transform: translateX(-50%); padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: #172725ed; text-align: center; width: max-content; max-width: 85%; }
.feedback strong, .feedback span { display: block; }
.feedback strong { color: #edbd87; font-weight: 850; }
.feedback[data-type="clean"] strong { color: #d0e8ab; }
.feedback span { margin-top: 2px; color: #f2e4d1; font-size: .81rem; }
.result { inset: 50% auto auto 50%; transform: translate(-50%,-45%); width: min(480px,82vw); padding: clamp(16px,3vw,33px); background: #192826f5; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 15px 60px #19232291; }
.result h2 { font-size: clamp(1.8rem,5vw,3.4rem); }
.result dl { display: flex; gap: 2rem; margin: 1.15rem 0 .45rem; }
.result dt { font-size: .75rem; letter-spacing: .12em; color: #ddc7a9; font-weight: 850; }
.result dd { font-variant-numeric: tabular-nums; font-size: 1.65rem; font-weight: 850; margin: 0; }
.result .description { margin: .65rem 0 1rem; max-width: 40ch; font-size: .95rem; }
.result kbd { margin-left: .5rem; }
.rotate, .touch-controls { display: none; }
.error { position: absolute; inset: auto 1rem 1rem; padding: 1rem; background: #202927; }

@media (pointer: coarse) {
  .touch-guide { display: block; font-size: .84rem; margin: .7rem 0 0; }
  .keyboard-guide, .restart kbd, .result kbd { display: none; }
  [data-phase="running"] .touch-controls { display: flex; }
  .touch-controls { position: absolute; inset: auto max(13px,env(safe-area-inset-right)) max(10px,env(safe-area-inset-bottom)) max(13px,env(safe-area-inset-left)); justify-content: space-between; align-items: end; pointer-events: none; user-select: none; }
  .steering, .pedals button { pointer-events: auto; touch-action: none; }
  .steering { width: clamp(126px,23vw,185px); height: clamp(62px,22vh,115px); display: flex; justify-content: space-between; align-items: center; padding: 0 12px; border-radius: 14px; background: #172725a8; border: 1px solid #fff1da88; position: relative; font-size: 1.35rem; }
  .steering i { position: absolute; left: 50%; top: 50%; width: 31px; aspect-ratio: 1; margin: -15.5px; border-radius: 50%; background: #f9e6c9a8; border: 1px solid #fff2df; pointer-events: none; }
  .pedals { display: flex; align-items: end; gap: 7px; }
  .pedals button { min-width: 64px; height: clamp(55px,17vh,86px); border-radius: 12px; border: 1px solid #fff1da88; background: #172725cb; font-size: .79rem; font-weight: 850; text-transform: uppercase; }
  .pedals #throttle { min-width: 82px; height: clamp(67px,22vh,110px); background: #fcb05be6; color: #222723; }
  .pedals button.is-held { filter: brightness(1.28); box-shadow: inset 0 0 0 2px #fff5d9; }
  .drive-status { left: 50%; transform: translateX(-50%); gap: 15px; bottom: max(13px,env(safe-area-inset-bottom)); }
  .drive-status span { white-space: nowrap; font-size: 10px; }
  .drive-status .clean output { font-size: 1.25rem; }
  .restart { bottom: auto; top: max(50px,calc(env(safe-area-inset-top) + 40px)); right: max(13px,env(safe-area-inset-right)); min-height: 34px; }
}
@media (max-height: 535px) {
  .top { inset: max(8px,env(safe-area-inset-top)) max(13px,env(safe-area-inset-right)) auto max(13px,env(safe-area-inset-left)); }
  .brand { font-size: 12px; gap: 6px; }
  .brand i { width: 23px; height: 23px; }
  .settings button { min-height: 34px; }
  .timing { min-width: 174px; padding: 5px 11px 9px; gap: 8px; }
  .timing span { font-size: 9px; }
  .timing output { font-size: 16px; min-width: 60px; margin-top: 3px; }
  .progress { bottom: 3px; }
  .intro { transform: translateY(-40%); }
  h1 { font-size: clamp(2.7rem,11.6vh,4.25rem); }
  .description { margin: .7rem 0; font-size: .95rem; }
  .primary { min-height: 41px; padding: .38rem .8rem; }
  .mode { margin-bottom: .42rem; }
  .feedback { top: max(54px,calc(env(safe-area-inset-top) + 48px)); }
  .result dl { margin-top: .7rem; }
}
@media (pointer: coarse) and (orientation: portrait) {
  .rotate { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center; background: #192826; padding: 2rem; }
  .rotate strong { color: var(--amber); font-size: 1.8rem; }
  .intro, .top, .result, .feedback, .drive-status, .restart, .touch-controls { visibility: hidden; }
}
