:root {
  color-scheme: dark;
  --bg: #10121a;
  --panel: #1b1f2c;
  --text: #e9ecf5;
  --muted: #9aa3b8;
  --accent: #2f6ef2;
  --ok: #3fbf6f;
  --err: #ff7a6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, Segoe UI, sans-serif; }
body { overscroll-behavior: none; }
#loader { max-width: 560px; margin: 0 auto; padding: 32px 16px; }
h1 { margin: 0 0 8px; font-size: 32px; letter-spacing: 0.02em; }
h2 { font-size: 16px; margin: 24px 0 4px; color: var(--muted); }
.lede { color: var(--muted); margin-top: 0; }
.roms { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 8px; }
.roms li { display: flex; justify-content: space-between; gap: 12px; background: var(--panel); padding: 12px 14px; border-radius: 10px; }
.roms .status { color: var(--muted); white-space: nowrap; }
.roms li.ok .status { color: var(--ok); }
.roms li.ok .status::before { content: '✓ '; }
.pick { display: inline-block; background: var(--panel); border: 1px dashed #4a5168; padding: 12px 16px; border-radius: 10px; cursor: pointer; }
.pick input { display: none; }
#loader.drag .pick { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 14px; }
#rom-error { color: var(--err); min-height: 1.5em; font-size: 14px; }
button { font: inherit; }
#start { display: block; width: 100%; padding: 14px; font-size: 18px; font-weight: 600; border: 0; border-radius: 10px; background: var(--accent); color: white; cursor: pointer; }
#start:disabled { background: #333a4d; color: #7d859b; cursor: default; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; margin-top: 10px; cursor: pointer; padding: 0; }
kbd { background: var(--panel); border: 1px solid #3a4157; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 13px; }
.controls p { color: var(--muted); font-size: 14px; }

#game { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #000; }
#game[hidden] { display: none; }
#screen { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.hud-buttons { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; opacity: 0.35; transition: opacity .2s; }
.hud-buttons:hover { opacity: 1; }
.hud-buttons button { background: #0008; color: white; border: 1px solid #fff3; border-radius: 6px; width: 36px; height: 36px; cursor: pointer; }

#touch { display: none; }
body.touch #touch { display: flex; width: 100%; height: min(220px, 35vh); justify-content: space-between; align-items: flex-start; padding-top: 14px !important; gap: 8px; position: relative; padding: 0 max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); touch-action: none; user-select: none; -webkit-user-select: none; }
.dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); flex-shrink: 0; }
.dpad .key { background: #2a2f40; color: #aab; display: grid; place-items: center; font-size: 18px; }
.dpad div:nth-child(2) { border-radius: 8px 8px 0 0; }
.dpad div:nth-child(8) { border-radius: 0 0 8px 8px; }
.dpad div:nth-child(4) { border-radius: 8px 0 0 8px; }
.dpad div:nth-child(6) { border-radius: 0 8px 8px 0; }
.dpad div:nth-child(5) { background: #2a2f40; }
.mid { position: absolute; left: 50%; transform: translateX(-50%); bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 12px; }
.small { background: #2a2f40; color: #aab; font-size: 11px; padding: 6px 10px; border-radius: 12px; }
.ab { display: flex; gap: 10px; align-items: flex-start; flex-shrink: 0; }
.ab .round:first-child { margin-top: 26px; } /* B sits lower than A, like the NES pad */
.round { width: 58px; height: 58px; flex-shrink: 0; border-radius: 50%; background: #b8323a; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; }
body.touch #game { justify-content: flex-start; padding-top: env(safe-area-inset-top); }
