:root {
  --bg-deep: #0a0a1a;
  --bg-panel: #0d1b2e;
  --bg-card: #111a2e;
  --vic-cyan: #4DF0FF;
  --vic-blue: #1A34FF;
  --vic-green: #44E237;
  --vic-red: #B61F21;
  --vic-yellow: #D8E232;
  --vic-white: #FFFFFF;
  --vic-beige: #d4c5a9;
  --vic-brown: #6b5c3e;
  --bezel-color: #2a2520;
  --text-dim: #6688aa;
}

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

body {
  background: var(--bg-deep);
  font-family: 'JetBrains Mono', monospace;
  color: #c0d0e0;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: 
    radial-gradient(ellipse at 50% 0%, rgba(77,240,255,0.03) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(26,52,255,0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }

/* Header */
.header-area { padding: 12px 16px; position: relative; z-index: 1; }
.header-inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.header-title { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.15em; color: var(--vic-cyan); font-family: 'Share Tech Mono', monospace; }
.header-subtitle { font-size: 0.7rem; opacity: 0.5; margin-top: 4px; }
.power-status { display: flex; align-items: center; gap: 12px; }

/* Main Content */
.main-content { flex: 1; padding: 8px 16px; position: relative; z-index: 1; }
.content-inner { max-width: 72rem; margin: 0 auto; }

/* Panels */
.panel {
  background: var(--bg-card);
  border: 1px solid #1a2a40;
  border-radius: 8px;
  padding: 16px;
}

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-title { font-size: 0.75rem; font-weight: 700; color: var(--vic-cyan); }
.hint-text { font-size: 0.7rem; opacity: 0.4; }

/* ROM Grid */
.rom-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 768px) { .rom-grid { grid-template-columns: 1fr; } }

.rom-slot {
  border: 2px dashed #334;
  border-radius: 8px;
  padding: 12px;
  transition: all 0.3s;
  cursor: pointer;
}
.rom-slot:hover { border-color: var(--vic-cyan); background: rgba(77,240,255,0.03); }
.rom-slot.loaded { border-color: var(--vic-green); border-style: solid; background: rgba(68,226,55,0.05); }
.rom-slot-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.rom-label { font-size: 0.75rem; font-weight: 700; color: var(--vic-cyan); }
.rom-status-loaded { font-size: 0.75rem; color: var(--vic-green); }
.rom-status-missing { font-size: 0.75rem; color: var(--vic-red); }
.rom-addr { font-size: 0.7rem; opacity: 0.6; margin-bottom: 4px; }
.rom-info { font-size: 0.7rem; opacity: 0.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rom-info.loaded { color: #88aa88; opacity: 1; }

.power-btn-container { display: flex; justify-content: center; }

/* CRT & Monitor */
.screen-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 16px; }

.crt-screen {
  position: relative;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 30px rgba(77,240,255,0.15),
    0 0 60px rgba(77,240,255,0.05),
    inset 0 0 80px rgba(0,0,0,0.8);
  width: 560px;
  max-width: 90vw;
}

.crt-screen canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

.scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.12) 0px,
    rgba(0,0,0,0.12) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 2;
}

.phosphor-glow {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  box-shadow: inset 0 0 60px rgba(77,240,255,0.06);
  pointer-events: none;
  z-index: 3;
  border-radius: 16px;
}

.monitor-bezel {
  background: linear-gradient(180deg, #3a3530 0%, #2a2520 40%, #1a1510 100%);
  padding: 20px;
  border-radius: 24px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05);
  display: inline-block;
}

.bezel-controls { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding: 0 8px; }
.bezel-controls-left, .bezel-controls-right { display: flex; gap: 8px; }
.bezel-btn {
  font-size: 0.7rem; padding: 4px 8px; border-radius: 4px;
  background: #333; color: #888; border: 1px solid #444;
  cursor: pointer; font-family: 'JetBrains Mono', monospace;
}
.bezel-btn:hover { background: #444; }
.bezel-btn.active-pause { background: #553300; color: #ffaa00; }

/* Power Button */
.power-led {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; transition: all 0.3s;
}
.power-led.on { background: #44E237; box-shadow: 0 0 6px #44E237, 0 0 12px rgba(68,226,55,0.4); }
.power-led.off { background: #333; }

.power-btn {
  background: linear-gradient(180deg, #c0392b 0%, #922b21 100%);
  color: white; border: none; padding: 12px 32px; border-radius: 6px;
  font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 14px;
  cursor: pointer; text-transform: uppercase; letter-spacing: 2px;
  box-shadow: 0 4px 0 #6b1a12, 0 6px 12px rgba(0,0,0,0.4);
  transition: all 0.1s;
}
.power-btn:hover:not(:disabled) { transform: translateY(1px); box-shadow: 0 3px 0 #6b1a12, 0 4px 8px rgba(0,0,0,0.4); }
.power-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #6b1a12, 0 2px 4px rgba(0,0,0,0.4); }
.power-btn:disabled { background: linear-gradient(180deg, #555 0%, #333 100%); box-shadow: 0 4px 0 #222, 0 6px 12px rgba(0,0,0,0.4); cursor: not-allowed; opacity: 0.6; }
.power-btn.running { background: linear-gradient(180deg, #27ae60 0%, #1e8449 100%); box-shadow: 0 4px 0 #145a2e, 0 6px 12px rgba(0,0,0,0.4); }

/* Toggle Buttons */
.toggle-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.toggle-btn {
  font-size: 0.7rem; padding: 6px 12px; border-radius: 4px; font-weight: 700;
  background: #111a2e; color: var(--vic-cyan); border: 1px solid #1a3050;
  cursor: pointer; font-family: 'JetBrains Mono', monospace; opacity: 0.5;
}
.toggle-btn.active { background: #1a3050; opacity: 1; }

/* Virtual Keyboard */
.vkeyboard { display: flex; flex-direction: column; gap: 4px; align-items: center; user-select: none; }
.vkey-row { display: flex; gap: 4px; justify-content: center; }

.vkey {
  background: linear-gradient(180deg, #d4c5a9 0%, #c4b599 100%);
  color: #222; border: 1px solid #a09070; border-radius: 4px;
  padding: 4px 6px; font-family: 'JetBrains Mono', monospace;
  font-size: 10px; font-weight: 700; cursor: pointer;
  min-width: 28px; text-align: center;
  box-shadow: 0 2px 0 #8a7a5a; transition: all 0.05s; user-select: none;
}
.vkey:active, .vkey.pressed {
  transform: translateY(2px); box-shadow: 0 0 0 #8a7a5a;
  background: linear-gradient(180deg, #b4a589 0%, #a49579 100%);
}
.vkey.special {
  background: linear-gradient(180deg, #8b7355 0%, #6b5335 100%);
  color: #e0d0c0; border-color: #5a4325; box-shadow: 0 2px 0 #4a3315;
}
.vkey.special:active, .vkey.special.pressed {
  background: linear-gradient(180deg, #6b5335 0%, #4b3315 100%);
  transform: translateY(2px); box-shadow: 0 0 0 #4a3315;
}

/* Sound Mixer */
.mixer-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
@media (max-width: 768px) { .mixer-grid { grid-template-columns: repeat(2, 1fr); } }
.mixer-label { font-size: 0.7rem; opacity: 0.6; margin-bottom: 4px; }
.mixer-value { font-size: 0.7rem; text-align: center; opacity: 0.4; }
.mixer-mute-btn {
  font-size: 0.7rem; width: 100%; margin-top: 4px; padding: 4px 8px;
  border-radius: 4px; border: 1px solid #444; cursor: pointer;
  font-family: 'JetBrains Mono', monospace; background: #333; color: #888;
}
.mixer-mute-btn.muted { background: #550000; color: #ff4444; }
.channel-btn {
  font-size: 0.7rem; width: 100%; padding: 4px 8px; border-radius: 4px;
  border: 1px solid #333; cursor: pointer; font-family: 'JetBrains Mono', monospace;
}
.channel-btn.on { background: #003300; color: var(--vic-green); }
.channel-btn.off { background: #330000; color: var(--vic-red); }
.speed-control { margin-top: 12px; }
.speed-row { display: flex; align-items: center; gap: 8px; }
.speed-row input { flex: 1; }
.speed-value { font-size: 0.7rem; width: 48px; text-align: right; color: var(--vic-cyan); }

/* Debug Panel */
.debug-panel { font-size: 11px; line-height: 1.4; }
.debug-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .debug-grid { grid-template-columns: 1fr; } }
.debug-section-title { font-size: 0.7rem; font-weight: 700; opacity: 0.6; margin-bottom: 8px; }
.reg-list { display: flex; flex-direction: column; gap: 4px; }
.reg-row { display: flex; justify-content: space-between; }
.reg-name { opacity: 0.6; }
.reg-val { color: var(--vic-cyan); font-weight: 700; }
.flags-row { display: flex; gap: 4px; }
.flag-on { color: var(--vic-green); font-weight: 700; }
.flag-off { color: #445; }
.flag-dim { opacity: 0.2; }
.status-detail { font-size: 0.65rem; opacity: 0.4; margin-top: 8px; }

.vic-regs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; font-size: 10px; }
.vic-reg-row { display: flex; justify-content: space-between; }
.vic-reg-name { opacity: 0.5; }
.vic-reg-val { color: var(--vic-cyan); }
.vic-reg-span { grid-column: span 2; }
.blink-note { display: flex; align-items: center; gap: 8px; border-top: 1px solid #1a2a40; padding-top: 4px; margin-top: 4px; }
.blink-note-text { color: var(--vic-yellow); font-size: 9px; }
.blink-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--vic-yellow); animation: blink 1s step-end infinite; }

.disasm-list { font-family: 'JetBrains Mono', monospace; font-size: 10px; display: flex; flex-direction: column; gap: 2px; }
.disasm-line { display: flex; gap: 8px; padding: 1px 4px; border-radius: 2px; }
.disasm-line.current { color: var(--vic-cyan); background: rgba(77,240,255,0.05); }
.disasm-line .arrow { width: 12px; }
.disasm-line.current .arrow { color: var(--vic-green); }
.disasm-line .addr { opacity: 0.6; width: 40px; }

.debug-btn-row { display: flex; gap: 4px; margin-top: 8px; }
.debug-btn {
  font-size: 0.7rem; padding: 4px 8px; border-radius: 4px;
  background: #1a2a40; color: var(--vic-cyan); border: 1px solid #2a3a50;
  cursor: pointer; font-family: 'JetBrains Mono', monospace;
}
.debug-btn:hover { background: #2a3a50; }
.brk-btn { color: var(--vic-red); }
.breakpoint-row { display: flex; gap: 4px; margin-top: 8px; align-items: center; }
.brk-label { font-size: 0.7rem; opacity: 0.4; }
.debug-input {
  font-size: 0.7rem; padding: 4px 8px; border-radius: 4px; width: 64px;
  background: #0a0a1a; color: var(--vic-cyan); border: 1px solid #2a3a50;
  font-family: 'JetBrains Mono', monospace;
}
.mem-addr-row { display: flex; gap: 4px; margin-bottom: 8px; align-items: center; }
.mem-dump { overflow-x: auto; font-size: 9px; font-family: 'JetBrains Mono', monospace; line-height: 1.5; }
.mem-line { display: flex; gap: 4px; white-space: nowrap; }
.mem-addr { color: var(--vic-green); }
.mem-hex { color: #556; }
.mem-ascii { color: #888; }

/* Status Bar */
.status-bar {
  background: #080810; border-top: 1px solid #1a2a40;
  padding: 6px 16px; font-size: 11px; color: var(--text-dim);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  position: relative; z-index: 1;
}
.status-left { display: flex; gap: 16px; }
.status-right { display: flex; align-items: center; gap: 8px; }
.status-colors { display: flex; align-items: center; gap: 4px; font-size: 0.7rem; }
.status-color-label { color: var(--vic-cyan); }
.color-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 2px; border: 1px solid #555; }
.rom-indicators { display: flex; gap: 4px; }
.rom-ind { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.rom-ind.on { background: var(--vic-green); }
.rom-ind.off { background: var(--vic-red); }

/* Rainbow Stripe */
.rainbow-stripe {
  height: 4px;
  background: linear-gradient(90deg, 
    #B61F21 0%, #B61F21 16.66%,
    #D8E232 16.66%, #D8E232 33.33%,
    #44E237 33.33%, #44E237 50%,
    #4DF0FF 50%, #4DF0FF 66.66%,
    #1A34FF 66.66%, #1A34FF 83.33%,
    #B43FFF 83.33%, #B43FFF 100%
  );
  border-radius: 2px;
  margin: 4px 0;
}

/* Footer */
.footer-area {
  text-align: center; padding: 12px; font-size: 0.7rem; opacity: 0.3;
  position: relative; z-index: 1;
}
.footer-area a { color: var(--vic-cyan); text-decoration: none; }
.footer-area a:hover { opacity: 0.8; }

/* Memory Map Panel */
.memmap-panel { font-size: 11px; }

.memmap-carts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 768px) { .memmap-carts { grid-template-columns: 1fr; } }

.cart-card {
  display: flex;
  gap: 12px;
  background: #0a1018;
  border: 1px solid #1a2a40;
  border-radius: 8px;
  padding: 12px;
  transition: border-color 0.3s;
}
.cart-card:hover { border-color: var(--vic-cyan); }

.cart-pcb {
  min-width: 110px;
  background: #1a3a20;
  border-radius: 4px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  border: 1px solid #2a5a30;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.4);
}
.cart-pcb.pcb-16k { min-width: 130px; }

.cart-pcb::before {
  content: '';
  position: absolute;
  top: 3px; right: 3px;
  width: 6px; height: 6px;
  border-radius: 50%;
  border: 1px solid #4a7a50;
  opacity: 0.6;
}

.cart-chip-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.cart-chip {
  background: #111;
  color: #8a8a8a;
  font-size: 6px;
  font-family: 'JetBrains Mono', monospace;
  padding: 4px 6px;
  border-radius: 2px;
  text-align: center;
  line-height: 1.4;
  border: 1px solid #333;
  min-width: 42px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.cart-chip.small { min-width: 36px; }
.cart-chip.accent { border-color: var(--vic-cyan); color: var(--vic-cyan); opacity: 0.7; }
.cart-chip.decoder { border-color: #886600; color: #aa8800; font-size: 5.5px; min-width: 36px; }

.cart-traces {
  height: 8px;
  background: repeating-linear-gradient(
    90deg,
    transparent 0px, transparent 3px,
    #3a7a40 3px, #3a7a40 4px
  );
  opacity: 0.4;
  border-radius: 1px;
}
.cart-traces-16k {
  height: 12px;
  background:
    repeating-linear-gradient(90deg, transparent 0px, transparent 3px, #3a7a40 3px, #3a7a40 4px),
    repeating-linear-gradient(0deg, transparent 0px, transparent 3px, #3a7a40 3px, #3a7a40 4px);
  opacity: 0.3;
  border-radius: 1px;
}

.cart-edge-connector {
  display: flex;
  gap: 2px;
  justify-content: center;
  margin-top: auto;
  padding-top: 4px;
  border-top: 2px solid #c8a000;
}
.cart-pin {
  width: 4px;
  height: 8px;
  background: #c8a000;
  border-radius: 0 0 1px 1px;
}

.cart-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.cart-title { font-size: 0.8rem; font-weight: 700; color: var(--vic-cyan); }
.cart-subtitle { font-size: 0.65rem; color: var(--vic-yellow); opacity: 0.7; }
.cart-desc { font-size: 0.65rem; opacity: 0.5; line-height: 1.5; flex: 1; }

.cart-dip {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.dip-label { font-size: 0.6rem; opacity: 0.4; }
.dip-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 20px;
  font-size: 7px;
  font-weight: 700;
  border-radius: 2px;
  border: 1px solid #444;
  font-family: 'JetBrains Mono', monospace;
}
.dip-switch.on {
  background: linear-gradient(180deg, #1a5a00 0%, #0a3a00 100%);
  color: var(--vic-green);
  border-color: #2a6a10;
  box-shadow: 0 0 4px rgba(68,226,55,0.2);
}
.dip-switch.off {
  background: linear-gradient(180deg, #333 0%, #222 100%);
  color: #555;
}
.dip-inline {
  background: #1a2a40;
  padding: 0 4px;
  border-radius: 2px;
  color: var(--vic-cyan);
  font-size: 0.65rem;
}

.memmap-info-text {
  background: #080810;
  border: 1px solid #1a2a40;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 16px;
  font-size: 0.7rem;
  line-height: 1.6;
  opacity: 0.75;
}
.memmap-info-text p { margin-bottom: 6px; }
.memmap-info-text p:last-child { margin-bottom: 0; }
.memmap-info-text strong { color: var(--vic-cyan); font-weight: 700; }
.memmap-compat-note {
  color: var(--vic-yellow) !important;
  opacity: 0.8 !important;
  border-left: 2px solid var(--vic-yellow);
  padding-left: 8px;
  margin-top: 4px !important;
}

.memmap-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--vic-cyan);
  margin-bottom: 8px;
}

.memmap-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}

.memmap-row {
  display: grid;
  grid-template-columns: 48px 1fr 180px 52px 20px;
  gap: 6px;
  align-items: center;
  padding: 3px 6px;
  border-radius: 3px;
  transition: background 0.15s;
  cursor: default;
}
.memmap-row:hover { background: rgba(77,240,255,0.04); }
@media (max-width: 768px) {
  .memmap-row { grid-template-columns: 40px 1fr 100px 42px 16px; font-size: 9px; }
}

.memmap-addr {
  font-size: 0.65rem;
  color: var(--vic-green);
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}

.memmap-bar {
  height: 14px;
  background: #0a0a1a;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid #1a2a40;
}

.memmap-fill {
  height: 100%;
  border-radius: 1px;
  transition: width 0.3s;
}

.ram-fill { background: linear-gradient(90deg, #1a34ff 0%, #2a44ff 100%); opacity: 0.7; }
.rom-fill { background: linear-gradient(90deg, #B61F21 0%, #d02f31 100%); opacity: 0.7; }
.exp-fill {
  background: repeating-linear-gradient(90deg, #44E237 0px, #44E237 3px, #2a9a20 3px, #2a9a20 6px);
  opacity: 0.6;
}
.exp-rom-fill {
  background: repeating-linear-gradient(90deg, #B43FFF 0px, #B43FFF 3px, #8a2fcc 3px, #8a2fcc 6px);
  opacity: 0.6;
}
.io-fill { background: linear-gradient(90deg, #D8E232 0%, #c8d222 100%); opacity: 0.6; }
.color-fill { background: linear-gradient(90deg, #B5690E 0%, #c5791e 100%); opacity: 0.7; }
.color-exp-fill {
  background: repeating-linear-gradient(90deg, #B5690E 0px, #B5690E 3px, #956910 3px, #956910 6px);
  opacity: 0.5;
}

.memmap-label {
  font-size: 0.65rem;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.memmap-size {
  font-size: 0.6rem;
  opacity: 0.4;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

.memmap-cart-flag {
  font-size: 10px;
  text-align: center;
  width: 16px;
}
.cart-decoded { color: var(--vic-cyan); text-shadow: 0 0 4px rgba(77,240,255,0.4); }

.memmap-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.65rem;
  opacity: 0.5;
  padding-top: 8px;
  border-top: 1px solid #1a2a40;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 8px;
  border-radius: 1px;
}

.cart-decoded-legend {
  color: var(--vic-cyan);
  font-size: 10px;
}

/* Animations */
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes crt-on {
  0% { transform: scaleY(0.005) scaleX(0.8); opacity: 0.5; }
  40% { transform: scaleY(0.005) scaleX(1); opacity: 1; }
  60% { transform: scaleY(1) scaleX(1); opacity: 1; }
  100% { transform: scaleY(1) scaleX(1); opacity: 1; }
}

.crt-poweron { animation: crt-on 0.6s ease-out forwards; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a1a; }
::-webkit-scrollbar-thumb { background: #2a3a50; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a4a60; }

/* Range inputs */
input[type="range"] { accent-color: var(--vic-cyan); }