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

:root {
  --beige: #d4c5a9;
  --beige-light: #e8dcc8;
  --beige-dark: #b8a88c;
  --bezel-shadow: #8a7a5e;
  --crt-bg: #111;
  --green-led: #4cff4c;
  --red-led: #ff4040;
  --amber-led: #ffaa00;
  --text-mono: 'IBM Plex Mono', monospace;
  --text-display: 'VT323', monospace;
}

html, body {
  width: 100%;
  min-height: 100vh;
  background: linear-gradient(180deg, #3a3a3a 0%, #2a2a2a 40%, #1e1e1e 100%);
  color: #e0d8c8;
  font-family: var(--text-mono);
  overflow-x: hidden;
}

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px;
}

/* Title Bar */
#title-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  margin-bottom: 12px;
}

.ibm-stripes {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.stripe {
  width: 40px;
  height: 3px;
  border-radius: 1px;
}
.stripe.blue { background: #4178be; }
.stripe.red { background: #da1e28; }
.stripe.green { background: #198038; }

.title-text h1 {
  font-size: 26px;
  font-weight: 700;
  color: #f0e8d8;
  letter-spacing: 1px;
}

.title-text h1 .dash { color: #888; }

.subtitle {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
  letter-spacing: 0.5px;
}

/* Main Area */
#main-area {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

#monitor-section { flex: 1; min-width: 0; }

/* Monitor Bezel */
#monitor-bezel {
  background: linear-gradient(145deg, var(--beige-light) 0%, var(--beige) 50%, var(--beige-dark) 100%);
  border-radius: 16px;
  padding: 20px 24px 12px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    0 2px 8px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.3),
    inset 0 -2px 4px rgba(0,0,0,0.1);
  position: relative;
}

#monitor-inner {
  background: #222;
  border-radius: 8px;
  padding: 8px;
  box-shadow: inset 0 4px 16px rgba(0,0,0,0.8);
}

#crt-screen {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4/3;
}

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

#crt-screen.curved {
  border-radius: 12px;
}
#crt-screen.curved #cga-canvas {
  border-radius: 10px;
}

#scanline-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  z-index: 2;
  display: none;
}
#scanline-overlay.active { display: block; }

#crt-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.5) 100%);
  z-index: 3;
}

#crt-reflection {
  position: absolute;
  top: 5%;
  left: 10%;
  width: 40%;
  height: 20%;
  background: linear-gradient(135deg, rgba(255,255,255,0.04) 0%, transparent 100%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 4;
}

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

.monitor-led-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.3);
}
.led.off { background: #333; }
.led.green { background: var(--green-led); box-shadow: 0 0 6px var(--green-led); }
.led.red { background: var(--red-led); box-shadow: 0 0 6px var(--red-led); }
.led.amber { background: var(--amber-led); box-shadow: 0 0 6px var(--amber-led); }

.led-label {
  font-size: 9px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.monitor-model {
  font-size: 11px;
  color: #666;
  font-style: italic;
}

/* Display Controls */
#display-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input { display: none; }

.toggle-slider {
  width: 32px;
  height: 16px;
  background: #555;
  border-radius: 8px;
  position: relative;
  transition: background 0.2s;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: #aaa;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: #4178be;
}
.toggle-switch input:checked + .toggle-slider::after {
  transform: translateX(16px);
  background: #fff;
}

.toggle-label {
  font-size: 11px;
  color: #bbb;
}

.ctrl-btn {
  background: #444;
  border: 1px solid #666;
  color: #ddd;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
.ctrl-btn:hover { background: #555; }

/* Debug Panel */
#debug-panel {
  width: 280px;
  flex-shrink: 0;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  overflow: hidden;
  font-size: 11px;
  max-height: 80vh;
  overflow-y: auto;
}

.debug-header {
  background: #252525;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 1px;
  color: #888;
  border-bottom: 1px solid #333;
  user-select: none;
}

#debug-content { padding: 8px; }
#debug-content.collapsed { display: none; }

.debug-section {
  margin-bottom: 12px;
}
.debug-section h3 {
  font-size: 10px;
  color: #4178be;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
  border-bottom: 1px solid #2a2a2a;
  padding-bottom: 4px;
}

.reg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  font-family: var(--text-display);
  font-size: 14px;
}

.reg-item {
  display: flex;
  justify-content: space-between;
  padding: 1px 4px;
}
.reg-name { color: #888; }
.reg-val { color: var(--green-led); }

.code-display {
  font-family: var(--text-display);
  font-size: 13px;
  color: #aaa;
  max-height: 120px;
  overflow-y: auto;
  background: #111;
  padding: 4px 6px;
  border-radius: 3px;
  line-height: 1.4;
}

#perf-display {
  font-family: var(--text-display);
  font-size: 14px;
  color: #ccc;
}

#floppy-files-list {
  font-family: var(--text-display);
  font-size: 13px;
  color: #ccc;
}

/* System Unit */
#system-unit {
  background: linear-gradient(145deg, var(--beige-light) 0%, var(--beige) 50%, var(--beige-dark) 100%);
  border-radius: 10px;
  padding: 16px;
  margin-top: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.3);
}

