* { margin:0; padding:0; box-sizing:border-box; }

:root {
  --bg: #0d0d1a;
  --console-body: #d4d0c8;
  --console-dark: #b0aca0;
  --bezel: #2a2a2a;
  --lcd-light: #8B956D;
  --lcd-med: #6A7A3A;
  --lcd-dark: #3A4A1A;
  --lcd-darkest: #1A2A0A;
  --accent: #c4a035;
  --menu-bg: #1a1a2e;
  --menu-text: #8B956D;
  --debug-bg: #0a0a0a;
  --debug-text: #33ff33;
  --btn-red: #8b2020;
  --btn-gray: #555;
}

html, body {
  background: var(--bg);
  color: #ccc;
  font-family: 'JetBrains Mono', monospace;
  overflow-x: hidden;
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding-bottom: 60px;
}

/* Menu Bar */
#menu-bar {
  display: flex;
  width: 100%;
  background: var(--menu-bg);
  border-bottom: 2px solid #2a2a4e;
  padding: 0;
  z-index: 100;
  position: sticky;
  top: 0;
}

.menu-item {
  padding: 8px 16px;
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  color: var(--menu-text);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.menu-item:hover { background: #2a2a4e; color: #fff; }

#fps-counter {
  margin-left: auto;
  padding: 8px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--accent);
}

#menu-dropdown {
  position: absolute;
  top: 30px;
  background: #1a1a2e;
  border: 1px solid #2a2a4e;
  z-index: 101;
  min-width: 200px;
}

#menu-dropdown .dd-item {
  padding: 8px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: #aaa;
  cursor: pointer;
  border-bottom: 1px solid #1a1a28;
}

#menu-dropdown .dd-item:hover { background: #2a2a4e; color: #fff; }
#menu-dropdown .dd-sep { border-bottom: 1px solid #444; height: 0; }

/* Console Body */
#console-body {
  background: linear-gradient(145deg, #ddd8d0, #c4c0b8);
  border-radius: 20px;
  padding: 20px;
  margin-top: 20px;
  width: 520px;
  max-width: 95vw;
  box-shadow: 
    0 8px 30px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.3),
    inset 0 -2px 0 rgba(0,0,0,0.1);
  position: relative;
}

#console-top { text-align: center; }

#supervision-logo {
  font-family: 'Press Start 2P', cursive;
  font-size: 16px;
  color: #333;
  letter-spacing: 4px;
  margin-bottom: 10px;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
}

/* Screen Bezel */
#screen-bezel {
  position: relative;
  display: inline-block;
  background: var(--bezel);
  padding: 12px;
  border-radius: 8px;
  box-shadow: 
    inset 0 2px 8px rgba(0,0,0,0.8),
    0 1px 0 rgba(255,255,255,0.2);
}

#screen {
  display: block;
  width: 480px;
  height: 480px;
  max-width: 80vw;
  max-height: 80vw;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--lcd-light);
  border-radius: 2px;
}

#lcd-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 480px;
  height: 480px;
  max-width: 80vw;
  max-height: 80vw;
  pointer-events: none;
  opacity: 0.12;
  image-rendering: pixelated;
}

/* Cartridge Area */
#cartridge-area {
  text-align: center;
  margin: 12px 0 8px;
}

#cartridge-slot {
  display: inline-block;
}

#insert-cartridge-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  background: linear-gradient(180deg, #666, #444);
  color: #ddd;
  border: 2px solid #333;
  padding: 8px 24px;
  cursor: pointer;
  border-radius: 4px;
  letter-spacing: 1px;
  transition: all 0.15s;
}

#insert-cartridge-btn:hover {
  background: linear-gradient(180deg, #777, #555);
  color: #fff;
}

#insert-cartridge-btn:active {
  transform: translateY(2px);
}

#cartridge-label {
  background: linear-gradient(180deg, #e8e4d8, #d4d0c4);
  border: 2px solid #999;
  border-radius: 6px;
  padding: 6px 16px;
  margin-top: 6px;
  display: inline-block;
}

