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

:root {
  --bezel-cream: #d4c5a0;
  --bezel-dark: #b8a882;
  --bezel-shadow: #8a7b5e;
  --screen-bg: #0a0a0a;
  --key-dark: #2a2520;
  --key-text: #e0dcd0;
  --key-red: #c0392b;
  --green-glow: #33ff33;
  --amber-glow: #ffaa00;
  --debug-bg: #0a120a;
  --debug-text: #33ff33;
  --bbc-red: #e74c3c;
  --bbc-orange: #e67e22;
  --bbc-yellow: #f1c40f;
  --bbc-green: #27ae60;
  --bbc-blue: #2980b9;
}

body {
  background: #1a1a1a;
  font-family: 'Share Tech Mono', monospace;
  color: #ccc;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

#app-container {
  max-width: 900px;
  width: 100%;
  margin: 10px auto;
  position: relative;
}

/* Monitor Bezel */
#monitor-bezel {
  background: linear-gradient(180deg, #ddd0b0 0%, var(--bezel-cream) 15%, var(--bezel-dark) 100%);
  border-radius: 20px 20px 12px 12px;
  padding: 12px 20px 16px;
  box-shadow:
    0 8px 30px rgba(0,0,0,0.6),
    inset 0 2px 0 rgba(255,255,255,0.3),
    inset 0 -2px 4px rgba(0,0,0,0.2);
  position: relative;
}

#bezel-top {
  display: flex;
  align-items: center;
  padding: 4px 8px 8px;
  gap: 16px;
}

#rainbow-stripe {
  display: flex;
  gap: 0;
  height: 8px;
  flex-shrink: 0;
  border-radius: 2px;
  overflow: hidden;
}

#rainbow-stripe .stripe {
  width: 20px;
  height: 100%;
  display: block;
}
.stripe.red { background: var(--bbc-red); }
.stripe.orange { background: var(--bbc-orange); }
.stripe.yellow { background: var(--bbc-yellow); }
.stripe.green { background: var(--bbc-green); }
.stripe.blue { background: var(--bbc-blue); }

#bbc-logo {
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.logo-bbc {
  font-family: 'Share Tech Mono', monospace;
  font-weight: 900;
  font-size: 18px;
  color: #333;
  letter-spacing: 2px;
}
.logo-micro {
  font-size: 13px;
  color: #555;
  font-weight: bold;
}
.logo-model {
  font-size: 11px;
  color: #777;
}

/* Screen */
#screen-surround {
  background: #111;
  border-radius: 12px;
  padding: 12px;
  box-shadow: inset 0 4px 20px rgba(0,0,0,0.8);
}

#crt-container {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--screen-bg);
  box-shadow:
    0 0 60px rgba(51, 255, 51, 0.05),
    inset 0 0 80px rgba(0,0,0,0.5);
}

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

#crt-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

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

#vignette {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  box-shadow: inset 0 0 100px rgba(0,0,0,0.5);
  border-radius: 8px;
}

#screen-glare {
  position: absolute;
  top: 5%; left: 10%;
  width: 30%;
  height: 20%;
  pointer-events: none;
  background: radial-gradient(ellipse, rgba(255,255,255,0.03) 0%, transparent 70%);
  transform: rotate(-15deg);
}

/* Ticker */
#ticker-bar {
  background: #222;
  margin-top: 6px;
  border-radius: 4px;
  overflow: hidden;
  height: 20px;
  display: flex;
  align-items: center;
  padding: 0 8px;
}

#ticker-text {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--bbc-yellow);
  white-space: nowrap;
  animation: ticker-scroll 30s linear infinite;
}

@keyframes ticker-scroll {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-200%); }
}

