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

:root {
  --bg: #1a1410;
  --case-color: #8b7355;
  --case-dark: #5c4d3a;
  --bezel: #2a2218;
  --screen-green: #33ff33;
  --screen-amber: #ffaa00;
  --screen-color: var(--screen-green);
  --key-bg: #3a3530;
  --key-text: #d0c8b8;
  --accent: #4a7a3a;
  --danger: #8a3030;
  --panel-bg: #2a2520;
  --text-muted: #8a8070;
}

body {
  background: var(--bg);
  color: var(--key-text);
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 10px;
}

#pet-container {
  max-width: 900px;
  width: 100%;
}

header#title-bar {
  text-align: center;
  padding: 16px 0 8px;
  position: relative;
}

header h1 {
  font-family: 'VT323', monospace;
  font-size: 2.4em;
  color: #e8d8b8;
  letter-spacing: 4px;
  text-shadow: 0 0 20px rgba(232,216,184,0.3);
}

.subtitle {
  font-size: 0.75em;
  color: var(--text-muted);
  margin-top: 2px;
}

#power-led {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid #444;
}

.led-off { background: #400; box-shadow: inset 0 0 3px #200; }
.led-on { background: #0f0; box-shadow: 0 0 8px #0f0, 0 0 16px #0f0; }
.led-amber { background: #fa0; box-shadow: 0 0 8px #fa0; }

#monitor-bezel {
  background: linear-gradient(135deg, var(--case-color), var(--case-dark));
  border-radius: 16px;
  padding: 20px;
  margin: 8px 0;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.1), 0 4px 20px rgba(0,0,0,0.5);
}

#screen-wrapper {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.8), 0 0 30px rgba(51,255,51,0.05);
  aspect-ratio: 8/5;
}

#screen {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

#scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
  pointer-events: none;
}

body.amber-mode #screen-wrapper {
  box-shadow: inset 0 0 60px rgba(0,0,0,0.8), 0 0 30px rgba(255,170,0,0.05);
}

@keyframes warmup {
  0% { filter: brightness(0); }
  30% { filter: brightness(0.3); }
  100% { filter: brightness(1); }
}

.screen-warmup #screen {
  animation: warmup 1.5s ease-out;
}

#controls-panel {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.control-group {
  background: var(--panel-bg);
  border: 1px solid #3a3530;
  border-radius: 8px;
  padding: 10px 14px;
  flex: 1;
  min-width: 140px;
}

.control-group h3 {
  font-family: 'VT323', monospace;
  font-size: 0.9em;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.pet-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8em;
  font-weight: 700;
  padding: 6px 14px;
  border: none;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-text);
  cursor: pointer;
  margin: 2px;
  box-shadow: 0 2px 0 #1a1510;
  transition: all 0.05s;
}

