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

body {
  background: #0f0f23;
  color: #e0e0e0;
  font-family: 'VT323', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* Top Bar */
#top-bar {
  text-align: center;
  padding: 12px 20px 8px;
  width: 100%;
}

.rainbow-bar {
  height: 4px;
  background: linear-gradient(90deg, #000 0%, #fff 7%, #772d26 14%, #85d4dc 21%, #a85fb4 28%, #559e4a 35%, #42348b 42%, #bdcc71 50%, #a8734a 57%, #e9b287 64%, #b66862 71%, #c5ffff 78%, #e99df5 85%, #92df87 90%, #7e70ca 95%, #ffffb0 100%);
  margin-bottom: 10px;
  border-radius: 2px;
}

.title {
  font-family: 'Press Start 2P', cursive;
  font-size: 20px;
  color: #85d4dc;
  text-shadow: 0 0 20px rgba(133,212,220,0.4);
  letter-spacing: 2px;
}

.subtitle {
  font-size: 16px;
  color: #7e70ca;
  margin-top: 4px;
}

/* Main Area */
#main-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 10px;
  width: 100%;
  max-width: 900px;
}

/* CRT Screen */
#screen-container { position: relative; width: 100%; }

#crt-bezel {
  background: #1c1c1c;
  border-radius: 20px;
  padding: 16px;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.8),
    0 0 40px rgba(133,212,220,0.15),
    0 4px 20px rgba(0,0,0,0.6);
  margin: 0 auto;
  max-width: 780px;
}

#crt-inner {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.5);
}

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

#scanline-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  mix-blend-mode: multiply;
  z-index: 2;
}

#scanline-overlay.disabled { display: none; }

/* Status Bar */
#status-bar {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 6px 10px;
  font-size: 14px;
  color: #7e70ca;
  flex-wrap: wrap;
}

/* ROM Panel */
#rom-panel {
  background: #1a1a2e;
  border: 1px solid #2a2a4e;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 500px;
}

#rom-panel h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: #85d4dc;
  margin-bottom: 8px;
}

.rom-hint {
  font-size: 15px;
  color: #888;
  margin-bottom: 14px;
}

.rom-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin-bottom: 8px;
  background: #12122a;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid #2a2a4e;
  transition: border-color 0.2s;
  position: relative;
}

.rom-slot:hover { border-color: #85d4dc; }

.rom-slot input[type="file"] {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0;
  cursor: pointer;
}

.rom-icon { font-size: 28px; }
.rom-info { flex: 1; display: flex; flex-direction: column; }
.rom-info strong { font-size: 16px; color: #e0e0e0; }
.rom-info .rom-file { font-size: 13px; color: #888; }
.rom-info .rom-addr { font-size: 12px; color: #559e4a; }
.rom-status { font-size: 22px; }

#power-btn {
  width: 100%;
  padding: 14px;
  margin-top: 12px;
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: #000;
  background: #559e4a;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

#power-btn:disabled {
  background: #333;
  color: #666;
  cursor: not-allowed;
}

#power-btn:not(:disabled):hover {
  background: #92df87;
  box-shadow: 0 0 20px rgba(146,223,135,0.4);
}

#rom-cache-note {
  text-align: center;
  font-size: 12px;
  color: #555;
  margin-top: 8px;
}

#rom-panel.hidden-panel { display: none; }

/* Controls Bar */
#controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  justify-content: center;
  align-items: center;
  max-width: 900px;
}

#controls-bar button, #controls-bar select {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 6px 14px;
  background: #1a1a2e;
  color: #85d4dc;
  border: 1px solid #2a2a4e;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

#controls-bar button:hover:not(:disabled), #controls-bar select:hover:not(:disabled) {
  background: #2a2a4e;
  border-color: #85d4dc;
}

#controls-bar button:disabled, #controls-bar select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.vol-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

#vol-slider {
  width: 80px;
  accent-color: #85d4dc;
}

/* Keyboard Overlay */
#keyboard-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15,15,35,0.97);
  border-top: 2px solid #85d4dc;
  padding: 12px;
  z-index: 100;
  max-height: 50vh;
  overflow-y: auto;
}

#keyboard-overlay.hidden { display: none; }

#keyboard-close {
  position: absolute;
  top: 8px;
  right: 14px;
  font-size: 22px;
  cursor: pointer;
  color: #85d4dc;
}

#vkeyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.kb-row {
  display: flex;
  gap: 3px;
}

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 13px;
  padding: 4px 7px;
  min-width: 32px;
  text-align: center;
  background: #1a1a2e;
  border: 1px solid #3a3a5e;
  border-radius: 4px;
  color: #e0e0e0;
  cursor: pointer;
  user-select: none;
  transition: all 0.1s;
}

.kb-key:hover { background: #2a2a4e; border-color: #85d4dc; }
.kb-key.active { background: #85d4dc; color: #000; }

/* Debug Panel */
#debug-panel {
  background: #0d0d1a;
  border: 1px solid #2a2a4e;
  border-radius: 10px;
  padding: 14px;
  margin: 10px;
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 14px;
}

#debug-panel.hidden { display: none; }

.debug-section {
  background: #12122a;
  padding: 10px;
  border-radius: 6px;
}

.debug-section h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  color: #559e4a;
  margin-bottom: 6px;
}

.debug-mono {
  font-family: 'VT323', monospace;
  font-size: 14px;
  white-space: pre;
  line-height: 1.3;
  overflow-x: auto;
  color: #bdcc71;
}

.debug-btns {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  align-items: center;
}

.debug-btns button, .debug-btns input {
  font-family: 'VT323', monospace;
  font-size: 15px;
  padding: 4px 10px;
  background: #1a1a2e;
  color: #85d4dc;
  border: 1px solid #2a2a4e;
  border-radius: 4px;
}

.debug-mem-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.debug-mem-controls input {
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 2px 6px;
  width: 80px;
  background: #0d0d1a;
  color: #bdcc71;
  border: 1px solid #2a2a4e;
  border-radius: 3px;
}

.debug-mem-controls button {
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 2px 10px;
  background: #1a1a2e;
  color: #85d4dc;
  border: 1px solid #2a2a4e;
  border-radius: 3px;
  cursor: pointer;
}

/* Footer */
footer {
  padding: 14px;
  text-align: center;
  font-size: 14px;
  color: #555;
  width: 100%;
}

footer a {
  color: #85d4dc;
  text-decoration: none;
  margin-left: 12px;
}

footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 600px) {
  .title { font-size: 14px; }
  .subtitle { font-size: 13px; }
  #controls-bar { gap: 4px; }
  #controls-bar button, #controls-bar select { font-size: 13px; padding: 4px 8px; }
  #debug-panel { grid-template-columns: 1fr; }
  #crt-bezel { padding: 8px; border-radius: 12px; }
  .kb-key { font-size: 11px; padding: 3px 4px; min-width: 24px; }
}