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

:root {
  --green: #33FF33;
  --green-dim: #1a8a1a;
  --green-glow: #00FF41;
  --amber: #FF9500;
  --bg: #0A0A0A;
  --chrome: #1A1A1A;
  --chrome2: #2A2A2A;
  --chrome3: #333333;
  --key-bg: #E8DCC8;
  --key-border: #B0A08A;
  --key-text: #2A2200;
}

body {
  background: var(--bg);
  color: var(--green);
  font-family: 'VT323', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px;
}

/* Header */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--chrome3);
  margin-bottom: 10px;
}

.header-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--green);
  text-shadow: 0 0 10px var(--green-glow), 0 0 20px var(--green-dim);
  white-space: nowrap;
}

.status-leds {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.led {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #888;
}

.led-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  border: 1px solid #555;
}

.led-dot.on {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.led-dot.running {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse-led 1s infinite;
}

.led-dot.halted {
  background: #FF3333;
  box-shadow: 0 0 6px #FF3333;
}

@keyframes pulse-led {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Controls */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
}

.btn {
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 4px 10px;
  border: 1px solid var(--chrome3);
  background: var(--chrome2);
  color: var(--green);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.1s;
}

.btn:hover {
  background: var(--chrome3);
  border-color: var(--green-dim);
}

.btn:active {
  background: var(--green-dim);
  color: #000;
}

.btn-upload {
  position: relative;
  overflow: hidden;
}

.btn-upload input[type="file"] {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

.btn-amber {
  border-color: #664400;
  color: var(--amber);
}

.btn-amber:hover {
  border-color: var(--amber);
}

/* CRT Display */
.crt-bezel {
  background: #2a2a2a;
  border-radius: 20px;
  padding: 20px;
  margin: 10px 0;
  box-shadow: 
    inset 0 2px 4px rgba(0,0,0,0.8),
    0 4px 20px rgba(0,0,0,0.5),
    inset 0 0 30px rgba(0,0,0,0.3);
  border: 2px solid #3a3a3a;
  position: relative;
}

.crt-bezel::before {
  content: '';
  position: absolute;
  top: 4px; left: 4px; right: 4px; bottom: 4px;
  border-radius: 18px;
  border: 1px solid #444;
  pointer-events: none;
}

.crt-screen-wrap {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 
    inset 0 0 60px rgba(0, 255, 65, 0.03),
    inset 0 0 4px rgba(0,0,0,1);
}

.crt-screen-wrap canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
}

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

.screen-flicker {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  border-radius: 12px;
  animation: flicker 0.05s infinite;
}

@keyframes flicker {
  0% { opacity: 0; }
  50% { opacity: 0.008; background: rgba(255,255,255,0.01); }
  100% { opacity: 0; }
}

/* CRT curve effect */
.crt-curve {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  border-radius: 12px;
  box-shadow: 
    inset 0 0 80px rgba(0,0,0,0.4),
    inset 0 0 10px rgba(0,0,0,0.6);
}

/* Keyboard */
.keyboard {
  background: #3a3530;
  border-radius: 10px;
  padding: 12px;
  margin: 10px 0;
  box-shadow: 
    0 4px 15px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.05);
  border: 1px solid #4a4540;
}

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

.keyboard-row:last-child {
  margin-bottom: 0;
}

.key {
  font-family: 'VT323', monospace;
  font-size: 14px;
  font-weight: bold;
  color: var(--key-text);
  background: linear-gradient(180deg, #f0e8d8, #d8ccb8);
  border: 1px solid var(--key-border);
  border-radius: 4px;
  padding: 6px 0;
  min-width: 38px;
  text-align: center;
  cursor: pointer;
  box-shadow: 
    0 3px 0 #8a7a6a,
    0 4px 4px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.4);
  user-select: none;
  transition: all 0.05s;
  position: relative;
}

.key:hover {
  background: linear-gradient(180deg, #f8f0e0, #e0d4c0);
  transform: translateY(1px);
  box-shadow: 
    0 2px 0 #8a7a6a,
    0 3px 3px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.4);
}

.key:active, .key.pressed {
  transform: translateY(3px);
  box-shadow: 
    0 0px 0 #8a7a6a,
    0 1px 2px rgba(0,0,0,0.3),
    inset 0 1px 2px rgba(0,0,0,0.2);
  background: linear-gradient(180deg, #d0c8b8, #c8bca8);
}

.key.wide { min-width: 70px; font-size: 11px; }
.key.wider { min-width: 85px; font-size: 11px; }
.key.space { flex: 1; min-width: 200px; }

.key.active-modifier {
  background: linear-gradient(180deg, #FFB840, #E89800);
  color: #000;
  box-shadow: 
    0 3px 0 #996600,
    0 4px 4px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.4),
    0 0 8px rgba(255, 149, 0, 0.4);
}

/* Debug Panel */
.debug-panel {
  background: var(--chrome);
  border: 1px solid var(--chrome3);
  border-radius: 6px;
  padding: 10px;
  margin: 10px 0;
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--green);
}

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

.debug-reg {
  display: flex;
  gap: 4px;
}

.debug-reg .label {
  color: var(--green-dim);
}

.debug-flags {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.debug-flag {
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 14px;
}

.debug-flag.set {
  background: var(--green-dim);
  color: #000;
}

.debug-flag.clear {
  background: var(--chrome2);
  color: #555;
}

.debug-mem {
  font-size: 14px;
  line-height: 1.4;
  color: var(--green-dim);
  word-break: break-all;
}

.debug-mem-input {
  background: var(--chrome2);
  border: 1px solid var(--chrome3);
  color: var(--green);
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 2px 6px;
  width: 60px;
  border-radius: 3px;
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--chrome2);
  border: 1px solid var(--green-dim);
  color: var(--green);
  padding: 10px 16px;
  border-radius: 6px;
  font-family: 'VT323', monospace;
  font-size: 16px;
  z-index: 1000;
  animation: toast-in 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

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

/* Footer */
.footer {
  text-align: center;
  padding: 16px 0;
  font-size: 14px;
  color: #555;
  border-top: 1px solid var(--chrome3);
  margin-top: 10px;
}

.footer a {
  color: var(--green-dim);
  text-decoration: none;
}

.footer a:hover {
  color: var(--green);
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 600px) {
  .header-title { font-size: 11px; }
  .key { min-width: 26px; font-size: 11px; padding: 5px 0; }
  .key.wide { min-width: 48px; font-size: 9px; }
  .key.wider { min-width: 58px; font-size: 9px; }
  .crt-bezel { padding: 10px; border-radius: 14px; }
  .keyboard { padding: 6px; }
  .keyboard-row { gap: 2px; margin-bottom: 2px; }
}