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

:root {
  --bg: #0e0e1a;
  --panel-bg: #1a1a2e;
  --panel-border: #2a2a4a;
  --cyan: #85d4dc;
  --yellow: #bdcc71;
  --light-yellow: #ffffb0;
  --blue: #42348b;
  --light-blue: #7e70ca;
  --beige: #e9b287;
  --orange: #a8734a;
  --red: #772d26;
  --green: #559e4a;
  --text: #c5ffff;
  --text-dim: #6688aa;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  min-height: 100vh;
  overflow-x: hidden;
}

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

header {
  text-align: center;
  padding: 16px 12px 8px;
  background: linear-gradient(180deg, #2a1a0e 0%, var(--bg) 100%);
  border-bottom: 2px solid var(--orange);
}

header h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: 24px;
  color: var(--beige);
  text-shadow: 2px 2px 0 #3a2010, 0 0 20px rgba(233,178,135,0.3);
  letter-spacing: 2px;
}

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

#main-layout {
  display: flex;
  flex: 1;
  gap: 12px;
  padding: 12px;
  justify-content: center;
  align-items: flex-start;
}

#left-panel {
  width: 240px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#right-panel {
  width: 280px;
  min-width: 200px;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 10px;
}

.panel-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  color: var(--cyan);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.rom-slot {
  margin-bottom: 8px;
}

.rom-slot label {
  display: block;
  font-size: 11px;
  color: var(--light-yellow);
  margin-bottom: 3px;
}

.rom-addr {
  color: var(--text-dim);
  font-size: 9px;
}

.rom-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rom-input-row input[type="file"] {
  flex: 1;
  font-size: 10px;
  color: var(--text);
  background: #111;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 3px;
}

.rom-input-row input[type="file"]::file-selector-button {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 2px;
  padding: 2px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  cursor: pointer;
}

.rom-status {
  font-size: 16px;
  color: #555;
}
.rom-status.loaded { color: var(--green); }
.rom-status.error { color: var(--red); }

#btn-power {
  width: 100%;
  padding: 10px;
  font-family: 'Press Start 2P', cursive;
  font-size: 11px;
  background: linear-gradient(180deg, #3a1a0a, #1a0a00);
  color: var(--beige);
  border: 2px solid var(--orange);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 6px;
}

#btn-power:not(:disabled):hover {
  background: linear-gradient(180deg, #5a3020, #3a1a0a);
  box-shadow: 0 0 12px rgba(233,178,135,0.4);
}

#btn-power:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#btn-power.powered {
  background: linear-gradient(180deg, #0a2a0a, #001a00);
  border-color: var(--green);
  color: var(--green);
  box-shadow: 0 0 8px rgba(85,158,74,0.3);
}

.periph-slot {
  margin-bottom: 6px;
}

.periph-slot label {
  display: block;
  font-size: 11px;
  color: var(--light-yellow);
  margin-bottom: 2px;
}

.periph-slot input[type="file"] {
  width: 100%;
  font-size: 10px;
  color: var(--text);
  background: #111;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 3px;
}

.periph-slot input[type="file"]::file-selector-button {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 2px;
  padding: 2px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  cursor: pointer;
}

.periph-info {
  font-size: 9px;
  color: var(--text-dim);
}

.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.control-buttons button {
  flex: 1 1 auto;
  min-width: 60px;
  padding: 5px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  background: #222;
  color: var(--cyan);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}

.control-buttons button:hover {
  background: #333;
  border-color: var(--cyan);
}

.control-buttons button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.control-buttons button.active {
  background: var(--blue);
  border-color: var(--light-blue);
  color: #fff;
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.volume-row input[type="range"] {
  flex: 1;
  accent-color: var(--cyan);
}

/* CRT Bezel */
#crt-bezel {
  position: relative;
  background: linear-gradient(160deg, #3a3a3a, #1a1a1a, #2a2a2a);
  border-radius: 20px;
  padding: 24px 28px 32px;
  box-shadow: 
    0 4px 20px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05);
}

#power-led {
  position: absolute;
  top: 10px;
  right: 36px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #333;
  box-shadow: none;
  transition: all 0.3s;
}

#crt-bezel.crt-on #power-led {
  background: #4f4;
  box-shadow: 0 0 6px #4f4, 0 0 12px rgba(0,255,0,0.3);
}

#screen-wrapper {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.8);
}

#canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 576px;
  height: 408px;
}

#scanlines {
  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;
}

#scanlines.off { display: none; }

#bezel-label {
  text-align: center;
  font-size: 9px;
  color: #666;
  margin-top: 8px;
  letter-spacing: 3px;
  text-transform: uppercase;
}

#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  padding: 8px;
  font-size: 10px;
  color: var(--text-dim);
}

#status-bar span {
  white-space: nowrap;
}

/* Debug Panel */
#debug-panel.hidden { display: none; }

#vic-regs {
  font-size: 10px;
  line-height: 1.6;
}

.reg-row {
  display: flex;
  gap: 6px;
  padding: 1px 0;
  border-bottom: 1px solid rgba(42,42,74,0.5);
}

.reg-addr { color: var(--orange); min-width: 40px; }
.reg-val { color: var(--light-yellow); min-width: 28px; }
.reg-bin { color: var(--text-dim); min-width: 72px; font-size: 9px; }
.reg-desc { color: var(--cyan); font-size: 9px; }

#cpu-state {
  font-size: 10px;
  line-height: 1.8;
  color: var(--light-yellow);
}

.cpu-reg { color: var(--beige); }
.cpu-flag { color: var(--cyan); }
.cpu-flag.set { color: var(--green); font-weight: bold; }

/* Virtual Keyboard */
#virtual-keyboard {
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

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

.kb-key {
  min-width: 36px;
  height: 30px;
  padding: 2px 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  background: linear-gradient(180deg, #7a6a5a, #5a4a3a);
  color: #fff;
  border: 1px solid #8a7a6a;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: all 0.1s;
}

.kb-key:active, .kb-key.pressed {
  background: linear-gradient(180deg, #5a4a3a, #3a2a1a);
  transform: translateY(1px);
  border-color: var(--cyan);
  box-shadow: 0 0 4px rgba(133,212,220,0.3);
}

.kb-key.wide { min-width: 60px; }
.kb-key.xwide { min-width: 90px; }
.kb-key.space { min-width: 200px; }
.kb-key.special {
  background: linear-gradient(180deg, #4a3a5a, #2a1a3a);
  border-color: #6a5a7a;
}

footer {
  text-align: center;
  padding: 12px;
}

footer a {
  color: var(--blue);
  text-decoration: none;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
}

footer a:hover { color: var(--light-blue); }

@media (max-width: 1100px) {
  #main-layout { flex-direction: column; align-items: center; }
  #left-panel, #right-panel { width: 100%; max-width: 580px; }
  #canvas { width: 100%; height: auto; }
}

@media (max-width: 600px) {
  header h1 { font-size: 14px; }
  #crt-bezel { padding: 12px 10px 20px; border-radius: 12px; }
  #canvas { width: 100%; height: auto; }
  .kb-key { min-width: 24px; height: 24px; font-size: 7px; }
  .kb-key.wide { min-width: 40px; }
  .kb-key.xwide { min-width: 56px; }
  .kb-key.space { min-width: 120px; }
}