/* Custom Design System & Global Styles */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #131a26;
  --bg-bezel: #252a34;
  --bg-panel: rgba(19, 26, 38, 0.7);

  /* Tandy Color Computer 2 case plastic */
  --coco-beige: #ddd3b8;
  --coco-beige-shadow: #c4b896;
  --coco-beige-edge: #a89873;
  --coco-beige-text: #4a4330;
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #e6edf3;
  --text-secondary: #90a0b8;
  --text-muted: #5e6b7e;
  
  /* Glowing Palette */
  --neon-green: #00ff66;
  --crt-green: #33ff33;
  --crt-green-glow: rgba(51, 255, 51, 0.15);
  --neon-blue: #0088ff;
  --neon-red: #ff3344;
  --neon-orange: #ffaa00;
  
  --font-body: 'Outfit', sans-serif;
  --font-mono: 'Share Tech Mono', monospace;
  --font-retro: 'Press Start 2P', monospace;
  --font-tandy-logo: 'Baloo 2', sans-serif;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(at 0% 0%, rgba(0, 136, 255, 0.08) 0, transparent 50%),
    radial-gradient(at 100% 0%, rgba(0, 255, 102, 0.08) 0, transparent 50%);
  background-attachment: fixed;
}

/* Header Styles */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem 2.5rem;
  background: rgba(10, 14, 23, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-logo .brand {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.1rem;
  color: var(--text-primary);
  text-transform: uppercase;
}

.header-logo .model {
  color: var(--neon-orange);
  font-weight: 600;
  font-size: 1.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05rem;
}

.header-logo .decorator {
  color: var(--text-muted);
  margin: 0 0.5rem;
  font-weight: 300;
}

.header-logo .sub-brand {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  letter-spacing: 0.05rem;
}

.system-status {
  display: flex;
  gap: 1.5rem;
  font-family: var(--font-mono);
}

.status-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

.status-item .label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.status-item .val {
  color: var(--neon-green);
  text-shadow: 0 0 4px rgba(0, 255, 102, 0.4);
}

/* Main Container Layout */
.app-container {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 2rem;
  padding: 2rem 2.5rem;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  flex-grow: 1;
}

/* Left Section: Bezel & Virtual Keyboard */
.left-section {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Curved CRT Monitor Case */
.crt-case {
  background-color: var(--coco-beige);
  border-radius: 20px;
  padding: 25px;
  box-shadow:
    inset 0 4px 6px rgba(255, 255, 255, 0.4),
    inset 0 -10px 20px rgba(0, 0, 0, 0.15),
    0 15px 35px rgba(0, 0, 0, 0.5);
  border: 4px solid var(--coco-beige-edge);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.crt-screen-bezel {
  background: #15181f;
  border-radius: 12px;
  padding: 20px;
  box-shadow: inset 0 5px 15px rgba(0,0,0,0.8), 0 2px 3px rgba(255,255,255,0.05);
  border: 2px solid #2d323f;
}

.crt-screen-container {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  box-shadow: 0 0 20px rgba(0,0,0,0.9);
}

/* Full Screen (F8): the Fullscreen API is requested on .crt-screen-bezel
   (the existing direct parent of .crt-screen-container), which becomes a
   flex container that centers its child. This is the standard, reliable
   letterboxing pattern (the same one video players use) -- flexbox
   correctly sizes an aspect-ratio child from a definite cross-axis size,
   unlike position:fixed + explicit dimensions, which fights unpredictably
   with the browser's internal top-layer fullscreen layout.
   Kept as separate rules, not a comma-joined selector list: a selector a
   browser doesn't recognize (e.g. Firefox and :-webkit-full-screen) drops
   the ENTIRE rule it's joined with, not just itself. */
.crt-screen-bezel:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  background: #000;
  border: none;
  box-shadow: none;
  padding: 0;
  border-radius: 0;
}

.crt-screen-bezel:-webkit-full-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  background: #000;
  border: none;
  box-shadow: none;
  padding: 0;
  border-radius: 0;
}

.crt-screen-bezel:fullscreen .crt-screen-container {
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  flex-shrink: 0;
  border-radius: 0;
  box-shadow: none;
}

.crt-screen-bezel:-webkit-full-screen .crt-screen-container {
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  flex-shrink: 0;
  border-radius: 0;
  box-shadow: none;
}

#coco-screen {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  filter: contrast(1.1) brightness(1.05);
}

