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

:root {
  --bg-dark: #0a0a14;
  --bg-panel: #12121f;
  --bg-bezel: #2a1f0e;
  --border-color: #3a2a15;
  --text-primary: #85d4dc;
  --text-secondary: #bdcc71;
  --text-dim: #556;
  --accent-brown: #a8734a;
  --accent-orange: #e9b287;
  --accent-cyan: #85d4dc;
  --accent-green: #559e4a;
  --accent-red: #772d26;
  --accent-yellow: #bdcc71;
  --btn-bg: #1a1a2e;
  --btn-border: #4a3a25;
}

body {
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: 'Share Tech Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 50px);
}

/* ===== ROM Panel ===== */
#rom-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 20px;
  max-width: 800px;
  width: 100%;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

#rom-title {
  color: var(--accent-cyan);
  font-family: 'VT323', monospace;
  font-size: 14px;
  line-height: 1.3;
  text-align: center;
  white-space: pre;
}

.rom-subtitle {
  color: var(--accent-yellow);
  font-family: 'VT323', monospace;
  font-size: 22px;
  margin-top: 10px;
  animation: blink 1.2s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

#rom-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  margin: 30px 0;
  width: 100%;
}

.rom-slot {
  background: var(--bg-panel);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  width: 220px;
  text-align: center;
  transition: border-color 0.3s;
}

.rom-slot.loaded {
  border-color: var(--accent-green);
}

.rom-label {
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: var(--accent-orange);
  margin-bottom: 4px;
}

.rom-address {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.rom-dropzone {
  background: #0d0d1a;
  border: 2px dashed #333;
  border-radius: 6px;
  padding: 20px 10px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.rom-dropzone:hover, .rom-dropzone.dragover {
  border-color: var(--accent-cyan);
  background: #111125;
}

.drop-text {
  font-size: 11px;
  color: var(--text-dim);
}

.rom-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.rom-status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--accent-red);
}

.rom-status.loaded {
  color: var(--accent-green);
}

#power-on-btn {
  font-family: 'VT323', monospace;
  font-size: 28px;
  padding: 14px 50px;
  background: var(--accent-red);
  color: #fff;
  border: 3px solid #551a14;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 2px;
}

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

#power-on-btn:not(:disabled):hover {
  background: #993322;
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(119, 45, 38, 0.5);
}

/* ===== Emulator ===== */
#emulator {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeIn 0.4s ease;
}

.hidden { display: none !important; }

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
}

.indicator {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--accent-green);
  color: #000;
  margin-right: 6px;
  font-weight: bold;
}

#speed-display {
  font-size: 13px;
  color: var(--accent-yellow);
}

#top-controls {
  display: flex;
  gap: 8px;
}

#top-controls button {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--text-primary);
  padding: 4px 10px;
  cursor: pointer;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  border-radius: 4px;
  transition: background 0.2s;
}

#top-controls button:hover {
  background: #252540;
}

/* ===== CRT Screen ===== */
#screen-area {
  padding: 20px;
  width: 100%;
  display: flex;
  justify-content: center;
}

#crt-bezel {
  background: linear-gradient(135deg, #3a2a10, #2a1a08, #3a2a10);
  border-radius: 20px;
  padding: 20px;
  box-shadow:
    0 0 0 3px #1a1008,
    0 0 0 6px #4a3a20,
    0 0 40px rgba(0,0,0,0.8),
    inset 0 0 30px rgba(0,0,0,0.5);
}

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

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

#scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
  pointer-events: none;
}

/* CRT vignette */
#crt-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
}

/* ===== Control Bar ===== */
#control-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  width: 100%;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  justify-content: center;
  align-items: center;
}

.hw-btn {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #2a2a40, #1a1a2e);
  color: var(--text-primary);
  border: 2px solid var(--btn-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.hw-btn:hover {
  background: linear-gradient(180deg, #3a3a55, #2a2a40);
  border-color: var(--accent-cyan);
}

.hw-btn:active {
  transform: scale(0.97);
}

.hw-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#main-controls {
  display: flex;
  gap: 8px;
}

#storage-controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.storage-slot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.storage-label {
  font-size: 11px;
  color: var(--text-dim);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden-input {
  display: none;
}

/* ===== Debug Panel ===== */
#debug-toggle-bar {
  width: 100%;
  text-align: center;
}

#debug-toggle-btn {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 20px;
}

#debug-toggle-btn:hover {
  color: var(--text-primary);
}

#debug-panel {
  width: 100%;
  background: #050510;
  border: 1px solid #1a1a30;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  font-size: 12px;
  color: #33cc66;
  max-height: 350px;
  overflow-y: auto;
}

#debug-panel h3 {
  font-family: 'VT323', monospace;
  font-size: 15px;
  color: #55ee88;
  margin-bottom: 8px;
  border-bottom: 1px solid #1a2a1a;
  padding-bottom: 4px;
}

#cpu-regs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.reg {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.reg-name {
  font-size: 10px;
  color: #448;
}

.reg-val {
  font-family: 'Share Tech Mono', monospace;
  font-size: 14px;
  color: #6f6;
}

#cpu-flags {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.flag {
  padding: 2px 6px;
  background: #111;
  border: 1px solid #222;
  border-radius: 3px;
  font-size: 11px;
  color: #444;
}

.flag.active {
  color: #6f6;
  border-color: #363;
  background: #0a1a0a;
}

#vic-regs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  font-size: 11px;
}

.vic-reg-item {
  background: #0a0a15;
  padding: 3px 6px;
  border-radius: 2px;
}

#disasm-view, #mem-view {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  white-space: pre;
  overflow: auto;
  max-height: 200px;
  color: #4a4;
}

#mem-addr-input {
  background: #111;
  border: 1px solid #333;
  color: #6f6;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  width: 50px;
  padding: 2px 4px;
  margin-left: 8px;
  text-transform: uppercase;
}

/* ===== Virtual Keyboard ===== */
#virtual-keyboard {
  width: 100%;
  max-width: 700px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 10px 0;
}

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

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 12px;
  padding: 6px 4px;
  min-width: 32px;
  background: linear-gradient(180deg, #5a4a3a, #3a2a1a);
  color: #e8d8c0;
  border: 1px solid #6a5a4a;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.1s;
  user-select: none;
}

.kb-key:hover {
  background: linear-gradient(180deg, #6a5a4a, #4a3a2a);
}

.kb-key.active, .kb-key:active {
  background: var(--accent-cyan);
  color: #000;
  transform: translateY(1px);
}

.kb-key.wide { min-width: 50px; }
.kb-key.wider { min-width: 70px; }
.kb-key.space { min-width: 200px; }

/* ===== Footer ===== */
#footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 16px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid #1a1a2a;
  width: 100%;
  margin-top: auto;
}

#footer a {
  color: var(--accent-cyan);
  text-decoration: none;
}

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

/* ===== Responsive ===== */
@media (max-width: 600px) {
  #rom-title { font-size: 10px; }
  .rom-slot { width: 100%; max-width: 280px; }
  #crt-bezel { padding: 10px; border-radius: 12px; }
  #debug-panel { grid-template-columns: 1fr; }
  .kb-key { font-size: 10px; min-width: 24px; padding: 5px 2px; }
  .kb-key.space { min-width: 120px; }
  #control-bar { flex-direction: column; align-items: center; }
  #top-bar { flex-wrap: wrap; gap: 6px; }
}