#cart-name {
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  color: #333;
  display: block;
}

#cart-size {
  font-size: 9px;
  color: #666;
}

/* Controls */
#controls-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding: 0 10px;
}

/* D-Pad */
#dpad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.dpad-row {
  display: flex;
  align-items: center;
  gap: 0;
}

.dpad-btn {
  width: 40px;
  height: 40px;
  background: linear-gradient(145deg, #4a4a4a, #333);
  border: 2px solid #222;
  color: #aaa;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.05s;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: linear-gradient(145deg, #333, #222);
  transform: scale(0.95);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

#dpad-up { border-radius: 6px 6px 0 0; }
#dpad-down { border-radius: 0 0 6px 6px; }
#dpad-left { border-radius: 6px 0 0 6px; }
#dpad-right { border-radius: 0 6px 6px 0; }

.dpad-center {
  width: 40px;
  height: 40px;
  background: #3a3a3a;
  border: 2px solid #222;
}

/* Meta buttons */
#meta-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.meta-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 6px;
  background: linear-gradient(145deg, #666, #555);
  color: #ccc;
  border: 2px solid #444;
  padding: 6px 14px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.05s;
}

.meta-btn:active, .meta-btn.pressed {
  background: linear-gradient(145deg, #444, #333);
  transform: scale(0.95);
}

/* A/B Buttons */
#ab-buttons {
  display: flex;
  gap: 12px;
  align-items: center;
}

.action-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border: 3px solid #222;
  transition: all 0.05s;
}

#btn-a {
  background: linear-gradient(145deg, #a03030, #7a2020);
  color: #eee;
}

#btn-b {
  background: linear-gradient(145deg, #606060, #444);
  color: #ddd;
}

.action-btn:active, .action-btn.pressed {
  transform: scale(0.92);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}

#btn-a:active, #btn-a.pressed { background: linear-gradient(145deg, #7a2020, #5a1010); }
#btn-b:active, #btn-b.pressed { background: linear-gradient(145deg, #444, #333); }

/* Test ROMs */
#test-roms {
  text-align: center;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 2px solid #b0aca0;
}

.test-rom-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  color: #666;
  margin-bottom: 8px;
}

.test-rom-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: #555;
  color: #ddd;
  border: 1px solid #444;
  padding: 5px 12px;
  margin: 0 3px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}

.test-rom-btn:hover { background: #777; color: #fff; }

/* Debug Panel */
#debug-panel {
  width: 520px;
  max-width: 95vw;
  margin-top: 16px;
}

.debug-header {
  background: var(--debug-bg);
  border: 1px solid #1a3a1a;
  padding: 8px 12px;
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  color: var(--debug-text);
  cursor: pointer;
  user-select: none;
}

.debug-header:hover { background: #111; }

.debug-content {
  background: var(--debug-bg);
  border: 1px solid #1a3a1a;
  border-top: none;
  padding: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--debug-text);
}

#registers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.reg {
  background: #0a1a0a;
  padding: 3px 8px;
  border: 1px solid #1a3a1a;
  border-radius: 2px;
}

.reg-label { color: #559955; margin-right: 4px; }

#disasm {
  background: #050a05;
  padding: 6px;
  border: 1px solid #1a3a1a;
  font-size: 10px;
  min-height: 80px;
  max-height: 160px;
  overflow-y: auto;
  margin-bottom: 8px;
  white-space: pre;
  line-height: 1.4;
}

#debug-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.dbg-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: #1a2a1a;
  color: var(--debug-text);
  border: 1px solid #2a4a2a;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: 2px;
}

.dbg-btn:hover { background: #2a3a2a; }

#cycle-info {
  display: flex;
  gap: 20px;
  font-size: 10px;
  color: #559955;
  margin-bottom: 8px;
}

#hex-viewer { margin-top: 6px; }

#hex-addr {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: #0a0a0a;
  color: var(--debug-text);
  border: 1px solid #2a4a2a;
  padding: 4px 8px;
  width: 100px;
  margin-bottom: 4px;
}

