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

:root {
  --beige: #d4c5a0;
  --beige-light: #e8dcc4;
  --beige-dark: #b8a882;
  --charcoal: #1a1a2e;
  --monitor-dark: #0d0d0d;
  --green-phosphor: #33ff33;
  --white-phosphor: #e0e0d0;
  --crt-bg: #000000;
  --key-bg: #d8d0bc;
  --key-shadow: #9e9680;
  --key-text: #2a2a2a;
  --accent-red: #cc3333;
  --led-green: #00ff44;
  --led-off: #333;
}

body {
  background: var(--charcoal);
  background-image:
    radial-gradient(ellipse at 50% 30%, #1e1e3a 0%, #0f0f1e 70%);
  font-family: 'IBM Plex Mono', monospace;
  color: #ccc;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
}

#pet-machine {
  max-width: 820px;
  width: 100%;
  background: linear-gradient(180deg, var(--beige-light) 0%, var(--beige) 30%, var(--beige-dark) 100%);
  border-radius: 20px;
  padding: 12px 18px 18px;
  box-shadow:
    0 8px 40px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.3);
  margin-bottom: 10px;
}

/* NAMEPLATE */
#nameplate {
  text-align: center;
  padding: 6px 0 4px;
}
#nameplate-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.pet-logo {
  font-family: 'VT323', monospace;
  font-size: 14px;
  letter-spacing: 4px;
  color: #555;
  text-transform: uppercase;
}
.pet-model {
  font-family: 'VT323', monospace;
  font-size: 28px;
  letter-spacing: 3px;
  color: #3a3a3a;
  font-weight: bold;
}
.tagline {
  font-size: 10px;
  color: #777;
  margin-top: 2px;
}
#power-led-container {
  display: flex;
  align-items: center;
  gap: 4px;
}
#power-led {
  width: 10px; height: 10px;
  border-radius: 50%;
  transition: all 0.3s;
}
.led-on {
  background: var(--led-green);
  box-shadow: 0 0 8px var(--led-green), 0 0 16px var(--led-green);
}
.led-off {
  background: #442222;
  box-shadow: none;
}
.led-label {
  font-size: 9px;
  color: #666;
  text-transform: uppercase;
}

/* MONITOR */
#monitor-bezel {
  background: #111;
  border-radius: 14px;
  padding: 14px;
  margin: 6px 0;
  box-shadow:
    inset 0 4px 20px rgba(0,0,0,0.8),
    0 2px 4px rgba(0,0,0,0.3);
}
#crt-container {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--crt-bg);
  box-shadow: 0 0 30px rgba(51,255,51,0.1);
}
#screen {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 6px;
}
#scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  pointer-events: none;
  border-radius: 6px;
}
#crt-glow {
  position: absolute;
  top: -2px; left: -2px; right: -2px; bottom: -2px;
  border-radius: 8px;
  pointer-events: none;
  box-shadow: inset 0 0 60px rgba(51,255,51,0.06);
}
body.white-phosphor #crt-glow {
  box-shadow: inset 0 0 60px rgba(224,224,208,0.06);
}
body.white-phosphor #crt-container {
  box-shadow: 0 0 30px rgba(224,224,208,0.08);
}

