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

:root {
  --bg-dark: #0f0e0c;
  --bg-panel: #1a1714;
  --bg-board: #1e1b16;
  --bg-inset: #0d0c0a;
  --amber: #ff9b00;
  --amber-dim: #4a2d00;
  --amber-glow: #ffb84d;
  --red-led: #ff2222;
  --red-dim: #4a0808;
  --green-term: #33ff33;
  --green-dim: #0a3a0a;
  --text-light: #c8b89a;
  --text-dim: #6b5e4e;
  --border-color: #2a2520;
  --accent: #8b6914;
}

body {
  background: var(--bg-dark);
  color: var(--text-light);
  font-family: 'VT323', monospace;
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(139,105,20,0.03) 0%, transparent 70%),
    radial-gradient(ellipse at 80% 50%, rgba(255,155,0,0.02) 0%, transparent 70%);
}

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

header {
  text-align: center;
  padding: 16px 10px 10px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 12px;
}

header h1 {
  font-family: 'Share Tech Mono', monospace;
  font-size: 36px;
  color: var(--amber);
  text-shadow: 0 0 20px rgba(255,155,0,0.5), 0 0 40px rgba(255,155,0,0.2);
  letter-spacing: 6px;
  text-transform: uppercase;
}

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

header .status-bar {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 8px;
  font-size: 14px;
}

header .status-item {
  color: var(--text-dim);
}

header .status-item span {
  color: var(--amber);
}

#main-layout {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

#left-panel {
  flex: 0 0 272px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#center-panel {
  flex: 1 1 400px;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#right-panel {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 620px;
  overflow-y: auto;
}

.panel-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.03);
}

.panel-title {
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
}

/* Pixie Display */
#pixie-display {
  border: 3px solid #2a2520;
  border-radius: 8px;
  background: #000;
  box-shadow: 0 0 20px rgba(0,0,0,0.8), inset 0 0 30px rgba(0,0,0,0.5);
  image-rendering: pixelated;
}

.pixie-bezel {
  background: #1a1714;
  border: 2px solid #2a2520;
  border-radius: 12px;
  padding: 8px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.6);
}

/* Seven Segment Display */
.seven-seg-container {
  display: flex;
  gap: 4px;
  justify-content: center;
  align-items: center;
  background: var(--bg-inset);
  border-radius: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.6);
}

.seven-seg-digit {
  width: 32px;
  height: 48px;
  position: relative;
}

/* Toggle Switches */
.switch-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
}

.toggle-switch {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.toggle-switch .label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
}

.switch-track {
  width: 24px;
  height: 44px;
  background: linear-gradient(180deg, #1a1714 0%, #0d0c0a 100%);
  border: 1px solid #3a3530;
  border-radius: 4px;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.switch-handle {
  width: 20px;
  height: 20px;
  background: linear-gradient(180deg, #d4c5a9 0%, #8a7a5a 100%);
  border: 1px solid #6b5e4e;
  border-radius: 3px;
  position: absolute;
  left: 1px;
  transition: top 0.1s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.switch-handle.on { top: 1px; }
.switch-handle.off { top: 21px; }

/* Control Buttons */
.ctrl-btn {
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.1s ease;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4);
}

.ctrl-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.btn-red {
  background: linear-gradient(180deg, #cc2222 0%, #881111 100%);
  color: #fff;
  border: 1px solid #aa1111;
}

.btn-red:hover { background: linear-gradient(180deg, #dd3333 0%, #992222 100%); }

.btn-green {
  background: linear-gradient(180deg, #228822 0%, #115511 100%);
  color: #fff;
  border: 1px solid #117711;
}

.btn-amber {
  background: linear-gradient(180deg, #8b6914 0%, #5a4410 100%);
  color: #fff;
  border: 1px solid #6b5210;
}

.btn-dark {
  background: linear-gradient(180deg, #3a3530 0%, #1a1714 100%);
  color: var(--text-light);
  border: 1px solid #4a4540;
}

/* Hex Keypad */
.hex-keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  max-width: 240px;
  margin: 0 auto;
}

.hex-key {
  font-family: 'VT323', monospace;
  font-size: 20px;
  padding: 10px;
  background: linear-gradient(180deg, #2a2520 0%, #1a1714 100%);
  color: var(--text-light);
  border: 1px solid #3a3530;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.08s ease;
}

.hex-key:hover { background: linear-gradient(180deg, #3a3530 0%, #2a2520 100%); }
.hex-key.active { background: var(--amber); color: #000; }

/* Memory View */
.memory-view {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--green-term);
  background: var(--bg-inset);
  padding: 6px;
  border-radius: 4px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  white-space: pre;
}

.memory-view .pc-highlight {
  background: rgba(255,155,0,0.2);
  color: var(--amber);
}

.memory-view .breakpoint {
  background: rgba(255,34,34,0.2);
  color: var(--red-led);
}

/* Registers */
.reg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px 12px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  color: var(--green-term);
}

.reg-item {
  display: flex;
  justify-content: space-between;
}

.reg-label { color: var(--text-dim); }
.reg-value { color: var(--green-term); }

/* Disassembly */
.disasm-view {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--green-term);
  background: var(--bg-inset);
  padding: 6px;
  border-radius: 4px;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
}

.disasm-line { padding: 1px 4px; }
.disasm-current { background: rgba(255,155,0,0.15); color: var(--amber); }

/* Bottom Panel */
#bottom-panel {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 8px;
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}

#speed-control, #program-loader {
  flex: 1 1 300px;
}

.speed-slider {
  width: 100%;
  accent-color: var(--amber);
  margin: 6px 0;
}

select, textarea, input[type="text"] {
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  background: var(--bg-inset);
  color: var(--text-light);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 6px 8px;
  width: 100%;
}

select:focus, textarea:focus { outline: 1px solid var(--amber); }

textarea {
  min-height: 50px;
  resize: vertical;
}

/* LED */
.led {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin: 0 4px;
  transition: all 0.15s ease;
}

.led-red-on {
  background: var(--red-led);
  box-shadow: 0 0 8px var(--red-led), 0 0 16px rgba(255,34,34,0.4);
}

.led-red-off {
  background: var(--red-dim);
}

.led-amber-on {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber), 0 0 16px rgba(255,155,0,0.4);
}

.led-amber-off {
  background: var(--amber-dim);
}

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

footer a {
  color: var(--amber);
  text-decoration: none;
}

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

/* CRT Effect Overlay */
.crt-overlay {
  pointer-events: none;
  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
  );
  border-radius: 8px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-inset); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Tooltip */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #2a2520;
  color: var(--text-light);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 3px;
  white-space: nowrap;
  z-index: 100;
  pointer-events: none;
  border: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 1000px) {
  #main-layout { flex-direction: column; align-items: center; }
  #left-panel, #center-panel, #right-panel { flex: 1 1 auto; width: 100%; max-width: 500px; }
  #right-panel { max-height: none; }
}

@media (max-width: 500px) {
  header h1 { font-size: 24px; letter-spacing: 3px; }
  .switch-track { width: 20px; height: 36px; }
  .switch-handle { width: 16px; height: 16px; }
  .switch-handle.off { top: 17px; }
}