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

:root {
  --bg: #0d0d1a;
  --bezel: #3a3a3a;
  --bezel-light: #555;
  --bezel-dark: #222;
  --text: #c8d0d8;
  --accent: #f0c040;
  --danger: #d03030;
  --cpc-blue: #0000a8;
  --cpc-yellow: #ffff00;
  --cpc-green: #00ff00;
  --panel-bg: #1a1a2e;
  --btn-bg: #2a2a3e;
  --btn-border-light: #4a4a5e;
  --btn-border-dark: #111;
}

body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 0%, #1a1a3a 0%, var(--bg) 70%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.008) 2px, rgba(255,255,255,0.008) 4px);
  color: var(--text);
  font-family: 'Share Tech Mono', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

#app {
  width: 100%;
  max-width: 900px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* Monitor */
#monitor-frame {
  background: linear-gradient(180deg, #4a4a4a 0%, #333 40%, #2a2a2a 100%);
  border-radius: 18px;
  padding: 18px 20px 24px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.1),
    inset 0 -1px 0 rgba(0,0,0,0.3);
  width: 100%;
  max-width: 820px;
}

#monitor-bezel {
  background: linear-gradient(180deg, #2e2e2e, #1e1e1e);
  border-radius: 10px;
  padding: 10px;
  border: 1px solid #111;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}

#monitor-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #666;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 3px;
}

#screen-container {
  position: relative;
  width: 100%;
  aspect-ratio: 768 / 544;
  overflow: hidden;
  border-radius: 8px;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.5),
    0 0 15px rgba(0,80,200,0.1);
}

#canvas {
  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;
  z-index: 2;
}

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

/* Controls */
#controls {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 12px;
  background: linear-gradient(180deg, #222236, #1a1a2e);
  border-radius: 10px;
  border: 1px solid #333;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}

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

.label {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #888;
  letter-spacing: 1px;
  margin-right: 4px;
}

.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: linear-gradient(180deg, #3a3a50, #2a2a3e);
  color: #c8d0e0;
  box-shadow:
    0 3px 0 #111,
    inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.05s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #111, inset 0 1px 0 rgba(255,255,255,0.05);
}

.btn:hover {
  background: linear-gradient(180deg, #4a4a60, #3a3a4e);
}

.btn-primary {
  background: linear-gradient(180deg, #2060c0, #1848a0);
  color: #fff;
  box-shadow: 0 3px 0 #0a2860, inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-primary:hover { background: linear-gradient(180deg, #2870d0, #2050b0); }

.btn-danger {
  background: linear-gradient(180deg, #c03030, #a02020);
  color: #fff;
  box-shadow: 0 3px 0 #601010, inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-danger:hover { background: linear-gradient(180deg, #d04040, #b03030); }

.btn-accent {
  background: linear-gradient(180deg, #c09020, #a07818);
  color: #fff;
  box-shadow: 0 3px 0 #604010, inset 0 1px 0 rgba(255,255,255,0.15);
}

.btn-mode {
  width: 32px;
  text-align: center;
  padding: 8px 0;
}

.btn-mode.active {
  background: linear-gradient(180deg, #2060c0, #1848a0);
  color: #fff;
  box-shadow: 0 1px 0 #0a2860, inset 0 2px 4px rgba(0,0,0,0.3);
  transform: translateY(1px);
}

.load-offset-group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.hex-prefix {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  margin-left: 2px;
}

#load-offset {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  width: 48px;
  padding: 5px 4px;
  background: #0a0a18;
  color: var(--accent);
  border: 1px solid #444;
  border-radius: 3px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  outline: none;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.4);
}

#load-offset:focus {
  border-color: var(--accent);
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.4), 0 0 6px rgba(240, 192, 64, 0.3);
}

.mode-selector, .speed-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

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

#speed-value {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  min-width: 60px;
}

/* Status */
#status-bar {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 6px 12px;
  background: #111120;
  border-radius: 6px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: #6a8;
  border: 1px solid #222;
}

#status-bar span {
  white-space: nowrap;
}

/* Palette */
#palette-viewer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: #111120;
  border-radius: 6px;
  border: 1px solid #222;
}

#palette-swatches {
  display: flex;
  gap: 2px;
}

.palette-swatch {
  width: 16px;
  height: 16px;
  border: 1px solid #444;
  border-radius: 2px;
}

/* Memory Panel */
#memory-panel {
  width: 100%;
  max-width: 820px;
  background: #0a0a12;
  border: 1px solid #1a3a1a;
  border-radius: 8px;
  overflow: hidden;
}

#memory-panel.hidden { display: none; }

#memory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #1a2a1a;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #4a8;
}

.btn-close {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
}
.btn-close:hover { color: #fff; }

#memory-dump {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: #0f0;
  padding: 8px 12px;
  overflow-x: auto;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.4;
}

#memory-dump .pc-highlight {
  background: #2a4a2a;
  color: #4f4;
}

/* Virtual Keyboard */
#virtual-keyboard {
  width: 100%;
  max-width: 820px;
  background: #222236;
  border-radius: 10px;
  padding: 10px;
  border: 1px solid #333;
}

#virtual-keyboard.hidden { display: none; }

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

.kb-key {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  min-width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #4a4a58, #3a3a48);
  color: #ccc;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 2px 0 #111, inset 0 1px 0 rgba(255,255,255,0.08);
  padding: 0 4px;
  transition: all 0.05s;
}

.kb-key:active, .kb-key.pressed {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #111;
  background: linear-gradient(180deg, #5a5a68, #4a4a58);
  color: var(--accent);
}

.kb-key.wide { min-width: 56px; }
.kb-key.wider { min-width: 80px; }
.kb-key.space { min-width: 200px; }

/* Footer */
footer {
  margin-top: 12px;
  padding: 12px;
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #555;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

footer a {
  color: #5588cc;
  text-decoration: none;
}
footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 600px) {
  #app { padding: 8px; }
  #monitor-frame { padding: 10px 12px 14px; border-radius: 12px; }
  .btn { font-size: 7px; padding: 6px 10px; }
  #status-bar { font-size: 8px; }
  .control-group { justify-content: center; }
  input[type="range"] { width: 70px; }
  .kb-key { min-width: 22px; height: 24px; font-size: 6px; }
  .kb-key.space { min-width: 120px; }
}