:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b1020;
  color: #f9fafb;
  --panel-bg: rgba(15, 23, 42, 0.78);
  --panel-border: rgba(255, 255, 255, 0.14);
  --muted: #cbd5e1;
  --accent: #93c5fd;
  --accent-strong: #60a5fa;
  --chip-bg: rgba(15, 23, 42, 0.72);
  --screen-scale: 2;
  --screen-base-w: 256px;
  --screen-base-h: 240px;
  --screen-w: calc(var(--screen-base-w) * var(--screen-scale));
  --screen-h: calc(var(--screen-base-h) * var(--screen-scale));
  --screen-aspect: 1.0666666667;
  --fullscreen-screen-w: var(--screen-w);
  --fullscreen-screen-h: var(--screen-h);
}


* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% -8%, rgba(96, 165, 250, 0.34), transparent 34%),
    radial-gradient(circle at 100% 10%, rgba(168, 85, 247, 0.20), transparent 28%),
    radial-gradient(circle at 80% 105%, rgba(20, 184, 166, 0.20), transparent 30%),
    linear-gradient(135deg, #08111f 0%, #0f172a 48%, #111827 100%);
}

main {
  width: min(100%, 1180px);
  display: grid;
  gap: 18px;
}

.panel {
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.82), var(--panel-bg));
  backdrop-filter: blur(18px);
  border-radius: 28px;
  padding: 22px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255,255,255,0.05);
}

.top {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  align-items: start;
}

.hero-copy { min-width: 0; }
.eyebrow {
  display: inline-flex;
  width: fit-content;
  margin: 0 0 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(96, 165, 250, 0.14);
  color: #dbeafe;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  letter-spacing: -0.04em;
}

