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

:root {
  --phosphor: #33ff33;
  --phosphor-dim: #1a8c1a;
  --phosphor-glow: #33ff3366;
  --bg-dark: #0a0a0a;
  --bg-panel: #141414;
  --bg-panel-border: #222;
  --keycap: #f0ead6;
  --keycap-dark: #d4cdb8;
  --keycap-text: #333;
  --keycap-shadow: #8a8475;
  --amber: #ffaa00;
  --red: #ff3333;
}

html, body {
  background: var(--bg-dark);
  color: #ccc;
  font-family: 'IBM Plex Mono', monospace;
  height: 100%;
  overflow-x: hidden;
}

#root { min-height: 100vh; }

@keyframes flicker {
  0% { opacity: 1; }
  3% { opacity: 0.97; }
  6% { opacity: 1; }
  50% { opacity: 0.99; }
  53% { opacity: 0.96; }
  56% { opacity: 1; }
}

@keyframes bootGlow {
  0% { filter: brightness(0); }
  50% { filter: brightness(1.3); }
  100% { filter: brightness(1); }
}

.crt-screen {
  position: relative;
  background: #000;
  border: 3px solid #222;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(51, 255, 51, 0.08), inset 0 0 80px rgba(0,0,0,0.6);
  animation: flicker 8s infinite;
}

.crt-screen::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.15) 0px,
    rgba(0, 0, 0, 0.15) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 10;
}

.crt-screen::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%);
  pointer-events: none;
  z-index: 11;
}

.terminal-canvas {
  display: block;
  image-rendering: pixelated;
  width: 100%;
  height: 100%;
}

.key-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  background: linear-gradient(180deg, var(--keycap) 0%, var(--keycap-dark) 100%);
  color: var(--keycap-text);
  border: 1px solid #b8b2a0;
  border-radius: 5px;
  padding: 6px 4px;
  min-width: 32px;
  min-height: 34px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--keycap-shadow), 0 4px 8px rgba(0,0,0,0.4);
  transition: all 0.05s ease;
  user-select: none;
  -webkit-user-select: none;
  text-align: center;
  line-height: 1.1;
}

.key-btn:hover {
  background: linear-gradient(180deg, #f7f2e2 0%, #e0d9c4 100%);
}

.key-btn:active, .key-btn.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--keycap-shadow), 0 2px 4px rgba(0,0,0,0.3);
}

.key-btn.locked {
  background: linear-gradient(180deg, #ffe4a0 0%, #ddc070 100%);
  border-color: var(--amber);
  box-shadow: 0 3px 0 #a08030, 0 4px 8px rgba(0,0,0,0.4), 0 0 8px rgba(255,170,0,0.3);
}

.key-btn.wide { min-width: 70px; }
.key-btn.space { flex: 1; min-width: 180px; }
.key-btn.cr-key { min-width: 56px; background: linear-gradient(180deg, #ffe8d0 0%, #e8c8a0 100%); border-color: #c0a070; }

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

.btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 16px;
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  background: #222;
  color: #ccc;
}

.btn:hover { background: #333; border-color: #666; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-boot {
  background: linear-gradient(180deg, #2a6a2a 0%, #1a4a1a 100%);
  color: var(--phosphor);
  border-color: var(--phosphor-dim);
  font-size: 14px;
  padding: 10px 24px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.btn-boot:hover:not(:disabled) {
  background: linear-gradient(180deg, #3a8a3a 0%, #2a6a2a 100%);
  box-shadow: 0 0 12px var(--phosphor-glow);
}

.btn-danger { border-color: #662222; color: #ff6666; }
.btn-danger:hover { background: #331111; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-dot.running { background: var(--phosphor); box-shadow: 0 0 6px var(--phosphor); }
.status-dot.halted { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status-dot.idle { background: #666; }

.upload-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #1a1a1a;
  border: 1px dashed #333;
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.upload-slot:hover { border-color: #555; }
.upload-slot.loaded { border-color: var(--phosphor-dim); border-style: solid; }

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

.footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: #555;
  border-top: 1px solid #1a1a1a;
  margin-top: 20px;
}

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

.help-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.help-content {
  background: var(--bg-panel);
  border: 1px solid #333;
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  color: #ccc;
}

.help-content h2 { color: var(--phosphor); margin-bottom: 12px; font-family: 'VT323', monospace; font-size: 24px; }
.help-content code { color: var(--phosphor); background: #1a1a1a; padding: 2px 6px; border-radius: 3px; font-size: 13px; }
.help-content p { margin-bottom: 10px; font-size: 13px; line-height: 1.5; }

.mem-inspector {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--phosphor-dim);
  line-height: 1.4;
}

.mem-inspector .changed { color: var(--amber); }

@media (max-width: 768px) {
  .key-btn { font-size: 9px; min-width: 26px; min-height: 28px; padding: 4px 2px; }
  .key-btn.wide { min-width: 50px; }
  .key-btn.space { min-width: 100px; }
}