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

body {
  background: #1a1a1a;
  background-image:
    radial-gradient(ellipse at 50% 0%, #2a2218 0%, #1a1a1a 70%);
  font-family: 'VT323', monospace;
  color: #e0d8c0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10px;
}

#app {
  max-width: 720px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Header */
#header {
  width: 100%;
  background: linear-gradient(180deg, #d4c8a8 0%, #b8a880 50%, #c8bc98 100%);
  border-radius: 10px 10px 4px 4px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.5),
    inset 0 -2px 0 rgba(0,0,0,0.15),
    0 2px 8px rgba(0,0,0,0.3);
  position: relative;
}

#rainbow-stripe {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 8px;
  flex-shrink: 0;
}

.stripe { height: 6px; border-radius: 1px; }
.stripe.red { background: #c04040; }
.stripe.orange { background: #d08030; }
.stripe.yellow { background: #d0c040; }
.stripe.green { background: #40a040; }

#header-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: #3a3020;
  letter-spacing: 2px;
}

#header-subtitle {
  font-size: 13px;
  color: #6a6050;
  margin-left: auto;
}

/* ROM Panel */
#rom-panel {
  width: 100%;
  background: linear-gradient(180deg, #3a3530 0%, #2a2520 100%);
  border: 2px solid #5a5040;
  border-radius: 6px;
  padding: 14px;
  transition: all 0.4s ease;
}

#rom-panel.collapsed {
  max-height: 0;
  padding: 0;
  border: none;
  overflow: hidden;
  margin: 0;
}

#rom-panel-title {
  text-align: center;
  font-size: 16px;
  color: #b8a870;
  margin-bottom: 12px;
  letter-spacing: 3px;
}

#rom-slots {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rom-slot {
  background: #1e1c18;
  border: 1px solid #4a4030;
  border-radius: 4px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.rom-label {
  font-size: 16px;
  color: #e0c870;
  font-weight: bold;
  min-width: 130px;
}

.rom-file {
  font-size: 13px;
  color: #887860;
  flex: 1;
  min-width: 200px;
}

.rom-slot input[type="file"] { display: none; }

.rom-btn {
  background: #5a5040;
  color: #e0d8c0;
  border: none;
  border-radius: 3px;
  padding: 4px 12px;
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 15px;
  transition: background 0.2s;
}

.rom-btn:hover { background: #7a7060; }

.rom-status {
  font-size: 15px;
  min-width: 120px;
}

#power-btn {
  display: block;
  margin: 14px auto 0;
  background: linear-gradient(180deg, #c04040 0%, #902020 100%);
  color: white;
  border: 2px solid #e06060;
  border-radius: 6px;
  padding: 10px 40px;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.3s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

#power-btn:disabled {
  background: #4a4040;
  border-color: #5a5050;
  color: #888;
  cursor: not-allowed;
}

#power-btn:not(:disabled):hover {
  background: linear-gradient(180deg, #e05050 0%, #b03030 100%);
  box-shadow: 0 0 20px rgba(255,60,60,0.4);
}

/* Monitor */
#monitor-frame {
  background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
  border-radius: 16px;
  padding: 18px 18px 8px;
  border: 2px solid #3a3a3a;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.08),
    0 4px 20px rgba(0,0,0,0.5);
  width: 100%;
  max-width: 620px;
}

#monitor-bezel {
  background: #0a0a0a;
  border-radius: 12px;
  padding: 8px;
  border: 3px solid #333;
}

#monitor-screen-wrap {
  position: relative;
  width: 100%;
  padding-top: 82.4%; /* aspect ratio */
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

#screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
  pointer-events: none;
  border-radius: 8px;
}

#scanlines.off { display: none; }

#monitor-label {
  text-align: center;
  font-size: 12px;
  color: #555;
  margin-top: 6px;
  letter-spacing: 4px;
}

#monitor-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  margin: 4px auto;
  transition: background 0.3s;
}

#monitor-led.on {
  background: #40ff40;
  box-shadow: 0 0 6px #40ff40;
}

/* Control Bar */
#control-bar {
  width: 100%;
  max-width: 620px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: #2a2520;
  border-radius: 4px;
  border: 1px solid #4a4030;
}

.ctrl-btn {
  background: #4a4030;
  color: #d0c8a0;
  border: 1px solid #6a6050;
  border-radius: 3px;
  padding: 4px 10px;
  font-family: 'VT323', monospace;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
}