h2 { margin: 0 0 8px; }
p { margin: 0; color: #cbd5e1; line-height: 1.55; }
.hint { margin-top: 10px; color: #93c5fd; }

.page-drop-overlay {
  position: fixed;
  inset: 16px;
  z-index: 9999;
  display: grid;
  place-items: center;
  border: 3px dashed rgba(147, 197, 253, 0.84);
  border-radius: 30px;
  background: rgba(15, 23, 42, 0.72);
  color: #dbeafe;
  font-size: clamp(1.25rem, 4vw, 2.2rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  text-align: center;
  opacity: 0;
  transform: scale(0.985);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12), 0 26px 80px rgba(0,0,0,0.42);
}

body.page-dragover .page-drop-overlay {
  opacity: 1;
  transform: scale(1);
}

.emulator-panel { display: grid; gap: 14px; }

.toolbar,
.controls,
.toolbar-group,
.virtual-pad {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.toolbar { justify-content: space-between; }
.top-controls { display: grid; gap: 10px; width: 100%; }

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 18px;
  background: rgba(2, 6, 23, 0.32);
}

.control-label {
  flex: 0 0 74px;
  color: #bfdbfe;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-spoiler {
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(2, 6, 23, 0.32);
}

.control-spoiler > summary {
  padding: 10px 12px;
  color: #bfdbfe;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-spoiler > summary::marker { color: #93c5fd; }

.control-spoiler-body {
  display: grid;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.control-spoiler-body .control-group {
  background: rgba(15, 23, 42, 0.34);
}

.run-controls button,
.savestate-controls button,
.debug-controls button { min-width: 78px; }
.mode-controls button,
.option-controls button { min-width: 132px; }
.toolbar-label { font-weight: 800; color: #e5e7eb; }

.savestate-stats {
  flex: 1 1 320px;
  min-width: 260px;
  color: #bfdbfe;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: var(--chip-bg);
  color: #e5e7eb;
  font-size: 0.84rem;
  font-weight: 800;
  user-select: none;
}

.chip-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-strong);
}

.chip-toggle:has(input:focus-visible) {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.chip-toggle:has(input:not(:checked)) {
  color: #94a3b8;
  background: rgba(2, 6, 23, 0.50);
  border-color: rgba(148, 163, 184, 0.20);
}

.mode-chip { min-width: 48px; justify-content: center; }

.mode-help {
  flex: 1 1 240px;
  color: #a7f3d0;
  font-size: 0.78rem;
  line-height: 1.35;
  padding: 2px 4px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 9px 13px;
  font-weight: 800;
  color: #0f172a;
  background: linear-gradient(180deg, #f8fafc, #cbd5e1);
  cursor: pointer;
}

button.primary { background: linear-gradient(180deg, #bfdbfe, #60a5fa); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.active,
button[aria-pressed="true"] {
  background: linear-gradient(180deg, #dbeafe, #93c5fd);
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.22);
}

.volume-control input,
.timing-control input[type="range"] {
  width: min(260px, 42vw);
  accent-color: #93c5fd;
}

.timing-control input[type="range"] {
  width: min(220px, 34vw);
}

.timing-control datalist { display: none; }

.volume-value {
  min-width: 3.5ch;
  color: #dbeafe;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.perf-status {
  margin-left: auto;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.46);
  color: #dbeafe;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.screen-scroll { width: 100%; overflow: auto; padding: 4px 0 2px; }
.screen-shell { width: var(--screen-w); height: var(--screen-h); margin: 0 auto; line-height: 0; position: relative; }

canvas {
  display: block;
  width: var(--screen-w);
  height: var(--screen-h);
  max-width: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #020617;
  border-radius: 18px;
  border: 0;
  box-shadow: 0 0 0 1px rgba(147,197,253,0.28), 0 22px 60px rgba(0,0,0,0.34), 0 0 0 8px rgba(15,23,42,0.42);
  outline: none;
}

canvas:focus {
  box-shadow: 0 0 0 1px #93c5fd, 0 0 0 4px rgba(147, 197, 253, 0.18), 0 22px 60px rgba(0,0,0,0.34);
}

.screen-fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.20);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.76);
  color: #e5e7eb;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease, background 140ms ease, transform 140ms ease;
}

.screen-shell.fullscreen-ui-active .screen-fullscreen-btn,
.screen-fullscreen-btn:focus-visible,
.screen-fullscreen-btn:hover {
  opacity: 1;
  pointer-events: auto;
}

.screen-fullscreen-btn:hover {
  transform: translateY(-1px);
  background: rgba(30, 41, 59, 0.92);
}

html.screen-pseudo-fullscreen-active,
html.screen-pseudo-fullscreen-active body {
  overflow: hidden !important;
  overscroll-behavior: none;
  background: #000;
}

.screen-shell.fullscreen-active,
.screen-shell:fullscreen,
.screen-shell:-webkit-full-screen {
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: 100vw;
  max-width: 100dvw;
  max-height: 100vh;
  max-height: 100dvh;
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  background: #000;
  overflow: hidden;
}

.screen-shell.fullscreen-active > #screen,
.screen-shell.fullscreen-active > .stream-remote-canvas,
.screen-shell:fullscreen > #screen,
.screen-shell:fullscreen > .stream-remote-canvas,
.screen-shell:-webkit-full-screen > #screen,
.screen-shell:-webkit-full-screen > .stream-remote-canvas {
  width: var(--fullscreen-screen-w) !important;
  height: var(--fullscreen-screen-h) !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0;
  min-height: 0;
  flex: 0 0 auto;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

.screen-shell.fullscreen-active > .stream-remote-canvas,
.screen-shell:fullscreen > .stream-remote-canvas,
.screen-shell:-webkit-full-screen > .stream-remote-canvas {
  position: absolute;
  inset: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.screen-shell.fullscreen-active > .stream-remote-video,
.screen-shell:fullscreen > .stream-remote-video,
.screen-shell:-webkit-full-screen > .stream-remote-video {
  width: var(--fullscreen-screen-w) !important;
  height: var(--fullscreen-screen-h) !important;
  max-width: none !important;
  max-height: none !important;
  min-width: 0;
  min-height: 0;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

.screen-shell.fullscreen-active .screen-fullscreen-btn,
.screen-shell:fullscreen .screen-fullscreen-btn,
.screen-shell:-webkit-full-screen .screen-fullscreen-btn {
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
}

.screen-shell.fullscreen-active .stream-remote-audio,
.screen-shell:fullscreen .stream-remote-audio,
.screen-shell:-webkit-full-screen .stream-remote-audio {
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(var(--touch-edge), env(safe-area-inset-bottom));
}

.screen-shell.streaming-viewer-active > #screen {
  opacity: 0;
}

.screen-shell .stream-remote-video,
.screen-shell .stream-remote-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.screen-shell .stream-remote-audio {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 3;
}

.touch-controls-overlay {
  --touch-size: 40px;
  --touch-edge: 10px;
  --touch-font-size: 14px;
  --touch-small-font-size: 11px;
  position: absolute;
  inset: 0;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: opacity 160ms ease;
}

.touch-controls-overlay[hidden] { display: none !important; }
.screen-shell.touch-controls-enabled .touch-controls-overlay { opacity: 1; }

.touch-btn {
  position: absolute;
  width: var(--touch-size);
  height: var(--touch-size);
  min-width: 0;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(15, 23, 42, 0.48);
  color: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 28px rgba(0,0,0,0.30), inset 0 0 0 1px rgba(255,255,255,0.08);
  font-weight: 950;
  font-size: var(--touch-font-size);
  line-height: 1;
  text-align: center;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(8px);
}

.touch-btn:active,
.touch-btn.pressed {
  transform: scale(0.94);
  background: rgba(96, 165, 250, 0.66);
  border-color: rgba(191, 219, 254, 0.74);
}

.touch-shoulder {
  top: auto;
  bottom: calc(max(var(--touch-edge), env(safe-area-inset-bottom)) + (var(--touch-size) * 3.05) + 8px);
  width: calc(var(--touch-size) * 1.25);
  height: calc(var(--touch-size) * 0.66);
  border-radius: 999px;
}
.touch-l { left: max(var(--touch-edge), env(safe-area-inset-left)); }
.touch-r { right: max(var(--touch-edge), env(safe-area-inset-right)); }

.touch-dpad,
.touch-face-buttons,
.touch-menu-buttons {
  position: absolute;
  pointer-events: none;
}

.touch-dpad {
  left: max(var(--touch-edge), env(safe-area-inset-left));
  bottom: max(var(--touch-edge), env(safe-area-inset-bottom));
  width: calc(var(--touch-size) * 3);
  height: calc(var(--touch-size) * 3);
}
.touch-dpad .touch-up { left: var(--touch-size); top: 0; }
.touch-dpad .touch-left { left: 0; top: var(--touch-size); }
.touch-dpad .touch-right { left: calc(var(--touch-size) * 2); top: var(--touch-size); }
.touch-dpad .touch-down { left: var(--touch-size); top: calc(var(--touch-size) * 2); }

.touch-face-buttons {
  right: max(var(--touch-edge), env(safe-area-inset-right));
  bottom: max(var(--touch-edge), env(safe-area-inset-bottom));
  width: calc(var(--touch-size) * 2.1);
  height: calc(var(--touch-size) * 2.1);
}
.touch-face-buttons .touch-a { right: 0; top: 0; }
.touch-face-buttons .touch-b { left: 0; bottom: 0; }

.touch-menu-buttons {
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: clamp(8px, 2vmin, 18px);
  transform: translateX(-50%);
}
.touch-menu-buttons .touch-small {
  position: relative;
  width: calc(var(--touch-size) * 1.3);
  height: calc(var(--touch-size) * 0.62);
  font-size: var(--touch-small-font-size);
  border-radius: 999px;
}

.screen-shell[data-scale="1"] .touch-controls-overlay {
  --touch-size: 24px;
  --touch-edge: 4px;
  --touch-font-size: 12px;
  --touch-small-font-size: 10px;
}
.screen-shell[data-scale="2"] .touch-controls-overlay {
  --touch-size: 48px;
  --touch-edge: 8px;
  --touch-font-size: 16px;
  --touch-small-font-size: 13px;
}
.screen-shell[data-scale="3"] .touch-controls-overlay {
  --touch-size: 72px;
  --touch-edge: 12px;
  --touch-font-size: 20px;
  --touch-small-font-size: 16px;
}

.screen-shell.fullscreen-active .touch-controls-overlay,
.screen-shell:fullscreen .touch-controls-overlay,
.screen-shell:-webkit-full-screen .touch-controls-overlay {
  --touch-size: clamp(44px, 9.5vmin, 82px);
  --touch-edge: max(14px, 2vmin);
  --touch-font-size: clamp(14px, 2.9vmin, 22px);
  --touch-small-font-size: clamp(11px, 2.2vmin, 18px);
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls-overlay { opacity: 0.72; }
}

.kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.input-status {
  padding: 8px 10px;
  border: 1px solid rgba(147, 197, 253, 0.35);
  background: rgba(37, 99, 235, 0.12);
  border-radius: 12px;
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.virtual-pad:not(.touch-controls-overlay) button { padding: 7px 10px; font-size: 12px; }
.info-debug-panel { display: grid; gap: 12px; }

details {
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(2, 6, 23, 0.36);
}

summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 900;
  color: #e5e7eb;
  user-select: none;
}

.log,
.debug-panel {
  overflow: auto;
  padding: 14px;
  margin: 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  background: rgba(2, 6, 23, 0.72);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  color: #dbeafe;
}

.log { max-height: 180px; }
.debug-panel { max-height: 260px; white-space: pre; }
.profile-panel { white-space: pre-wrap; }

.rom-url-loader {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.rom-url-loader input {
  min-width: min(320px, 90vw);
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(2, 6, 23, 0.62);
  color: #f8fafc;
  font: 14px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.small-hint { margin-top: 8px; font-size: 0.9rem; }
.debug-disabled #debugDetails,
.debug-disabled #profilerDetails { display: none; }
.debug-disabled.profiler-enabled #profilerDetails { display: block; }

.mode-controls #coreEngineToggleBtn.core-switch {
  min-width: 184px;
  position: relative;
  padding-left: 58px;
  padding-right: 18px;
  text-align: left;
  overflow: hidden;
}

.core-switch::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 34px;
  height: 20px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.28);
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.16);
}

.core-switch::after {
  content: "";
  position: absolute;
  left: 17px;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: #0f172a;
  transition: transform 150ms ease;
}

.core-switch[aria-checked="true"]::after { transform: translate(14px, -50%); }
.core-switch-label { position: relative; z-index: 1; }
body.core-wasm-mode .js-core-option { opacity: 0.66; }
body.core-wasm-mode .option-controls::after {
  content: "No preexisting emulator core is embedded; this WASM module is a from-scratch scaffold.";
  color: #bfdbfe;
  font-size: 0.78rem;
  line-height: 1.35;
  padding: 2px 4px;
}

#profilerToggleBtn[aria-pressed="true"] {
  border-color: rgba(52, 211, 153, 0.9);
  background: #bbf7d0;
  color: #052e16;
}

@media (max-width: 900px) {
  body { padding: 14px; }
  .top { grid-template-columns: 1fr; }
  .toolbar { justify-content: start; }
  .perf-status { margin-left: 0; width: 100%; text-align: center; }
}

@media (max-width: 560px) {
  .control-label { flex-basis: 100%; }
  .mode-controls button,
  .option-controls button,
  .run-controls button,
  .debug-controls button { flex: 1 1 140px; min-width: 0; }
  .mode-help { flex-basis: 100%; }
}

.save-library-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8em;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(147, 197, 253, 0.16);
  color: #dbeafe;
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.save-library-body { gap: 10px; }
.save-library-actions .mode-help { color: #bfdbfe; }

.save-library-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-height: 420px;
  overflow: auto;
  padding-right: 4px;
}

.save-library-empty {
  padding: 10px 12px;
  border: 1px dashed rgba(147, 197, 253, 0.24);
  border-radius: 14px;
  color: #cbd5e1;
}

.save-library-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 2px solid rgba(147, 197, 253, 0.26);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.72), rgba(15, 23, 42, 0.48));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 10px 24px rgba(0,0,0,0.18);
}