/* CRT Scanlines Overlay */
.scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%, 
    rgba(0, 0, 0, 0.25) 50%
  ), linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.06),
    rgba(0, 255, 0, 0.02),
    rgba(0, 0, 255, 0.06)
  );
  background-size: 100% 4px, 6px 100%;
  pointer-events: none;
  z-index: 10;
}

/* Phosphor Glow effect */
.phosphor-glow {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at center,
    transparent 40%,
    rgba(0, 255, 102, 0.04) 90%
  );
  pointer-events: none;
  z-index: 11;
}

/* Curved glass screen glare */
.screen-glare {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at 50% 0%,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0) 70%
  );
  pointer-events: none;
  z-index: 12;
}

/* CRT Monitor Controls Bar */
.crt-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background: var(--coco-beige-shadow);
  border-radius: 8px;
  height: 60px;
  border: 1px solid var(--coco-beige-edge);
}

.power-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-power-switch {
  background: linear-gradient(180deg, #323846, #1e222a);
  border: 1px solid #12151c;
  color: var(--text-primary);
  border-radius: 6px;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 3px 5px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.1s ease;
}

.btn-power-switch:hover {
  background: linear-gradient(180deg, #42495a, #262c36);
}

.btn-power-switch:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.btn-power-switch .icon {
  font-size: 1rem;
}

.led-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.led {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.3), 0 0 2px rgba(0,0,0,0.8);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.led.off {
  background-color: #4b0000;
}

.led.on {
  background-color: var(--neon-green);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.5), 0 0 12px var(--neon-green);
}

.led-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--coco-beige-text);
}

.badge-tandy {
  font-family: var(--font-tandy-logo);
  font-weight: 800;
  font-size: 1.2rem;
  color: rgba(158, 55, 30, 0.55);
  letter-spacing: 0.05rem;
  transform: skewX(-10deg);
}

.fullscreen-hint {
  margin-top: -0.75rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--coco-beige-text);
  opacity: 0.6;
}

.fullscreen-hint kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--coco-beige-shadow);
  border: 1px solid var(--coco-beige-edge);
  box-shadow: 0 1px 0 var(--coco-beige-edge);
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.btn-action {
  font-family: var(--font-mono);
  font-weight: bold;
  padding: 0.5rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 3px 5px rgba(0,0,0,0.4);
  transition: all 0.2s;
  border: 1px solid rgba(0, 0, 0, 0.4);
}

.red-btn {
  background: linear-gradient(135deg, #ff4757, #ff2e44);
  color: white;
}

.red-btn:hover {
  background: linear-gradient(135deg, #ff6b7b, #ff4757);
}

.red-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Virtual Keyboard Styling */
.virtual-keyboard {
  background: rgba(10, 14, 23, 0.5);
  border-radius: 12px;
  padding: 15px;
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 6px;
}

.keyboard-row:last-child {
  margin-bottom: 0;
}

.key {
  background: linear-gradient(180deg, #323846, #1d212b);
  border: 1px solid rgba(0,0,0,0.4);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.1s ease;
  box-shadow: 0 3px 0px #12151c, 0 4px 6px rgba(0,0,0,0.4);
  flex-grow: 1;
  text-align: center;
  min-width: 32px;
}

.key:hover {
  background: linear-gradient(180deg, #3a4253, #222733);
}

.key:active, .key.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0px #12151c, 0 1px 3px rgba(0,0,0,0.4);
  background: var(--neon-blue);
  color: #fff;
  border-color: rgba(255,255,255,0.1);
}

.key-special {
  background: linear-gradient(180deg, #262c38, #151920);
  color: var(--neon-orange);
  font-size: 0.75rem;
}

.key-double {
  flex-grow: 2;
}

.key-space {
  flex-grow: 8;
}

/* Scrollbar styles for panels */
.right-section::-webkit-scrollbar {
  width: 6px;
}
.right-section::-webkit-scrollbar-track {
  background: transparent;
}
.right-section::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}
.right-section::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

.right-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel-glass {
  background: var(--bg-panel);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  backdrop-filter: blur(12px) saturate(180%);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.control-panel h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
  border-left: 3px solid var(--neon-blue);
  padding-left: 8px;
}

.panel-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  line-height: 1.2rem;
}

/* Panel Header Inline */
.panel-header-inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.panel-header-inline h3 {
  margin-bottom: 0;
}

/* Sliders */
.slider-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  height: 8px;
  border-radius: 4px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--neon-blue);
  box-shadow: 0 0 8px rgba(0, 136, 255, 0.5);
  cursor: pointer;
  transition: background-color 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #33a3ff;
}

