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

:root {
  --bg: #0d0d1a;
  --console-dark: #3a3a3a;
  --console-mid: #555555;
  --console-light: #6e6e6e;
  --bezel: #2a2a2a;
  --green1: #0f380f;
  --green2: #306230;
  --green3: #8bac0f;
  --green4: #9bbc0f;
  --neon: #39ff14;
  --neon-dim: #1a8a0a;
  --text: #c0c0c0;
  --text-bright: #e0ffe0;
  --danger: #ff3344;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', monospace;
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(ellipse at 20% 50%, rgba(57, 255, 20, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(57, 255, 20, 0.02) 0%, transparent 50%);
}

#app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px;
  position: relative;
}

/* Info Panel */
#info-toggle {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--console-dark);
  border: 2px solid var(--neon-dim);
  color: var(--neon);
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.2s;
}
#info-toggle:hover {
  background: var(--neon-dim);
  color: #fff;
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.4);
}

#info-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s;
}
#info-panel.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#info-content {
  background: #1a1a2e;
  border: 2px solid var(--neon-dim);
  border-radius: 8px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  font-size: 16px;
  line-height: 1.6;
}
#info-content h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--neon);
  margin-bottom: 16px;
}
#info-content h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--green4);
  margin: 16px 0 8px;
}
#info-content ul {
  list-style: none;
  padding-left: 8px;
}
#info-content li::before {
  content: '► ';
  color: var(--neon-dim);
}
#info-content li {
  margin: 4px 0;
}
.disclaimer {
  margin-top: 16px;
  padding: 12px;
  background: rgba(57,255,20,0.05);
  border: 1px dashed var(--neon-dim);
  border-radius: 4px;
  font-style: italic;
  text-align: center;
}
.disclaimer span {
  font-size: 13px;
  color: #888;
}
#info-close {
  display: block;
  margin: 16px auto 0;
  padding: 8px 20px;
  background: var(--neon-dim);
  border: none;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  border-radius: 4px;
}
#info-close:hover {
  background: var(--neon);
  color: #000;
}

/* Main Layout */
#main-layout {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* Console */
#console-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Cartridge Zone */
#cartridge-zone {
  width: 300px;
  margin-bottom: -4px;
  z-index: 2;
  position: relative;
}

#cartridge-slot {
  background: linear-gradient(180deg, #4a4a4a, #3a3a3a);
  border: 2px solid #555;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.3s;
}
#cartridge-slot:hover {
  border-color: var(--neon-dim);
  box-shadow: 0 0 10px rgba(57,255,20,0.15);
}
#cartridge-slot.drag-over {
  border-color: var(--neon);
  box-shadow: 0 0 20px rgba(57,255,20,0.3);
}

#drop-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  text-align: center;
  color: #aaa;
  line-height: 1.8;
  pointer-events: none;
}
#drop-text span {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: #777;
}

#cartridge {
  position: absolute;
  width: 120px;
  height: 70px;
  background: linear-gradient(180deg, #2a2a5a, #1a1a3a);
  border: 2px solid #4a4a8a;
  border-radius: 6px 6px 0 0;
  top: -70px;
  transition: top 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
#cartridge.inserted {
  top: 8px;
}
#cartridge.hidden { display: none; }
#cartridge-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--green4);
  background: rgba(0,0,0,0.4);
  padding: 3px 8px;
  border-radius: 2px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Console Body */
#console-body {
  background: linear-gradient(180deg, #6e6e6e 0%, #555 30%, #4a4a4a 100%);
  border: 3px solid #777;
  border-radius: 12px;
  padding: 12px;
  width: 360px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.1);
}

#console-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 0 4px;
}

#logo-area {
  display: flex;
  flex-direction: column;
}
.logo-bit {
  font-family: 'VT323', monospace;
  font-size: 12px;
  color: #999;
  letter-spacing: 2px;
}
.logo-gamate {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: #ddd;
  text-shadow: 1px 1px 0 #333;
  letter-spacing: 3px;
}

#power-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 10px;
  background: #3a3a3a;
  border: 2px solid #555;
  border-radius: 4px;
  transition: all 0.2s;
}
#power-btn:hover {
  border-color: #888;
}
#power-btn span {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #aaa;
}
#power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #400;
  transition: all 0.3s;
}
#power-led.on {
  background: var(--neon);
  box-shadow: 0 0 8px var(--neon), 0 0 16px rgba(57,255,20,0.3);
}

/* Screen */
#screen-bezel {
  background: #1a1a1a;
  border: 3px solid #333;
  border-radius: 6px;
  padding: 8px;
  margin: 0 auto 12px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.8);
}

#screen-inner {
  position: relative;
  width: 480px;
  max-width: 100%;
  aspect-ratio: 160 / 152;
  overflow: hidden;
  border-radius: 2px;
  background: var(--green1);
}

#canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

#lcd-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.12) 2px,
    rgba(0,0,0,0.12) 3px
  );
  mix-blend-mode: multiply;
}

#screen-off-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: var(--green2);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.5s;
}
#screen-off-text.hidden { opacity: 0; }

/* Controls */
#controls-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
}