.pet-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.pet-btn:hover { background: #4a4540; }

.power-btn { background: var(--accent); color: #fff; }
.power-btn:hover { background: #5a8a4a; }
.danger-btn { background: var(--danger); color: #fff; }
.danger-btn:hover { background: #9a4040; }
.small-btn { font-size: 0.7em; padding: 4px 10px; }

.radio-group { display: flex; flex-direction: column; gap: 4px; }
.radio-group label {
  font-size: 0.8em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.radio-group input[type="radio"] {
  accent-color: var(--screen-green);
}

#rom-panel {
  background: var(--panel-bg);
  border: 1px solid #3a3530;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
}

#rom-panel h3 {
  font-family: 'VT323', monospace;
  font-size: 0.9em;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 2px;
}

#rom-dropzone {
  border: 2px dashed #4a4540;
  border-radius: 6px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  margin-bottom: 10px;
}

#rom-dropzone:hover, #rom-dropzone.dragover {
  border-color: var(--screen-green);
}

#rom-dropzone p { font-size: 0.8em; color: var(--text-muted); }
#rom-file-input { display: none; }

#rom-checklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px;
  margin-bottom: 8px;
}

.rom-item {
  font-size: 0.75em;
  padding: 3px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rom-item .rom-icon { width: 16px; text-align: center; }
.rom-loaded { color: #4a4; }
.rom-missing { color: #a44; }

#peripheral-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.peripheral {
  background: var(--panel-bg);
  border: 1px solid #3a3530;
  border-radius: 8px;
  padding: 10px;
}

.peripheral h3 { font-size: 0.8em; margin-bottom: 4px; }
.peripheral-info { font-size: 0.65em; color: var(--text-muted); margin-bottom: 6px; }
.periph-input { display: none; }
.periph-status { font-size: 0.7em; color: var(--text-muted); margin-top: 4px; word-break: break-all; }

#keyboard-container {
  background: linear-gradient(135deg, #3a3530, #2a2520);
  border-radius: 10px;
  padding: 12px;
  margin: 8px 0;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 0.75em;
  min-width: 32px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--key-bg);
  color: var(--key-text);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  padding: 0 4px;
  box-shadow: 0 2px 0 #1a1510, inset 0 1px 0 rgba(255,255,255,0.08);
  transition: all 0.03s;
  user-select: none;
  white-space: nowrap;
}

.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  box-shadow: none;
  background: #2a2520;
}

.kb-key.wide { min-width: 56px; font-size: 0.6em; }
.kb-key.space-key { min-width: 180px; }
.kb-key.return-key { min-width: 64px; background: #4a5540; }
.kb-key.shift-key { min-width: 48px; background: #3a3a40; }
.kb-separator { width: 12px; }

#debug-toggle-bar { text-align: center; margin: 4px 0; }

#debug-panel {
  background: var(--panel-bg);
  border: 1px solid #3a3530;
  border-radius: 8px;
  padding: 12px;
  margin: 4px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  transition: max-height 0.3s;
  overflow: hidden;
}

#debug-panel.collapsed { display: none; }

#debug-registers h3, #memory-viewer h3 {
  font-family: 'VT323', monospace;
  font-size: 0.85em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.reg-row, .flag-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.reg-label { font-size: 0.75em; color: var(--text-muted); }
.reg-val { font-size: 0.8em; color: var(--screen-green); font-weight: 700; min-width: 28px; }

.flag {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  font-size: 0.7em;
  font-weight: 700;
  border-radius: 3px;
  background: #1a1510;
  color: #555;
}

.flag.flag-set { background: var(--accent); color: #fff; }
.flag-unused { opacity: 0.3; }

.disasm-text { font-size: 0.75em; color: var(--screen-green); margin-left: 8px; }

#debug-controls { display: flex; gap: 4px; align-items: flex-start; }

#memory-viewer { flex: 1; min-width: 300px; }
#memory-viewer input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8em;
  width: 50px;
  background: #1a1510;
  border: 1px solid #3a3530;
  color: var(--screen-green);
  padding: 2px 4px;
  border-radius: 3px;
}

#mem-dump {
  font-size: 0.65em;
  color: var(--screen-green);
  background: #0a0a08;
  padding: 6px;
  border-radius: 4px;
  margin-top: 4px;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.4;
}

footer {
  text-align: center;
  padding: 12px;
  font-size: 0.7em;
  color: var(--text-muted);
}

footer a {
  color: var(--screen-green);
  text-decoration: none;
  margin-right: 12px;
}

footer a:hover { text-decoration: underline; }
.footer-text { display: block; margin-top: 4px; font-size: 0.85em; }

@media (max-width: 600px) {
  header h1 { font-size: 1.6em; }
  #monitor-bezel { padding: 10px; }
  .kb-key { min-width: 24px; height: 24px; font-size: 0.6em; }
  .kb-key.wide { min-width: 40px; }
  .kb-key.space-key { min-width: 100px; }
  #peripheral-panel { grid-template-columns: 1fr 1fr; }
}