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

:root {
  --bg: #0d0d1a;
  --bezel: #2a2a2a;
  --bezel-light: #3a3a3a;
  --panel: #383838;
  --panel-light: #4a4a4a;
  --crt-bg: #001100;
  --crt-fg: #33ff33;
  --crt-glow: #22cc22;
  --key-bg: #e8e0d0;
  --key-active: #ccc5b0;
  --key-text: #222;
  --accent: #4A6FC4;
  --red: #cc3333;
  --green: #33aa33;
  --yellow: #ccaa33;
  --font-retro: 'VT323', monospace;
  --font-mono: 'IBM Plex Mono', monospace;
}

body {
  background: var(--bg);
  background-image: 
    radial-gradient(ellipse at 50% 20%, #1a1a3e 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, #0a1a2e 0%, transparent 50%);
  color: #ccc;
  font-family: var(--font-mono);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 10px;
}

#pet-container {
  max-width: 820px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

#header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 20px 8px;
  width: 100%;
}
#header .brand { font-size: 24px; }
#header h1 {
  font-family: var(--font-retro);
  font-size: 32px;
  color: #fff;
  letter-spacing: 3px;
}
#header .subtitle {
  font-size: 11px;
  color: #888;
  font-style: italic;
}

/* CRT Monitor */
#monitor-bezel {
  background: var(--bezel);
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 720px;
  box-shadow:
    inset 0 2px 0 var(--bezel-light),
    0 8px 32px rgba(0,0,0,0.6);
  border: 2px solid #444;
}

#screen-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 320/200;
  border-radius: 12px;
  overflow: hidden;
  background: var(--crt-bg);
  box-shadow:
    0 0 40px rgba(34, 204, 34, 0.15),
    0 0 80px rgba(34, 204, 34, 0.05),
    inset 0 0 60px rgba(0,0,0,0.5);
}

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

#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;
}

/* Control Panel */
#control-panel {
  width: 100%;
  max-width: 720px;
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid #555;
  border-top: none;
  flex-wrap: wrap;
}

.control-section {
  flex: 1;
  min-width: 180px;
  padding: 8px;
  background: var(--panel-light);
  border-radius: 6px;
}
.control-section h3 {
  font-family: var(--font-retro);
  font-size: 16px;
  color: var(--accent);
  margin-bottom: 6px;
}

.rom-controls { display: flex; gap: 6px; margin-bottom: 6px; }

#rom-status {
  font-size: 11px;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
}
#rom-status .rom-ok { color: #4c4; }
#rom-status .rom-miss { color: #c44; }