/* D-Pad */
#dpad-area {
  flex-shrink: 0;
}
#dpad {
  display: grid;
  grid-template-columns: 36px 36px 36px;
  grid-template-rows: 36px 36px 36px;
  gap: 0;
}
.dpad-btn {
  background: #2a2a2a;
  border: 2px solid #444;
  color: #999;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: #444;
  color: var(--neon);
  border-color: var(--neon-dim);
}
.dpad-up { grid-column: 2; grid-row: 1; border-radius: 4px 4px 0 0; }
.dpad-left { grid-column: 1; grid-row: 2; border-radius: 4px 0 0 4px; }
.dpad-right { grid-column: 3; grid-row: 2; border-radius: 0 4px 4px 0; }
.dpad-down { grid-column: 2; grid-row: 3; border-radius: 0 0 4px 4px; }
.dpad-center { grid-column: 2; grid-row: 2; background: #333; }

/* Middle Buttons */
#middle-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sys-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  background: #444;
  border: 2px solid #555;
  border-radius: 12px;
  color: #aaa;
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.sys-btn:active, .sys-btn.pressed {
  background: #666;
  color: var(--neon);
}

/* A/B Buttons */
#ab-area {
  display: flex;
  gap: 10px;
  align-items: center;
}
.action-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b2252, #6a1a3e);
  border: 3px solid #a03060;
  color: #ddd;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.1s;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.action-btn:active, .action-btn.pressed {
  background: linear-gradient(135deg, #a03060, #8b2252);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
  transform: translateY(2px);
}
#btn-b { margin-top: 16px; }

/* Speaker */
#speaker-grille {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 20px;
  margin-top: 4px;
  align-items: flex-end;
}
.grille-line {
  width: 60px;
  height: 2px;
  background: #3a3a3a;
  border-radius: 1px;
}

/* Hardware Panel */
#hw-panel {
  width: 280px;
  background: #111118;
  border: 2px solid #2a2a3a;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  flex-shrink: 0;
}
#hw-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--neon);
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: 2px;
}

.hw-section {
  background: rgba(57,255,20,0.03);
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 8px;
}
.hw-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--green3);
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.hw-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
}
.reg-label {
  color: #888;
  font-size: 14px;
}
.reg-val {
  color: var(--neon);
  font-size: 14px;
  font-family: 'VT323', monospace;
}

.hw-status {
  margin-top: 4px;
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #666;
  padding: 3px;
  border-top: 1px solid #2a2a3a;
}
.hw-status.running {
  color: var(--neon);
  animation: blink 1s infinite;
}
@keyframes blink {
  50% { opacity: 0.5; }
}

/* PSG Channels */
#psg-channels {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.psg-ch {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ch-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: #888;
  width: 40px;
  flex-shrink: 0;
}
.freq-bar-bg {
  flex: 1;
  height: 8px;
  background: #1a1a2a;
  border-radius: 2px;
  overflow: hidden;
}
.freq-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--neon-dim), var(--neon));
  border-radius: 2px;
  transition: width 0.1s;
}
.noise-bar {
  background: linear-gradient(90deg, #884400, #ff8800);
}
.ch-freq {
  font-size: 12px;
  color: #666;
  width: 50px;
  text-align: right;
  flex-shrink: 0;
}

#rom-info {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  word-break: break-all;
}

/* Toolbar */
#toolbar {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.tool-btn {
  flex: 1;
  padding: 6px;
  background: #1a1a2e;
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  transition: all 0.2s;
}
.tool-btn:hover {
  border-color: var(--neon-dim);
  color: var(--neon);
}

/* Footer */
footer {
  text-align: center;
  padding: 16px;
  margin-top: 16px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #555;
}
footer a {
  color: var(--neon-dim);
  text-decoration: none;
}
footer a:hover {
  color: var(--neon);
  text-decoration: underline;
}
.sep {
  margin: 0 8px;
}

/* CRT Power Animation */
@keyframes powerOn {
  0% { transform: scaleY(0.005) scaleX(0.3); filter: brightness(10); }
  30% { transform: scaleY(0.005) scaleX(1); }
  50% { transform: scaleY(1) scaleX(1); filter: brightness(2); }
  100% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
}
@keyframes powerOff {
  0% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
  40% { transform: scaleY(1) scaleX(1); filter: brightness(2); }
  60% { transform: scaleY(0.005) scaleX(1); }
  100% { transform: scaleY(0.005) scaleX(0); filter: brightness(10); opacity: 0; }
}

#screen-inner.power-on canvas {
  animation: powerOn 0.6s ease-out forwards;
}
#screen-inner.power-off canvas {
  animation: powerOff 0.4s ease-in forwards;
}

/* Responsive */
@media (max-width: 800px) {
  #main-layout {
    flex-direction: column;
    align-items: center;
  }
  #hw-panel {
    width: 100%;
    max-width: 360px;
  }
  #console-body {
    width: 100%;
    max-width: 360px;
  }
  #cartridge-zone {
    width: 100%;
    max-width: 300px;
  }
  #screen-bezel {
    padding: 4px;
  }
}

@media (max-width: 400px) {
  #console-body {
    padding: 8px;
  }
  .action-btn {
    width: 38px;
    height: 38px;
    font-size: 10px;
  }
  .dpad-btn {
    width: 32px;
    height: 32px;
  }
  #dpad {
    grid-template-columns: 32px 32px 32px;
    grid-template-rows: 32px 32px 32px;
  }
}