:root {
  --bg: #0b131b;
  --panel: #121d28;
  --panel-2: #182634;
  --line: #263a4d;
  --text: #e8eef4;
  --muted: #8da2b5;
  --accent: #f2a93b;
  --accent-2: #2bb3a3;
  --danger: #e5533d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- game stage ---------- */
#stage {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  background: #000;
  cursor: none;
}
#stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#stage.classic { width: min(100vw, calc(100vh * 7 / 9)); height: min(100vh, calc(100vw * 9 / 7)); }
#stage.classic #game { image-rendering: pixelated; }
#stage.classic #hud { display: none; }
#crt {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.2) 3px, rgba(0,0,0,.2) 4px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 58%, rgba(0,0,0,.5) 100%);
}
#stage.classic #crt { display: block; }

/* ---------- menu ---------- */
.overlay {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 28px 20px;
  background:
    linear-gradient(rgba(38,58,77,.22) 1px, transparent 1px) 0 0 / 100% 48px,
    linear-gradient(90deg, rgba(38,58,77,.22) 1px, transparent 1px) 0 0 / 48px 100%,
    radial-gradient(ellipse at 50% 0%, #16283a 0%, var(--bg) 62%);
}
.menu-inner { width: 100%; max-width: 1240px; margin: auto; }

.masthead { margin-bottom: 26px; }
.eyebrow {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .28em;
  text-transform: uppercase;
}
.masthead h1 {
  margin: 8px 0 10px;
  font-size: clamp(40px, 7vw, 76px);
  line-height: .95;
  font-weight: 800;
  letter-spacing: .04em;
  font-stretch: condensed;
}
.masthead h1 span {
  color: var(--accent);
  font-weight: 300;
  letter-spacing: .12em;
}
.tag { margin: 0; max-width: 620px; color: var(--muted); font-size: 16px; line-height: 1.5; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.mode {
  display: block;
  padding: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.mode:hover, .mode.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 18px 40px rgba(0,0,0,.45);
  transform: translateY(-2px);
}
.mode.unavailable .preview { opacity: .25; }
.mode:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; }
.preview { position: relative; aspect-ratio: 16 / 9; background: #000; }
.preview canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.classic-preview canvas { image-rendering: pixelated; object-fit: contain; }
.pv-scan {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.22) 3px, rgba(0,0,0,.22) 4px);
}
.mode-meta { display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px 18px; border-top: 1px solid var(--line); }
.mode-meta h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: .08em; text-transform: uppercase; }
.mode-meta p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.key, kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  font: 600 12px Consolas, "Cascadia Mono", monospace;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
}
.mode.selected .key, .mode:hover .key { color: #1a1206; background: var(--accent); border-color: var(--accent); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin-top: 22px;
  padding: 14px 18px;
  background: rgba(18,29,40,.7);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.ctl { display: flex; align-items: center; gap: 6px; }
.ctl span { margin-left: 4px; color: var(--muted); font-size: 13px; }

.menu-foot {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}
.menu-foot b { color: var(--text); }
.menu-foot .hi b { color: var(--accent); font-family: Consolas, monospace; font-size: 15px; }

@media (max-width: 900px) {
  .modes { grid-template-columns: 1fr; }
  .overlay { align-items: flex-start; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5,10,15,.72);
  backdrop-filter: blur(3px);
}
.modal {
  width: 100%;
  max-width: 440px;
  padding: 26px 28px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal h3 { margin: 0 0 12px; font-size: 22px; letter-spacing: .1em; text-transform: uppercase; }
#modal-body { color: var(--muted); font-size: 15px; line-height: 1.55; }
#modal-body .stat { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
#modal-body .stat b { color: var(--text); font-family: Consolas, monospace; font-size: 17px; }
#modal-body .stat.best b { color: var(--accent); }
#modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.btn {
  flex: 1 1 auto;
  padding: 11px 16px;
  font: 600 13px "Segoe UI", system-ui, sans-serif;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { color: #1a1206; background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: #ffbe55; }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
