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

:root {
  --c64-blue: #6C6CFF;
  --c64-dark-blue: #3F3FBF;
  --c64-light-blue: #7C7CFF;
  --c64-bg: #40318D;
  --bezel-color: #8B7355;
  --bezel-dark: #5C4A32;
  --bezel-light: #C4A87C;
  --key-color: #4A4035;
  --key-light: #6B5D4F;
  --screen-glow: rgba(108, 108, 255, 0.15);
}

html, body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  background: #1a1a1a;
  font-family: 'Share Tech Mono', monospace;
  color: #ccc;
}

body {
  background: 
    radial-gradient(ellipse at center, #2a2218 0%, #0d0d0d 100%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10px;
}

#app-container {
  width: 100%;
  max-width: 1000px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#monitor-housing {
  background: linear-gradient(180deg, var(--bezel-light) 0%, var(--bezel-color) 30%, var(--bezel-dark) 100%);
  border-radius: 20px 20px 12px 12px;
  padding: 16px 20px 12px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.2),
    inset 0 -2px 4px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 960px;
}

#monitor-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 8px;
}

#model-label {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: #3a2f1a;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}

.led-off, .led-on {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid #333;
}
.led-off { background: #333; }
.led-on { 
  background: #4f4; 
  box-shadow: 0 0 6px #4f4, 0 0 12px #2a2;
  animation: led-blink 0.5s ease-in-out infinite alternate;
}

@keyframes led-blink {
  0% { opacity: 0.7; }
  100% { opacity: 1; }
}

#crt-frame {
  background: #111;
  border-radius: 12px;
  padding: 10px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}

#crt-screen {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  box-shadow: 
    0 0 30px var(--screen-glow),
    inset 0 0 60px rgba(0,0,0,0.5);
}

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

#scanlines {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.12) 2px,
    rgba(0,0,0,0.12) 4px
  );
  pointer-events: none;
  z-index: 2;
}

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

#drop-zone {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border: 3px dashed var(--c64-blue);
  border-radius: 8px;
}

#drop-zone.hidden { display: none; }

.drop-text {
  font-family: 'VT323', monospace;
  font-size: 32px;
  color: var(--c64-blue);
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

#monitor-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px 2px;
  flex-wrap: wrap;
  justify-content: center;
}

#file-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

#load-btn {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 4px 14px;
  background: linear-gradient(180deg, #5a4a3a, #3a2a1a);
  color: #ddd;
  border: 2px solid #2a1a0a;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 1px;
  white-space: nowrap;
}
#load-btn:hover { background: linear-gradient(180deg, #6a5a4a, #4a3a2a); }

.disk-icon { color: #4f4; margin-right: 4px; }

#preset-select {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  background: #2a2a2a;
  color: #aaa;
  border: 1px solid #555;
  padding: 4px 6px;
  border-radius: 3px;
  max-width: 160px;
}

#emu-controls {
  display: flex;
  gap: 4px;
}

#emu-controls button, #audio-controls button {
  font-size: 16px;
  width: 34px;
  height: 30px;
  background: linear-gradient(180deg, #4a4a4a, #2a2a2a);
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#emu-controls button:hover, #audio-controls button:hover {
  background: linear-gradient(180deg, #5a5a5a, #3a3a3a);
}
#emu-controls button:active, #audio-controls button:active {
  transform: translateY(1px);
}

#audio-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

#volume-slider {
  width: 60px;
  accent-color: var(--c64-blue);
  height: 20px;
}

#oscilloscope {
  border: 1px solid #444;
  border-radius: 3px;
  background: #000;
  height: 30px;
  width: 120px;
}

#keyboard-toggle-bar {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 960px;
  justify-content: center;
}

#keyboard-toggle-bar button {
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 6px 18px;
  background: var(--bezel-dark);
  color: #ccc;
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 1px;
  min-height: 36px;
}
#keyboard-toggle-bar button:hover {
  background: var(--bezel-color);
}

