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

:root {
  --bg-dark: #0d0d0d;
  --bg-charcoal: #1a1a1a;
  --bezel-light: #C9B89D;
  --bezel-dark: #A89878;
  --bezel-shadow: #8A7B65;
  --green-phosphor: #33FF33;
  --amber-phosphor: #FFB000;
  --white-phosphor: #E0E0E0;
  --screen-color: var(--green-phosphor);
  --screen-glow: rgba(51, 255, 51, 0.3);
}

body {
  background: linear-gradient(180deg, var(--bg-charcoal) 0%, var(--bg-dark) 100%);
  color: #ccc;
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
}

#app { width: 100%; max-width: 1200px; padding: 10px; }

/* Loading Screen */
#loading-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: #000; display: flex; align-items: center; justify-content: center;
  animation: fadeOutLoading 0.5s ease 2.5s forwards;
}
.loading-content { text-align: center; }
.apple-logo { font-size: 64px; animation: pulse 1s ease-in-out infinite; }
.loading-text { font-family: 'Press Start 2P', cursive; font-size: 24px; color: #fff; margin: 20px 0 8px; }
.loading-sub { font-family: 'IBM Plex Mono', monospace; font-size: 14px; color: #33FF33; }
.loading-bar { width: 200px; height: 4px; background: #333; margin: 20px auto; border-radius: 2px; overflow: hidden; }
.loading-fill { width: 0%; height: 100%; background: #33FF33; animation: loadFill 2s ease forwards; }

@keyframes loadFill { to { width: 100%; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes fadeOutLoading { to { opacity: 0; pointer-events: none; } }

/* Toolbar */
#toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px 12px; margin-bottom: 8px;
  background: linear-gradient(180deg, #3a3a3a 0%, #2a2a2a 100%);
  border-radius: 8px; border: 1px solid #444;
}
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-label { font-size: 11px; color: #999; font-family: 'Press Start 2P', cursive; }
.toolbar-btn {
  font-family: 'Press Start 2P', cursive; font-size: 10px;
  padding: 6px 12px; border: 2px solid #555; border-radius: 4px;
  background: linear-gradient(180deg, #4a4a4a, #333);
  color: #ccc; cursor: pointer; transition: all 0.1s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
}
.toolbar-btn:hover { background: linear-gradient(180deg, #5a5a5a, #444); }
.toolbar-btn:active { box-shadow: inset 0 2px 4px rgba(0,0,0,0.5); transform: translateY(1px); }
.toolbar-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.toolbar-btn.active { border-color: var(--green-phosphor); color: var(--green-phosphor); }
.toolbar-btn.power-on { border-color: #4f4; color: #4f4; background: linear-gradient(180deg, #2a3a2a, #1a2a1a); }
.toolbar-select {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  padding: 4px 8px; background: #222; color: #ccc; border: 1px solid #555;
  border-radius: 4px; cursor: pointer;
}

/* Monitor */
#monitor-container { display: flex; flex-direction: column; align-items: center; }

#bezel {
  background: linear-gradient(180deg, var(--bezel-light) 0%, var(--bezel-dark) 100%);
  padding: 20px 28px 16px;
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7), inset 0 2px 4px rgba(255,255,255,0.3), inset 0 -2px 4px rgba(0,0,0,0.2);
  position: relative;
}

.apple-stripes {
  display: flex; height: 6px; margin-bottom: 12px; border-radius: 3px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.stripe { flex: 1; }
.s1 { background: #61BB46; } .s2 { background: #FDB827; } .s3 { background: #F5821F; }
.s4 { background: #E03A3E; } .s5 { background: #963D97; } .s6 { background: #009DDC; }

#screen-inset {
  position: relative;
  background: #000;
  border-radius: 12px;
  padding: 16px;
  box-shadow: inset 0 4px 20px rgba(0,0,0,0.8), 0 0 30px var(--screen-glow), 0 0 60px var(--screen-glow);
  overflow: hidden;
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 560px; height: 384px;
  cursor: text;
  border-radius: 4px;
}

#scanlines {
  position: absolute; inset: 16px; pointer-events: none; border-radius: 4px;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 1px, rgba(0,0,0,0.15) 1px, rgba(0,0,0,0.15) 2px);
}
#crt-overlay {
  position: absolute; inset: 16px; pointer-events: none; border-radius: 4px;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

.bezel-bottom {
  display: flex; align-items: center; gap: 10px; margin-top: 10px; padding-left: 4px;
}
.bezel-label { font-family: 'Press Start 2P', cursive; font-size: 10px; color: #5a5040; text-transform: lowercase; }
#power-led {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.3);
  transition: all 0.3s;
}
.led-off { background: #4a2020; box-shadow: none; }
.led-on { background: #44ff44; box-shadow: 0 0 6px #44ff44, 0 0 12px #44ff44; }

#focus-hint {
  font-family: 'Press Start 2P', cursive; font-size: 9px; color: #666;
  margin-top: 8px; text-align: center; transition: opacity 0.3s;
}
#focus-hint.hidden { opacity: 0; }

/* CRT Power animations */
@keyframes crt-on {
  0% { transform: scaleY(0.01) scaleX(0.8); filter: brightness(3); }
  40% { transform: scaleY(0.01) scaleX(1); filter: brightness(2); }
  60% { transform: scaleY(1) scaleX(1); filter: brightness(1.5); }
  100% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
}
@keyframes crt-off {
  0% { transform: scaleY(1) scaleX(1); filter: brightness(1); }
  40% { transform: scaleY(1) scaleX(1); filter: brightness(2); }
  70% { transform: scaleY(0.01) scaleX(1); filter: brightness(3); }
  100% { transform: scaleY(0) scaleX(0); filter: brightness(0); }
}
#screen.powering-on { animation: crt-on 0.6s ease-out forwards; }
#screen.powering-off { animation: crt-off 0.4s ease-in forwards; }

/* Debug Panel */
#debug-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: 340px;
  background: #111; border-left: 2px solid #333;
  overflow-y: auto; z-index: 100;
  transform: translateX(0); transition: transform 0.3s;
}
#debug-panel.hidden { transform: translateX(100%); pointer-events: none; }
.debug-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: #1a1a1a; border-bottom: 1px solid #333;
  font-family: 'Press Start 2P', cursive; font-size: 11px; color: var(--green-phosphor);
}
.debug-close { background: none; border: none; color: #888; font-size: 18px; cursor: pointer; }
.debug-content { padding: 10px 14px; }
.debug-section { margin-bottom: 14px; }
.debug-section h3 { font-family: 'Press Start 2P', cursive; font-size: 9px; color: #888; margin-bottom: 6px; }
.register-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: 13px; }
.register-grid div { background: #1a1a1a; padding: 4px 6px; border-radius: 3px; }
.register-grid span { color: var(--green-phosphor); font-weight: 700; }
#flag-labels {
  display: flex; gap: 0; margin-top: 4px; font-size: 10px;
}
#flag-labels span {
  flex: 1; text-align: center; padding: 2px; background: #1a1a1a;
  border: 1px solid #222; color: #666; font-family: 'IBM Plex Mono', monospace;
}
.mono-box {
  background: #0a0a0a; border: 1px solid #222; border-radius: 4px;
  padding: 6px 8px; font-size: 11px; line-height: 1.6;
  font-family: 'IBM Plex Mono', monospace; color: #aaa;
  max-height: 200px; overflow-y: auto;
}
.mono-box .current { color: var(--green-phosphor); font-weight: 700; }
.mem-dump { font-size: 10px; line-height: 1.5; max-height: 300px; white-space: pre; }
.debug-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.debug-btn {
  font-family: 'Press Start 2P', cursive; font-size: 9px;
  padding: 5px 10px; background: #222; border: 1px solid #444;
  color: #ccc; border-radius: 3px; cursor: pointer;
}
.debug-btn:hover { background: #333; }
.debug-input {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  padding: 4px 8px; background: #1a1a1a; border: 1px solid #444;
  color: var(--green-phosphor); border-radius: 3px; width: 120px;
}
.debug-input.small { width: 60px; }

/* Status Bar */
#status-bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 6px 12px; margin-top: 8px;
  background: #151515; border-radius: 6px; border: 1px solid #2a2a2a;
  font-size: 11px; color: #666;
}
.rom-badge { color: var(--green-phosphor); }

/* Footer */
#footer {
  text-align: center; padding: 12px; margin-top: 12px;
  font-size: 11px; color: #555;
}
#footer a { color: var(--green-phosphor); text-decoration: none; margin-left: 12px; }
#footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 700px) {
  #bezel { padding: 12px 14px 10px; border-radius: 14px; }
  #screen-inset { padding: 8px; }
  #screen { width: 280px; height: 192px; }
  .apple-stripes { height: 4px; margin-bottom: 8px; }
  #toolbar { font-size: 9px; }
  #debug-panel { width: 100%; }
  .register-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
  #screen { width: 100%; height: auto; aspect-ratio: 280/192; }
}