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

:root {
  --beige: #c8b88a;
  --beige-light: #d9ccaa;
  --beige-dark: #a89868;
  --charcoal: #1a1a1a;
  --panel-bg: #222;
  --text: #e0e0e0;
  --accent: #ff4444;
  --green: #33ff33;
  --amber: #ffaa00;
  --cga-blue: #0000aa;
  --mono: 'IBM Plex Mono', 'Courier New', monospace;
}

html, body {
  background: var(--charcoal);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* Toolbar */
#toolbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: #181818;
  border-bottom: 1px solid #333;
  flex-wrap: wrap;
  gap: 6px;
}
.toolbar-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--beige-light);
  letter-spacing: 1px;
}
.toolbar-brand .js { color: var(--accent); }
.toolbar-center, .toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.toolbar-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #aaa;
}
.toolbar-item select {
  background: #333;
  color: #eee;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 4px;
  font-family: var(--mono);
  font-size: 11px;
}
.toolbar-btn {
  background: #333;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  transition: background 0.15s;
}
.toolbar-btn:hover { background: #444; }
.toolbar-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Main Area */
#main-area {
  display: flex;
  gap: 12px;
  padding: 16px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 1200px;
}

/* Monitor */
#monitor-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}
#monitor {
  background: linear-gradient(180deg, var(--beige-light) 0%, var(--beige) 40%, var(--beige-dark) 100%);
  border-radius: 18px;
  padding: 24px 28px 14px 28px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 2px 0 rgba(255,255,255,0.15);
  position: relative;
}
#monitor-bezel {
  background: #111;
  border-radius: 10px;
  padding: 10px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8), 0 0 4px rgba(0,0,0,0.5);
}
#screen-container {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  line-height: 0;
}
#canvas {
  display: block;
  width: 640px;
  height: 400px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
}
/* CRT effect */
body.crt #screen-container {
  box-shadow: 0 0 60px rgba(100,255,100,0.04), inset 0 0 30px rgba(0,0,0,0.3);
}
body.crt #canvas {
  filter: contrast(1.05) brightness(1.02);
}
#scanlines {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  border-radius: 4px;
}
body.crt #scanlines { display: block; }

/* Phosphor tints */
body.phosphor-green #canvas { filter: contrast(1.1) brightness(1.05) sepia(0.3) hue-rotate(80deg) saturate(2); }
body.phosphor-amber #canvas { filter: contrast(1.1) brightness(1.05) sepia(0.6) saturate(1.5); }
body.phosphor-green.crt #screen-container { box-shadow: 0 0 60px rgba(50,255,50,0.08), inset 0 0 30px rgba(0,0,0,0.3); }
body.phosphor-amber.crt #screen-container { box-shadow: 0 0 60px rgba(255,170,0,0.08), inset 0 0 30px rgba(0,0,0,0.3); }

#monitor-badge {
  text-align: center;
  margin-top: 8px;
  font-size: 10px;
  font-weight: 700;
  color: #555;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* Control Panel */
