:root {
  --bg: #111522;
  --panel: rgba(10, 12, 24, 0.9);
  --ink: #f4f4f4;
  --accent: #ffd23f;
  --red: #e8443a;
  --pad: #2a3048;
  --pad-on: #4a5480;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "DotGothic16", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 16px max(8px, env(safe-area-inset-bottom));
}

/* 240x320 を整数倍に近い大きさで。タッチ端末はパッドの分だけ高さを空ける */
.stage {
  position: relative;
  --h: min(calc(100dvh - 60px), calc((100vw - 32px) * 4 / 3), 960px);
  width: calc(var(--h) * 3 / 4);
  height: var(--h);
}

@media (pointer: coarse) {
  .stage { --h: min(calc(100dvh - 150px), calc((100vw - 32px) * 4 / 3), 960px); }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  border-radius: 4px;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }

.panel {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 6px;
  padding: 18px 16px;
  text-align: center;
  line-height: 1.5;
}
.panel[hidden] { display: none; }

h1 {
  margin: 0 0 8px;
  font-size: clamp(26px, 7vw, 40px);
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--red);
  letter-spacing: 0.08em;
  line-height: 1.2;
}
h2 { margin: 0 0 12px; font-size: clamp(20px, 5.5vw, 28px); color: var(--accent); }

.lead { margin: 0 0 10px; font-size: 16px; }
.rules { list-style: none; padding: 0; margin: 0 0 10px; text-align: left; font-size: 13px; }
.rules li { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0; }
.dot { flex: none; width: 10px; height: 10px; margin-top: 5px; }
.dot.heart { background: #ff5fa2; }
.dot.wall { background: repeating-linear-gradient(90deg, #fff 0 3px, #e8443a 3px 6px); }
.dot.car { background: #ffd23f; }
.keys, .tip { margin: 6px 0; font-size: 12px; color: #c8cbe0; }
.hi { margin: 10px 0 0; font-size: 13px; color: #c8cbe0; }
.result { margin: 4px 0; font-size: 20px; }
.result.small { font-size: 13px; color: #c8cbe0; }

.btn {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 12px;
  font: inherit;
  font-size: 20px;
  color: #111;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 4px 0 #b08a12;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b08a12; }
.btn.sub { background: #c8cbe0; box-shadow: 0 4px 0 #7a7e98; font-size: 16px; }

.car-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.car-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  font: inherit;
  color: var(--ink);
  text-align: left;
  background: #1c2136;
  border: 3px solid #3a4160;
  border-radius: 8px;
  cursor: pointer;
}
.car-opt.on { border-color: var(--accent); background: #2b3150; box-shadow: 0 0 0 2px rgba(255, 210, 63, 0.35); }
.car-pic { flex: none; width: 30px; height: 45px; image-rendering: pixelated; }
.car-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.car-txt b { font-size: 15px; font-weight: normal; color: var(--accent); }
.car-txt small { font-size: 10px; color: #c8cbe0; margin-bottom: 3px; }
.stat { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-size: 10px; white-space: nowrap; }
.stat-l { color: #9aa3cc; }
.stat-b { color: #ff8a5a; font-size: 8px; letter-spacing: -1px; }
@media (max-width: 420px) {
  .car-opt { gap: 5px; padding: 6px 4px; }
  .car-pic { width: 20px; height: 30px; }
  .stat { font-size: 9px; }
  .stat-b { font-size: 7px; }
}
.stat-b i { font-style: normal; color: #3a4160; }
.link-btn {
  margin-top: 8px;
  font: inherit;
  font-size: 13px;
  color: #9aa3cc;
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

.corner {
  position: absolute;
  bottom: 6px;
  right: 4px;
  display: flex;
  gap: 6px;
}
.mini {
  width: 34px;
  height: 34px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  cursor: pointer;
}
.mini.off { opacity: 0.45; text-decoration: line-through; }

.pad {
  display: none;
  width: 100%;
  max-width: 520px;
  justify-content: space-between;
  gap: 12px;
}
.pad-group { display: flex; gap: 10px; }
.pad-btn {
  width: 76px;
  height: 76px;
  font-family: "Press Start 2P", monospace;
  font-size: 24px;
  color: var(--ink);
  background: var(--pad);
  border: 3px solid #6a7398;
  border-radius: 14px;
  touch-action: none;
}
.pad-btn.gear { font-size: 13px; border-radius: 50%; }
.pad-btn.low { border-color: #4fb0ff; }
.pad-btn.high { border-color: var(--red); }
.pad-btn.on { background: var(--pad-on); transform: scale(0.95); }

.touch-only { display: none; }

@media (pointer: coarse) {
  .pad { display: flex; }
  .touch-only { display: block; }
  .pc-only { display: none; }
  .back { display: none; }
}

.back { margin: 0; font-size: 13px; }
.back a { color: #8f96bb; }