#hex-dump {
  font-size: 9px;
  white-space: pre;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  color: #448844;
}

/* Sound Debug */
.channel-viz {
  margin-bottom: 8px;
  border: 1px solid #1a3a1a;
  padding: 6px;
}

.ch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 10px;
}

.mute-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  background: #1a2a1a;
  color: var(--debug-text);
  border: 1px solid #2a4a2a;
  padding: 2px 8px;
  cursor: pointer;
}

.mute-btn.muted { color: #aa3333; background: #2a1a1a; border-color: #4a2a2a; }

.ch-scope {
  width: 100%;
  height: 40px;
  background: #050a05;
  border: 1px solid #1a3a1a;
  display: block;
}

.ch-info { font-size: 9px; color: #559955; margin-top: 3px; }

#master-vol {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  margin-top: 6px;
}

#volume-slider {
  flex: 1;
  accent-color: var(--debug-text);
}

/* ROM Info */
#rom-info {
  width: 520px;
  max-width: 95vw;
  margin-top: 12px;
  background: var(--debug-bg);
  border: 1px solid #1a3a1a;
  padding: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--debug-text);
}

.rom-info-header {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  color: var(--accent);
  margin-bottom: 6px;
}

#rom-details { margin-bottom: 6px; color: #aaa; }

#rom-hexdump {
  white-space: pre;
  font-size: 9px;
  color: #448844;
  max-height: 100px;
  overflow-y: auto;
}

/* Modal */
#modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#modal {
  background: #1a1a2e;
  border: 2px solid #2a2a4e;
  border-radius: 8px;
  padding: 24px;
  max-width: 500px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  color: #ccc;
}

#modal-close {
  position: absolute;
  top: 8px; right: 12px;
  background: none;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
}

#modal-content {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
}

#modal-content h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 12px;
}

#modal-content h3 {
  font-size: 12px;
  color: var(--menu-text);
  margin: 12px 0 6px;
}

#modal-content p { margin-bottom: 8px; }

#modal-content kbd {
  background: #333;
  padding: 1px 6px;
  border: 1px solid #555;
  border-radius: 3px;
  font-size: 10px;
}

/* Screenshot */
#screenshot-btn {
  position: fixed;
  bottom: 60px;
  right: 16px;
  background: var(--menu-bg);
  border: 1px solid #2a2a4e;
  color: #ccc;
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 50;
  transition: all 0.15s;
}

#screenshot-btn:hover { background: #2a2a4e; transform: scale(1.1); }

/* Fun Facts */
#fun-facts {
  width: 520px;
  max-width: 95vw;
  margin-top: 16px;
  padding: 10px;
  background: rgba(139,149,109,0.1);
  border: 1px solid rgba(139,149,109,0.2);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--menu-text);
  text-align: center;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Footer */
footer {
  margin-top: 24px;
  text-align: center;
}

footer a {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

footer a:hover { color: #fff; }

/* Hidden utility */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 560px) {
  #console-body { padding: 12px; width: 100%; border-radius: 12px; margin-top: 8px; }
  #screen { width: 320px; height: 320px; }
  #lcd-overlay { width: 320px; height: 320px; }
  #supervision-logo { font-size: 12px; }
  .dpad-btn { width: 36px; height: 36px; }
  .dpad-center { width: 36px; height: 36px; }
  .action-btn { width: 44px; height: 44px; font-size: 10px; }
  #debug-panel, #rom-info, #fun-facts { width: 100%; }
}

/* LCD Flicker Animation */
@keyframes lcd-flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.98; }
}

#screen { animation: lcd-flicker 0.1s infinite; }

/* Glitch screen effect */
@keyframes glitch {
  0% { transform: translate(0); }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(2px, -1px); }
  60% { transform: translate(-1px, 2px); }
  80% { transform: translate(1px, -2px); }
  100% { transform: translate(0); }
}

.glitch-active #screen {
  animation: glitch 0.15s infinite;
}