:root {
  color-scheme: dark;
  --bg: #05070c;
  --panel: #0d121c;
  --panel-2: #121a26;
  --line: #26354a;
  --ink: #ecf4ff;
  --muted: #91a3ba;
  --cyan: #39e7d6;
  --amber: #ffd166;
  --good: #68ef9d;
  --danger: #ff6b7a;
  --violet: #a987ff;
  --shadow: rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 20% -10%, rgba(57,231,214,.12), transparent 30rem),
    radial-gradient(circle at 90% 12%, rgba(169,135,255,.10), transparent 28rem),
    linear-gradient(180deg, #070a11, var(--bg));
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--cyan); }
button, input { font: inherit; }
button { touch-action: manipulation; }
.skip-link {
  position:fixed; z-index:100; top:10px; left:10px; min-height:44px; padding:10px 14px;
  display:flex; align-items:center; border-radius:8px; background:var(--cyan); color:var(--bg); font-weight:900;
  transform:translateY(-160%);
}
.skip-link:focus { transform:translateY(0); }
:focus-visible { outline:3px solid var(--amber); outline-offset:3px; }
.site-header {
  border-bottom: 1px solid rgba(145,163,186,.18);
  background: rgba(5,7,12,.84);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  width: min(1240px, calc(100% - 32px));
  margin: auto;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 46px; height: 46px; border: 1px solid var(--cyan); border-radius: 12px;
  display: grid; place-items: center; font: 800 12px/1 ui-monospace, monospace; letter-spacing: .08em;
  color: var(--cyan); box-shadow: inset 0 0 22px rgba(57,231,214,.08), 0 0 24px rgba(57,231,214,.08);
}
.brand strong { display: block; font-size: 16px; }
.brand span { color: var(--muted); font-size: 12px; }
.back-link { min-width:44px; min-height:44px; display:inline-flex; align-items:center; justify-content:center; text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 9px 13px; font-size: 12px; }
.game-switcher { border-top: 1px solid rgba(145,163,186,.12); overflow: hidden; }
.game-switcher-inner { width: min(1240px, calc(100% - 32px)); margin: auto; min-height: 58px; display: flex; align-items: stretch; gap: 5px; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none; }
.game-switcher-inner::-webkit-scrollbar { display: none; }
.game-switcher-label { flex: 0 0 auto; padding: 0 11px 0 0; display: grid; place-items: center; color: var(--muted); font: 800 9px/1 ui-monospace, monospace; letter-spacing: .12em; }
.game-switcher a { flex: 0 0 auto; min-width: 128px; min-height: 50px; padding: 8px 12px; border-bottom: 2px solid transparent; display: grid; align-content: center; gap: 4px; color: #cad6e5; text-decoration: none; font: 800 11px/1.1 ui-monospace, monospace; }
.game-switcher a small { color: var(--muted); font: 700 8px/1 ui-monospace, monospace; letter-spacing: .08em; }
.game-switcher a:hover { background: rgba(255,255,255,.035); color: var(--cyan); }
.game-switcher a[aria-current="page"] { border-bottom-color: var(--cyan); background: rgba(57,231,214,.075); color: var(--cyan); }
.game-switcher a[aria-current="page"] small { color: var(--cyan); }
.wrap { width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 64px; }
.hero { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr); gap: 24px; align-items: stretch; margin-bottom: 24px; }
.hero-copy, .spec-card, .panel {
  min-width: 0;
  border: 1px solid rgba(145,163,186,.18);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(18,26,38,.95), rgba(9,14,22,.95));
  box-shadow: 0 24px 80px var(--shadow);
}
.hero-copy { padding: clamp(24px, 5vw, 54px); position: relative; overflow: hidden; }
.hero-copy::after { content:""; position:absolute; width:280px; height:280px; border:1px solid rgba(57,231,214,.16); border-radius:50%; right:-120px; top:-120px; box-shadow: 0 0 0 32px rgba(57,231,214,.025),0 0 0 64px rgba(57,231,214,.018); }
.eyebrow { color: var(--cyan); font: 700 12px/1.3 ui-monospace, monospace; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: 12px 0 14px; font-size: clamp(32px, 5vw, 64px); line-height: .98; max-width: 900px; }
.lead { color: #bfd0e5; font-size: clamp(16px, 2vw, 21px); line-height: 1.55; max-width: 760px; }
.hero-tags { display:flex; flex-wrap:wrap; gap:8px; margin-top:20px; }
.tag { border:1px solid var(--line); color:var(--muted); border-radius:999px; padding:7px 10px; font: 700 11px/1 ui-monospace, monospace; }
.spec-card { padding: 22px; display:grid; gap:10px; align-content:center; }
.spec-row { display:flex; justify-content:space-between; gap:20px; padding:10px 0; border-bottom:1px solid rgba(145,163,186,.12); font-size:13px; }
.spec-row:last-child { border:0; }
.spec-row span { color:var(--muted); }
.spec-row strong { text-align:right; }
.lab-grid { display:grid; grid-template-columns:minmax(0, 1.55fr) minmax(320px,.75fr); gap:24px; align-items:start; }
.panel { padding: 18px; }
.panel h2, .panel h3 { margin:0 0 8px; }
.panel p { color:var(--muted); line-height:1.55; }
.machine-panel { padding: 14px; }
.screen-shell { border:1px solid #263249; background:#020305; border-radius:14px; padding:12px; box-shadow: inset 0 0 40px rgba(0,0,0,.8); }
.screen-top { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:10px; color:var(--muted); font:700 11px/1 ui-monospace, monospace; }
.status { display:flex; align-items:center; gap:8px; color:var(--good); }
.led { width:9px; height:9px; border-radius:50%; background:currentColor; box-shadow:0 0 12px currentColor; }
canvas { width:100%; height:auto; display:block; background:#000; image-rendering:pixelated; border-radius:5px; outline:1px solid rgba(255,255,255,.06); }
.controls { display:flex; flex-wrap:wrap; gap:9px; margin-top:12px; }
.controls button, .rom-card button, .primary-action {
  min-height:44px; border:1px solid #33445d; border-radius:9px; color:var(--ink); background:#131d2a; padding:10px 13px; cursor:pointer; font:800 11px/1 ui-monospace, monospace; letter-spacing:.04em;
}
.controls button:hover, .rom-card button:hover, .primary-action:hover { border-color:var(--cyan); color:var(--cyan); }
.controls button:focus-visible, .touch-key:focus-visible { outline:2px solid var(--amber); outline-offset:2px; }
.toggle { min-height:44px; display:flex; align-items:center; gap:8px; border:1px solid #33445d; border-radius:9px; padding:7px 10px; color:var(--muted); font-size:12px; }
.control-help {
  margin:13px 0 0; padding:11px 12px; display:flex; flex-wrap:wrap; align-items:center; gap:7px 9px;
  border:1px solid rgba(145,163,186,.14); border-radius:10px; background:rgba(5,8,13,.56);
  color:var(--muted); font-size:12px; line-height:1.5;
}
.control-group { display:inline-flex; flex-wrap:wrap; align-items:center; gap:5px; }
.key-cluster { display:inline-flex; flex-wrap:wrap; align-items:center; gap:3px; }
.control-help kbd {
  display:inline-grid; place-items:center; min-width:26px; min-height:24px; padding:2px 6px;
  border:1px solid #46546a; border-bottom-width:2px; border-radius:5px; background:#101620;
  color:#e8edf4; font:800 10px/1 ui-monospace,monospace; box-shadow:inset 0 -1px rgba(255,255,255,.04);
}
.key-join { color:#718198; font-size:10px; }
.control-action { color:#c7d4e4; }
.control-divider { color:#526178; }
.control-goal { flex-basis:100%; padding-top:8px; border-top:1px solid rgba(145,163,186,.10); color:#91a3ba; }
.debug-panel { display:grid; gap:14px; }
.debug-head { display:flex; justify-content:space-between; gap:12px; align-items:center; }
.debug-head span { color:var(--cyan); font:700 11px/1 ui-monospace, monospace; }
.metrics { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
.metric { min-width:0; border:1px solid rgba(145,163,186,.14); background:#090e16; border-radius:10px; padding:9px; }
.metric span { display:block; color:var(--muted); font:700 10px/1.2 ui-monospace, monospace; text-transform:uppercase; margin-bottom:5px; }
.metric b { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font:800 13px/1.3 ui-monospace, monospace; }
.regs { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px; }
.reg { border:1px solid rgba(57,231,214,.16); border-radius:8px; padding:7px; background:rgba(57,231,214,.025); }
.reg span { display:block; font:700 9px/1 ui-monospace, monospace; color:var(--muted); }
.reg b { font:800 12px/1.4 ui-monospace, monospace; }
.trace, pre { overflow:auto; white-space:pre; }
.trace { height:170px; border:1px solid rgba(145,163,186,.14); border-radius:10px; background:#05080d; padding:11px; color:#c5d7e9; font:12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.touch-controls {
  display:none; grid-template-columns:minmax(148px,1fr) minmax(0,1fr); align-items:center; gap:16px;
  margin-top:10px; padding:12px; border:1px solid rgba(57,231,214,.18); border-radius:12px;
  background:linear-gradient(135deg,rgba(57,231,214,.055),rgba(9,14,22,.96));
  user-select:none; -webkit-user-select:none; touch-action:none;
}
.touch-dpad { display:grid; grid-template-columns:repeat(3,54px); grid-template-rows:repeat(2,46px); justify-content:start; gap:5px; }
.touch-dpad > span { display:none; }
.touch-dpad-vertical { grid-template-columns:54px; grid-template-rows:repeat(2,46px); align-content:center; }
.touch-dpad-horizontal { display:flex; align-items:center; align-self:center; }
.touch-actions { display:flex; align-items:center; justify-content:flex-end; gap:12px; }
.touch-key { border:1px solid #3b506f; background:#111a27; color:var(--ink); border-radius:13px; font:800 12px ui-monospace,monospace; min-width:54px; min-height:46px; touch-action:none; }
.touch-key.action { width:auto; min-width:72px; height:68px; padding-inline:12px; border-radius:999px; color:var(--amber); font-size:10px; }
.touch-key.pressed { background:#263955; border-color:var(--cyan); transform:translateY(1px); }
.touch-up { grid-column:2; grid-row:1; }
.touch-left { grid-column:1; grid-row:2; }
.touch-down { grid-column:2; grid-row:2; }
.touch-right { grid-column:3; grid-row:2; }
.touch-controls[data-touch-profile="racing"] { border-color:rgba(255,209,102,.24); }
.touch-controls[data-touch-profile="single-action"] { grid-template-columns:1fr; }
.touch-controls[data-touch-profile="single-action"] .touch-dpad { display:none; }
.touch-controls[data-touch-profile="single-action"] .touch-actions { justify-content:center; }
.section { margin-top:24px; }
.section-kicker { color:var(--cyan); font:800 10px/1.2 ui-monospace,monospace; letter-spacing:.16em; margin-bottom:7px; }
.version-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr)); gap:12px; margin-top:16px; }
.version-card { border:1px solid var(--line); border-radius:12px; padding:16px; background:#0d131d; }
.version-card.current { border-color:rgba(57,231,214,.55); box-shadow:inset 0 0 30px rgba(57,231,214,.04); }
.version-card span { display:block; color:var(--cyan); font:800 10px/1.2 ui-monospace,monospace; letter-spacing:.1em; }
.version-card strong { display:block; margin-top:7px; }
.version-card p { margin:7px 0 13px; color:var(--muted); font-size:12px; }
.version-card a { min-height:44px; display:inline-flex; align-items:center; color:var(--amber); font:800 10px/1 ui-monospace,monospace; }
.arch-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:12px; margin-top:16px; }
.arch-card { border:1px solid rgba(145,163,186,.14); border-radius:12px; background:#090e16; padding:14px; }
.arch-card span { color:var(--cyan); font:700 10px/1 ui-monospace,monospace; }
.arch-card strong { display:block; margin:8px 0 5px; }
.arch-card p { margin:0; font-size:13px; }
.memory-table { width:100%; border-collapse:collapse; margin-top:14px; font-size:13px; }
.memory-table th, .memory-table td { text-align:left; border-bottom:1px solid rgba(145,163,186,.14); padding:10px; vertical-align:top; }
.memory-table th { color:var(--muted); font:700 10px/1 ui-monospace,monospace; }
.memory-table code { color:var(--amber); }
.rom-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px; margin-top:14px; }
.rom-card {
  position:relative; min-width:0; min-height:136px; overflow:hidden;
  border:1px solid #3a465a; border-radius:8px; padding:17px 13px 14px;
  background:linear-gradient(135deg,#151b24,#090d13);
}
.rom-card::before,.rom-card::after {
  content:""; position:absolute; left:8px; right:8px; height:4px;
  background:repeating-linear-gradient(90deg,#5f6874 0 4px,transparent 4px 9px); opacity:.5;
}
.rom-card::before { top:3px; }
.rom-card::after { bottom:3px; }
.rom-card strong { display:block; color:var(--amber); font:800 12px/1.3 ui-monospace,monospace; overflow-wrap:anywhere; }
.rom-card span { display:block; color:#c3ccd8; font-size:11px; margin:7px 0; }
.rom-card small { display:block; color:#7f8da0; font:9px/1.5 ui-monospace,monospace; overflow-wrap:anywhere; }
.rom-card button { margin-top:9px; min-height:44px; padding:9px; }
.rom-note { margin-top:14px; }
.code-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-top:14px; }
.code-card { min-width:0; border:1px solid rgba(145,163,186,.14); border-radius:12px; overflow:hidden; background:#05080d; }
.code-card h4 { margin:0; padding:10px 12px; background:#101823; color:var(--muted); font:800 11px/1 ui-monospace,monospace; }
.code-card pre { margin:0; min-height:280px; max-height:420px; padding:13px; font:12px/1.5 ui-monospace,monospace; color:#c9dbee; }
.note { border-left:3px solid var(--amber); padding:12px 14px; background:rgba(255,209,102,.06); border-radius:0 10px 10px 0; color:#d9e3ef; line-height:1.55; }
.signal-flow { display:flex; flex-wrap:wrap; align-items:center; gap:8px; margin-top:16px; }
.flow-block { border:1px solid #33445d; border-radius:9px; padding:10px 12px; color:var(--muted); background:#090e16; font:700 10px/1.2 ui-monospace,monospace; transition:.12s ease; }
.flow-block.active { color:#07110e; background:var(--good); border-color:var(--good); box-shadow:0 0 18px rgba(104,239,157,.32); }
.flow-arrow { color:var(--amber); font:800 14px/1 ui-monospace,monospace; }
.footer { margin-top:34px; padding:24px 0; border-top:1px solid rgba(145,163,186,.16); display:flex; flex-wrap:wrap; justify-content:space-between; gap:10px; color:var(--muted); font-size:12px; }
.footer a { min-height:44px; display:inline-flex; align-items:center; }
@media (max-width: 980px) {
  .hero, .lab-grid { grid-template-columns:minmax(0,1fr); }
  .arch-grid, .rom-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .debug-panel { grid-template-columns:1fr; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior:auto; }
  *, *::before, *::after { animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; }
}
@media (hover:none), (pointer:coarse) {
  .touch-controls { display:grid; }
}
@media (max-width: 720px) {
  .game-switcher-inner { width: min(100% - 20px, 1240px); }
  .game-switcher-label { position: sticky; z-index: 2; left: 0; padding-inline: 8px 12px; background: #070a11; }
  .game-switcher a { min-width: 118px; }
  .header-inner, .wrap { width:min(100% - 20px, 1240px); }
  .back-link span { display:none; }
  .hero-copy { padding:25px 20px; }
  .panel { padding:13px; }
  .touch-controls {
    display:grid; grid-template-columns:minmax(148px,1fr) minmax(0,1fr); gap:10px;
    padding:10px 10px max(10px,env(safe-area-inset-bottom));
  }
  .touch-dpad { grid-template-columns:repeat(3,46px); grid-template-rows:repeat(2,44px); gap:5px; }
  .touch-dpad-vertical { grid-template-columns:46px; grid-template-rows:repeat(2,44px); }
  .touch-dpad { justify-content:center; }
  .touch-actions { justify-content:flex-end; flex-wrap:wrap; gap:8px; }
  .touch-key { min-width:46px; min-height:44px; }
  .touch-key.action { min-width:64px; height:62px; padding-inline:10px; }
  .code-grid { grid-template-columns:1fr; }
  .arch-grid, .rom-grid { grid-template-columns:1fr; }
  .regs { grid-template-columns:repeat(3,minmax(0,1fr)); }
  .memory-table { font-size:11px; }
  .memory-table th, .memory-table td { padding:8px 5px; }
  .control-help { align-items:flex-start; }
  .control-group { flex-basis:100%; }
  .control-divider { display:none; }
}
@media (max-width: 360px) {
  .touch-controls { grid-template-columns:138px minmax(0,1fr); padding-inline:7px; }
  .touch-dpad { grid-template-columns:repeat(3,42px); grid-template-rows:repeat(2,42px); gap:4px; }
  .touch-dpad-vertical { grid-template-columns:42px; grid-template-rows:repeat(2,42px); }
  .touch-key { min-width:42px; min-height:42px; }
  .touch-key.action { min-width:58px; height:58px; padding-inline:8px; }
}