/* Controls Bar */
#controls-bar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 4px;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ctrl-btn {
  font-family: 'Share Tech Mono', monospace;
  background: linear-gradient(180deg, #444 0%, #2a2a2a 100%);
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.1s;
}
.ctrl-btn:hover { background: linear-gradient(180deg, #555 0%, #333 100%); }
.ctrl-btn:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(0,0,0,0.3); }

.ctrl-btn.red-btn {
  background: linear-gradient(180deg, #d44 0%, #a22 100%);
  color: white;
  border-color: #c33;
}
.ctrl-btn.red-btn:hover { background: linear-gradient(180deg, #e55 0%, #b33 100%); }

.ctrl-select {
  font-family: 'Share Tech Mono', monospace;
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
}

.ctrl-label {
  font-size: 11px;
  color: #999;
}

.ctrl-range {
  width: 60px;
  accent-color: var(--green-glow);
}
.vol-range { width: 40px; }

#speed-display {
  font-size: 11px;
  color: var(--green-glow);
  min-width: 35px;
}

#oscilloscope {
  background: #111;
  border: 1px solid #333;
  border-radius: 3px;
}

/* Keyboard */
#keyboard-container {
  padding: 8px;
  background: linear-gradient(180deg, #3a3530 0%, #2a2520 100%);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 3px;
  user-select: none;
}

.key-row {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.key {
  font-family: 'Share Tech Mono', monospace;
  background: linear-gradient(180deg, #3a3530 0%, var(--key-dark) 100%);
  color: var(--key-text);
  border: 1px solid #444;
  border-radius: 4px;
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
  box-shadow: 0 3px 0 #111, 0 4px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.08);
  transition: all 0.05s;
  flex-shrink: 0;
}

.key:active, .key.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #111, 0 2px 3px rgba(0,0,0,0.3);
}

.key.fn-key {
  background: linear-gradient(180deg, #d44 0%, #a22 100%);
  color: white;
  border-color: #c33;
  min-width: 38px;
  font-size: 10px;
}

.key.wide { min-width: 48px; }
.key.wider { min-width: 64px; }
.key.space-key { min-width: 200px; flex-grow: 1; max-width: 300px; }
.key.return-key { min-width: 56px; background: linear-gradient(180deg, #444 0%, #333 100%); }

/* Status Bar */
#status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 12px;
  background: #111;
  border-radius: 4px;
  font-size: 11px;
  color: #888;
  flex-wrap: wrap;
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.led.red { background: #c0392b; box-shadow: 0 0 6px #c0392b; }
.led.green { background: #27ae60; box-shadow: 0 0 6px #27ae60; }

/* Debug Panel */
#debug-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 280px;
  height: 100vh;
  background: var(--debug-bg);
  border-left: 2px solid #1a3a1a;
  overflow-y: auto;
  z-index: 1000;
  font-family: 'VT323', monospace;
  color: var(--debug-text);
  font-size: 14px;
  padding: 8px;
  box-shadow: -4px 0 20px rgba(0,0,0,0.5);
  transition: transform 0.3s;
}

#debug-panel.hidden {
  transform: translateX(100%);
}

#debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px;
  border-bottom: 1px solid #1a3a1a;
  margin-bottom: 8px;
  font-size: 16px;
}

#debug-close {
  background: none;
  border: none;
  color: var(--debug-text);
  cursor: pointer;
  font-size: 18px;
}

.reg-row {
  display: flex;
  gap: 8px;
  padding: 2px 4px;
}
.reg-name { color: #1a8a1a; }
.reg-val { color: var(--green-glow); }

.flags-row {
  gap: 4px;
  margin: 4px 0;
}
.flag {
  display: inline-block;
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  background: #0a1a0a;
  border: 1px solid #1a3a1a;
  border-radius: 2px;
  font-size: 12px;
}
.flag.set {
  background: #1a5a1a;
  color: var(--green-glow);
}

.debug-section-title {
  color: #1a8a1a;
  border-bottom: 1px solid #1a3a1a;
  padding: 4px 0;
  margin: 8px 0 4px;
  font-size: 13px;
}

#mem-addr-input {
  background: #0a1a0a;
  border: 1px solid #1a3a1a;
  color: var(--green-glow);
  font-family: 'VT323', monospace;
  font-size: 13px;
  width: 50px;
  padding: 2px 4px;
  margin-left: 8px;
}

#mem-dump {
  font-size: 11px;
  line-height: 1.4;
  white-space: pre;
  overflow-x: auto;
  color: #22aa22;
}

#disasm-list {
  font-size: 12px;
  line-height: 1.5;
}
.disasm-line { padding: 1px 4px; }
.disasm-line.current { background: #1a3a1a; color: var(--green-glow); }

/* Help Overlay */
#help-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#help-overlay.hidden { display: none; }

#help-content {
  background: #1a1a1a;
  border: 2px solid var(--bbc-yellow);
  border-radius: 12px;
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  color: #ddd;
  position: relative;
}

#help-content h2 {
  font-family: 'VT323', monospace;
  color: var(--bbc-yellow);
  font-size: 24px;
  margin-bottom: 16px;
}
#help-content h3 {
  color: var(--green-glow);
  margin: 12px 0 4px;
  font-size: 14px;
}
#help-content code {
  background: #222;
  color: var(--bbc-yellow);
  padding: 1px 4px;
  border-radius: 2px;
  font-family: 'VT323', monospace;
  font-size: 15px;
}

#help-close {
  position: absolute;
  top: 10px; right: 14px;
  background: none;
  border: none;
  color: var(--bbc-yellow);
  font-size: 24px;
  cursor: pointer;
}

.help-grid {
  display: flex;
  gap: 24px;
}
.help-col { flex: 1; font-size: 13px; line-height: 1.8; }

/* Toast */
#toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: var(--bbc-yellow);
  border: 1px solid var(--bbc-yellow);
  padding: 10px 20px;
  border-radius: 8px;
  font-family: 'VT323', monospace;
  font-size: 16px;
  z-index: 3000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  transition: opacity 0.3s;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* Footer */
#app-footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: #555;
  max-width: 900px;
  width: 100%;
}
.footer-link {
  display: inline-block;
  margin-top: 4px;
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--bbc-yellow);
  text-decoration: none;
  background: #111;
  padding: 4px 12px;
  border-radius: 4px;
}
.footer-link:hover { color: #fff; background: #222; }
.footer-disclaimer { display: block; margin-bottom: 6px; }

/* Mobile */
@media (max-width: 640px) {
  #app-container { margin: 4px; }
  #monitor-bezel { padding: 8px 10px 10px; border-radius: 12px 12px 8px 8px; }
  #screen-surround { padding: 6px; }
  .key { min-width: 24px; height: 26px; font-size: 9px; }
  .key.fn-key { min-width: 28px; font-size: 8px; }
  .key.wide { min-width: 34px; }
  .key.wider { min-width: 44px; }
  .key.space-key { min-width: 120px; }
  .key.return-key { min-width: 40px; }
  #controls-bar { flex-direction: column; }
  .help-grid { flex-direction: column; }
  #debug-panel { width: 100%; }
  #status-bar { font-size: 10px; gap: 8px; }
}