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

:root {
  --green: #33ff33;
  --green-dim: #00cc00;
  --green-dark: #001100;
  --bg: #0a0a0a;
  --case-dark: #2a2a2a;
  --case-mid: #3a3a3a;
  --case-light: #4a4a4a;
  --key-bg: #e8e0d0;
  --key-text: #1a1a1a;
  --kb-base: #1a1410;
  --accent: #ff6600;
}

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

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

/* Control Bar */
#control-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(180deg, var(--case-light), var(--case-dark));
  border-radius: 12px 12px 0 0;
  border: 2px solid #555;
  border-bottom: none;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 12px;
  padding: 6px 14px;
  border: 2px solid #666;
  border-radius: 4px;
  background: linear-gradient(180deg, #555, #333);
  color: #ccc;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.1s;
}
.control-btn:hover { background: linear-gradient(180deg, #666, #444); color: #fff; }
.control-btn:active { transform: scale(0.96); }
.control-btn.small { font-size: 10px; padding: 4px 8px; }

.led {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #600;
  box-shadow: 0 0 4px #300;
  margin-right: 4px;
  transition: all 0.3s;
}
.led.on {
  background: #0f0;
  box-shadow: 0 0 8px #0f0, 0 0 16px #0a0;
}

.ram-label, .debug-label {
  font-size: 12px;
  color: #aaa;
  font-weight: 500;
}

#ram-selector {
  display: flex;
  gap: 2px;
}

.ram-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  padding: 4px 10px;
  border: 1px solid #555;
  background: #222;
  color: #888;
  cursor: pointer;
  transition: all 0.15s;
}
.ram-btn:first-child { border-radius: 3px 0 0 3px; }
.ram-btn:last-child { border-radius: 0 3px 3px 0; }
.ram-btn.active {
  background: var(--green-dark);
  color: var(--green);
  border-color: var(--green-dim);
}

.debug-label input { accent-color: var(--green); }

/* CRT Bezel */
#crt-bezel {
  background: linear-gradient(180deg, #444 0%, #2a2a2a 30%, #222 100%);
  border: 2px solid #555;
  border-top: none;
  padding: 24px 28px 16px;
  position: relative;
}

#crt-inner {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: var(--green-dark);
  box-shadow:
    0 0 30px rgba(0, 255, 0, 0.15),
    0 0 60px rgba(0, 255, 0, 0.05),
    inset 0 0 80px rgba(0, 0, 0, 0.5);
}

#screen {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 16px;
  opacity: 0;
  transition: opacity 0.5s ease-in;
}
#screen.on { opacity: 1; }

#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: 16px;
}

#screen-glow {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 60%,
    rgba(0, 0, 0, 0.4) 100%
  );
  pointer-events: none;
  border-radius: 16px;
}

#brand-plate {
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 14px;
  color: #888;
  letter-spacing: 6px;
  padding: 10px;
  text-shadow: 0 1px 0 #000;
}

/* Collapsible Sections */
.collapsed-section {
  background: #181818;
  border: 1px solid #333;
  margin-top: 2px;
}

.section-header {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--green);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid #222;
  transition: background 0.15s;
}
.section-header:hover { background: #222; }

.section-body {
  padding: 12px 16px;
  display: none;
}
.collapsed-section.open .section-body { display: block; }

/* ROM Panel */
#rom-dropzone {
  border: 2px dashed #444;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: #666;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 12px;
  position: relative;
}
#rom-dropzone.dragover {
  border-color: var(--green);
  background: rgba(0, 255, 0, 0.03);
  color: var(--green);
}
#rom-dropzone input {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0;
  cursor: pointer;
}

#rom-status-table {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
}
#rom-status-table th {
  text-align: left;
  color: #888;
  border-bottom: 1px solid #333;
  padding: 4px 8px;
}
#rom-status-table td {
  padding: 3px 8px;
  border-bottom: 1px solid #1a1a1a;
  color: #aaa;
  font-family: 'Share Tech Mono', monospace;
}

/* Device Sections */
.device-section {
  padding: 10px 0;
  border-bottom: 1px solid #222;
}
.device-section:last-child { border-bottom: none; }
.device-section h3 {
  font-size: 12px;
  color: var(--green-dim);
  margin-bottom: 8px;
}
.device-section input[type="file"] {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 6px;
}
.device-section select {
  background: #222;
  color: var(--green);
  border: 1px solid #444;
  padding: 2px 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
}

#prg-info {
  font-size: 12px;
  color: var(--green);
  margin: 4px 0;
  font-family: 'Share Tech Mono', monospace;
}

#tape-status {
  font-size: 11px;
  color: var(--accent);
  margin: 4px 0;
}
#tape-progress-bar {
  height: 6px;
  background: #222;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}
#tape-progress {
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 0.3s;
}

/* Debug Panel */
#cpu-state {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: #888;
  margin-bottom: 8px;
  font-family: 'Share Tech Mono', monospace;
}
#cpu-state b { color: var(--green); margin-left: 2px; }

#debug-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

#disasm-view {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: #888;
  background: #111;
  padding: 6px;
  border-radius: 4px;
  margin-bottom: 8px;
  max-height: 100px;
  overflow-y: auto;
  white-space: pre;
}

#memory-viewer {
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
}
#memory-viewer label { color: #888; }
#mem-addr {
  background: #111;
  color: var(--green);
  border: 1px solid #444;
  padding: 2px 4px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  width: 50px;
}
#mem-dump {
  background: #111;
  padding: 6px;
  border-radius: 4px;
  margin-top: 4px;
  color: #888;
  max-height: 120px;
  overflow-y: auto;
  font-size: 10px;
}

/* Virtual Keyboard */
#keyboard-container {
  background: var(--kb-base);
  padding: 12px;
  border: 2px solid #555;
  border-top: none;
  border-radius: 0 0 12px 12px;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

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

.kb-key {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  min-width: 32px;
  height: 28px;
  padding: 2px 4px;
  background: var(--key-bg);
  color: var(--key-text);
  border: 1px solid #bbb;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
  transition: all 0.08s;
  line-height: 1.1;
  box-shadow: 0 2px 0 #999;
}
.kb-key:hover {
  background: #d8d0c0;
}
.kb-key:active, .kb-key.pressed {
  background: #c8c0b0;
  transform: translateY(1px);
  box-shadow: 0 1px 0 #888;
}
.kb-key.wide { min-width: 52px; }
.kb-key.wider { min-width: 68px; }
.kb-key.space { min-width: 180px; }
.kb-key.numpad {
  background: #d0d8d0;
  border-color: #aab8aa;
}
.kb-key.numpad-sep {
  width: 6px;
  min-width: 6px;
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: default;
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  padding: 10px 16px;
  background: #1a2a1a;
  border: 1px solid var(--green-dim);
  color: var(--green);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  border-radius: 6px;
  animation: toast-in 0.3s ease-out;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.toast.warn {
  border-color: var(--accent);
  color: var(--accent);
  background: #2a1a0a;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Footer */
#footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: #336633;
}
#footer a {
  color: var(--green-dim);
  text-decoration: none;
}
#footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 640px) {
  #crt-bezel { padding: 12px 8px 8px; }
  .kb-key { min-width: 22px; height: 24px; font-size: 7px; }
  .kb-key.wide { min-width: 36px; }
  .kb-key.wider { min-width: 48px; }
  .kb-key.space { min-width: 100px; }
  #control-bar { padding: 8px; gap: 6px; }
  .control-btn { font-size: 10px; padding: 4px 8px; }
  .ram-btn { font-size: 9px; padding: 3px 6px; }
}