#system-unit-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

/* Floppy Drive */
#floppy-bay {
  background: #c0b090;
  border-radius: 6px;
  padding: 10px 14px;
  border: 1px solid #a09070;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

.bay-label {
  font-size: 9px;
  color: #666;
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-transform: uppercase;
}

#floppy-drive {
  display: flex;
  align-items: center;
  gap: 10px;
}

#floppy-slot {
  width: 140px;
  height: 14px;
  background: linear-gradient(180deg, #1a1a1a 0%, #333 20%, #222 80%, #111 100%);
  border-radius: 2px;
  position: relative;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.1);
  overflow: hidden;
  transition: all 0.2s;
}

#floppy-slit {
  position: absolute;
  inset: 4px 10px;
  background: #0a0a0a;
  border-radius: 1px;
  box-shadow: inset 0 0 2px rgba(0,0,0,0.8);
}

#floppy-disk-sprite {
  position: absolute;
  bottom: -18px;
  left: 10%;
  width: 80%;
  height: 16px;
  background: linear-gradient(180deg, #2a2a2a, #1a1a1a);
  border-radius: 1px 1px 0 0;
  opacity: 0;
  transition: transform 0.4s ease-out, opacity 0.1s;
  pointer-events: none;
}

#floppy-slot.inserting #floppy-disk-sprite {
  opacity: 1;
  transform: translateY(-14px);
  background: linear-gradient(180deg, #333, #222);
}

#floppy-slot.ejecting #floppy-disk-sprite {
  opacity: 1;
  transform: translateY(4px);
  transition: transform 0.3s ease-in, opacity 0.3s 0.2s;
}

#floppy-head-indicator {
  position: absolute;
  bottom: 0;
  left: 15%;
  width: 4px;
  height: 2px;
  background: transparent;
  border-radius: 1px;
  transition: left 0.05s linear;
}

.floppy-accessing #floppy-head-indicator {
  background: rgba(255, 170, 0, 0.6);
  box-shadow: 0 0 3px rgba(255, 170, 0, 0.3);
  animation: head-seek 0.15s ease-in-out infinite alternate;
}

@keyframes head-seek {
  0% { left: 15%; }
  100% { left: 75%; }
}

#floppy-slot #floppy-led {
  position: absolute;
  right: -16px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}

#floppy-buttons {
  display: flex;
  gap: 6px;
}

.floppy-btn {
  background: #b0a080;
  border: 1px solid #908060;
  color: #333;
  font-family: var(--text-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 0.5px;
}
.floppy-btn:hover:not(:disabled) { background: #c0b090; }
.floppy-btn:disabled { opacity: 0.5; cursor: default; }

#floppy-status {
  font-size: 10px;
  color: #555;
  min-width: 100px;
}

/* System Buttons */
#system-buttons {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.power-btn {
  width: 50px;
  height: 32px;
  background: #cc2222;
  border: 2px solid #881111;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.power-btn.on {
  background: #991111;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.rocker-switch {
  display: flex;
  justify-content: space-between;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  line-height: 28px;
}

.btn-label {
  font-size: 9px;
  color: #555;
  text-align: center;
  display: block;
  margin-top: 4px;
  letter-spacing: 1px;
}