/* CONTROL PANEL */
#control-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 4px;
  align-items: flex-start;
}
.ctrl-group {
  background: rgba(0,0,0,0.08);
  border-radius: 6px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.ctrl-label {
  font-size: 9px;
  text-transform: uppercase;
  color: #666;
  letter-spacing: 2px;
  font-weight: bold;
}

.pet-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: bold;
  padding: 5px 10px;
  border: none;
  border-radius: 4px;
  background: linear-gradient(180deg, #e0d8c4 0%, #c8bfa8 100%);
  color: #333;
  cursor: pointer;
  box-shadow: 0 2px 0 #999, 0 3px 6px rgba(0,0,0,0.2);
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.1s;
}
.pet-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 #999, 0 1px 3px rgba(0,0,0,0.2);
}
.pet-btn:hover { background: linear-gradient(180deg, #ece4d0 0%, #d4ccb4 100%); }
.power-btn { background: linear-gradient(180deg, #66bb66 0%, #448844 100%); color: #fff; box-shadow: 0 2px 0 #336633; }
.power-btn:hover { background: linear-gradient(180deg, #77cc77 0%, #559955 100%); }
.off-btn { background: linear-gradient(180deg, #cc5555 0%, #993333 100%); box-shadow: 0 2px 0 #662222; }
.off-btn:hover { background: linear-gradient(180deg, #dd6666 0%, #aa4444 100%); }
.small-btn { font-size: 10px; padding: 3px 8px; }

#ram-selector { display: flex; gap: 3px; }
.ram-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: bold;
  padding: 4px 8px;
  border: 2px solid #888;
  border-radius: 3px;
  background: #bbb;
  color: #333;
  cursor: pointer;
}
.ram-btn.selected {
  background: #ffcc33;
  border-color: #aa8800;
  color: #333;
}

#rom-status {
  font-size: 9px;
  max-width: 200px;
  line-height: 1.3;
}
.rom-ok { color: #228822; }
.rom-missing { color: #884444; }

#speed-slider { width: 80px; accent-color: var(--beige-dark); }
#speed-label { font-size: 10px; color: #555; }

/* PERIPHERAL PANEL */
#peripheral-panel {
  margin: 4px 0;
  background: rgba(0,0,0,0.06);
  border-radius: 8px;
  overflow: hidden;
}
.periph-tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 4px;
  background: rgba(0,0,0,0.05);
}
.periph-tab {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  padding: 4px 8px;
  border: none;
  background: rgba(0,0,0,0.08);
  color: #666;
  cursor: pointer;
  border-radius: 3px;
}
.periph-tab.active {
  background: var(--beige-dark);
  color: #222;
}
.periph-content {
  padding: 8px;
  font-size: 11px;
}
.drive-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.drive-label { font-weight: bold; color: #444; font-size: 11px; }
.drive-led {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #442222;
}
.drive-led.active { background: #ff4444; box-shadow: 0 0 6px #ff4444; }
.ieee-badge {
  font-size: 8px;
  background: #444;
  color: #ddd;
  padding: 1px 4px;
  border-radius: 2px;
}
#prg-info, #tape-info, #floppy5-info, #floppy8-info, #hdd-info {
  font-size: 10px;
  color: #555;
  margin-top: 4px;
}

/* TAPE DECK */
#tape-deck {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.tape-reel {
  width: 30px; height: 30px;
  border: 3px solid #666;
  border-radius: 50%;
  background: #444;
  position: relative;
}
.tape-reel::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 8px; height: 8px;
  background: #888;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.tape-reel.spinning {
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tape-controls { display: flex; gap: 3px; }
.tape-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  padding: 3px 6px;
  border: 1px solid #888;
  background: #bbb;
  border-radius: 2px;
  cursor: pointer;
}
.baud-indicator {
  font-size: 9px;
  color: var(--accent-red);
  font-weight: bold;
}

/* KEYBOARD */
#keyboard {
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
}
.kb-row {
  display: flex;
  gap: 3px;
  flex-wrap: nowrap;
  justify-content: center;
}
.kb-key {
  font-family: 'VT323', monospace;
  font-size: 12px;
  min-width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #f0ead6 0%, #ddd4bc 100%);
  color: var(--key-text);
  border: 1px solid #b0a890;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--key-shadow);
  padding: 0 3px;
  user-select: none;
  transition: all 0.05s;
  white-space: nowrap;
  text-align: center;
}
.kb-key:active, .kb-key.pressed {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--key-shadow);
  background: #c8c0aa;
}
.kb-key.wide { min-width: 48px; font-size: 9px; }
.kb-key.space { min-width: 160px; }
.kb-key.return-key { min-width: 56px; }
.kb-key.shift-key { background: linear-gradient(180deg, #e0dac8 0%, #ccc4aa 100%); }
.kb-key.numpad { background: linear-gradient(180deg, #d8e0d0 0%, #c0c8b4 100%); }
.kb-sep { width: 12px; }

/* DEBUG */
#debug-toggle-bar { text-align: center; margin: 4px 0; }
#debug-panel {
  background: #0a0a0a;
  border-radius: 6px;
  padding: 8px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--green-phosphor);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
#mem-inspector {
  grid-column: 1 / -1;
}
#mem-inspector input {
  font-family: 'VT323', monospace;
  font-size: 14px;
  background: #111;
  color: var(--green-phosphor);
  border: 1px solid #333;
  width: 50px;
  padding: 2px 4px;
}
#mem-dump {
  font-size: 12px;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
}

/* HELP MODAL */
#help-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#help-content {
  background: var(--beige);
  color: #222;
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.5;
}
#help-content h2 { font-family: 'VT323', monospace; font-size: 24px; margin-bottom: 8px; }
#help-content h3 { margin-top: 12px; margin-bottom: 4px; font-size: 14px; }
#help-content ul { margin-left: 16px; font-size: 11px; }
#help-content li { margin: 2px 0; }

/* FOOTER */
#footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  font-size: 10px;
  color: #555;
  flex-wrap: wrap;
  justify-content: center;
}
#footer a {
  color: #88aa88;
  text-decoration: none;
}
#footer a:hover { text-decoration: underline; }

/* RESPONSIVE */
@media (max-width: 700px) {
  #pet-machine { padding: 6px 8px 12px; border-radius: 12px; }
  .pet-model { font-size: 20px; }
  .kb-key { min-width: 22px; height: 24px; font-size: 10px; }
  .kb-key.wide { min-width: 36px; font-size: 8px; }
  .kb-key.space { min-width: 100px; }
  .kb-sep { width: 6px; }
  #control-panel { gap: 4px; }
}