.file-btn, .small-btn {
  display: inline-block;
  padding: 4px 10px;
  background: #666;
  color: #eee;
  border: 1px solid #888;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
}
.file-btn:hover, .small-btn:hover { background: #777; }

select {
  background: #555;
  color: #eee;
  border: 1px solid #888;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.power-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.power-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-retro);
  font-size: 16px;
  font-weight: bold;
  text-transform: uppercase;
}
.power-btn.on { background: var(--green); color: #fff; }
.power-btn.on:hover { background: #44cc44; }
.power-btn.reset { background: var(--yellow); color: #222; }
.power-btn.reset:hover { background: #ddbb44; }
.power-btn.off { background: var(--red); color: #fff; }
.power-btn.off:hover { background: #dd4444; }

#speed-indicator {
  margin-top: 6px;
  font-size: 12px;
  color: #aaa;
  font-family: var(--font-retro);
}

/* Peripheral Panel */
#peripheral-panel {
  width: 100%;
  max-width: 720px;
  background: var(--panel);
  border: 1px solid #555;
  border-top: none;
}

.periph-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid #555;
}
.periph-tab {
  padding: 6px 12px;
  background: transparent;
  color: #aaa;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  border-bottom: 2px solid transparent;
}
.periph-tab:hover { color: #eee; }
.periph-tab.active { color: var(--crt-fg); border-bottom-color: var(--crt-fg); }

.periph-content { position: relative; }
.periph-pane {
  display: none;
  padding: 10px;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.periph-pane.active { display: flex; }
.periph-status { font-size: 12px; color: #aaa; }

/* Debug */
#debug-registers {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-family: var(--font-retro);
  font-size: 16px;
  color: var(--crt-fg);
}
#debug-registers b { color: #fff; }

/* Keyboard Buffer Debug Display */
#debug-keybuf {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding: 6px 8px;
  background: #0a0a1a;
  border: 1px solid #333;
  border-radius: 4px;
}
.keybuf-label {
  font-family: var(--font-retro);
  font-size: 13px;
  color: #8888cc;
}
.keybuf-count {
  font-family: var(--font-retro);
  font-size: 14px;
  color: var(--crt-fg);
  min-width: 32px;
}
.keybuf-count.full { color: #ff4444; }
.keybuf-slots {
  display: flex;
  gap: 2px;
}
.keybuf-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 22px;
  background: #111;
  border: 1px solid #444;
  border-radius: 2px;
  font-family: var(--font-retro);
  font-size: 12px;
  color: #555;
  transition: all 0.1s;
}
.keybuf-slot.active {
  background: #0a1a0a;
  border-color: var(--crt-fg);
  color: var(--crt-fg);
  box-shadow: 0 0 4px rgba(34, 204, 34, 0.3);
}
.keybuf-slot.newest {
  background: #0a2a0a;
  border-color: #66ff66;
  color: #66ff66;
}
.linebuf-display {
  font-family: var(--font-retro);
  font-size: 12px;
  color: var(--crt-fg);
  background: #0a0a0a;
  border: 1px solid #333;
  border-radius: 2px;
  padding: 2px 6px;
  min-width: 80px;
  max-width: 300px;
  min-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#debug-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
  flex-wrap: wrap;
}
#debug-controls input {
  background: #333;
  color: var(--crt-fg);
  border: 1px solid #666;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 12px;
}
#debug-memory {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  align-items: flex-start;
  flex-wrap: wrap;
}
#debug-memory input {
  background: #333;
  color: var(--crt-fg);
  border: 1px solid #666;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 12px;
}
#dbg-memdump {
  font-family: var(--font-retro);
  font-size: 14px;
  color: var(--crt-fg);
  background: #111;
  padding: 4px;
  border-radius: 3px;
  white-space: pre;
  width: 100%;
  min-height: 20px;
  max-height: 120px;
  overflow: auto;
}

/* Virtual Keyboard */
#keyboard-plate {
  width: 100%;
  max-width: 720px;
  background: #3a3530;
  border: 2px solid #555;
  border-top: none;
  border-radius: 0 0 12px 12px;
  padding: 12px 8px 16px;
}

#virtual-keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

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

.kb-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 32px;
  padding: 0 5px;
  background: var(--key-bg);
  color: var(--key-text);
  border: 1px solid #bbb;
  border-bottom: 3px solid #999;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: bold;
  user-select: none;
  white-space: nowrap;
  transition: all 0.05s;
}
.kb-key:active, .kb-key.pressed {
  background: var(--key-active);
  border-bottom-width: 1px;
  transform: translateY(2px);
}
.kb-key.wide { min-width: 64px; }
.kb-key.xwide { min-width: 140px; }
.kb-key.special { background: #c8c0b0; }

/* Status Bar */
#status-bar {
  width: 100%;
  max-width: 720px;
  display: flex;
  gap: 20px;
  padding: 8px 12px;
  font-size: 12px;
  color: #888;
  font-family: var(--font-retro);
  font-size: 14px;
}
#machine-state { color: var(--crt-fg); }

/* Footer */
#footer {
  padding: 16px;
  font-size: 11px;
  color: #666;
  text-align: center;
}
#footer a { color: var(--accent); text-decoration: none; }
#footer a:hover { text-decoration: underline; }
.disclaimer { font-style: italic; }

/* Responsive */
@media (max-width: 600px) {
  #header h1 { font-size: 20px; letter-spacing: 1px; }
  #header .subtitle { display: none; }
  #monitor-bezel { padding: 12px; border-radius: 12px; }
  .kb-key { min-width: 26px; height: 26px; font-size: 9px; padding: 0 2px; }
  .kb-key.wide { min-width: 44px; }
  .kb-key.xwide { min-width: 90px; }
  .kb-row .kb-separator { width: 6px; }
  .control-section { min-width: 140px; }
}