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

:root {
  --phosphor: #33ff33;
  --phosphor-dim: #0a4a0a;
  --phosphor-glow: rgba(51, 255, 51, 0.3);
  --bg: #0c0c0c;
  --bezel: #1a1a1a;
  --bezel-inner: #111;
  --key-bg: #d4cfc4;
  --key-text: #222;
  --key-shadow: #8a8578;
  --key-highlight: #eee9de;
}

body {
  background: var(--bg);
  color: #aaa;
  font-family: 'IBM Plex Mono', monospace;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(40,40,40,0.5) 0%, transparent 70%),
    url("data:image/svg+xml,%3Csvg width='4' height='4' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='1' height='1' fill='rgba(255,255,255,0.015)'/%3E%3C/svg%3E");
}

#app {
  width: 100%;
  max-width: 720px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#bezel {
  background: var(--bezel);
  border-radius: 18px;
  padding: 16px;
  box-shadow:
    0 0 0 2px #333,
    0 0 0 4px #111,
    inset 0 2px 8px rgba(255,255,255,0.04),
    0 8px 32px rgba(0,0,0,0.8);
  width: 100%;
  max-width: 680px;
}

#bezel-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--phosphor);
  box-shadow: 0 0 6px var(--phosphor-glow);
  flex-shrink: 0;
}

#title {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: #ccc;
  letter-spacing: 3px;
  flex-shrink: 0;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.tb-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  background: #2a2a2a;
  color: #aaa;
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.1s;
}
.tb-btn:hover { background: #3a3a3a; color: #ddd; }
.tb-btn:active { background: #222; transform: translateY(1px); }

#programs {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  padding: 3px 6px;
  background: #2a2a2a;
  color: #aaa;
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
}

#speed-indicator {
  font-size: 10px;
  color: #666;
  font-weight: 500;
}

#screen-wrap {
  position: relative;
  background: #050505;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.9), inset 0 0 4px rgba(0,0,0,1);
  padding: 12px;
}

#canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 6px;
}

#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.12) 2px,
    rgba(0,0,0,0.12) 4px
  );
  border-radius: 12px;
}

/* Keyboard */
#keyboard {
  width: 100%;
  max-width: 680px;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px;
  background: linear-gradient(145deg, #2c2a25, #1e1c18);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
}

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

.key {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--key-text);
  background: linear-gradient(180deg, var(--key-highlight) 0%, var(--key-bg) 60%, var(--key-shadow) 100%);
  border: none;
  border-radius: 5px;
  padding: 8px 6px 10px;
  min-width: 34px;
  cursor: pointer;
  box-shadow:
    0 3px 0 #6b6560,
    0 4px 4px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.6);
  transition: all 0.05s;
  user-select: none;
  -webkit-user-select: none;
  text-align: center;
  line-height: 1;
}

.key:active, .key.pressed {
  transform: translateY(2px);
  box-shadow:
    0 1px 0 #6b6560,
    0 2px 2px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.4);
}

.key.wide { min-width: 60px; padding-left: 10px; padding-right: 10px; }
.key.wider { min-width: 80px; }
.key.space-bar { flex: 1; max-width: 320px; min-width: 160px; }

.key.special {
  background: linear-gradient(180deg, #c44 0%, #a33 60%, #822 100%);
  color: #fff;
  box-shadow:
    0 3px 0 #611,
    0 4px 4px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,200,200,0.4);
}

/* Debug */
#debug-toggle-wrap {
  width: 100%;
  max-width: 680px;
  margin-top: 8px;
}
#debug-toggle {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  background: transparent;
  border: 1px solid #333;
  color: #666;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: 4px;
  width: 100%;
}
#debug-toggle:hover { color: #aaa; border-color: #555; }

#debug-panel {
  width: 100%;
  max-width: 680px;
  background: #141414;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 4px;
  transition: max-height 0.3s, opacity 0.3s, padding 0.3s;
  overflow: hidden;
}
#debug-panel.collapsed {
  max-height: 0;
  opacity: 0;
  padding: 0 14px;
  border-color: transparent;
}

#registers {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.reg {
  display: flex;
  align-items: center;
  gap: 6px;
}
.reg label {
  font-size: 10px;
  color: #666;
  font-weight: 700;
}
.reg span {
  font-size: 13px;
  color: var(--phosphor);
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
}

#flags {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.flag {
  display: inline-block;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  border-radius: 3px;
  background: #222;
  color: #444;
  border: 1px solid #333;
  transition: all 0.15s;
}
.flag.active {
  background: var(--phosphor-dim);
  color: var(--phosphor);
  border-color: var(--phosphor);
  box-shadow: 0 0 4px var(--phosphor-glow);
}

#disasm {
  margin-top: 8px;
  font-size: 12px;
  color: #888;
}

#debug-controls {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}

footer {
  margin-top: 20px;
  text-align: center;
  font-size: 11px;
  color: #444;
  padding: 16px;
}
footer a {
  color: #666;
  text-decoration: none;
  border-bottom: 1px solid #444;
}
footer a:hover { color: #aaa; }

@media (max-width: 500px) {
  #bezel { padding: 8px; border-radius: 10px; }
  #screen-wrap { padding: 6px; border-radius: 8px; }
  #title { font-size: 10px; letter-spacing: 2px; }
  .key { font-size: 9px; min-width: 26px; padding: 6px 3px 8px; }
  .key.wide { min-width: 44px; }
  .key.wider { min-width: 56px; }
  #keyboard { padding: 8px; gap: 3px; }
  .key-row { gap: 3px; }
}