:root {
  color-scheme: dark;
  --milk: #f0ecdf;
  --ink: #20211d;
  --clay: #c87564;
  --dim: #b9b6ac;
  --gold: #eac38b;
  --line: #ffffff24;
  --panel: #1d211eed;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--milk);
  background: #191a18;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% -20%, #4a4035 0, #262622 42%, #191a18 73%);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; font: inherit; color: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
a { color: inherit; }
p { margin: 0; }

.game-shell {
  container-type: inline-size;
  z-index: 0;
  position: relative;
  margin: 0 auto;
  width: min(100%, 520px);
  height: 100vh;
  height: 100dvh;
  max-height: 980px;
  min-height: 490px;
  overflow: hidden;
  background: var(--ink);
}

.map-view {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(146px, 0.87fr) minmax(150px, 1.13fr) auto;
  background: #20211d;
}

.topbar {
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 15px 8px;
  gap: 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -.035em;
}

.brand img { flex: 0 0 32px; border-radius: 50%; }

.sound, .icon-button {
  min-height: 39px;
  min-width: 39px;
  padding: 4px 10px;
  background: #1a1c19dd;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 650;
}

.sound:hover, .icon-button:hover, .secondary:hover { background: #3a3a31; }
.sound-symbol { display: inline-block; position: relative; line-height: 1; font-size: 19px; vertical-align: -2px; }
.sound.off .sound-symbol { color: #aaa69b; }
.sound.off .sound-symbol::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 47%;
  transform: rotate(-44deg);
  height: 1px;
  background: var(--milk);
}

.hero {
  position: relative;
  isolation: isolate;
  min-height: 0;
  overflow: hidden;
  margin: 0 14px 10px;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: #30312c;
}

.hero::before {
  content: "";
  position: absolute;
  z-index: -2;
  inset: 0;
  background: linear-gradient(90deg,#1e201dec 0%,#26241eaf 42%,#24241f4a 100%), url("./media/scene.jpg") center 50%/cover;
}

.hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(0deg,#1f211ddd,transparent 53%);
}

.hero-copy {
  position: absolute;
  z-index: 1;
  inset: auto 0 13px 14px;
  pointer-events: none;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(40px, 12.8cqw, 66px);
  font-weight: 950;
  line-height: .83;
  letter-spacing: -.088em;
  text-transform: uppercase;
  text-shadow: 0 2px 14px #0008;
}

.hero p {
  width: min(58%, 224px);
  color: #e2dccf;
  font-size: 13px;
  line-height: 1.3;
  font-weight: 620;
  text-shadow: 0 1px 4px #111;
}

.mascot {
  position: absolute;
  z-index: 0;
  right: -5.8%;
  top: 50%;
  transform: translateY(-47%);
  height: 111%;
  max-width: 65%;
  object-fit: contain;
  filter: drop-shadow(1px 0 #eee3ce) drop-shadow(-1px 0 #eee3ce) drop-shadow(0 -1px #eee3ce) drop-shadow(0 6px 12px #0709069c);
}

.route {
  position: relative;
  min-height: 0;
  margin: 0 14px;
  border: 1px solid var(--line);
  border-radius: 23px;
  isolation: isolate;
  background: #272c28;
  overflow: hidden;
}

#route-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.stops { margin: 0; padding: 0; list-style: none; }
.stops li { position: absolute; top: var(--top); left: var(--left); transform: translateY(-50%); }
.stops li:nth-child(1) { --left: 11%; --top: 80%; }
.stops li:nth-child(2) { --left: 43%; --top: 48%; }
.stops li:nth-child(3) { --left: 14%; --top: 17%; }

.stop {
  display: flex;
  align-items: center;
  text-align: left;
  gap: 6px;
  border: 0;
  border-radius: 14px;
  background: none;
  padding: 0;
}

.stop-pin {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid #b3a994;
  color: var(--milk);
  background: #252821;
  box-shadow: 0 3px 12px #131711c9;
  font-size: 19px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.stop-copy {
  display: grid;
  gap: 2px;
  padding: 5px 9px 5px 8px;
  border: 1px solid #ede2cf33;
  border-radius: 9px;
  background: #1b201bee;
  box-shadow: 0 2px 7px #1317118a;
  white-space: nowrap;
}

.stop strong { font-size: clamp(11px, 3.2cqw, 14px); letter-spacing: -.035em; }
.stop small { color: #c8b9a1; font-size: 10px; font-weight: 620; }
.stop[aria-pressed="true"] .stop-pin { color: #242017; background: var(--gold); border-color: #ffe0a5; box-shadow: 0 0 15px #f6c1727a; }
.stop[aria-pressed="true"] .stop-copy { border-color: #f1c38588; }
.stop[aria-disabled="true"] .stop-pin { background: #31342e; color: #afad9e; border-color: #787971; }
.stop[aria-disabled="true"] .stop-copy { background: #232723ed; }
.stop[aria-disabled="true"] { cursor: default; }

.map-actions {
  display: grid;
  gap: 8px;
  padding: 9px 14px max(12px, env(safe-area-inset-bottom));
}

.map-hint { min-height: 1em; text-align: center; font-size: 11px; color: #cbc3b3; }
.primary, .secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  min-height: 47px;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 850;
  text-decoration: none;
}

.primary {
  padding: 8px 14px;
  border: 1px solid #fff1d6;
  background: var(--milk);
  color: #22221c;
}
.primary:hover { background: #fff5df; }
.primary:active, .secondary:active { transform: translateY(1px); }
.button-arrow { font-size: 23px; line-height: 1; font-weight: 480; }

.secondary {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: #262821;
}

.race-view, #race-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#race-canvas { touch-action: none; user-select: none; outline: none; background: #15191f; }
.race-top { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 8px; place-items: start stretch; pointer-events: none; }
.hud { flex: 1; padding: 7px 10px 8px; border: 1px solid var(--line); border-radius: 13px; background: #20211deb; font-variant-numeric: tabular-nums; }
.hud-numbers { display: flex; justify-content: space-between; gap: 5px; }
.hud small { display: block; color: #d5ccbb; font-size: 10px; font-weight: 680; }
.hud strong { display: block; font-size: 20px; line-height: 1.15; letter-spacing: -.055em; }
.rank-total { color: var(--dim); font-size: 12px; }
.hud-time { text-align: right; }
.bar { margin-top: 7px; height: 3px; border-radius: 6px; background: #6b6757; }
.bar span { display: block; width: 100%; height: 100%; transform: scaleX(0); transform-origin: left; background: var(--gold); border-radius: 6px; }
.race-actions { display: flex; gap: 5px; align-self: flex-start; pointer-events: auto; }
.race-actions button { padding: 5px; min-height: 42px; min-width: 42px; font-size: 19px; }
.count { position: absolute; inset: 29% 7% auto; text-align: center; font-size: clamp(42px, 15cqw, 82px); font-weight: 950; line-height: 1; letter-spacing: -.08em; text-shadow: 0 5px 16px #111; pointer-events: none; }
.race-bottom { position: absolute; left: 11px; right: 11px; bottom: max(10px, env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 5px; pointer-events: none; }
.charge-panel { min-width: 162px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 12px; background: #20211de8; }
.charge-copy { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 11px; }
.charge-copy span { color: var(--gold); font-variant-numeric: tabular-nums; }
.cells { display: grid; margin-top: 4px; gap: 3px; grid-template-columns: repeat(5, 1fr); }
.cells i { height: 5px; border-radius: 2px; background: #6e6658; }
.cells i.filled { background: #f6cc88; box-shadow: 0 0 6px #ffd59766; }
.race-view.boost .charge-panel { border-color: #ffdd9b; box-shadow: 0 0 19px #e7a54180; }
.input-help, .playing { font-size: 11px; text-align: center; text-shadow: 0 1px 4px #121313; }
.input-help { width: fit-content; padding: 4px 8px; border-radius: 7px; background: #22241fea; }
.playing { color: #f5ead5; font-weight: 620; }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 14px; z-index: 2; background: #131713b8; backdrop-filter: blur(5px); }
.dialog { width: 100%; max-width: 365px; display: grid; gap: 11px; padding: 17px; border: 1px solid #e1cfac56; border-radius: 24px; background: var(--panel); box-shadow: 0 24px 54px #0008; }
.dialog h2 { margin: 0; font-size: clamp(31px, 10cqw, 52px); line-height: .99; font-weight: 920; letter-spacing: -.075em; }
.dialog p { color: #ddd2bf; font-size: 13px; line-height: 1.35; }
.dialog .result-track { color: var(--gold); font-size: 12px; font-weight: 700; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 2px 0 0; }
.result-stats div { border: 1px solid var(--line); border-radius: 11px; padding: 7px 8px; }
.result-stats dt { font-size: 11px; color: var(--dim); }
.result-stats dd { margin: 0; color: var(--milk); font-weight: 850; font-size: 21px; font-variant-numeric: tabular-nums; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.dev { position: absolute; top: 88px; left: 5px; z-index: 3; padding: 4px; background: #161b18e6; color: #d1ecd9; font: 11px monospace; pointer-events: none; }

@media (min-width: 610px) {
  .game-shell {
    width: min(calc((100dvh - 28px) * .5625), 520px);
    min-width: 326px;
    height: calc(100dvh - 28px);
    border-radius: 29px;
    border: 1px solid #f0dec73d;
    box-shadow: 0 26px 80px #0c0d0a9c;
  }
}

@media (max-height: 640px) {
  .map-view { grid-template-rows: auto minmax(135px, .88fr) minmax(155px, 1.12fr) auto; }
  .hero-copy { bottom: 9px; }
  .hero p { font-size: 11px; }
  .stop-pin { width: 33px; height: 33px; flex-basis: 33px; font-size: 16px; }
  .map-actions { gap: 5px; }
  .primary, .secondary { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0ms !important; transition-duration: 0ms !important; }
}