.save-library-item.current {
  border-color: rgba(52, 211, 153, 0.68);
  background: linear-gradient(180deg, rgba(8, 95, 78, 0.32), rgba(6, 78, 59, 0.22));
}

.save-library-art {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 92px;
  justify-self: center;
  width: 100%;
}

.save-library-art img {
  display: block;
  width: 100%;
  max-width: 148px;
  height: auto;
  filter: drop-shadow(0 12px 18px rgba(0,0,0,0.38));
}

.save-library-art-label {
  position: absolute;
  left: 50%;
  bottom: 20%;
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.72);
  color: #f8fafc;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.save-library-content {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.save-library-title-row,
.save-library-row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.save-library-title-row {
  justify-content: space-between;
  gap: 12px;
}

.save-library-title-wrap {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.save-library-title-row strong {
  color: #f8fafc;
  font-size: 1rem;
}

.save-library-subtitle {
  color: #bfdbfe;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.save-library-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(147, 197, 253, 0.14);
  color: #dbeafe;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.save-library-meta {
  color: #cbd5e1;
  font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.save-library-row-actions button {
  padding: 7px 10px;
  font-size: 12px;
}

@media (max-width: 1000px) {
  .save-library-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .save-library-list {
    grid-template-columns: 1fr;
  }

  .save-library-item {
    justify-items: center;
  }

  .save-library-content {
    width: 100%;
  }

  .save-library-title-row {
    align-items: start;
  }
}

.keybind-body { gap: 10px; }
.keybind-actions .mode-help { color: #bfdbfe; }

.keybind-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.keybind-player-group {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(147, 197, 253, 0.18);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.28);
}

.keybind-player-heading {
  margin: 0;
  color: #bfdbfe;
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.keybind-player-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}

.keybind-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid rgba(147, 197, 253, 0.18);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.38);
}