.preset-buttons {
  display: flex;
  gap: 8px;
}

.preset-buttons button {
  flex: 1;
}

/* General Button overrides & classes */
.btn-sm {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, #0088ff, #0055ff);
  color: white;
  border: none;
  font-weight: bold;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 8px rgba(0, 136, 255, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #33a3ff, #0066ff);
  box-shadow: 0 6px 12px rgba(0, 136, 255, 0.4);
}

.btn-secondary {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.15);
}

.btn-danger {
  background: linear-gradient(135deg, #ff4444, #cc1111);
  color: white;
  border: none;
  font-weight: bold;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 8px rgba(255, 68, 68, 0.3);
}

.btn-danger:hover {
  background: linear-gradient(135deg, #ff6666, #dd2222);
  box-shadow: 0 6px 12px rgba(255, 68, 68, 0.4);
}

/* Progress bar */
.progress-container {
  width: 100%;
  background: rgba(0,0,0,0.3);
  height: 18px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--neon-blue), var(--neon-green));
  width: 0%;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #fff;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.1s ease;
}

/* Code & Status Panels */
.mono-code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.3rem;
  overflow-x: auto;
}

.mono-code .val {
  color: var(--neon-orange);
}

.mono-code .addr {
  color: var(--text-muted);
}

.mono-code .bytes {
  color: var(--text-secondary);
}

.mono-code .mnem {
  color: var(--neon-green);
  font-weight: bold;
}

/* Active disassembly highlighting */
#debug-disasm .line.active {
  background: rgba(0, 255, 102, 0.08);
  border-left: 2px solid var(--neon-green);
  padding-left: 4px;
}

#mem-start-addr {
  width: 70px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--neon-orange);
  font-family: var(--font-mono);
  text-align: center;
  padding: 2px;
  outline: none;
}

#mem-start-addr:focus {
  border-color: var(--neon-orange);
}

.hex-input-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Auto-Typer textarea */
#typer-text {
  width: 100%;
  height: 100px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  resize: none;
  outline: none;
  margin-bottom: 12px;
}

#typer-text:focus {
  border-color: var(--neon-blue);
}

.typer-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.typer-speed-container {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.typer-speed-container input[type="range"] {
  width: 80px;
}

.typer-buttons {
  display: flex;
  gap: 8px;
}

/* Footer Styling */
.app-footer {
  text-align: center;
  padding: 1.5rem;
  background: rgba(5, 7, 12, 0.9);
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-color);
  font-family: var(--font-mono);
}

.debug-container {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1rem;
}

.debug-top-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.5rem;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  .debug-top-row {
    grid-template-columns: 1fr;
  }
}

/* Virtual Hardware Media Slots */
.media-slot {
  background: rgba(10, 14, 23, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.media-slot:hover {
  border-color: rgba(0, 255, 102, 0.2);
  box-shadow: 0 0 8px rgba(0, 255, 102, 0.05);
}
.media-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.media-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}
.media-status {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-status.active {
  color: var(--neon-green);
  text-shadow: 0 0 4px rgba(0, 255, 102, 0.4);
  border: 1px solid rgba(0, 255, 102, 0.15);
  background: rgba(0, 30, 10, 0.3);
}
.media-actions {
  display: flex;
  gap: 8px;
}
.media-actions button {
  flex: 1;
}
