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

:root {
  --bg: #0d0d1a;
  --bezel: #2a2a3a;
  --bezel-light: #3a3a4a;
  --phosphor: #33ff33;
  --phosphor-dim: #0a3a0a;
  --phosphor-glow: rgba(51,255,51,0.3);
  --text: #aabbaa;
  --text-bright: #ccddcc;
  --accent: #446644;
  --panel-bg: #151525;
  --btn-bg: #222235;
  --btn-hover: #333348;
  --key-bg: #1a1a2e;
  --key-text: #99aa99;
  --key-special: #2a2a4e;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Share Tech Mono', 'Courier New', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 15px 30px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 15px;
  border-bottom: 1px solid #333;
  margin-bottom: 15px;
}

header h1 {
  font-family: 'VT323', monospace;
  font-size: 1.6em;
  color: var(--phosphor);
  text-shadow: 0 0 10px var(--phosphor-glow);
  letter-spacing: 2px;
}

.subtitle {
  font-size: 0.75em;
  color: #667766;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

#status-led {
  font-size: 1.4em;
  transition: all 0.3s;
}

.led-off { color: #662222; text-shadow: none; }
.led-on { color: #33ff33; text-shadow: 0 0 8px #33ff33; animation: pulse-led 2s infinite; }

@keyframes pulse-led {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#power-btn {
  background: linear-gradient(180deg, #3a3a4a, #222233);
  border: 2px solid #555;
  border-radius: 6px;
  padding: 6px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

#power-btn:hover { border-color: var(--phosphor); }
#power-btn:active { transform: scale(0.96); }

.power-label {
  color: var(--text);
  font-family: 'VT323', monospace;
  font-size: 1em;
  letter-spacing: 2px;
}

#power-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  transition: all 0.3s;
}

.power-off { background: #440000; box-shadow: none; }
.power-on { background: #33ff33; box-shadow: 0 0 6px #33ff33; }

/* Monitor Bezel */
#monitor-bezel {
  background: linear-gradient(145deg, #2e2e3e, #1a1a2a);
  border: 3px solid #3a3a4a;
  border-radius: 20px;
  padding: 20px 20px 10px;
  box-shadow: 0 0 30px rgba(0,0,0,0.5), inset 0 0 20px rgba(0,0,0,0.3);
  margin-bottom: 15px;
}

#screen-container {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8), 0 0 15px var(--phosphor-glow);
  aspect-ratio: 320/200;
  max-width: 100%;
}

#screen {
  width: 100%;
  height: 100%;
  display: block;
  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;
}

#scanlines.hidden { display: none; }

#bezel-label {
  text-align: center;
  font-family: 'VT323', monospace;
  font-size: 0.85em;
  color: #555;
  letter-spacing: 4px;
  margin-top: 8px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 0;
  flex-wrap: wrap;
}

.tab {
  background: var(--btn-bg);
  border: 1px solid #333;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 6px 14px;
  color: var(--text);
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 0.95em;
  letter-spacing: 1px;
  transition: all 0.15s;
}

.tab:hover { background: var(--btn-hover); }
.tab.active { background: var(--panel-bg); color: var(--phosphor); border-bottom-color: var(--panel-bg); }

.tab-content {
  display: none;
  background: var(--panel-bg);
  border: 1px solid #333;
  border-radius: 0 6px 6px 6px;
  padding: 15px;
  min-height: 120px;
}

.tab-content.active { display: block; }

.tab-content h3 {
  font-family: 'VT323', monospace;
  color: var(--phosphor);
  font-size: 1.1em;
  margin-bottom: 10px;
  letter-spacing: 2px;
}

.hint { font-size: 0.8em; color: #667; margin-bottom: 10px; }

/* Upload Button */
.upload-btn {
  display: inline-block;
  background: linear-gradient(180deg, #3a4a3a, #222832);
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 8px 20px;
  color: var(--phosphor);
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 1em;
  letter-spacing: 2px;
  text-align: center;
  transition: all 0.15s;
  margin-bottom: 12px;
}

.upload-btn:hover { background: #334433; border-color: var(--phosphor); }
.upload-btn.small { font-size: 0.85em; padding: 5px 12px; }

/* ROM Status */
#rom-status {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.rom-item {
  font-size: 0.8em;
  padding: 3px 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 3px;
}

.rom-item .rom-icon { margin-right: 4px; }
.rom-item.loaded { color: #33ff33; }
.rom-item.loaded .rom-icon { color: #33ff33; }
.rom-item:not(.loaded) .rom-icon { color: #cc3333; }

/* RAM */
.ram-options { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.ram-options label { cursor: pointer; font-size: 0.9em; }
.ram-options input[type="radio"] { accent-color: var(--phosphor); }

#memmap { margin-top: 10px; }
.membar {
  display: flex;
  height: 24px;
  border-radius: 3px;
  overflow: hidden;
  font-size: 0.6em;
  text-align: center;
  line-height: 24px;
}

.mm-ram { background: #336633; color: #fff; }
.mm-empty { background: #1a1a1a; }
.mm-screen { background: #336699; color: #fff; }
.mm-charrom { background: #665533; color: #fff; }
.mm-expansion { background: #2a2a2a; color: #555; }
.mm-rom { background: #663333; color: #ddd; }

/* Peripherals */
.peripheral-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.peripheral {
  background: rgba(0,0,0,0.3);
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px;
  text-align: center;
}

.peripheral-icon { font-size: 1.8em; margin-bottom: 4px; }
.peripheral-label { font-size: 0.75em; color: #888; margin-bottom: 6px; }
.periph-status { font-size: 0.7em; color: var(--phosphor); margin-top: 4px; min-height: 1.2em; }

/* Debug */
.debug-controls { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }

.ctrl-btn {
  background: var(--btn-bg);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 5px 12px;
  color: var(--text);
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 0.9em;
  transition: all 0.15s;
}

.ctrl-btn:hover { background: var(--btn-hover); border-color: var(--phosphor); color: var(--phosphor); }

#cpu-registers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #000;
  padding: 10px;
  border-radius: 4px;
  border: 1px solid #222;
  margin-bottom: 8px;
}

.reg { display: flex; gap: 6px; align-items: center; }
.reg-label { color: #666; font-size: 0.8em; min-width: 22px; }
.reg-val { color: var(--phosphor); font-family: 'Share Tech Mono', monospace; font-size: 0.85em; }

#clock-speed { font-size: 0.8em; color: #666; }

/* Display Options */
.display-options { display: flex; flex-direction: column; gap: 10px; }
.color-options { display: flex; gap: 6px; }

.color-btn {
  background: var(--btn-bg);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 14px;
  color: var(--text);
  cursor: pointer;
  font-family: 'VT323', monospace;
  transition: all 0.15s;
}

.color-btn:hover { border-color: #888; }
.color-btn.active { border-color: var(--phosphor); color: var(--phosphor); }

.toggle-label { cursor: pointer; font-size: 0.9em; display: flex; align-items: center; gap: 6px; }
.toggle-label input { accent-color: var(--phosphor); }

/* Keyboard */
#keyboard {
  display: flex;
  gap: 10px;
  background: linear-gradient(180deg, #222233, #1a1a2a);
  border: 2px solid #333;
  border-radius: 10px;
  padding: 12px;
  margin-top: 15px;
  flex-wrap: wrap;
}

#keyboard-main { flex: 1; min-width: 0; }
#keyboard-numpad {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-left: 1px solid #333;
  padding-left: 10px;
}

.kb-row { display: flex; gap: 3px; margin-bottom: 3px; }

.kb-key {
  background: linear-gradient(180deg, #2a2a3e, #1e1e2e);
  border: 1px solid #444;
  border-radius: 3px;
  padding: 4px 6px;
  min-width: 28px;
  height: 28px;
  color: var(--key-text);
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 0.7em;
  text-align: center;
  line-height: 20px;
  user-select: none;
  transition: all 0.1s;
  white-space: nowrap;
  overflow: hidden;
}

.kb-key:hover { background: #333348; border-color: #666; }
.kb-key:active, .kb-key.pressed { background: #444458; transform: translateY(1px); border-color: var(--phosphor); color: var(--phosphor); }

.kb-key.special {
  background: linear-gradient(180deg, #2a2a4e, #1e1e3e);
  border-color: #555;
  min-width: 42px;
  color: #aabbcc;
}

.kb-key.wide { min-width: 56px; }
.kb-key.space { min-width: 140px; }

footer {
  text-align: center;
  padding: 20px 0 10px;
}

footer a {
  color: #445;
  text-decoration: none;
  font-size: 0.8em;
  letter-spacing: 1px;
  transition: color 0.2s;
}

footer a:hover { color: var(--phosphor); }

/* Amber theme */
.amber { --phosphor: #ffb000; --phosphor-dim: #3a2800; --phosphor-glow: rgba(255,176,0,0.3); --accent: #664400; }
.amber #screen-container { box-shadow: inset 0 0 40px rgba(0,0,0,0.8), 0 0 15px rgba(255,176,0,0.3); }

/* White theme */
.white-phosphor { --phosphor: #e0e0e0; --phosphor-dim: #2a2a2a; --phosphor-glow: rgba(224,224,224,0.2); --accent: #555; }
.white-phosphor #screen-container { box-shadow: inset 0 0 40px rgba(0,0,0,0.8), 0 0 15px rgba(224,224,224,0.2); }

@keyframes tape-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tape-spinning { animation: tape-spin 0.5s linear infinite; display: inline-block; }

@media (max-width: 600px) {
  #app { padding: 5px 8px 20px; }
  header h1 { font-size: 1.1em; }
  #monitor-bezel { padding: 10px 10px 6px; border-radius: 12px; }
  #rom-status { grid-template-columns: 1fr; }
  #cpu-registers { grid-template-columns: repeat(2, 1fr); }
  .kb-key { min-width: 22px; height: 24px; font-size: 0.6em; padding: 2px 3px; }
  .kb-key.special { min-width: 32px; }
  .kb-key.wide { min-width: 40px; }
  .kb-key.space { min-width: 80px; }
  .peripheral-grid { grid-template-columns: 1fr 1fr; }
}