@import url("https://fonts.googleapis.com/css2?family=Alegreya+SC:wght@500;700;800&family=Onest:wght@400;500;600;700&display=swap");

:root {
  --font-display: "Alegreya SC", Georgia, serif;
  --font-heading: var(--font-display);
  --font-text: "Onest", system-ui, sans-serif;
  --rose: oklch(from var(--coin-2) 0.58 0.13 h);
  --cream: oklch(0.975 0.02 88);
  --shade-ink: oklch(0.24 0.035 150);
}

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { background: var(--shade-ink); -webkit-tap-highlight-color: transparent; }
.k-app { min-height: 100dvh; }
/* the stage is pinned to the window itself, so nothing (focus, a tall panel, the mobile address bar) can shrink it */
.stage { position: fixed; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; cursor: grab; }
#gl:active { cursor: grabbing; }

.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

kbd {
  display: inline-grid; place-items: center;
  min-width: 1.75em; height: 1.75em; padding: 0 0.4em;
  font: 600 0.78rem/1 var(--font-text);
  color: var(--ink-1);
  background: var(--surface-1);
  border: 1.5px solid var(--outline);
  border-radius: 7px;
  box-shadow: 0 2px 0 var(--outline);
}
kbd.wide { min-width: 3.6em; }

/* ---------------------------------------------------------------- title screen */
.intro {
  position: absolute; inset: 0; z-index: 3;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  justify-items: center;
  padding: max(var(--s-7), env(safe-area-inset-top)) var(--s-5) max(var(--s-4), env(safe-area-inset-bottom));
  pointer-events: none;
  transition: opacity 600ms var(--ease-out), transform 600ms var(--ease-out), visibility 0s linear 600ms;
}
.intro::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120% 60% at 50% 0%, oklch(0.2 0.04 250 / 0.28), transparent 60%),
    linear-gradient(to top, oklch(0.2 0.03 150 / 0.45), transparent 32%);
}
.intro__top { text-align: center; grid-row: 1; }
.intro__card { grid-row: 3; align-self: end; }
.intro__foot { grid-row: 4; }
.intro__title {
  margin: 0;
  font: 800 clamp(3.4rem, 10.5vw, 9.5rem)/0.86 var(--font-display);
  letter-spacing: 0.035em;
  color: var(--cream);
  text-shadow: 0 2px 0 oklch(0.3 0.04 150 / 0.35), 0 10px 40px oklch(0.22 0.05 160 / 0.45);
  text-wrap: balance;
}
.intro__sub {
  margin: var(--s-3) 0 0;
  font: 500 clamp(1rem, 1.6vw, 1.3rem)/1.3 var(--font-text);
  color: var(--cream);
  /* a soft dark wash behind the line so it reads on the pale noon sky as well as at night */
  display: inline-block;
  padding: 7px 16px;
  border-radius: var(--r-2);
  background: oklch(0.26 0.04 155 / 0.55);
}
.intro__card {
  pointer-events: auto;
  width: min(640px, 100%);
  padding: var(--s-5) var(--s-5) var(--s-4);
  background: var(--surface-1);
  background-image: var(--panel-image, none);
  border: var(--outline-w) solid var(--outline);
  border-radius: var(--r-4);
  box-shadow: 0 18px 50px oklch(0.2 0.04 150 / 0.35);
  color: var(--ink-1);
}
.intro__line { margin: 0 0 var(--s-4); font-size: 1.05rem; line-height: 1.5; color: var(--ink-1); text-wrap: pretty; }
.intro__row { display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap; }
.intro__go { min-width: 9.5rem; font-size: 1.15rem; letter-spacing: 0.01em; }
.intro__keys { margin: 0; display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; color: var(--ink-2); font-size: 0.92rem; }
.intro__keys kbd + kbd { margin-left: 0.05rem; }
.intro__err { margin: var(--s-3) 0 0; color: var(--bad-ink); font-weight: 600; }
.intro__foot { margin: var(--s-3) 0 0; font-size: 0.85rem; color: var(--cream); padding: 4px 12px; border-radius: var(--r-2); background: oklch(0.26 0.04 155 / 0.6); width: fit-content; }
body[data-state=driving] .intro { opacity: 0; visibility: hidden; transform: translateY(12px); }

/* ---------------------------------------------------------------- HUD */
.hud { transition: opacity 400ms var(--ease-out), visibility 0s; }
body[data-state=intro] .hud,
body[data-photo=on] .hud { opacity: 0; visibility: hidden; transition: opacity 250ms var(--ease-out), visibility 0s linear 250ms; }
body[data-state=intro] .hud > * { pointer-events: none; }

.hud__mark {
  display: flex; align-items: center; gap: var(--s-2);
  padding: 6px 14px 6px 6px;
  background: var(--surface-1);
  border: var(--outline-w) solid var(--outline);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
  font: 700 1.15rem/1 var(--font-display);
  letter-spacing: 0.03em;
  color: var(--ink-1);
}
.hud__mark img { border-radius: 8px; display: block; }