.keybind-row.waiting {
  border-color: rgba(52, 211, 153, 0.72);
  background: rgba(6, 78, 59, 0.22);
}

.keybind-name {
  color: #dbeafe;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.keybind-button {
  min-width: 0;
  padding: 7px 10px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1000px) {
  .keybind-list {
    grid-template-columns: 1fr;
  }

  .keybind-player-grid {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }
}

@media (max-width: 700px) {
  .keybind-player-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .keybind-player-grid {
    grid-template-columns: 1fr;
  }
}

.streaming-panel {
  display: grid;
  gap: 16px;
}
.streaming-panel > .top-controls {
  margin-top: 2px;
}


.streaming-header {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
  align-items: start;
}

.stream-status {
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid rgba(147, 197, 253, 0.28);
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.36);
  color: #bfdbfe;
  font-size: 0.86rem;
  font-weight: 800;
}

.stream-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stream-grid-simple {
  grid-template-columns: minmax(0, 1fr);
}

.stream-card {
  display: grid;
  gap: 11px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 20px;
  background: rgba(2, 6, 23, 0.30);
}

.stream-card h3 {
  margin: 0;
  color: #e0f2fe;
}

.stream-field {
  display: grid;
  gap: 6px;
  color: #bfdbfe;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stream-field input,
.stream-field select {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.80);
  color: #f8fafc;
  font: 13px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  text-transform: none;
  letter-spacing: normal;
}

