:root {
  --bg-deep: #0a0a1a;
  --bg-panel: #12122a;
  --bg-input: #0d0d20;
  --border: #2a2a5a;
  --border-bright: #4040e0;
  --cyan: #40e0d0;
  --purple: #7b68ee;
  --blue: #4040e0;
  --green: #39ff14;
  --yellow: #ffe066;
  --red: #ff4444;
  --orange: #ff8844;
  --text: #d0d0e8;
  --text-dim: #6868a0;
  --white: #eeeeff;
}

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

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

body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.06) 2px, rgba(0,0,0,0.06) 4px);
}

#root { min-height: 100vh; display: flex; flex-direction: column; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

@keyframes flash-register { 0% { background-color: rgba(64,224,208,0.4); } 100% { background-color: transparent; } }
@keyframes flash-mem { 0% { background-color: rgba(255,224,102,0.5); } 100% { background-color: transparent; } }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes bootFlicker { 0% { opacity: 0; } 10% { opacity: 1; } 12% { opacity: 0.3; } 14% { opacity: 1; } 100% { opacity: 1; } }
@keyframes pulse-chip { 0%,100% { box-shadow: 0 0 4px rgba(64,224,208,0.3); } 50% { box-shadow: 0 0 12px rgba(64,224,208,0.8); } }
@keyframes envelope-pulse { 0%,100% { opacity: 0.6; } 50% { opacity: 1; } }

.animate-blink { animation: blink 1s step-end infinite; }
.flash-reg { animation: flash-register 0.6s ease-out; }
.flash-mem { animation: flash-mem 1.2s ease-out; }
.chip-pulse { animation: pulse-chip 1.5s ease-in-out infinite; }

.glow-cyan { text-shadow: 0 0 8px rgba(64,224,208,0.6); }
.glow-green { text-shadow: 0 0 8px rgba(57,255,20,0.6); }
.glow-purple { text-shadow: 0 0 8px rgba(123,104,238,0.6); }

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  position: relative;
}
.panel:hover { border-color: var(--border-bright); }
.panel-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  color: var(--cyan);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(64,64,224,0.08);
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-editor {
  background: var(--bg-input);
  color: var(--green);
  font-family: 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  border: none;
  outline: none;
  resize: none;
  width: 100%;
  padding: 10px;
  tab-size: 8;
}
.code-editor::placeholder { color: var(--text-dim); }

.btn {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan); background: rgba(64,224,208,0.08); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { border-color: var(--cyan); color: var(--cyan); background: rgba(64,224,208,0.1); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { border-color: var(--red); color: #fff; background: rgba(255,68,68,0.2); }

.flag-on { background: rgba(57,255,20,0.2); color: var(--green); border-color: var(--green); text-shadow: 0 0 6px rgba(57,255,20,0.8); }
.flag-off { background: rgba(40,40,80,0.3); color: var(--text-dim); border-color: var(--border); }

.mem-row { font-family: 'Fira Code', monospace; font-size: 12px; line-height: 1.4; }
.mem-addr { color: var(--purple); }
.mem-byte { color: var(--text); }
.mem-ascii { color: var(--text-dim); }
.mem-pc { background: rgba(64,224,208,0.25); color: var(--cyan); }
.mem-sp { background: rgba(123,104,238,0.2); }
.mem-io { background: rgba(255,224,102,0.15); color: var(--yellow); }
.mem-vic { background: rgba(255,68,68,0.15); color: var(--orange); }
.mem-sid { background: rgba(57,255,20,0.15); color: var(--green); }
.mem-cia { background: rgba(123,104,238,0.15); color: var(--purple); }
.mem-write { animation: flash-mem 1.2s ease-out; }

.console-output {
  font-family: 'Fira Code', monospace;
  font-size: 12px;
  background: var(--bg-input);
  color: var(--text);
  padding: 6px;
  overflow-y: auto;
  max-height: 100px;
}
.console-error { color: var(--red); }
.console-info { color: var(--cyan); }
.console-warn { color: var(--yellow); }

.chip-tab {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}
.chip-tab:hover { border-color: var(--cyan); color: var(--cyan); }
.chip-tab.active { color: var(--cyan); border-color: var(--cyan); background: rgba(64,224,208,0.12); }

.mobile-tab {
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
}
.mobile-tab.active { color: var(--cyan); border-color: var(--cyan); background: rgba(64,224,208,0.1); }

.c64-color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  cursor: pointer;
  vertical-align: middle;
}

.sid-key {
  width: 22px;
  height: 48px;
  border: 1px solid #555;
  background: #eee;
  cursor: pointer;
  display: inline-block;
  margin: 0 1px;
  transition: background 0.1s;
}
.sid-key:hover { background: #ddd; }
.sid-key:active, .sid-key.pressed { background: var(--cyan); }
.sid-key-black {
  width: 14px;
  height: 30px;
  background: #222;
  border: 1px solid #000;
  cursor: pointer;
  display: inline-block;
  margin: 0 -7px;
  position: relative;
  z-index: 1;
  vertical-align: top;
}
.sid-key-black:hover { background: #444; }
.sid-key-black:active, .sid-key-black.pressed { background: var(--blue); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  height: 4px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  background: var(--cyan);
  cursor: pointer;
}

select {
  font-family: 'VT323', monospace;
  font-size: 15px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 3px 6px;
  outline: none;
  cursor: pointer;
}
select:hover { border-color: var(--cyan); }
select option { background: var(--bg-panel); color: var(--text); }

input[type="text"], input[type="number"] {
  font-family: 'VT323', monospace;
  font-size: 15px;
  background: var(--bg-input);
  color: var(--cyan);
  border: 1px solid var(--border);
  padding: 3px 6px;
  outline: none;
}
input:focus { border-color: var(--cyan); }

.c64-boot {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #4040e0;
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 40px;
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: #a0a0ff;
  animation: bootFlicker 0.8s ease-out;
}

.reg-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
  min-width: 60px;
  transition: all 0.3s;
}
.reg-box.changed { animation: flash-register 0.6s ease-out; }

.bit-indicator {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 4px;
  border: 1px solid var(--border);
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  min-width: 28px;
  transition: all 0.2s;
}

.video-canvas {
  background: #000;
  border: 2px solid var(--border);
  image-rendering: pixelated;
}

.oscilloscope-canvas {
  background: #0a0a0a;
  border: 1px solid var(--border);
}

.timer-bar {
  height: 8px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}
.timer-bar-fill {
  height: 100%;
  background: var(--cyan);
  transition: width 0.1s;
}

@media (max-width: 1024px) {
  .desktop-layout { display: none !important; }
  .mobile-wrapper { display: flex !important; }
}
@media (min-width: 1025px) {
  .desktop-layout { display: flex !important; }
  .mobile-wrapper { display: none !important; }
}