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

:root {
  --bg: #1a1a1a;
  --panel: #2a2a2a;
  --green: #33ff33;
  --amber: #ffaa00;
  --beige: #c4a882;
  --red: #ff3333;
  --blue: #3388ff;
  --orange: #ff8833;
  --text: #cccccc;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  max-width: 820px;
  width: 100%;
  padding: 10px;
}

header {
  text-align: center;
  padding: 12px 0 8px;
}

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

.power-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #550000;
  box-shadow: none;
  transition: all 0.3s;
}

.power-led.on {
  background: #ff0000;
  box-shadow: 0 0 8px #ff0000, 0 0 16px #ff000088;
  animation: pulse-led 1.5s infinite;
}

@keyframes pulse-led {
  0%, 100% { box-shadow: 0 0 8px #ff0000, 0 0 16px #ff000088; }
  50% { box-shadow: 0 0 12px #ff0000, 0 0 24px #ff0000aa; }
}

h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: #ffffff;
  text-shadow: 0 0 10px #33ff3344;
}

.subtitle {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--green);
  margin-top: 4px;
  opacity: 0.8;
}

#monitor-bezel {
  position: relative;
  background: #333;
  border-radius: 16px;
  padding: 16px;
  margin: 8px auto;
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.1),
    inset 0 -2px 4px rgba(0,0,0,0.5),
    0 4px 20px rgba(0,0,0,0.8),
    0 0 60px rgba(51,255,51,0.05);
  max-width: 800px;
}

#canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
  border-radius: 4px;
  image-rendering: pixelated;
}

.crt-overlay {
  position: absolute;
  top: 16px; left: 16px; right: 16px; bottom: 16px;
  border-radius: 4px;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0.15) 0px,
      rgba(0,0,0,0.15) 1px,
      transparent 1px,
      transparent 3px
    );
  mix-blend-mode: multiply;
}

.crt-overlay.off {
  display: none;
}

#controls {
  background: var(--beige);
  border-radius: 8px;
  padding: 10px;
  margin: 8px 0;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.3),
    inset 0 -2px 4px rgba(0,0,0,0.2),
    0 2px 8px rgba(0,0,0,0.5);
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.control-row:last-child { margin-bottom: 0; }

.ctrl-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 8px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  box-shadow:
    0 3px 0 rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.2);
  transition: all 0.1s;
}

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

.ctrl-btn.green { background: #22aa22; }
.ctrl-btn.green:hover { background: #33cc33; }
.ctrl-btn.red { background: #cc2222; }
.ctrl-btn.red:hover { background: #dd3333; }
.ctrl-btn.yellow { background: #aa8800; }
.ctrl-btn.yellow:hover { background: #ccaa00; }
.ctrl-btn.orange { background: #cc6622; }
.ctrl-btn.orange:hover { background: #dd7733; }
.ctrl-btn.blue { background: #2266cc; }
.ctrl-btn.blue:hover { background: #3377dd; }
.ctrl-btn.small { font-size: 8px; padding: 6px 10px; }

.speed-display {
  font-family: 'VT323', monospace;
  font-size: 18px;
  background: #111;
  color: var(--green);
  padding: 4px 12px;
  border-radius: 3px;
  border: 1px solid #444;
  min-width: 100px;
  text-align: center;
}

.upload-slot {
  flex: 1;
  min-width: 200px;
  background: #3a3020;
  border: 2px solid #5a4a30;
  border-radius: 6px;
  padding: 8px;
  text-align: center;
}

.slot-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--amber);
  margin-bottom: 6px;
}

.file-input { display: none; }

.file-label {
  display: inline-block;
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: #fff;
  background: #555;
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.2s;
}

.file-label:hover { background: #777; }

.file-info {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--green);
  margin-top: 4px;
  min-height: 18px;
}

.progress-bar {
  height: 6px;
  background: #222;
  border-radius: 3px;
  margin-top: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  width: 0%;
  transition: width 0.1s;
}

.volume-slider {
  width: 100px;
  accent-color: var(--green);
}

#scopeCanvas {
  background: #000;
  border: 1px solid #333;
  border-radius: 3px;
}

#debug-toggle-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

#debug-panel {
  background: var(--panel);
  border-radius: 6px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  overflow: hidden;
  transition: max-height 0.3s, opacity 0.3s, padding 0.3s;
  max-height: 600px;
  opacity: 1;
}

#debug-panel.collapsed {
  max-height: 0;
  opacity: 0;
  padding: 0 10px;
}

#debug-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--amber);
  margin-bottom: 6px;
}

#debug-panel pre {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--green);
  background: #111;
  padding: 6px;
  border-radius: 3px;
  overflow: auto;
  max-height: 200px;
  white-space: pre;
  line-height: 1.3;
}

#memMapCanvas {
  width: 100%;
  height: 24px;
  border-radius: 3px;
}

.hex-input {
  font-family: 'VT323', monospace;
  font-size: 14px;
  background: #111;
  color: var(--green);
  border: 1px solid #444;
  padding: 2px 6px;
  width: 60px;
  border-radius: 2px;
}

#keyboard-panel {
  margin: 8px 0;
}

#virtual-keyboard {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--beige);
  padding: 8px;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), 0 2px 8px rgba(0,0,0,0.5);
}

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

.kb-key {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 4px 4px 2px;
  min-width: 28px;
  text-align: center;
  background: #e8dcc8;
  color: #333;
  border: 1px solid #999;
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 0 #999;
  transition: all 0.05s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.kb-key-label {
  font-size: 7px;
  line-height: 1.2;
}

.kb-key-hid {
  font-size: 5px;
  color: #888;
  line-height: 1;
  opacity: 0.7;
}

.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  box-shadow: 0 0 0 #999;
  background: #ccc0a8;
}

.kb-key.wide { min-width: 48px; }
.kb-key.xwide { min-width: 80px; }
.kb-key.space { min-width: 180px; }

#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: #888;
  padding: 6px 0;
  border-top: 1px solid #333;
}

#statusState { color: var(--amber); font-weight: bold; }

footer {
  text-align: center;
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: #555;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

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

@media (max-width: 600px) {
  h1 { font-size: 12px; }
  .subtitle { font-size: 13px; }
  .ctrl-btn { font-size: 8px; padding: 6px 10px; }
  #debug-panel { grid-template-columns: 1fr; }
  .kb-key { font-size: 6px; min-width: 22px; padding: 4px 2px; }
  .kb-key.space { min-width: 120px; }
}