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

:root {
  --bg-dark: #0d0d1a;
  --bg-panel: rgba(20, 20, 40, 0.9);
  --bezel: #c4b08a;
  --bezel-dark: #8a7a5a;
  --accent: #55a049;
  --accent-light: #94e089;
  --text: #e0dcc8;
  --text-dim: #8a8670;
  --border-color: #40318d;
  --vic-blue: #87d6dd;
  --vic-purple: #aa5fb6;
  --vic-red: #782922;
  --vic-green: #55a049;
  --vic-yellow: #bfce72;
}

body {
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(66, 52, 139, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(119, 45, 38, 0.1) 0%, transparent 50%);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#app {
  width: 100%;
  max-width: 900px;
  padding: 10px;
}

#top-bar {
  text-align: center;
  padding: 20px 10px 10px;
}

#top-bar h1 {
  font-size: 16px;
  color: var(--vic-yellow);
  text-shadow: 2px 2px 0 var(--vic-red), 0 0 20px rgba(189, 204, 113, 0.3);
  letter-spacing: 1px;
}

.subtitle {
  font-size: 8px;
  color: var(--text-dim);
  margin-top: 8px;
  letter-spacing: 2px;
}

.panel {
  background: var(--bg-panel);
  border: 2px solid var(--border-color);
  border-radius: 4px;
  padding: 15px;
  margin: 10px 0;
}

#rom-upload {
  text-align: center;
}

#rom-upload h2 {
  font-size: 12px;
  color: var(--vic-blue);
  margin-bottom: 8px;
}

.rom-info {
  font-size: 7px;
  color: var(--text-dim);
  margin-bottom: 15px;
}

.rom-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}

.rom-slot {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--bezel-dark);
  border-radius: 4px;
  padding: 10px;
  width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.rom-slot label {
  font-size: 9px;
  text-align: center;
  color: var(--vic-yellow);
}

.rom-file-name {
  font-size: 6px;
  color: var(--text-dim);
}

.rom-slot input[type="file"] {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--text);
  width: 100%;
}

.rom-status {
  font-size: 20px;
}

#power-on {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  padding: 15px 40px;
  background: linear-gradient(180deg, #3a3a3a 0%, #222 100%);
  color: #666;
  border: 3px solid #555;
  border-radius: 8px;
  cursor: not-allowed;
  transition: all 0.3s;
  text-shadow: none;
}

#power-on:not(:disabled) {
  background: linear-gradient(180deg, #4a7a3a 0%, #2a5a1a 100%);
  color: var(--accent-light);
  border-color: var(--accent);
  cursor: pointer;
  text-shadow: 0 0 10px rgba(146, 223, 135, 0.5);
  box-shadow: 0 0 20px rgba(85, 158, 74, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

#power-on:not(:disabled):hover {
  background: linear-gradient(180deg, #5a9a4a 0%, #3a7a2a 100%);
  box-shadow: 0 0 30px rgba(85, 158, 74, 0.5), inset 0 1px 0 rgba(255,255,255,0.2);
}

#power-on:not(:disabled):active {
  transform: scale(0.97);
}

#crt-bezel {
  background: linear-gradient(135deg, var(--bezel) 0%, var(--bezel-dark) 100%);
  border-radius: 16px;
  padding: 20px;
  margin: 10px auto;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 2px 0 rgba(255,255,255,0.2),
    inset 0 -2px 0 rgba(0,0,0,0.3);
  position: relative;
}

#crt-inner {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 3px solid #333;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
}

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

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

#scanline-overlay.active {
  display: block;
}

#bezel-label {
  text-align: center;
  font-size: 10px;
  color: var(--bezel-dark);
  margin-top: 10px;
  letter-spacing: 4px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}

#control-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

#control-bar button, #control-bar select {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #3a3a5a 0%, #2a2a4a 100%);
  color: var(--text);
  border: 2px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

#control-bar button:hover, #control-bar select:hover {
  background: linear-gradient(180deg, #4a4a7a 0%, #3a3a6a 100%);
  border-color: var(--vic-blue);
}

#control-bar button.active {
  background: linear-gradient(180deg, #4a7a3a 0%, #2a5a1a 100%);
  border-color: var(--accent);
}

#volume-slider {
  width: 80px;
  accent-color: var(--accent);
}

.collapsible h3 {
  font-size: 10px;
  cursor: pointer;
  user-select: none;
  color: var(--vic-blue);
  transition: color 0.2s;
}

.collapsible h3:hover {
  color: var(--vic-yellow);
}

.collapsible h3 .arrow {
  font-size: 8px;
  display: inline-block;
  transition: transform 0.2s;
}

.collapsible h3.open .arrow {
  transform: rotate(90deg);
}

.panel-content {
  margin-top: 10px;
}

.storage-row {
  margin-bottom: 10px;
}

.storage-row label {
  font-size: 9px;
  display: block;
  margin-bottom: 5px;
}

.storage-row input[type="file"] {
  font-size: 7px;
  font-family: 'Press Start 2P', monospace;
  color: var(--text);
}

.file-list {
  font-size: 7px;
  color: var(--text-dim);
  margin-top: 5px;
}

#debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.debug-section {
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 8px;
}

.debug-section h4 {
  font-size: 8px;
  color: var(--vic-purple);
  margin-bottom: 5px;
}

.debug-section pre {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--accent-light);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 150px;
  overflow-y: auto;
}

#debug-controls {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#debug-controls button, #debug-controls input {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 10px;
  background: rgba(0,0,0,0.5);
  color: var(--text);
  border: 1px solid var(--border-color);
  border-radius: 3px;
}

#debug-controls button {
  cursor: pointer;
}

#debug-controls button:hover {
  border-color: var(--vic-blue);
}

#debug-controls label {
  font-size: 7px;
}

#debug-controls input[type="text"] {
  width: 50px;
}

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

.mem-controls input {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 4px;
  width: 60px;
  background: rgba(0,0,0,0.5);
  color: var(--text);
  border: 1px solid var(--border-color);
}

.mem-controls button {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.5);
  color: var(--text);
  border: 1px solid var(--border-color);
  cursor: pointer;
}

#keyboard-visual {
  display: grid;
  gap: 3px;
  font-size: 6px;
}

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

.kb-key {
  background: linear-gradient(180deg, #4a4a4a 0%, #2a2a2a 100%);
  border: 1px solid #666;
  border-radius: 3px;
  padding: 4px 6px;
  min-width: 28px;
  text-align: center;
  color: var(--text);
  font-size: 6px;
  line-height: 1.4;
  transition: all 0.1s;
}

.kb-key.pressed {
  background: linear-gradient(180deg, var(--accent) 0%, #2a5a1a 100%);
  border-color: var(--accent-light);
  color: #fff;
}

.kb-key .pc-key {
  font-size: 5px;
  color: var(--vic-blue);
  display: block;
}

footer {
  text-align: center;
  padding: 20px;
  font-size: 7px;
  color: var(--text-dim);
  margin-top: auto;
}

footer a {
  color: var(--vic-blue);
  text-decoration: none;
  display: block;
  margin-top: 5px;
}

footer a:hover {
  color: var(--vic-yellow);
}

@media (max-width: 600px) {
  #top-bar h1 { font-size: 11px; }
  .rom-slot { width: 100%; }
  #debug-grid { grid-template-columns: 1fr; }
  #crt-bezel { padding: 10px; border-radius: 10px; }
}