.stream-field select {
  appearance: none;
}

.stream-settings {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stream-settings-simple {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stream-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.stream-actions-primary button {
  min-width: 128px;
}

.stream-connection-details {
  padding: 8px 10px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.48);
  color: #cbd5e1;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  overflow-wrap: anywhere;
}

.stream-remote-video,
.stream-remote-canvas {
  display: none;
  width: var(--screen-w);
  height: var(--screen-h);
  max-width: none;
  border: 0;
  border-radius: 18px;
  background: #020617;
  object-fit: contain;
  box-shadow: 0 0 0 1px rgba(147, 197, 253, 0.34), 0 22px 60px rgba(0,0,0,0.34), 0 0 0 8px rgba(15,23,42,0.42);
}

.stream-remote-video.active,
.stream-remote-canvas.active {
  display: block;
}

.stream-remote-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.stream-remote-audio {
  position: fixed !important;
  left: -10000px !important;
  top: 0 !important;
  right: auto !important;
  bottom: auto !important;
  display: block;
  width: 1px;
  height: 1px;
  opacity: 0.001;
  pointer-events: none;
}

.stream-remote-audio.active {
  display: block;
}

@media (max-width: 900px) {
  .stream-grid {
    grid-template-columns: 1fr;
  }
  .stream-settings,
  .stream-settings-simple {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .stream-settings,
  .stream-settings-simple {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1149.98px) {
  .controls-hint,
  #controlsHint {
    display: none !important;
  }
}

.audio-channel-controls .mode-help,
.audio-quality-controls .mode-help {
  color: #bfdbfe;
}

.audio-select-field {
  min-width: 190px;
  flex: 1 1 210px;
}

.audio-select-field select {
  min-height: 36px;
}

.link-cable-controls .compact-field {
  min-width: 160px;
  flex: 1 1 220px;
}

.link-cable-controls #linkRoomCode {
  text-transform: uppercase;
}

.link-cable-controls button {
  min-width: 104px;
}

.link-status {
  color: #bfdbfe;
}

.link-help {
  color: #a7f3d0;
}

.gba-link-debug-panel {
  display: grid;
  gap: 8px;
  padding: 10px 0 0;
}

.gba-link-debug-controls button {
  min-width: 104px;
}

.gba-link-debug-output {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid rgba(147, 197, 253, 0.24);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.86);
  color: #dbeafe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.38;
  tab-size: 2;
  white-space: pre;
}