.hud__tools { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; justify-content: flex-end; }
.tools { display: flex; gap: var(--s-2); }
.tod { box-shadow: var(--shadow-1); margin: 0; }
.tod label { gap: 6px; }
.tod label .ico { width: 17px; height: 17px; }
.tool { box-shadow: var(--shadow-1); }
.tool--more { display: none; }
.tool .ico--off { display: none; }
.tool[aria-pressed=false] .ico--on { display: none; }
.tool[aria-pressed=false] .ico--off { display: block; }
body[data-cam=hood] [data-action=camera] { background: var(--highlight); }

/* the controls card */
.hint {
  width: 300px;
  padding: var(--s-4);
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out), visibility 0s;
}
.hint[data-open=false] { opacity: 0; transform: translateY(8px); visibility: hidden; pointer-events: none; transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out), visibility 0s linear 200ms; }
.hint__head { display: flex; align-items: center; justify-content: space-between; margin: -4px -6px var(--s-2) 0; }
.hint__title { margin: 0; font: 700 1.25rem/1 var(--font-display); letter-spacing: 0.02em; }
.hint__list { margin: 0; display: grid; gap: 7px; }
.hint__list > div { display: grid; grid-template-columns: 5.4rem 1fr; align-items: center; gap: var(--s-3); }
.hint__list dt { display: flex; gap: 4px; }
.hint__list dd { margin: 0; font-size: 0.9rem; color: var(--ink-1); }
.hint__drag { font-weight: 600; font-size: 0.85rem; color: var(--ink-2); padding-left: 2px; }
.hint__phone { margin: 0; padding-left: 1.1rem; display: grid; gap: 4px; font-size: 0.92rem; }

/* the enamel speedometer */
.speedo { position: relative; width: 188px; height: 188px; filter: drop-shadow(0 10px 24px oklch(0.2 0.04 150 / 0.4)); }
.speedo__dial { width: 100%; height: 100%; display: block; }
.speedo__bezel { fill: var(--inverse); stroke: oklch(from var(--inverse) calc(l + 0.12) c h); stroke-width: 2; }
.speedo .tk { stroke: var(--ink-2); stroke-width: 1.4; stroke-linecap: round; }
.speedo .tk--major { stroke: var(--ink-1); stroke-width: 2.6; }
.speedo .tk-num { font: 600 13px var(--font-text); fill: var(--ink-1); text-anchor: middle; font-variant-numeric: tabular-nums; }
.speedo__rpm-track { fill: none; stroke: oklch(from var(--ink-1) l c h / 0.12); stroke-width: 5; stroke-linecap: round; }
.speedo__rpm { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; }
.speedo__rpm.hot { stroke: var(--rose); }
.speedo__needle path { fill: var(--rose); }
.speedo__needle circle { fill: var(--inverse); stroke: var(--cream); stroke-width: 2; }
.speedo__read {
  position: absolute; left: 50%; top: 57%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; line-height: 1;
}
.speedo__num { font: 800 1.9rem/1 var(--font-display); color: var(--ink-1); font-variant-numeric: tabular-nums lining-nums; }
.speedo__unit { font-size: 0.7rem; font-weight: 600; color: var(--ink-2); margin-top: 2px; }
.speedo__gear {
  position: absolute; left: 50%; bottom: 5px; transform: translateX(-50%);
  min-width: 26px; height: 22px; padding: 0 6px; display: grid; place-items: center;
  font: 700 0.85rem/1 var(--font-text); color: var(--on-inverse);
  background: oklch(from var(--inverse) calc(l + 0.08) c h);
  border-radius: 6px;
}

