:root {
  --bg-primary: #0a0e0a;
  --bg-secondary: #0d120d;
  --bg-panel: #0a100a;
  --text-primary: #00ff41;
  --text-dim: #00aa2a;
  --text-dimmer: #006618;
  --glow: rgba(0, 255, 65, 0.15);
  --glow-strong: rgba(0, 255, 65, 0.3);
  --border: #00551a;
  --highlight: #ffb000;
  --highlight-dim: #aa7500;
  --error: #ff3333;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

[data-theme="amber"] {
  --text-primary: #ffb000;
  --text-dim: #aa7500;
  --text-dimmer: #664700;
  --glow: rgba(255, 176, 0, 0.15);
  --glow-strong: rgba(255, 176, 0, 0.3);
  --border: #553a00;
  --highlight: #00ff41;
  --highlight-dim: #00aa2a;
}

[data-theme="white"] {
  --bg-primary: #111111;
  --bg-secondary: #161616;
  --bg-panel: #131313;
  --text-primary: #cccccc;
  --text-dim: #888888;
  --text-dimmer: #555555;
  --glow: rgba(204, 204, 204, 0.1);
  --glow-strong: rgba(204, 204, 204, 0.2);
  --border: #333333;
  --highlight: #66bbff;
  --highlight-dim: #3388cc;
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  overflow-x: hidden;
}

/* Scanline overlay */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* CRT flicker */
@keyframes flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.97; }
  94% { opacity: 1; }
}

body {
  animation: flicker 8s infinite;
}

/* Register flash animation */
@keyframes registerFlash {
  0% { background-color: var(--glow-strong); }
  100% { background-color: transparent; }
}

.reg-flash {
  animation: registerFlash 0.6s ease-out;
}

/* LED indicators */
.led-on {
  background: var(--text-primary);
  box-shadow: 0 0 6px var(--text-primary), 0 0 12px var(--glow);
}

.led-off {
  background: var(--text-dimmer);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dimmer);
}

/* Glow borders */
.glow-border {
  border: 1px solid var(--border);
  box-shadow: 0 0 8px var(--glow), inset 0 0 8px var(--glow);
}

/* Button styles */
.btn-retro {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-mono);
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 1px 1px 0 var(--text-dimmer), inset 0 1px 0 rgba(255,255,255,0.05);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1px;
  font-weight: 600;
}

.btn-retro:hover {
  background: var(--glow);
  box-shadow: 0 0 12px var(--glow), 1px 1px 0 var(--text-dimmer);
}

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

.btn-retro.active {
  background: var(--glow-strong);
  border-color: var(--text-dim);
}

/* Code editor */
.code-editor {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  border: none;
  outline: none;
  resize: none;
  width: 100%;
  caret-color: var(--text-primary);
}

.code-editor::selection {
  background: var(--glow-strong);
}

/* Memory byte highlight */
@keyframes memWrite {
  0% { color: #ffffff; background: var(--glow-strong); }
  100% { color: var(--text-primary); background: transparent; }
}

.mem-write {
  animation: memWrite 1.5s ease-out;
}

/* IP pulse */
@keyframes ipPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.ip-line {
  background: rgba(255, 176, 0, 0.2);
  animation: ipPulse 1.5s infinite;
}

/* Panel headers */
.panel-header {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

/* Chip ASCII art container */
.chip-art {
  font-size: 9px;
  line-height: 1.2;
  color: var(--text-dim);
}

/* Tooltip */
.tooltip-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 11px;
  padding: 8px;
  box-shadow: 0 0 12px var(--glow);
  z-index: 1000;
  position: absolute;
  max-width: 300px;
}

/* Mobile responsive */
@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
  }
}