.gba-link-debug-output::placeholder {
  color: #93a4ba;
}

.save-library-warning {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 14px;
  background: rgba(120, 53, 15, 0.24);
  color: #fde68a;
  font-size: 0.88rem;
}

.rewind-panel {
  width: min(100%, calc(var(--screen-w) + 48px));
  margin: 8px auto 0;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
  border: 1px solid rgba(147, 197, 253, 0.18);
  border-radius: 18px;
  background: rgba(2, 6, 23, 0.34);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.rewind-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.rewind-control {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  align-items: center;
  gap: 10px;
}

.rewind-panel.rewind-disabled {
  opacity: 0.78;
}

.rewind-panel.rewind-disabled .rewind-status {
  color: #cbd5e1;
}

@media (max-width: 620px) {
  .rewind-toolbar {
    grid-template-columns: 1fr;
  }

  .rewind-toolbar > button {
    width: 100%;
  }
}

.rewind-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent-strong);
}

.rewind-status {
  color: #bfdbfe;
  font-size: 0.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.simple-profiler-panel {
  white-space: normal;
  font-family: inherit;
}

.simple-profiler {
  display: grid;
  gap: 10px;
  font: 13px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #dbeafe;
}

.simple-profiler-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.simple-profiler-head span,
.simple-profiler-label span,
.simple-profiler-subline {
  display: block;
  color: #93c5fd;
  font-size: 0.82rem;
}

.simple-profiler-total {
  flex: 0 0 auto;
  font-weight: 700;
  color: #f8fafc;
  text-align: right;
}

.simple-profiler-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.3fr) minmax(140px, 2fr) minmax(105px, auto);
  gap: 10px;
  align-items: center;
}

.simple-profiler-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}

.simple-profiler-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(96, 165, 250, 0.85), rgba(52, 211, 153, 0.9));
}

.simple-profiler-value {
  font: 12px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #f8fafc;
  text-align: right;
  white-space: nowrap;
}

.simple-profiler-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.12);
}

.simple-profiler-meta span {
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(96, 165, 250, 0.12);
  color: #bfdbfe;
  font-size: 0.78rem;
}

.simple-profiler-empty {
  padding: 4px 0;
  color: #bfdbfe;
}

@media (max-width: 640px) {
  .simple-profiler-head,
  .simple-profiler-row {
    grid-template-columns: 1fr;
  }
  .simple-profiler-head { display: grid; }
  .simple-profiler-total,
  .simple-profiler-value { text-align: left; }
}

/* Pass253: online link safety lock for timing and rewind controls. */
.link-feature-locked {
  opacity: 0.52;
  filter: grayscale(0.85);
}

.link-feature-locked input,
.link-feature-locked button,
.link-feature-locked select {
  cursor: not-allowed;
}

.link-feature-locked .toolbar-label,
.link-feature-locked .rewind-status,
.link-feature-locked .volume-value {
  color: #94a3b8;
}

/* RFU relay live debug status: structured, colored queue-pressure view. */
.link-status.rfu-debug-status {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(147, 197, 253, 0.24);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.64);
  color: #dbeafe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.rfu-debug-title {
  color: #bfdbfe;
  font-weight: 700;
}

.rfu-debug-line strong {
  color: #f8fafc;
  font-weight: 700;
}

.rfu-debug-metric {
  white-space: nowrap;
}

.rfu-debug-label {
  color: #93c5fd;
}

.rfu-debug-value,
.rfu-debug-count {
  font-weight: 800;
}