.turbo-btn {
  background: #b0a080;
  border: 1px solid #908060;
  color: #333;
  font-family: var(--text-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 1px;
}
.turbo-btn.active {
  background: #ffaa00;
  color: #222;
}

#speed-display {
  text-align: center;
  margin-top: 4px;
  font-family: var(--text-display);
  font-size: 18px;
  color: #ff3333;
  background: #1a0000;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid #333;
}
.speed-unit { font-size: 11px; color: #cc2222; }

.reset-btn {
  width: 28px;
  height: 28px;
  background: #999;
  border: 2px solid #777;
  border-radius: 50%;
  cursor: pointer;
  font-size: 7px;
  font-family: var(--text-mono);
  font-weight: 700;
  color: #333;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}
.btn-label-small {
  font-size: 8px;
  color: #555;
  display: block;
  margin-top: 2px;
  text-align: center;
}

#volume-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vol-label {
  font-size: 10px;
  color: #555;
  font-weight: 600;
  white-space: nowrap;
}

#volume-slider {
  width: 80px;
  accent-color: var(--bezel-shadow);
}

#intel-sticker {
  margin-left: auto;
  background: linear-gradient(135deg, #e8e0d0, #d0c8b8);
  border: 1px solid #b0a890;
  border-radius: 3px;
  padding: 6px 10px;
  text-align: center;
  font-family: sans-serif;
  line-height: 1.1;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.sticker-inner {
  font-size: 12px;
  font-weight: 700;
  color: #0060a8;
}
.sticker-inside {
  font-size: 10px;
  font-style: italic;
  color: #0060a8;
}
.sticker-tm { font-size: 6px; }

/* Keyboard Bar */
#keyboard-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  margin-top: 10px;
  background: #1a1a1a;
  border-radius: 4px;
  font-size: 11px;
}
.kb-indicator { color: #888; }
#kb-status { color: var(--green-led); }
#key-press-indicator {
  font-family: var(--text-display);
  font-size: 14px;
  color: #ffaa00;
  min-width: 120px;
  text-align: right;
}

/* Footer */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 8px;
  font-size: 12px;
  color: #666;
}
footer a { color: #4178be; text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #111; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

/* Responsive */
@media (max-width: 900px) {
  #main-area { flex-direction: column; }
  #debug-panel { width: 100%; max-height: 300px; }
  #system-unit-inner { flex-direction: column; align-items: flex-start; }
  #intel-sticker { margin-left: 0; }
}

@keyframes floppy-access {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.floppy-accessing #floppy-led {
  animation: floppy-access 0.15s infinite;
}

.floppy-accessing #floppy-slot {
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.7), 0 0 4px rgba(255, 170, 0, 0.1);
}

/* Floppy file listing styles (DOS-like) */
.disk-info-header {
  background: #0a0a14;
  border: 1px solid #2a2a3a;
  border-radius: 3px;
  padding: 5px 6px;
  margin-bottom: 6px;
}

.disk-info-label {
  font-family: var(--text-display);
  font-size: 13px;
  color: #ffaa00;
  font-weight: bold;
  letter-spacing: 1px;
}

.disk-info-meta {
  font-family: var(--text-display);
  font-size: 11px;
  color: #666;
  margin-top: 2px;
}

.disk-info-bar {
  width: 100%;
  height: 6px;
  background: #1a1a2a;
  border-radius: 3px;
  margin: 4px 0 2px;
  overflow: hidden;
  border: 1px solid #2a2a3a;
}

.disk-info-used {
  height: 100%;
  background: linear-gradient(90deg, #4178be, #55aaff);
  border-radius: 2px;
  transition: width 0.3s;
}

.dir-listing {
  font-family: var(--text-display);
  font-size: 12px;
  background: #0a0a0a;
  border: 1px solid #222;
  border-radius: 3px;
  padding: 4px;
  max-height: 160px;
  overflow-y: auto;
}

.dir-entry {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 1px 3px;
  border-radius: 2px;
  line-height: 1.5;
}

.dir-entry:hover {
  background: #1a1a2a;
}

.dir-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-size {
  color: #888;
  font-size: 11px;
  white-space: nowrap;
  text-align: right;
  min-width: 50px;
}

.dir-date {
  color: #555;
  font-size: 10px;
  white-space: nowrap;
}

.file-normal .dir-name { color: #ccc; }
.file-dir .dir-name { color: #ffaa00; }
.file-dir .dir-name::before { content: '📁 '; font-size: 10px; }
.file-hidden .dir-name { color: #555; font-style: italic; }

.dir-summary {
  color: #4178be;
  font-size: 11px;
  padding-top: 3px;
  margin-top: 3px;
  border-top: 1px solid #222;
}

/* Floppy insert button pulse */
#btn-insert-floppy {
  position: relative;
  transition: all 0.2s;
}

#btn-insert-floppy:hover:not(:disabled) {
  background: #c8b898;
  box-shadow: 0 0 8px rgba(255, 170, 0, 0.15);
}