.ctrl-btn:hover { background: #6a6050; }
.ctrl-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ctrl-btn.active { background: #5a7040; border-color: #7a9060; }

#ctrl-volume {
  width: 60px;
  accent-color: #7a9060;
}

#speed-display {
  font-size: 15px;
  color: #40ff40;
  margin-left: auto;
  background: #0a0a0a;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid #333;
}

/* Virtual Keyboard */
#keyboard {
  width: 100%;
  max-width: 620px;
  background: linear-gradient(180deg, #c8b890 0%, #a89870 100%);
  border-radius: 8px;
  padding: 10px 6px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.3),
    0 3px 10px rgba(0,0,0,0.3);
}

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

.key {
  background: linear-gradient(180deg, #7a6e58 0%, #5a5040 100%);
  color: #f0e8d0;
  border: 1px solid #8a7e68;
  border-bottom: 2px solid #3a3020;
  border-radius: 3px;
  min-width: 32px;
  height: 32px;
  font-family: 'VT323', monospace;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1;
  padding: 2px 4px;
  user-select: none;
  transition: all 0.1s;
}

.key:hover { background: linear-gradient(180deg, #8a7e68 0%, #6a6050 100%); }
.key:active, .key.pressed {
  background: #3a3020;
  border-bottom: 1px solid #3a3020;
  transform: translateY(1px);
}

.key-sm { min-width: 40px; font-size: 11px; }
.key-md { min-width: 50px; font-size: 11px; }
.key-lg { min-width: 70px; }
.key-space { min-width: 280px; }
.key-fn { min-width: 46px; background: linear-gradient(180deg, #6a5e48 0%, #4a4030 100%); }
.fn-row { margin-top: 4px; }

/* Peripherals */
#peripherals {
  width: 100%;
  max-width: 620px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.periph-panel {
  flex: 1;
  min-width: 260px;
  background: linear-gradient(180deg, #d0c8a8 0%, #b0a880 100%);
  border-radius: 6px;
  border: 2px solid #a09070;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.periph-title {
  background: #3a3530;
  color: #c8b880;
  padding: 5px 10px;
  font-size: 13px;
  letter-spacing: 2px;
  text-align: center;
}

.periph-body {
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.periph-panel input[type="file"] { display: none; }

.periph-btn {
  background: #5a5040;
  color: #e0d8c0;
  border: none;
  border-radius: 3px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 14px;
  transition: background 0.2s;
}

.periph-btn:hover { background: #7a7060; }

.periph-file {
  font-size: 13px;
  color: #5a5040;
  flex: 1;
}

.disk-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4a0000;
  border: 1px solid #2a0000;
  transition: background 0.1s;
}

.disk-led.active {
  background: #ff2020;
  box-shadow: 0 0 8px #ff2020;
}

.tape-controls {
  display: flex;
  gap: 2px;
}

.tape-btn {
  background: #4a4030;
  color: #d0c8a0;
  border: 1px solid #6a6050;
  border-radius: 2px;
  width: 28px;
  height: 24px;
  font-size: 12px;
  cursor: pointer;
}

#tape-counter {
  background: #0a0a0a;
  color: #40ff40;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 2px;
  min-width: 36px;
  text-align: center;
}

/* Debug Panel */
#debug-panel {
  width: 100%;
  max-width: 620px;
  background: #0a0a0a;
  border: 1px solid #40ff40;
  border-radius: 4px;
  padding: 10px;
  font-size: 15px;
  color: #40ff40;
}

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

#debug-title {
  font-size: 16px;
  margin-bottom: 6px;
  letter-spacing: 3px;
}

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

#debug-registers b {
  color: #80ff80;
  margin-left: 4px;
}

#dbg-opcode {
  font-size: 14px;
  color: #b0ffb0;
  margin-bottom: 8px;
}

#debug-mem label {
  font-size: 14px;
}

#dbg-addr {
  background: #1a1a1a;
  color: #40ff40;
  border: 1px solid #40ff40;
  width: 60px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 2px 4px;
}

#dbg-hex {
  font-size: 13px;
  color: #60dd60;
  margin-top: 4px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.3;
}

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

#footer a {
  color: #b8a870;
  text-decoration: none;
}

#footer a:hover {
  color: #e0c870;
  text-decoration: underline;
}

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 640px) {
  .key { min-width: 24px; height: 28px; font-size: 11px; }
  .key-sm { min-width: 30px; }
  .key-md { min-width: 38px; }
  .key-lg { min-width: 54px; }
  .key-space { min-width: 180px; }
  .key-fn { min-width: 36px; }
  #header-text { font-size: 11px; }
  #header-subtitle { display: none; }
  .rom-file { min-width: 140px; font-size: 11px; }
  .rom-label { min-width: 100px; font-size: 14px; }
}