.rfu-debug-max,
.rfu-debug-suffix {
  color: #cbd5e1;
}

/* Account ROM library (server-side, authenticated, deduplicated ROM store). */
.account-library-body { gap: 10px; }
.account-login-actions .account-inline-input {
  min-width: 150px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  padding: 9px 12px;
  background: rgba(15, 23, 42, 0.80);
  color: #f8fafc;
  font: 13px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.account-login-actions .account-inline-input:focus-visible,
.account-rom-search-field input:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}
.account-status { color: #bfdbfe; }

.account-login-actions .button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.80);
  color: #bfdbfe;
  text-decoration: none;
  font-size: 13px;
}
.account-login-actions .button-link:hover { color: #f8fafc; border-color: rgba(191, 219, 254, 0.65); }
.account-rom-search-field {
  flex: 1 1 320px;
  min-width: min(100%, 280px);
}
.account-rom-actions button { min-width: 112px; }
.account-rom-actions code {
  color: #dbeafe;
  font-size: 0.75rem;
}
@media (max-width: 700px) {
  .account-login-actions .account-inline-input,
  .account-rom-search-field { flex: 1 1 100%; width: 100%; }
}

/* Pass412: streamer-side interactive controls. */
.stream-checkbox-control {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  min-height: 2.35rem;
}
.stream-checkbox-control input {
  width: auto;
  margin: 0;
}
.stream-field.disabled {
  opacity: 0.58;
}
.stream-interactive-status {
  margin-top: 0.55rem;
  color: var(--muted, #64748b);
  font-size: 0.86rem;
  line-height: 1.4;
}


/* Pass416: non-destructive offline/server save reconciliation. */
.save-conflict-dialog {
  width: min(760px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid rgba(147, 197, 253, 0.42);
  border-radius: 24px;
  background: #0f172a;
  color: #f8fafc;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.68);
}
.save-conflict-dialog::backdrop {
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(5px);
}
.save-conflict-form { padding: 22px; }
.save-conflict-form h2 { margin: 0 0 8px; }
.save-conflict-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.save-conflict-card {
  display: grid;
  gap: 9px;
  padding: 16px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 18px;
  background: rgba(30, 41, 59, 0.72);
}
.save-conflict-card time { color: #bfdbfe; font-weight: 800; }
.save-conflict-card span { color: #94a3b8; font-size: 0.86rem; }
.save-conflict-card button { margin-top: 8px; }
@media (max-width: 620px) {
  .save-conflict-options { grid-template-columns: 1fr; }
}

/* Pass418: native GB/GBC frames are only 160 px wide. Keep the controls at
   the same relative size as the GBA layout and omit hardware buttons that
   do not exist on the original GB/GBC. */
.screen-shell[data-touch-system="gb"] .touch-shoulder {
  display: none;
}

.screen-shell[data-touch-layout="compact"][data-scale="1"] .touch-controls-overlay {
  --touch-size: 16px;
  --touch-edge: 3px;
  --touch-font-size: 12px;
  --touch-small-font-size: 10px;
}
.screen-shell[data-touch-layout="compact"][data-scale="2"] .touch-controls-overlay {
  --touch-size: 32px;
  --touch-edge: 5px;
  --touch-font-size: 12px;
  --touch-small-font-size: 10px;
}
.screen-shell[data-touch-layout="compact"][data-scale="3"] .touch-controls-overlay {
  --touch-size: 48px;
  --touch-edge: 8px;
  --touch-font-size: 14px;
  --touch-small-font-size: 11px;
}


/* NES frontend adaptations layered on the GBA website layout. */
.nes-feature-note { color: #bfdbfe; font-size: 0.9rem; }
.nes-core-options { display: flex; flex-wrap: wrap; gap: 8px; }
.rom-path-field { flex: 1 1 260px; min-width: min(100%, 260px); }
.rom-path-field input { width: 100%; }
.save-library-item { min-height: 0; }
.save-library-art { display: grid; place-items: center; background: radial-gradient(circle at 40% 35%, rgba(96,165,250,.24), rgba(2,6,23,.85)); }
.save-library-art::before { content: "NES"; color: #dbeafe; font-weight: 950; letter-spacing: .08em; }
.save-library-art-label { display: none; }
.touch-controls-overlay .touch-shoulder { display: none; }
.screen-shell[data-scale="1"] .touch-controls-overlay { --touch-size: 27px; }
.screen-shell[data-scale="2"] .touch-controls-overlay { --touch-size: 48px; }
.screen-shell[data-scale="3"] .touch-controls-overlay { --touch-size: 66px; }
@media (max-width: 700px) {
  body { padding: 10px; }
  .panel { padding: 14px; border-radius: 20px; }
  .perf-status { width: 100%; margin-left: 0; text-align: center; }
}

/* Specialized same-origin embed used by /website/nes/race/. */
html.race-embed,
html.race-embed body { margin: 0; min-height: 0; background: #07090f; overflow: hidden; }
html.race-embed body > .page-drop-overlay,
html.race-embed main > .top,
html.race-embed #settingsPanel,
html.race-embed #infoDebugPanel,
html.race-embed .emulator-panel > .toolbar,
html.race-embed .input-status { display: none !important; }
html.race-embed main { width: 100%; max-width: none; margin: 0; padding: 0; }
html.race-embed .emulator-panel { margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; background: #07090f; min-height: 240px; }
html.race-embed .screen-scroll { margin: 0; padding: 0; overflow: hidden; display: grid; place-items: center; }
html.race-embed .screen-shell { margin: 0; }
html.race-embed #fullscreenBtn { opacity: .75; }

/* v36 SMB race player integration: racers play on the normal emulator page. */
.race-player-panel summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.race-player-summary { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; font-size: .74rem; }
#racePlayerBadge, #racePlayerCount { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; border: 1px solid rgba(148,163,184,.28); border-radius: 999px; color: #94a3b8; background: rgba(15,23,42,.72); font-weight: 850; letter-spacing: .04em; }
#racePlayerBadge[data-state="ready"] { color: #bbf7d0; border-color: rgba(74,222,128,.45); }
#racePlayerBadge[data-state="running"] { color: #fde68a; border-color: rgba(250,204,21,.5); }
.race-player-controls { align-items: center; }
.race-room-field { flex: 0 1 180px; }
.race-name-field { flex: 0 1 190px; }
.race-room-field input, .race-name-field input { width: 100%; }
.race-player-help { flex: 1 1 360px; }
.race-player-state { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 12px; border-top: 1px solid rgba(148,163,184,.14); color: #94a3b8; }
#racePlayerCountdown { color: #fde68a; min-width: 90px; }
#racePlayerStatus { flex: 1 1 360px; }
html.race-embed #racePlayerDetails { display: none !important; }

/* v40 shell navigation: runtime modules remain immutable v39. */
.hero-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hero-links .button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 9px 13px;
  border: 1px solid rgba(191, 219, 254, 0.34);
  border-radius: 999px;
  background: rgba(96, 165, 250, 0.14);
  color: #dbeafe;
  font-weight: 850;
  text-decoration: none;
}
.hero-links .button-link:hover { color: #f8fafc; border-color: rgba(191, 219, 254, 0.72); background: rgba(96, 165, 250, 0.22); }

/* v41 dedicated AI-training embed: always show the complete NES framebuffer at
   native 1x size. The normal emulator can remember 1x/2x/3x in localStorage,
   but that persisted scale must never make the small training iframe crop. */
html.ai-training-embed {
  --screen-scale: 1 !important;
  --screen-w: 256px !important;
  --screen-h: 240px !important;
}
html.ai-training-embed,
html.ai-training-embed body,
html.ai-training-embed main,
html.ai-training-embed .emulator-panel,
html.ai-training-embed .screen-scroll {
  width: 256px !important;
  max-width: 256px !important;
  height: 240px !important;
  min-height: 240px !important;
}
html.ai-training-embed .screen-shell,
html.ai-training-embed #screen,
html.ai-training-embed .stream-remote-canvas,
html.ai-training-embed .stream-remote-video {
  width: 256px !important;
  height: 240px !important;
  max-width: 256px !important;
  max-height: 240px !important;
}
html.ai-training-embed .screen-scroll {
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  display: block !important;
}
html.ai-training-embed .screen-shell { margin: 0 !important; }
html.ai-training-embed #fullscreenBtn,
html.ai-training-embed .touch-controls-overlay { display: none !important; }
