:root {
  --bg: #0a0e13;
  --surface: #111821;
  --surface-2: #17202b;
  --border: #243142;
  --text: #e6edf3;
  --muted: #8a98a8;
  --accent: #f2a541;
  --accent-ink: #1a1206;
  --accent-soft: rgba(242, 165, 65, 0.14);
  --teal: #2fb5a5;
  --danger: #e5534b;
  --radius: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; letter-spacing: 0.2px; white-space: nowrap; }
.brand strong { color: var(--accent); font-weight: 700; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); }

.game-tabs { display: flex; gap: 4px; }
.game-tabs button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}
.game-tabs button:hover { color: var(--text); background: var(--surface-2); }
.game-tabs button.active { color: var(--text); border-color: var(--border); background: var(--surface-2); }

.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 6px; cursor: pointer; font-weight: 500;
}
.segmented button.active { background: var(--accent); color: var(--accent-ink); }
.segmented button:not(.active):hover { color: var(--text); }

.actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { border-color: #33465c; background: #1c2734; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: #f6b660; border-color: #f6b660; }
.btn-lg { padding: 11px 30px; font-size: 16px; border-radius: 10px; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.on { color: var(--accent); }
#btnMute.muted .wave { display: none; }

/* ---- stage -------------------------------------------------------------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  background: radial-gradient(ellipse at center, #0f1620 0%, #06090d 75%);
}
.view { position: relative; flex: 1; min-width: 0; display: none; }
.stage[data-mode="remaster"] .view-remaster,
.stage[data-mode="classic"] .view-classic,
.stage[data-mode="split"] .view { display: block; }
.stage[data-mode="split"] .view-classic { border-left: 1px solid var(--border); flex: 0.8; }
.view-remaster canvas { display: block; width: 100%; height: 100%; }
.view-classic { display: none; }
.stage[data-mode="classic"] .view-classic,
.stage[data-mode="split"] .view-classic { display: grid; place-items: center; }
#classicCanvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 0 0 1px #1b2533, 0 20px 60px rgba(0, 0, 0, 0.6);
  background: #000;
}
.scanlines {
  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,0.22) 3px);
  mix-blend-mode: multiply;
  display: none;
}
.stage.crt .scanlines { display: block; }

.splash {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(6, 9, 13, 0.72);
  backdrop-filter: blur(6px);
  z-index: 5;
}
.splash.hidden { display: none; }
.splash-card {
  max-width: 460px; margin: 16px;
  text-align: center;
  padding: 34px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.splash-card h1 { margin: 0 0 10px; font-size: 26px; letter-spacing: -0.3px; }
.splash-card p { color: var(--muted); margin: 0 0 22px; }
.splash-card .hint { margin: 18px 0 0; font-size: 12.5px; }

.loading-badge {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 10px 18px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  font-size: 13px; z-index: 4;
}

/* ---- status bar --------------------------------------------------------- */
.statusbar {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 16px;
  font-size: 12px; color: var(--muted);
  background: var(--surface); border-top: 1px solid var(--border);
}
.statusbar .sep { width: 1px; height: 12px; background: var(--border); }
.statusbar .grow { flex: 1; }

/* ---- modals ------------------------------------------------------------- */
.modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(3, 6, 10, 0.66);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  pointer-events: auto;
  animation: fade 0.15s ease-out;
}
.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease-out;
}
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal h2 { margin: 0; font-size: 17px; }
.modal .body { padding: 14px 20px 6px; color: #c9d4de; }
.modal .body p { margin: 0 0 12px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.modal .close { width: 30px; height: 30px; }
.modal.error h2 { color: var(--danger); }

.bind-grid { display: grid; grid-template-columns: 1fr 108px 108px; gap: 6px 8px; align-items: center; margin: 4px 0 14px; }
.bind-name { color: var(--text); font-weight: 500; }
.bind-key {
  height: 32px; padding: 0 8px; border-radius: 8px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); border-bottom-width: 2px;
  font: 500 12px "JetBrains Mono", monospace; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bind-key:hover { border-color: var(--accent); }
.bind-key.listening { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.hint-text { color: var(--muted); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center; margin: 4px 0 12px; }
kbd {
  display: inline-block; min-width: 26px; text-align: center;
  padding: 2px 7px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border); border-bottom-width: 2px;
  font: 500 12px "JetBrains Mono", monospace; color: var(--text);
}

.field { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: 0; }
.field label { font-weight: 500; }
.field small { display: block; color: var(--muted); font-weight: 400; }
.field select, .field input[type="range"] { accent-color: var(--accent); }
.field select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 8px;
}
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: #2a3747; cursor: pointer; transition: background 0.15s;
}
.switch span::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #dfe7ef; transition: transform 0.15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

.dropzone {
  border: 1.5px dashed #34465b; border-radius: 12px;
  padding: 26px 16px; text-align: center; color: var(--muted);
  margin: 6px 0 12px; cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone strong { color: var(--text); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 8px 16px; }
  .actions { margin-left: 0; width: 100%; justify-content: space-between; }
  .brand span { display: none; }
  .stage[data-mode="split"] { flex-direction: column; }
  .stage[data-mode="split"] .view-classic { border-left: 0; border-top: 1px solid var(--border); }
}
