:root {
  color-scheme: dark;
  --bg: #080d0c;
  --panel: #111a18;
  --panel-2: #18231f;
  --line: #34453e;
  --text: #ecf7ef;
  --muted: #91a69b;
  --accent: #88e05d;
  --accent-2: #d4ff9c;
  --danger: #ff776f;
  --warning: #ffd36a;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 10%, #16251f 0, var(--bg) 46%),
    var(--bg);
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }

#app {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
}

.game-shell {
  width: min(100%, 540px);
  display: grid;
  gap: 7px;
}

.game-topbar,
.game-footer {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
}

.brand { color: var(--accent-2); }

.canvas-frame {
  position: relative;
  margin: 0 auto;
  width: min(calc((100dvh - 82px) * .75), 100%);
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #101714;
  box-shadow: 0 0 0 1px #030504, 0 14px 36px rgba(0, 0, 0, .36);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #111916;
  touch-action: none;
}

.flash-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: #fff;
}

.flash-layer.flash { animation: flash .18s steps(2, end); }
@keyframes flash { 50% { opacity: .45; } }

.icon-button,
.text-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  border-radius: 4px;
  cursor: pointer;
}
.icon-button { width: 30px; height: 25px; }
.text-button { padding: 4px 7px; font-size: 10px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 5, .78);
  backdrop-filter: blur(4px);
}
.overlay.is-visible { display: grid; }

.panel {
  width: min(100%, 390px);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  text-align: center;
}

.title-panel h1 {
  margin: 6px 0;
  color: var(--accent-2);
  font-size: clamp(40px, 12vw, 66px);
  line-height: .84;
  letter-spacing: -.08em;
  text-shadow: 3px 3px 0 #234c2c;
}

.eyebrow,
.subtitle,
.fineprint {
  margin: 0;
  letter-spacing: .12em;
}
.eyebrow { color: var(--accent); font-size: 11px; }
.subtitle { margin-top: 13px; color: var(--warning); font-size: 12px; }
.fineprint { margin-top: 16px; color: var(--muted); font-size: 9px; line-height: 1.5; }

.panel h2 {
  margin: 8px 0 18px;
  font-size: 28px;
  letter-spacing: -.04em;
}

.car-mark {
  height: 44px;
  margin: 20px auto 16px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 3px;
}
.car-mark .body {
  width: 92px;
  height: 24px;
  border: 4px solid var(--text);
  border-top-left-radius: 28px;
  border-top-right-radius: 18px;
  transform: skewX(-9deg);
}
.car-mark .wheel {
  width: 17px;
  height: 17px;
  margin-bottom: -5px;
  border: 4px solid var(--accent);
  border-radius: 50%;
}

.primary-button,
.secondary-button,
.choice-button {
  width: 100%;
  border-radius: 5px;
  cursor: pointer;
}
.primary-button,
.secondary-button {
  min-height: 45px;
  margin-top: 9px;
  padding: 10px 14px;
  font-weight: 700;
  letter-spacing: .06em;
}
.primary-button {
  border: 1px solid var(--accent-2);
  color: #071008;
  background: var(--accent);
}
.secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: transparent;
}

.howto-list {
  display: grid;
  gap: 8px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  text-align: left;
}
.howto-list li {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, .025);
}
.howto-list strong { color: var(--accent-2); font-size: 12px; }
.howto-list span { color: var(--muted); font-size: 11px; line-height: 1.45; }

.choice-panel { width: min(100%, 520px); }
.choice-list { display: grid; gap: 9px; }
.choice-button {
  min-height: 82px;
  padding: 11px 13px;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 11px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #0d1512;
  text-align: left;
}
.choice-button:hover,
.choice-button:focus-visible { border-color: var(--accent); }
.choice-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--accent-2);
  background: var(--panel-2);
  font-size: 18px;
}
.choice-copy { display: grid; gap: 4px; }
.choice-copy strong { color: var(--accent-2); font-size: 12px; }
.choice-copy small { color: var(--muted); font-size: 10px; line-height: 1.45; }
.choice-level { color: var(--warning); font-size: 11px; white-space: nowrap; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 18px;
}
.result-grid div {
  padding: 12px 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .025);
}
.result-grid dt { color: var(--muted); font-size: 10px; }
.result-grid dd { margin: 5px 0 0; color: var(--accent-2); font-size: 22px; }

.debug-panel {
  position: fixed;
  z-index: 50;
  right: 8px;
  bottom: 8px;
  width: 132px;
  padding: 8px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--danger);
  background: rgba(10, 10, 10, .92);
  font-size: 9px;
}
.debug-panel button {
  padding: 5px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
}

@media (max-width: 520px) {
  #app { padding-inline: 4px; }
  .game-shell { width: 100%; }
  .panel { padding: 19px; }
  .choice-button { grid-template-columns: 40px 1fr; }
  .choice-level { grid-column: 2; }
}