#control-panel {
  width: 100%;
  max-width: 696px;
  margin-top: 12px;
  background: linear-gradient(180deg, var(--beige-light) 0%, var(--beige) 100%);
  border-radius: 8px;
  padding: 10px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
}
.vents {
  height: 8px;
  background: repeating-linear-gradient(
    90deg,
    var(--beige-dark) 0px,
    var(--beige-dark) 3px,
    transparent 3px,
    transparent 6px
  );
  border-radius: 2px;
  margin-bottom: 8px;
  opacity: 0.5;
}
.controls-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.control-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.control-label {
  font-size: 8px;
  font-weight: 700;
  color: #555;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.power-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #888;
  background: linear-gradient(180deg, #cc3333, #991111);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
  transition: all 0.15s;
}
.power-button:active { transform: scale(0.95); }
.power-button.on {
  background: linear-gradient(180deg, #44cc44, #228822);
  box-shadow: 0 3px 8px rgba(0,0,0,0.4), 0 0 12px rgba(50,255,50,0.3);
}
.reset-button {
  padding: 4px 8px;
  font-size: 9px;
  font-family: var(--mono);
  background: #888;
  color: #222;
  border: 2px solid #666;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 700;
}
.reset-button:active { transform: scale(0.95); }

.led-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  border: 1px solid #222;
  transition: all 0.1s;
}
.led-indicator.on {
  background: var(--green);
  box-shadow: 0 0 6px rgba(50,255,50,0.5);
}
.led-indicator.active {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(255,170,0,0.6);
}

.floppy-slot {
  width: 120px;
  height: 28px;
  background: #222;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  position: relative;
  border: 1px solid #444;
}
.floppy-slot:hover { border-color: #888; }
.slot-opening {
  position: absolute;
  top: 6px; left: 8px; right: 8px;
  height: 3px;
  background: #000;
  border-radius: 1px;
}
.drive-label {
  font-size: 8px;
  color: #888;
  z-index: 1;
  pointer-events: none;
  text-align: center;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drive-label.loaded { color: var(--green); }
.eject-btn {
  position: absolute;
  right: 2px;
  top: 2px;
  width: 18px;
  height: 18px;
  font-size: 10px;
  background: #444;
  border: none;
  color: #ddd;
  cursor: pointer;
  border-radius: 2px;
  z-index: 2;
  line-height: 1;
  padding: 0;
}
.eject-btn:hover { background: var(--accent); }

.hdd-indicator-box {
  width: 100px;
  height: 28px;
  background: #222;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  border: 1px solid #444;
  gap: 4px;
}
.hdd-indicator-box:hover { border-color: #888; }

.hidden { display: none !important; }
.hidden-input { position: absolute; width: 0; height: 0; opacity: 0; }

/* Debug Panel */
#debug-panel {
  background: #181818;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px;
  width: 320px;
  max-height: 600px;
  overflow-y: auto;
  font-size: 11px;
}
#debug-panel h3 {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 2px;
}
#debug-panel h4 {
  font-size: 10px;
  color: #888;
  margin-bottom: 4px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.debug-section {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2a2a2a;
}
.mono-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  font-size: 10px;
}
.mono-grid .reg {
  color: #888;
}
.mono-grid .val {
  color: var(--green);
  font-weight: 700;
}
.flags-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.flags-grid .flag {
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 2px;
  background: #2a0000;
  color: #aa3333;
}
.flags-grid .flag.set {
  background: #002a00;
  color: var(--green);
}
.mono-block {
  background: #111;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  padding: 6px;
  font-size: 10px;
  color: #aaa;
  max-height: 140px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.4;
}
.mono-input {
  background: #222;
  border: 1px solid #444;
  color: var(--green);
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  width: 100px;
}
.mem-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}
.debug-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

/* Status Bar */
#status-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 4px 16px;
  background: #111;
  border-top: 1px solid #333;
  font-size: 10px;
  color: #666;
  flex-wrap: wrap;
}
.disk-light {
  padding: 0 4px;
  border-radius: 2px;
}
.disk-light.active {
  color: var(--amber);
  text-shadow: 0 0 4px rgba(255,170,0,0.5);
}

/* Footer */
#footer {
  padding: 12px;
  text-align: center;
  font-size: 11px;
  color: #555;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
#footer a {
  color: var(--accent);
  text-decoration: none;
}
#footer a:hover { text-decoration: underline; }
.footer-joke { color: #444; }

/* Fullscreen mode */
body.fullscreen #toolbar,
body.fullscreen #control-panel,
body.fullscreen #debug-panel,
body.fullscreen #status-bar,
body.fullscreen #footer { display: none !important; }
body.fullscreen #main-area { padding: 0; }
body.fullscreen #monitor-wrapper { width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; }
body.fullscreen #monitor { border-radius: 0; padding: 0; }
body.fullscreen #monitor-bezel { border-radius: 0; padding: 0; }
body.fullscreen #monitor-badge { display: none; }
body.fullscreen #canvas { width: 100vw; height: 100vh; border-radius: 0; }

/* Warm-up animation */
@keyframes warmup {
  0% { opacity: 0; filter: brightness(0); }
  30% { opacity: 0.3; filter: brightness(0.3); }
  100% { opacity: 1; filter: brightness(1); }
}
#canvas.warming-up {
  animation: warmup 1.5s ease-out forwards;
}

/* Responsive */
@media (max-width: 720px) {
  #canvas { width: 100%; height: auto; }
  #monitor { padding: 12px 12px 8px 12px; max-width: 100%; }
  .controls-row { gap: 8px; justify-content: center; }
  .floppy-slot { width: 100px; }
  .hdd-indicator-box { width: 80px; }
  #debug-panel { width: 100%; }
  #main-area { padding: 8px; }
}

/* Drag-over indicator */
.drag-over {
  border-color: var(--green) !important;
  box-shadow: 0 0 12px rgba(50,255,50,0.3) !important;
}