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

:root {
  --bg-dark: #0a0a14;
  --bg-panel: #111122;
  --bg-panel-inner: #0d0d1a;
  --border: #2a2a44;
  --accent-amber: #f5a623;
  --accent-green: #00ff41;
  --accent-red: #ff3333;
  --text: #c8c8d8;
  --text-dim: #666688;
  --key-bg: #2a2a3a;
  --key-top: #3a3a50;
  --key-highlight: #4a4a66;
}

body {
  background: var(--bg-dark);
  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: 12px 8px 8px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #14142a 0%, var(--bg-dark) 100%);
}

header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: var(--accent-amber);
  text-shadow: 0 0 10px rgba(245,166,35,0.4);
  letter-spacing: 2px;
}

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

#main-layout {
  display: flex;
  flex: 1;
  gap: 0;
  overflow: hidden;
}

.panel {
  width: 240px;
  min-width: 200px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
  padding: 8px;
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-section {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.panel-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--accent-amber);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#center-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  gap: 12px;
  min-width: 0;
}

/* Monitor Bezel */
#monitor-bezel {
  background: linear-gradient(145deg, #2a2a2a 0%, #1a1a1a 50%, #0e0e0e 100%);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 
    0 4px 20px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.05),
    inset 0 -2px 4px rgba(0,0,0,0.6);
  position: relative;
}

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

#screen {
  display: block;
  width: 720px;
  height: 672px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

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

.crt-overlay::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

.crt-off .crt-overlay {
  display: none;
}

#no-rom-msg {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--accent-green);
  z-index: 1;
  text-shadow: 0 0 8px rgba(0,255,65,0.5);
  line-height: 2;
}

/* Buttons */
.btn-retro {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 6px 12px;
  background: linear-gradient(180deg, #3a3a50 0%, #2a2a3a 100%);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  margin: 2px;
  transition: all 0.1s;
}

.btn-retro:hover {
  background: linear-gradient(180deg, #4a4a66 0%, #3a3a50 100%);
  border-color: var(--accent-amber);
}

.btn-retro:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

.btn-sm { font-size: 10px; padding: 4px 8px; }

.btn-power { width: 100%; }

.power-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* LEDs */
.led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #333;
  flex-shrink: 0;
}

.led-off { background: #333; }
.led-green { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.led-red { background: var(--accent-red); box-shadow: 0 0 6px var(--accent-red); }
.led-amber { background: var(--accent-amber); box-shadow: 0 0 6px var(--accent-amber); }

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 4px;
  padding: 16px 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  color: var(--text-dim);
  font-size: 10px;
}

.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent-amber);
  color: var(--text);
}

.file-info {
  font-size: 10px;
  margin-top: 6px;
  color: var(--accent-green);
}

.file-info pre {
  font-size: 9px;
  color: var(--text-dim);
  word-break: break-all;
  white-space: pre-wrap;
  margin-top: 4px;
}

/* Registers */
.reg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
}

.reg {
  display: flex;
  justify-content: space-between;
  background: var(--bg-panel-inner);
  padding: 3px 6px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

.reg-wide { grid-column: span 2; }

.reg-name { color: var(--accent-amber); font-size: 10px; }
.reg-val { color: var(--accent-green); font-size: 10px; }

.flags-row {
  display: flex;
  gap: 3px;
  margin-top: 6px;
  justify-content: center;
}

.flag {
  width: 22px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel-inner);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 9px;
  color: var(--text-dim);
  transition: all 0.15s;
}

.flag.active {
  color: #fff;
  background: var(--accent-amber);
  border-color: var(--accent-amber);
}

.flag-dim { color: #333; }

/* Status */
.status-leds {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: var(--text-dim);
}

.clock-info {
  font-size: 10px;
  color: var(--accent-green);
  margin-top: 4px;
}

/* Disassembly */
.disasm-view {
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-dim);
  max-height: 140px;
  overflow-y: auto;
  background: var(--bg-panel-inner);
  padding: 4px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

.disasm-view .current { color: var(--accent-green); font-weight: bold; }

/* Memory */
.mem-input-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  color: var(--accent-amber);
}

.mem-addr-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  width: 50px;
  background: var(--bg-panel-inner);
  color: var(--accent-green);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 3px 4px;
  text-transform: uppercase;
}

.mem-view {
  font-size: 9px;
  line-height: 1.5;
  color: var(--text-dim);
  background: var(--bg-panel-inner);
  padding: 4px;
  border-radius: 2px;
  border: 1px solid var(--border);
  max-height: 100px;
  overflow-y: auto;
  white-space: pre;
}

/* Keyboard Matrix */
.matrix-view {
  font-size: 8px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 1px;
}

.matrix-cell {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-panel-inner);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  color: var(--text-dim);
  border-radius: 1px;
}

.matrix-cell.active {
  background: var(--accent-green);
  color: #000;
}

.matrix-cell.header {
  background: transparent;
  border: none;
  color: var(--accent-amber);
  font-weight: bold;
}

/* On-Screen Keyboard */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 4px;
  background: linear-gradient(180deg, #222233 0%, #1a1a2a 100%);
  border-radius: 8px;
  border: 1px solid var(--border);
  max-width: 740px;
  width: 100%;
}

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

.kb-key {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  min-width: 36px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--key-top) 0%, var(--key-bg) 100%);
  color: #ddd;
  border: 1px solid #444;
  border-bottom: 3px solid #1a1a2a;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: all 0.05s;
  padding: 0 6px;
}

.kb-key:hover {
  background: linear-gradient(180deg, var(--key-highlight) 0%, var(--key-top) 100%);
}

.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  border-bottom-width: 1px;
  background: linear-gradient(180deg, var(--key-bg) 0%, #222238 100%);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

.kb-key.wide { min-width: 56px; }
.kb-key.wider { min-width: 72px; }
.kb-key.space { min-width: 200px; }

/* Slider */
.slider {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  margin: 6px 0;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent-amber);
  border-radius: 50%;
  cursor: pointer;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  margin: 4px 0;
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--accent-amber);
}

/* Footer */
footer {
  text-align: center;
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 9px;
  color: var(--text-dim);
}

footer a {
  color: var(--accent-amber);
  text-decoration: none;
  font-weight: bold;
}

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

/* Responsive */
@media (max-width: 1100px) {
  #main-layout { flex-direction: column; }
  .panel { width: 100%; min-width: 0; border: none; border-bottom: 1px solid var(--border); }
  #left-panel { display: flex; flex-wrap: wrap; gap: 12px; }
  #left-panel .panel-section { flex: 1; min-width: 180px; margin-bottom: 0; border-bottom: none; }
  #right-panel { display: flex; flex-wrap: wrap; gap: 12px; }
  #right-panel .panel-section { flex: 1; min-width: 180px; margin-bottom: 0; border-bottom: none; }
  #screen { width: 480px; height: 448px; }
  #monitor-bezel { padding: 12px; }
}

@media (max-width: 600px) {
  #screen { width: 320px; height: 299px; }
  .kb-key { min-width: 24px; height: 28px; font-size: 8px; padding: 0 3px; }
  .kb-key.wide { min-width: 38px; }
  .kb-key.wider { min-width: 50px; }
  .kb-key.space { min-width: 120px; }
  header h1 { font-size: 12px; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-panel-inner); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }