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

:root {
  --bg: #111111;
  --bg-panel: #1c1c1c;
  --border: #333;
  --text: #bbb;
  --text-dim: #777;
  --green: #33ff33;
  --green-dim: #0a3a0a;
  --green-glow: rgba(51, 255, 51, 0.25);
  --bezel: #c4b596;
  --bezel-dark: #a89a7e;
  --power-on: #2a9d2a;
  --power-off: #c33;
  --power-reset: #c9a633;
  --accent: #33cc33;
  --font-ui: 'Share Tech Mono', 'Courier New', monospace;
  --font-retro: 'VT323', monospace;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  min-height: 100vh;
  overflow-x: hidden;
}

body {
  background: radial-gradient(ellipse at center, #1a1a1a 0%, #0a0a0a 100%);
}

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

/* Top Bar */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: linear-gradient(180deg, #2a2a2a, #1a1a1a);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 10px;
}

.title-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cbm-logo {
  font-family: var(--font-retro);
  font-size: 28px;
  color: var(--bezel);
  background: linear-gradient(180deg, #d4c5a9, #a89a7e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: bold;
  letter-spacing: 2px;
}

#top-bar h1 {
  font-family: var(--font-retro);
  font-size: 26px;
  color: var(--bezel);
  letter-spacing: 1px;
}

.status-indicators {
  display: flex;
  gap: 16px;
}

.indicator {
  font-size: 11px;
  color: var(--text-dim);
  padding: 3px 8px;
  background: #0e0e0e;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
}

#cpu-state { color: var(--power-off); }
#cpu-state.running { color: var(--accent); }

/* Main Layout */
#main-layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

#center-column {
  flex: 1;
  min-width: 0;
}

/* Monitor Bezel */
#monitor-bezel {
  background: linear-gradient(160deg, #d4c5a9 0%, #b8a88a 40%, #a89a7e 100%);
  border-radius: 20px;
  padding: 24px 28px 16px;
  box-shadow:
    0 4px 20px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.2),
    inset 0 -2px 4px rgba(0,0,0,0.2);
  position: relative;
}

#screen-container {
  position: relative;
  background: #001100;
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.8),
    0 0 30px var(--green-glow),
    0 0 60px rgba(51, 255, 51, 0.1);
  border: 3px solid #222;
}

#screen {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0, 0, 0, 0.15) 1px,
    rgba(0, 0, 0, 0.15) 2px
  );
  pointer-events: none;
  mix-blend-mode: multiply;
}

#bezel-label {
  text-align: center;
  font-family: var(--font-ui);
  font-size: 11px;
  color: #7a6e5a;
  margin-top: 8px;
  letter-spacing: 3px;
  text-transform: uppercase;
}

/* Keyboard */
#keyboard-container {
  margin-top: 10px;
  background: linear-gradient(160deg, #d4c5a9 0%, #b8a88a 50%, #a89a7e 100%);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kb-row {
  display: flex;
  gap: 3px;
  justify-content: center;
  align-items: center;
}

.kb-row .kb-separator {
  width: 12px;
}

.kb-key {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 30px;
  padding: 2px 4px;
  font-family: var(--font-ui);
  font-size: 9px;
  color: #222;
  background: linear-gradient(180deg, #e8e8e8 0%, #ccc 100%);
  border: 1px solid #999;
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  text-align: center;
  line-height: 1.1;
  transition: all 0.05s;
  box-shadow: 0 2px 0 #888, 0 3px 4px rgba(0,0,0,0.3);
}

.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  box-shadow: 0 0 0 #888, 0 1px 2px rgba(0,0,0,0.3);
  background: linear-gradient(180deg, #ccc 0%, #b8b8b8 100%);
}

.kb-key.wide { min-width: 50px; }
.kb-key.wider { min-width: 68px; }
.kb-key.space { min-width: 180px; }
.kb-key.return-key { min-width: 60px; background: linear-gradient(180deg, #ddd 0%, #bbb 100%); }
.kb-key.shift-key { min-width: 50px; }
.kb-key.shift-key.active { background: linear-gradient(180deg, #ffa 0%, #cc8 100%); }
.kb-key.stop-key { background: linear-gradient(180deg, #f88 0%, #c55 100%); color: #fff; }
.kb-key.numpad { background: linear-gradient(180deg, #e0ddd0 0%, #c5c2b5 100%); }

/* Side Panel */
#side-panel {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.panel-title {
  font-size: 12px;
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
  background: linear-gradient(180deg, #252525, #1a1a1a);
  user-select: none;
  border-bottom: 1px solid var(--border);
}

.panel-title:hover { color: #fff; }

.panel-content {
  padding: 10px;
}

.panel-content.collapsed { display: none; }

/* ROM Slots */
.rom-slot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 10px;
  border-bottom: 1px solid #222;
}

.rom-slot:last-child { border-bottom: none; }

.rom-slot .rom-status { font-size: 14px; }
.rom-slot .rom-name {
  flex: 1;
  color: var(--text-dim);
  font-size: 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rom-slot .rom-addr {
  color: var(--accent);
  font-size: 9px;
  font-family: var(--font-ui);
}

.rom-slot label.file-btn-small {
  font-size: 9px;
  padding: 2px 6px;
  background: #333;
  border: 1px solid #555;
  border-radius: 3px;
  color: #aaa;
  cursor: pointer;
}

.rom-slot label.file-btn-small:hover { background: #444; color: #fff; }

/* File buttons */
.file-btn, .tool-btn, .dbg-btn {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 11px;
  padding: 6px 12px;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: all 0.1s;
}

.file-btn:hover, .tool-btn:hover, .dbg-btn:hover {
  background: #3a3a3a;
  color: #fff;
  border-color: #777;
}

.file-btn.small { font-size: 10px; padding: 4px 8px; }

.rom-actions {
  margin-top: 8px;
  text-align: center;
}

/* RAM selector */
.ram-selector {
  display: flex;
  gap: 16px;
}

.ram-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
}

.ram-option input { accent-color: var(--accent); }

/* Power Controls */
.power-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.power-btn {
  flex: 1;
  min-width: 70px;
  font-family: var(--font-retro);
  font-size: 16px;
  padding: 10px 8px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  transition: all 0.1s;
  box-shadow: 0 3px 0 rgba(0,0,0,0.4), 0 4px 8px rgba(0,0,0,0.3);
}

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

.power-on { background: linear-gradient(180deg, #3adf3a, #1a8a1a); }
.power-on:hover { background: linear-gradient(180deg, #4aef4a, #2a9a2a); }
.power-reset { background: linear-gradient(180deg, #dfba3a, #8a7a1a); }
.power-reset:hover { background: linear-gradient(180deg, #efca4a, #9a8a2a); }
.power-off { background: linear-gradient(180deg, #df3a3a, #8a1a1a); }
.power-off:hover { background: linear-gradient(180deg, #ef4a4a, #9a2a2a); }

/* Peripherals */
.peripheral-item {
  padding: 6px 0;
  border-bottom: 1px solid #222;
}

.peripheral-item:last-child { border-bottom: none; }
.peripheral-item h4 { font-size: 11px; color: var(--text); margin-bottom: 6px; }
.periph-status { font-size: 10px; color: var(--text-dim); margin-top: 4px; }

.auto-run-label {
  font-size: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  color: var(--text-dim);
  cursor: pointer;
}

/* Debug */
.debug-registers {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--accent);
  background: #0a0a0a;
  padding: 6px;
  border-radius: 3px;
  white-space: pre;
  line-height: 1.5;
  margin-bottom: 6px;
}

.debug-controls {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.debug-mem-input {
  margin-bottom: 6px;
  font-size: 11px;
}

.debug-mem-input input {
  background: #0a0a0a;
  border: 1px solid #333;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 11px;
  padding: 2px 4px;
  width: 50px;
}

.debug-mem, .debug-disasm {
  font-family: var(--font-ui);
  font-size: 9px;
  color: var(--green);
  background: #050505;
  padding: 6px;
  border-radius: 3px;
  white-space: pre;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 6px;
}

.speed-control {
  font-size: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.speed-control input[type="range"] {
  width: 100px;
  accent-color: var(--accent);
}

/* Footer */
footer {
  margin-top: 16px;
  padding: 12px;
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  border-top: 1px solid #222;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

footer a:hover { text-decoration: underline; }
footer small { font-size: 9px; color: #555; }

/* Responsive */
@media (max-width: 900px) {
  #main-layout {
    flex-direction: column;
  }
  #side-panel {
    width: 100%;
  }
}

/* CRT power-on animation */
@keyframes crt-on {
  0% { transform: scaleY(0.01) scaleX(0.5); filter: brightness(10); }
  40% { transform: scaleY(0.01) scaleX(1); filter: brightness(5); }
  60% { transform: scaleY(1) scaleX(1); filter: brightness(2); }
  100% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
}

#screen-container.powering-on #screen {
  animation: crt-on 0.4s ease-out;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #111; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #666; }