#virtual-keyboard {
  width: 100%;
  max-width: 960px;
  background: linear-gradient(180deg, #5a4a3a, #3a2a1a);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#virtual-keyboard.hidden { display: none; }

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

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 11px;
  min-width: 28px;
  height: 30px;
  background: linear-gradient(180deg, var(--key-light), var(--key-color));
  color: #ddd;
  border: 1px solid #2a1a0a;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  padding: 0 3px;
  text-align: center;
  line-height: 1;
  transition: transform 0.05s;
  touch-action: manipulation;
}
.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  background: linear-gradient(180deg, var(--key-color), #2a1a0a);
}
.kb-key.wide { min-width: 50px; }
.kb-key.wider { min-width: 72px; }
.kb-key.widest { min-width: 180px; }
.kb-key.fn-key { background: linear-gradient(180deg, #7a5a3a, #5a3a1a); }

#debugger-panel {
  width: 100%;
  max-width: 960px;
  background: #111;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  grid-template-rows: auto auto;
  gap: 8px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: #0f0;
}
#debugger-panel.hidden { display: none; }

#debugger-panel h3 {
  font-size: 11px;
  color: var(--c64-blue);
  margin-bottom: 4px;
  letter-spacing: 2px;
}

#reg-display, #disasm-display, #mem-display {
  font-size: 11px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 200px;
}

#mem-addr-input-wrap {
  margin-bottom: 4px;
}

#mem-addr-input {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  width: 60px;
  background: #000;
  color: #0f0;
  border: 1px solid #333;
  padding: 2px 4px;
}

#debug-controls {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
}

#debug-controls button {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  padding: 4px 12px;
  background: #222;
  color: #0f0;
  border: 1px solid #444;
  border-radius: 3px;
  cursor: pointer;
  min-height: 28px;
}
#debug-controls button:hover {
  background: #333;
}

#status-bar {
  width: 100%;
  max-width: 960px;
  display: flex;
  gap: 12px;
  padding: 4px 10px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 4px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: #888;
  flex-wrap: wrap;
  justify-content: center;
}

#status-state {
  color: #4f4;
  font-weight: bold;
}

#app-footer {
  width: 100%;
  max-width: 960px;
  text-align: center;
  padding: 10px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--c64-light-blue);
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

#app-footer a {
  color: var(--c64-blue);
  text-decoration: none;
}
#app-footer a:hover {
  text-decoration: underline;
}

/* Mobile responsive */
@media (max-width: 700px) {
  body { padding: 4px; }
  #monitor-housing { padding: 8px 6px 6px; border-radius: 10px 10px 6px 6px; }
  #crt-frame { padding: 4px; border-radius: 6px; }
  #monitor-controls { gap: 4px; padding: 6px 2px 2px; }
  #file-controls { gap: 4px; }
  #preset-select { font-size: 11px; max-width: 130px; }
  #emu-controls button, #audio-controls button { width: 30px; height: 28px; font-size: 14px; }
  .kb-key { min-width: 20px; height: 26px; font-size: 9px; padding: 0 2px; }
  .kb-key.wide { min-width: 36px; }
  .kb-key.wider { min-width: 50px; }
  .kb-key.widest { min-width: 100px; }
  .kb-row { gap: 1px; }
  #virtual-keyboard { padding: 4px; gap: 2px; }
  #debugger-panel { grid-template-columns: 1fr; font-size: 10px; }
  #debugger-panel h3 { font-size: 10px; }
  #reg-display, #disasm-display, #mem-display { font-size: 10px; max-height: 150px; }
  #oscilloscope { display: none; }
  #volume-slider { width: 40px; }
  #status-bar { font-size: 9px; gap: 6px; padding: 3px 6px; }
  #app-footer { font-size: 12px; gap: 10px; }
}

@media (max-width: 380px) {
  .kb-key { min-width: 17px; height: 24px; font-size: 8px; }
  .kb-key.wide { min-width: 30px; }
  .kb-key.wider { min-width: 42px; }
  .kb-key.widest { min-width: 80px; }
  #load-btn { font-size: 14px; padding: 3px 10px; }
  #monitor-controls { gap: 3px; }
}