/* ---------------------------------------------------------------- phone controls */
.touch { display: none; }
@media (pointer: coarse), (max-width: 760px) {
  .touch {
    position: absolute; inset: auto 0 0 0; z-index: 3;
    display: flex; justify-content: space-between; align-items: flex-end;
    padding: 0 max(var(--s-4), env(safe-area-inset-right)) max(var(--s-4), env(safe-area-inset-bottom)) max(var(--s-4), env(safe-area-inset-left));
    pointer-events: none;
    transition: opacity 300ms var(--ease-out);
  }
  body[data-state=intro] .touch, body[data-photo=on] .touch { opacity: 0; visibility: hidden; }
  .touch > * { pointer-events: auto; }
  .touch__wheel { width: 134px; height: 134px; touch-action: none; transform: rotate(var(--rot, 0deg)); filter: drop-shadow(0 8px 18px oklch(0.2 0.04 150 / 0.45)); }
  .touch__wheel svg { width: 100%; height: 100%; display: block; }
  .touch__wheel .rim { fill: none; stroke: var(--surface-1); stroke-width: 13; }
  .touch__wheel .hub { fill: var(--inverse); stroke: var(--surface-1); stroke-width: 3; }
  .touch__wheel .spoke { stroke: var(--surface-1); stroke-width: 9; stroke-linecap: round; }
  .touch__wheel .mark { stroke: var(--rose); stroke-width: 8; stroke-linecap: round; }
  .touch__right { display: flex; flex-direction: column; align-items: flex-end; gap: var(--s-3); }
  .touch__pedals { display: flex; align-items: flex-end; gap: var(--s-3); }
  .touch__pedal {
    display: grid; place-items: end center; padding-bottom: 10px;
    border-radius: var(--r-3);
    background: repeating-linear-gradient(to bottom, var(--surface-1) 0 10px, var(--surface-3) 10px 13px);
    border: var(--outline-w) solid var(--outline);
    box-shadow: 0 5px 0 oklch(from var(--outline) calc(l - 0.15) c h), 0 10px 22px oklch(0.2 0.04 150 / 0.4);
    font: 700 0.8rem/1 var(--font-text); color: var(--ink-1);
    touch-action: none;
    transition: transform 80ms var(--ease-out), box-shadow 80ms var(--ease-out);
  }
  .touch__pedal span { background: var(--surface-1); padding: 3px 6px; border-radius: 5px; }
  .touch__pedal--brake { width: 78px; height: 74px; }
  .touch__pedal--gas { width: 62px; height: 118px; }
  .touch__pedal[data-down] { transform: translateY(4px); box-shadow: 0 1px 0 oklch(from var(--outline) calc(l - 0.15) c h), 0 4px 10px oklch(0.2 0.04 150 / 0.4); background: var(--highlight); }
  .touch__small {
    height: 36px; padding: 0 14px; border-radius: 10px;
    font: 700 0.8rem/1 var(--font-text); color: var(--on-inverse);
    background: var(--inverse); border: var(--outline-w) solid oklch(from var(--inverse) calc(l + 0.15) c h);
    touch-action: none;
  }
  .touch__small[data-down] { background: var(--rose); }

  /* compact HUD */
  .hud__mark span { display: none; }
  .hud__mark { padding: 5px; }
  .tod label span { display: none; }
  .tod label { padding-inline: 9px; }
  .tools { gap: 6px; }
  .tools > .tool[data-action=camera], .tools > .tool[data-action=sound], .tools > .tool[data-action=hint-open] { display: none; }
  .tool--more { display: inline-flex; }
  .hud__tools { flex-wrap: nowrap; }
  /* the dial gets its own slot above the steering wheel, clear of the pedals */
  .speedo {
    position: absolute;
    /* out of the HUD's corner cell, so the offsets below measure from the screen, not from that cell */
    grid-area: auto; justify-self: auto; align-self: auto;
    left: calc(max(var(--s-4), env(safe-area-inset-left)) + 19px);
    bottom: calc(max(var(--s-4), env(safe-area-inset-bottom)) + 134px + var(--s-3));
    width: 96px; height: 96px;
  }
  .speedo .tk-num { display: none; }
  .speedo__num { font-size: 1.35rem; }
  .speedo__unit { font-size: 0.6rem; }
  .speedo__read { top: 56%; }
  .speedo__gear { bottom: 4px; height: 18px; min-width: 22px; font-size: 0.72rem; }
  .hint { position: absolute; top: calc(max(var(--s-4), env(safe-area-inset-top)) + 58px); left: max(var(--s-4), env(safe-area-inset-left)); width: min(300px, calc(100vw - 32px)); }
}
/* the start card keeps clear of the corner bubble at the bottom left */
@media (min-width: 761px) {
  .intro__card, .intro__foot { justify-self: end; }

}
@media (max-width: 760px) {
  .intro { padding-bottom: calc(max(var(--s-4), env(safe-area-inset-bottom)) + 120px); }
  .intro__foot { display: none; }
  .intro__line { font-size: 1rem; margin-bottom: var(--s-3); }
  .intro__line--long { display: none; }
  .intro__card { padding: var(--s-4); }
  .intro__go { width: 100%; }
}
@media (min-width: 761px) { .intro__line--short { display: none; } }
@media (max-width: 420px) {
  .tools .tool { width: 38px; height: 38px; }
  .tod label { padding-inline: 7px; }
  .intro__title { font-size: clamp(3rem, 15vw, 4.4rem); }
}

/* ---------------------------------------------------------------- rollover and photo mode */
.flip {
  position: absolute; left: 50%; top: 58%; transform: translate(-50%, 8px);
  z-index: 4; display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap; justify-content: center;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-5);
  opacity: 0; visibility: hidden;
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out), visibility 0s linear 250ms;
}
.flip__text { margin: 0; font-weight: 600; }
.flip kbd { margin-left: 6px; color: var(--ink-1); }
body[data-state=driving][data-flip=on][data-photo=off] .flip { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }

.photo-exit {
  position: absolute; top: max(var(--s-4), env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 5; gap: 8px;
  opacity: 0; visibility: hidden;
  transition: opacity 300ms var(--ease-out), visibility 0s linear 300ms;
}
.photo-exit kbd { height: 1.5em; font-size: 0.7rem; }
body[data-photo=on] .photo-exit { opacity: 1; visibility: visible; transition-delay: 0s; }
body[data-photo=on] .photo-exit[data-dim=true]:not(:hover):not(:focus-visible) { opacity: 0.22; }

@media (prefers-reduced-motion: reduce) {
  .intro, .hud, .hint, .flip, .photo-exit { transition-duration: 1ms; }
}
