/**
 * GeenaKB CRT/Oscilloscope Theme System
 *
 * Retro monochromatic phosphor display aesthetic with vintage monitor framing.
 * Supports 4 phosphor themes: Green, Amber, White, Blue
 */

/**
 * ==========================================================================
 * THEME COLOR DEFINITIONS
 * ==========================================================================
 */

/* Green Phosphor (P1 - Classic Oscilloscope) - AUTHENTIC VINTAGE */
[data-phosphor-theme="green"],
:root {
  --phosphor-primary: #39FF14;
  --phosphor-glow: rgba(57, 255, 20, 1.0);
  --phosphor-dim: rgba(57, 255, 20, 0.7);
  --phosphor-bright: #66FF44;
  --phosphor-dark: rgba(57, 255, 20, 0.4);
  --screen-background: #0a0f0a;
  --screen-ambient: rgba(57, 255, 20, 0.02);
  --monitor-bezel: #2a2a2a;
  --monitor-bezel-light: #3a3a3a;
  --control-panel-bg: #0f120f;

  /* Contrast & Brightness controls */
  --brightness: 1.3;
  --contrast: 1.2;
}

/* Amber Phosphor (Vintage Terminal) - ULTRA BRIGHT */
[data-phosphor-theme="amber"] {
  --phosphor-primary: #ffcc00;
  --phosphor-glow: rgba(255, 204, 0, 1.0);
  --phosphor-dim: rgba(255, 204, 0, 0.7);
  --phosphor-bright: #ffe066;
  --phosphor-dark: rgba(255, 204, 0, 0.4);
  --screen-background: #0f0a00;
  --screen-ambient: rgba(255, 204, 0, 0.02);
  --monitor-bezel: #2a2a2a;
  --monitor-bezel-light: #3a3a3a;
  --control-panel-bg: #151511;
}

/* White Phosphor (Scientific Display) - ULTRA BRIGHT */
[data-phosphor-theme="white"] {
  --phosphor-primary: #ffffff;
  --phosphor-glow: rgba(255, 255, 255, 1.0);
  --phosphor-dim: rgba(255, 255, 255, 0.7);
  --phosphor-bright: #ffffff;
  --phosphor-dark: rgba(255, 255, 255, 0.4);
  --screen-background: #0f0f0f;
  --screen-ambient: rgba(255, 255, 255, 0.02);
  --monitor-bezel: #2a2a2a;
  --monitor-bezel-light: #3a3a3a;
  --control-panel-bg: #151515;
}

/* Blue Phosphor (Retro IBM) - ULTRA BRIGHT */
[data-phosphor-theme="blue"] {
  --phosphor-primary: #00ffff;
  --phosphor-glow: rgba(0, 255, 255, 1.0);
  --phosphor-dim: rgba(0, 255, 255, 0.7);
  --phosphor-bright: #88ffff;
  --phosphor-dark: rgba(0, 255, 255, 0.4);
  --screen-background: #000a0a;
  --screen-ambient: rgba(0, 255, 255, 0.02);
  --monitor-bezel: #2a2a2a;
  --monitor-bezel-light: #3a3a3a;
  --control-panel-bg: #111515;
}

/**
 * ==========================================================================
 * TYPOGRAPHY
 * ==========================================================================
 */

/* Import retro monospace fonts */
@import url('https://fonts.googleapis.com/css2?family=VT323&family=Share+Tech+Mono&display=swap');

:root {
  --font-primary: 'VT323', 'Share Tech Mono', 'IBM Plex Mono', 'Courier New', monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
}

/**
 * ==========================================================================
 * CRT MONITOR STRUCTURE
 * ==========================================================================
 */

.crt-monitor {
  width: 100vw;
  height: 100vh;
  background: var(--monitor-bezel);
  padding: 20px;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
}

.crt-bezel {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    var(--monitor-bezel) 0%,
    var(--monitor-bezel-light) 50%,
    var(--monitor-bezel) 100%
  );
  border-radius: 12px;
  padding: 15px;
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.1),
    inset 0 -2px 4px rgba(0, 0, 0, 0.5),
    0 20px 60px rgba(0, 0, 0, 0.8);
  position: relative;
}

.crt-screen {
  width: 100%;
  height: 100%;
  background: var(--screen-background);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  box-shadow:
    inset 0 0 100px rgba(0, 0, 0, 0.7),
    0 0 80px var(--phosphor-glow),
    0 0 120px var(--phosphor-dark);
  animation: screen-flicker 0.15s infinite alternate;
}

@keyframes screen-flicker {
  0% { opacity: 1; }
  50% { opacity: 0.98; }
  100% { opacity: 1; }
}

/**
 * ==========================================================================
 * SCREEN EFFECTS
 * ==========================================================================
 */

/* CRT Vignette (Screen Edge Glow Falloff) - LIGHTER */
.crt-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 0%,
    transparent 60%,
    rgba(0, 0, 0, 0.2) 80%,
    rgba(0, 0, 0, 0.5) 100%
  );
  pointer-events: none;
  z-index: 100;
}

/* Scan Lines Effect Layer */
.crt-scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 1px,
    rgba(0, 0, 0, 0.5) 2px,
    transparent 3px,
    transparent 4px
  );
  pointer-events: none;
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.crt-screen.enable-scanlines .crt-scanlines {
  opacity: 1;
  animation: scanline-scroll 8s linear infinite;
}

@keyframes scanline-scroll {
  0% { transform: translateY(0px); }
  100% { transform: translateY(4px); }
}

/* Moving scan beam (sweeping oscilloscope line) */
.crt-scanbeam {
  position: absolute;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    var(--phosphor-glow) 30%,
    var(--phosphor-glow) 50%,
    var(--phosphor-glow) 70%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 98;
  opacity: 0;
  filter: blur(3px);
  transition: opacity 0.3s ease;
}

.crt-screen.enable-scanlines .crt-scanbeam {
  opacity: 0.25;
  animation: scanline-beam 3.5s ease-in-out infinite;
}

@keyframes scanline-beam {
  0% {
    top: -120px;
    opacity: 0.1;
  }
  50% {
    opacity: 0.35;
  }
  100% {
    top: 100%;
    opacity: 0.1;
  }
}

/* CRT Noise/Grain Texture */
.crt-noise {
  position: absolute;
  inset: 0;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300"><filter id="noise"><feTurbulence baseFrequency="0.9" numOctaves="4" /></filter><rect width="100%" height="100%" filter="url(%23noise)" opacity="0.05"/></svg>');
  pointer-events: none;
  z-index: 97;
  animation: noise-flicker 0.2s infinite;
  opacity: 0.3;
}

@keyframes noise-flicker {
  0% { opacity: 0.25; }
  50% { opacity: 0.35; }
  100% { opacity: 0.25; }
}

/* Phosphor Bloom (Intense Glow Bleeding) */
.crt-bloom {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    var(--phosphor-glow) 0%,
    var(--phosphor-dark) 30%,
    transparent 60%
  );
  pointer-events: none;
  z-index: 2;
  mix-blend-mode: screen;
  opacity: 0.4;
  filter: blur(40px);
}

/* Ambient screen glow (subtle phosphor wash) */
.crt-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    var(--screen-ambient) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 1;
}

/* Screen Glow (Outer Halo) - BRIGHTER */
.crt-screen::after {
  content: '';
  position: absolute;
  inset: -15px;
  background: radial-gradient(
    ellipse at center,
    var(--phosphor-glow) 0%,
    var(--phosphor-dark) 40%,
    transparent 70%
  );
  pointer-events: none;
  z-index: -1;
  opacity: 0.3;
}

/**
 * ==========================================================================
 * LAYOUT STRUCTURE
 * ==========================================================================
 */

.crt-viewport {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.crt-screen-area {
  grid-row: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  position: relative;
}

.crt-control-panel {
  grid-row: 2;
  height: auto;
  max-height: 30vh;
  background: var(--control-panel-bg);
  border-top: 2px solid var(--phosphor-dark);
  padding: 15px 20px;
  overflow-y: auto;
}

/**
 * ==========================================================================
 * PHOSPHOR TEXT STYLING
 * ==========================================================================
 */

.phosphor-text {
  color: var(--phosphor-primary);
  font-family: var(--font-primary);
  text-shadow:
    0 0 5px var(--phosphor-primary),
    0 0 10px var(--phosphor-glow),
    0 0 20px var(--phosphor-glow),
    0 0 30px var(--phosphor-glow),
    0 0 40px var(--phosphor-glow),
    0 0 50px var(--phosphor-dim),
    0 0 60px var(--phosphor-dim);
  letter-spacing: 0.05em;
  filter: brightness(var(--brightness)) contrast(var(--contrast));
}

.phosphor-text-bright {
  color: var(--phosphor-bright);
  text-shadow:
    0 0 8px var(--phosphor-primary),
    0 0 15px var(--phosphor-glow),
    0 0 30px var(--phosphor-glow),
    0 0 45px var(--phosphor-glow),
    0 0 60px var(--phosphor-glow),
    0 0 75px var(--phosphor-dim),
    0 0 90px var(--phosphor-dim);
  filter: brightness(calc(var(--brightness) * 1.3)) contrast(var(--contrast));
  animation: phosphor-intense-pulse 3s ease-in-out infinite;
}

@keyframes phosphor-intense-pulse {
  0%, 100% {
    filter: brightness(calc(var(--brightness) * 1.3)) contrast(var(--contrast)) drop-shadow(0 0 20px var(--phosphor-glow));
  }
  50% {
    filter: brightness(calc(var(--brightness) * 1.5)) contrast(var(--contrast)) drop-shadow(0 0 40px var(--phosphor-glow));
  }
}

.phosphor-text-dim {
  color: var(--phosphor-dim);
  text-shadow:
    0 0 5px var(--phosphor-dim),
    0 0 10px var(--phosphor-dim),
    0 0 20px var(--phosphor-dark);
  filter: brightness(var(--brightness)) contrast(var(--contrast));
}

/* Chromatic Aberration Effect (Subtle) */
.phosphor-text-aberration {
  position: relative;
}

.phosphor-text-aberration::before {
  content: attr(data-text);
  position: absolute;
  left: -1px;
  top: -1px;
  color: var(--phosphor-primary);
  opacity: 0.3;
  filter: blur(0.5px);
  z-index: -1;
}

/**
 * ==========================================================================
 * INTERACTIVE ELEMENTS
 * ==========================================================================
 */

/* Oscilloscope-Style Button */
.oscilloscope-button {
  background: transparent;
  color: var(--phosphor-primary);
  border: 2px solid var(--phosphor-primary);
  padding: 10px 20px;
  font-family: var(--font-primary);
  font-size: var(--text-base);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
  box-shadow:
    0 0 10px var(--phosphor-dark),
    inset 0 0 10px var(--phosphor-dark);
}

.oscilloscope-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--phosphor-dark);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

.oscilloscope-button:hover {
  text-shadow:
    0 0 5px var(--phosphor-primary),
    0 0 10px var(--phosphor-glow),
    0 0 20px var(--phosphor-glow),
    0 0 30px var(--phosphor-glow);
  box-shadow:
    0 0 30px var(--phosphor-glow),
    0 0 50px var(--phosphor-dark),
    inset 0 0 20px var(--phosphor-dark);
}

.oscilloscope-button:hover::before {
  transform: translateX(0);
}

.oscilloscope-button:active {
  animation: crt-flicker 0.15s;
  transform: scale(0.98);
}

@keyframes crt-flicker {
  0%, 100% { opacity: 1; }
  25% { opacity: 0.8; }
  50% { opacity: 0.95; }
  75% { opacity: 0.85; }
}

/* Input Fields */
.phosphor-input {
  background: transparent;
  color: var(--phosphor-primary);
  border: none;
  border-bottom: 2px solid var(--phosphor-dim);
  padding: 8px 12px;
  font-family: var(--font-primary);
  font-size: var(--text-base);
  outline: none;
  transition: all 0.3s ease;
  caret-color: var(--phosphor-primary);
}

.phosphor-input:focus {
  border-bottom-color: var(--phosphor-primary);
  text-shadow:
    0 0 5px var(--phosphor-primary),
    0 0 10px var(--phosphor-glow),
    0 0 20px var(--phosphor-glow);
  box-shadow:
    0 3px 15px var(--phosphor-glow),
    0 6px 30px var(--phosphor-dark);
}

.phosphor-input::placeholder {
  color: var(--phosphor-dim);
  opacity: 0.6;
}

/* Select/Dropdown */
.phosphor-select {
  background: var(--screen-background);
  color: var(--phosphor-primary);
  border: 2px solid var(--phosphor-dim);
  padding: 8px 12px;
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  text-transform: uppercase;
  cursor: pointer;
  outline: none;
  transition: all 0.3s ease;
}

.phosphor-select:hover {
  border-color: var(--phosphor-primary);
  box-shadow: 0 0 15px var(--phosphor-dark);
}

.phosphor-select:focus {
  border-color: var(--phosphor-bright);
  box-shadow: 0 0 20px var(--phosphor-glow);
}

.phosphor-select option {
  background: var(--screen-background);
  color: var(--phosphor-primary);
}

/**
 * ==========================================================================
 * MODAL SYSTEM
 * ==========================================================================
 */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--screen-background);
  border: 3px solid var(--phosphor-primary);
  border-radius: 4px;
  max-width: 800px;
  max-height: 80vh;
  width: 100%;
  box-shadow:
    0 0 50px var(--phosphor-glow),
    inset 0 0 30px var(--phosphor-dark);
  position: relative;
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 2px solid var(--phosphor-dim);
  font-size: var(--text-lg);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.modal-body {
  padding: 20px;
  max-height: 60vh;
  overflow-y: auto;
  font-size: var(--text-base);
  line-height: 1.6;
}

.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: var(--screen-background);
  border-left: 1px solid var(--phosphor-dark);
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--phosphor-dim);
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--phosphor-primary);
  box-shadow: 0 0 10px var(--phosphor-glow);
}

/**
 * ==========================================================================
 * OSCILLOSCOPE ANIMATIONS
 * ==========================================================================
 */

/* Sweep In Animation */
@keyframes oscilloscope-sweep-in {
  0% {
    transform: translateX(-100%);
    opacity: 0;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

.modal-sweep-in {
  animation: oscilloscope-sweep-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sweep Out Animation */
@keyframes oscilloscope-sweep-out {
  0% {
    transform: translateX(0);
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    transform: translateX(100%);
    opacity: 0;
  }
}

.modal-sweep-out {
  animation: oscilloscope-sweep-out 0.3s cubic-bezier(0.4, 0, 0.6, 1);
}

/* Phosphor Fade In */
@keyframes phosphor-fade-in {
  0% {
    opacity: 0;
    filter: blur(3px);
    text-shadow:
      0 0 20px var(--phosphor-glow),
      0 0 30px var(--phosphor-glow);
  }
  100% {
    opacity: 1;
    filter: blur(0);
    text-shadow:
      0 0 5px var(--phosphor-glow),
      0 0 10px var(--phosphor-glow);
  }
}

.phosphor-fade-in {
  animation: phosphor-fade-in 0.6s ease-out;
}

/* Typewriter Effect */
@keyframes typewriter {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes blink-cursor {
  50% { border-color: transparent; }
}

.typewriter-text {
  overflow: hidden;
  white-space: nowrap;
  border-right: 2px solid var(--phosphor-primary);
  display: inline-block;
  animation:
    typewriter 2s steps(40) forwards,
    blink-cursor 0.75s step-end infinite;
}

/* Pulse Effect */
@keyframes phosphor-pulse {
  0%, 100% {
    text-shadow:
      0 0 5px var(--phosphor-glow),
      0 0 10px var(--phosphor-glow);
  }
  50% {
    text-shadow:
      0 0 10px var(--phosphor-glow),
      0 0 20px var(--phosphor-glow),
      0 0 30px var(--phosphor-glow);
  }
}

.phosphor-pulse {
  animation: phosphor-pulse 2s ease-in-out infinite;
}

/**
 * ==========================================================================
 * THEME SELECTOR COMPONENT
 * ==========================================================================
 */

.theme-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  background: var(--control-panel-bg);
  border: 1px solid var(--phosphor-dark);
  border-radius: 4px;
}

.theme-selector-label {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.theme-color-swatches {
  display: flex;
  gap: 8px;
}

.theme-swatch {
  width: 24px;
  height: 24px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.theme-swatch.active {
  border-color: var(--phosphor-primary);
  box-shadow: 0 0 15px var(--phosphor-glow);
}

.theme-swatch:hover:not(.active) {
  transform: scale(1.1);
}

.theme-swatch.green { background: #39FF14; box-shadow: 0 0 10px rgba(57, 255, 20, 0.6); }
.theme-swatch.amber { background: #ffcc00; box-shadow: 0 0 10px rgba(255, 204, 0, 0.6); }
.theme-swatch.white { background: #ffffff; box-shadow: 0 0 10px rgba(255, 255, 255, 0.6); }
.theme-swatch.blue { background: #00ffff; box-shadow: 0 0 10px rgba(0, 255, 255, 0.6); }

/**
 * ==========================================================================
 * MERMAID DIAGRAM STYLING
 * ==========================================================================
 */

.mermaid-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 20px;
  text-align: center;
}

.mermaid-diagram {
  font-family: var(--font-primary) !important;
}

/* Monochromatic Mermaid Theme - ULTRA GLOW */
.mermaid .node rect,
.mermaid .node circle,
.mermaid .node ellipse,
.mermaid .node polygon,
.mermaid .node path {
  fill: transparent !important;
  stroke: var(--phosphor-primary) !important;
  stroke-width: 3px !important;
  filter:
    drop-shadow(0 0 8px var(--phosphor-glow))
    drop-shadow(0 0 15px var(--phosphor-glow))
    drop-shadow(0 0 25px var(--phosphor-dim));
}

.mermaid .node .label,
.mermaid text {
  fill: var(--phosphor-primary) !important;
  color: var(--phosphor-primary) !important;
  font-family: var(--font-primary) !important;
  font-weight: 700 !important;
  filter:
    drop-shadow(0 0 8px var(--phosphor-glow))
    drop-shadow(0 0 15px var(--phosphor-glow));
}

.mermaid .edgePath .path,
.mermaid .flowchart-link {
  stroke: var(--phosphor-primary) !important;
  stroke-width: 3px !important;
  filter:
    drop-shadow(0 0 6px var(--phosphor-glow))
    drop-shadow(0 0 12px var(--phosphor-glow))
    drop-shadow(0 0 20px var(--phosphor-dim));
}

.mermaid .edgeLabel {
  background-color: var(--screen-background) !important;
  color: var(--phosphor-primary) !important;
}

.mermaid .cluster rect,
.mermaid .cluster polygon {
  fill: var(--phosphor-dark) !important;
  stroke: var(--phosphor-dim) !important;
  stroke-width: 1px !important;
  stroke-dasharray: 5, 5;
}

/**
 * ==========================================================================
 * ACCESSIBILITY
 * ==========================================================================
 */

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .crt-screen.enable-scanlines::before,
  .modal-sweep-in,
  .modal-sweep-out,
  .phosphor-fade-in,
  .typewriter-text,
  .phosphor-pulse,
  .oscilloscope-button::before {
    animation: none !important;
  }

  * {
    transition-duration: 0.01ms !important;
  }

  .theme-swatch:hover:not(.active) {
    transform: none;
  }
}

/* Focus Styles */
*:focus-visible {
  outline: 2px solid var(--phosphor-primary);
  outline-offset: 4px;
  box-shadow: 0 0 10px var(--phosphor-glow);
}

/**
 * ==========================================================================
 * RESPONSIVE DESIGN
 * ==========================================================================
 */

/* Tablet */
@media (max-width: 1024px) {
  .crt-monitor {
    padding: 15px;
  }

  .crt-bezel {
    padding: 10px;
  }

  .crt-control-panel {
    max-height: 35vh;
  }

  :root {
    --text-base: 0.875rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .crt-monitor {
    padding: 10px;
  }

  .crt-bezel {
    padding: 8px;
    border-radius: 8px;
  }

  .crt-screen {
    border-radius: 4px;
  }

  .crt-control-panel {
    max-height: 40vh;
    padding: 10px 15px;
  }

  .phosphor-text {
    text-shadow:
      0 0 4px var(--phosphor-glow),
      0 0 8px var(--phosphor-glow);
  }

  .oscilloscope-button {
    padding: 8px 16px;
    font-size: var(--text-sm);
  }

  .theme-selector {
    flex-direction: column;
    align-items: stretch;
  }

  .theme-color-swatches {
    justify-content: center;
  }

  /* Disable chromatic aberration on mobile */
  .phosphor-text-aberration::before {
    display: none;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .crt-monitor {
    padding: 5px;
  }

  .crt-bezel {
    padding: 5px;
  }

  :root {
    --text-xs: 0.7rem;
    --text-sm: 0.8rem;
    --text-base: 0.85rem;
    --text-lg: 1rem;
    --text-xl: 1.125rem;
  }

  .modal-content {
    max-width: 100%;
    max-height: 90vh;
  }
}

/**
 * ==========================================================================
 * PERFORMANCE OPTIMIZATIONS
 * ==========================================================================
 */

/* GPU Acceleration */
.crt-screen,
.modal-content,
.crt-vignette,
.crt-screen.enable-scanlines::before,
.oscilloscope-button::before {
  transform: translateZ(0);
  will-change: transform;
}

/* Optimize Text Rendering */
.phosphor-text,
.phosphor-text-bright,
.phosphor-text-dim {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Optimize Shadows on Low-End Devices */
@media (max-resolution: 1dppx) {
  .phosphor-text {
    text-shadow: 0 0 8px var(--phosphor-glow);
  }

  .oscilloscope-button {
    box-shadow: 0 0 10px var(--phosphor-dark);
  }
}

/**
 * ==========================================================================
 * UTILITY CLASSES
 * ==========================================================================
 */

.uppercase { text-transform: uppercase; }
.lowercase { text-transform: lowercase; }
.monospace { font-family: var(--font-primary); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }

.p-2 { padding: 0.5rem; }
.p-4 { padding: 1rem; }
.m-2 { margin: 0.5rem; }
.m-4 { margin: 1rem; }

.hidden { display: none; }
.visible { display: block; }

/**
 * ==========================================================================
 * VINTAGE CRT MONITOR CONTROLS (Knobs & Dials)
 * ==========================================================================
 */

/* Control Panel Housing */
.monitor-controls {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #1a1a1a 0%, #252525 50%, #1a1a1a 100%);
  border: 2px solid var(--monitor-bezel);
  border-radius: 6px;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    inset 0 -1px 2px rgba(255, 255, 255, 0.1),
    0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Individual Control Knob */
.control-knob {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.knob-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--phosphor-dim);
  text-align: center;
}

/* Circular Knob Dial */
.knob-dial {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #3a3a3a, #1a1a1a);
  border: 3px solid #0a0a0a;
  position: relative;
  cursor: grab;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.8),
    inset 0 -1px 2px rgba(255, 255, 255, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
}

.knob-dial:active {
  cursor: grabbing;
  box-shadow:
    inset 0 3px 6px rgba(0, 0, 0, 0.9),
    inset 0 -1px 1px rgba(255, 255, 255, 0.1);
}

/* Knob Indicator Line */
.knob-dial::before {
  content: '';
  position: absolute;
  top: 5px;
  left: 50%;
  width: 3px;
  height: 15px;
  background: var(--phosphor-primary);
  box-shadow:
    0 0 8px var(--phosphor-glow),
    0 0 12px var(--phosphor-glow);
  transform-origin: 50% 20px;
  transform: translateX(-50%) rotate(var(--rotation, 0deg));
  transition: transform 0.1s ease-out;
}

/* Knob Center Dot */
.knob-dial::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: var(--phosphor-dim);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow:
    0 0 4px var(--phosphor-glow),
    inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Slider-Based Controls */
.display-controls {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--phosphor-dark);
  border-radius: 4px;
}

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

.control-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 70px;
}

.phosphor-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: var(--phosphor-dark);
  outline: none;
  border-radius: 2px;
}

.phosphor-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--phosphor-primary);
  cursor: pointer;
  border-radius: 50%;
  box-shadow: 0 0 8px var(--phosphor-glow);
}

.phosphor-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--phosphor-primary);
  cursor: pointer;
  border-radius: 50%;
  border: none;
  box-shadow: 0 0 8px var(--phosphor-glow);
}

.phosphor-slider:hover::-webkit-slider-thumb {
  box-shadow: 0 0 15px var(--phosphor-glow);
}

.phosphor-slider:hover::-moz-range-thumb {
  box-shadow: 0 0 15px var(--phosphor-glow);
}

/* Knob Value Display */
.knob-value {
  font-size: 0.6rem;
  color: var(--phosphor-dim);
  font-family: monospace;
}

/* Vintage Toggle Switch */
.vintage-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.toggle-switch {
  width: 40px;
  height: 60px;
  background: linear-gradient(to right, #1a1a1a, #2a2a2a, #1a1a1a);
  border: 3px solid #0a0a0a;
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.8),
    inset 0 -1px 2px rgba(255, 255, 255, 0.1),
    0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Toggle Lever */
.toggle-switch::before {
  content: '';
  position: absolute;
  left: 50%;
  width: 20px;
  height: 25px;
  background: linear-gradient(135deg, #3a3a3a, #2a2a2a);
  border: 2px solid #1a1a1a;
  border-radius: 4px;
  transform: translateX(-50%);
  transition: all 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Toggle OFF state */
.toggle-switch::before {
  top: 28px;
}

/* Toggle ON state */
.toggle-switch.on::before {
  top: 5px;
  background: linear-gradient(135deg, #3a3a3a, #2a2a2a);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.5),
    0 0 10px var(--phosphor-glow);
}

/* ON indicator light */
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 10px;
  left: 50%;
  width: 6px;
  height: 6px;
  background: var(--phosphor-primary);
  border-radius: 50%;
  transform: translateX(-50%);
  opacity: 0;
  box-shadow: 0 0 8px var(--phosphor-glow);
  transition: opacity 0.2s ease;
}

.toggle-switch.on::after {
  opacity: 1;
}

.toggle-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--phosphor-dim);
}

/* Degauss Button */
.degauss-button {
  background: linear-gradient(135deg, #2a2a2a, #1a1a1a);
  color: var(--phosphor-primary);
  border: 3px solid #0a0a0a;
  padding: 10px 20px;
  font-family: var(--font-primary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  cursor: pointer;
  border-radius: 4px;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    inset 0 -1px 2px rgba(255, 255, 255, 0.1),
    0 2px 4px rgba(0, 0, 0, 0.5);
  transition: all 0.1s ease;
  position: relative;
  overflow: hidden;
}

.degauss-button::before {
  content: '⚡';
  position: absolute;
  left: 8px;
  font-size: 1rem;
  filter: drop-shadow(0 0 4px var(--phosphor-glow));
}

.degauss-button:hover {
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    0 0 15px var(--phosphor-glow);
  text-shadow: 0 0 8px var(--phosphor-glow);
}

.degauss-button:active {
  box-shadow:
    inset 0 3px 6px rgba(0, 0, 0, 0.8),
    0 0 8px var(--phosphor-glow);
  transform: scale(0.95);
}

/**
 * ==========================================================================
 * SERVICE PANEL (Collapsible Monitor Adjustments)
 * ==========================================================================
 */

/* Always Visible Control Strip */
.control-strip-visible {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 8px 0;
}

/* Panel Toggle Button */
.panel-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #2a2a2a, #1a1a1a);
  color: var(--phosphor-primary);
  border: 3px solid #0a0a0a;
  padding: 8px 16px;
  font-family: var(--font-primary);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 4px;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    inset 0 -1px 2px rgba(255, 255, 255, 0.1),
    0 2px 4px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
}

.panel-toggle-btn:hover {
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    0 0 12px var(--phosphor-glow);
  text-shadow: 0 0 6px var(--phosphor-glow);
}

.panel-toggle-btn:active {
  transform: scale(0.95);
}

.panel-icon {
  font-size: 0.8rem;
  transition: transform 0.3s ease;
}

.panel-label {
  font-size: 0.65rem;
}

/* Service Panel Container */
.service-panel {
  max-height: 0;
  overflow: hidden;
  margin-top: 15px;
  transition: max-height 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  position: relative;
}

.service-panel[data-state="open"],
.service-panel[data-state="opening"] {
  max-height: 250px;
}

/* Panel Lid (Decorative Hinge Element) */
.panel-lid {
  position: relative;
  background: linear-gradient(to bottom, #2a2a2a, #1a1a1a);
  border: 2px solid var(--phosphor-dark);
  border-radius: 4px 4px 0 0;
  padding: 12px 20px;
  cursor: pointer;
  transform-origin: top center;
  transform-style: preserve-3d;
  perspective: 800px;
  transition: transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55),
              box-shadow 0.6s ease;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    0 2px 10px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.service-panel[data-state="opening"] .panel-lid,
.service-panel[data-state="open"] .panel-lid {
  transform: perspective(800px) rotateX(165deg);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.8),
    0 10px 30px rgba(0, 0, 0, 0.8);
}

/* Panel Label Text */
.panel-label-text {
  text-align: center;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  user-select: none;
}

/* Decorative Hinges */
.hinge {
  position: absolute;
  top: -4px;
  width: 24px;
  height: 8px;
  background: linear-gradient(to bottom, #555, #333);
  border: 1px solid #444;
  border-radius: 2px;
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.5);
}

.hinge::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  background: #222;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.8);
}

.hinge-left {
  left: 20px;
}

.hinge-right {
  right: 20px;
}

/* Decorative Screws */
.screw {
  position: absolute;
  width: 10px;
  height: 10px;
  background: radial-gradient(circle at 30% 30%, #555, #222);
  border-radius: 50%;
  border: 1px solid #333;
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Phillips head screw cross */
.screw::before,
.screw::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  background: #111;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.8);
}

.screw::before {
  width: 6px;
  height: 1px;
  transform: translate(-50%, -50%);
}

.screw::after {
  width: 1px;
  height: 6px;
  transform: translate(-50%, -50%);
}

.screw-tl {
  top: 3px;
  left: 15px;
}

.screw-tr {
  top: 3px;
  right: 15px;
}

.screw-bl {
  bottom: 3px;
  left: 15px;
}

.screw-br {
  bottom: 3px;
  right: 15px;
}

/* Panel Contents (All Adjustments) */
.panel-contents {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 20px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--phosphor-dark);
  border-top: none;
  border-radius: 0 0 4px 4px;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s ease 0.3s, transform 0.3s ease 0.3s;
}

.service-panel[data-state="opening"] .panel-contents,
.service-panel[data-state="open"] .panel-contents {
  opacity: 1;
  transform: translateY(0);
}

/* Simple Animation Mode (Fade In/Out) */
.service-panel[data-animation-mode="simple"] {
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.service-panel[data-animation-mode="simple"] .panel-lid {
  display: none;
}

.service-panel[data-animation-mode="simple"] .panel-contents {
  border-radius: 4px;
  border-top: 1px solid var(--phosphor-dark);
}

/* ============================================================
   ENHANCED DEGAUSS ANIMATION SYSTEM
   Multi-stage CRT degaussing with RGB chromatic aberration
   ============================================================ */

/* Stage 1: Collapse/Expand with Intense Wobble */
@keyframes degauss-collapse-expand {
  0% {
    transform: translate(0, 0) scale(1) skewX(0deg) skewY(0deg);
  }
  5% {
    transform: translate(-15px, 8px) scale(0.95, 1.08) skewX(-8deg) skewY(3deg);
  }
  10% {
    transform: translate(20px, -15px) scale(1.05, 0.92) skewX(10deg) skewY(-4deg);
  }
  15% {
    transform: translate(-25px, 12px) scale(0.88, 1.15) skewX(-12deg) skewY(5deg);
  }
  20% {
    transform: translate(18px, -20px) scale(1.12, 0.85) skewX(15deg) skewY(-6deg);
  }
  25% {
    transform: translate(-12px, 15px) scale(0.9, 1.1) skewX(-10deg) skewY(4deg);
  }
  35% {
    transform: translate(8px, -10px) scale(1.03, 0.97) skewX(6deg) skewY(-2deg);
  }
  45% {
    transform: translate(-5px, 8px) scale(0.98, 1.02) skewX(-4deg) skewY(2deg);
  }
  55% {
    transform: translate(6px, -6px) scale(1.01, 0.99) skewX(3deg) skewY(-1deg);
  }
  65% {
    transform: translate(-3px, 4px) scale(0.99, 1.01) skewX(-2deg) skewY(1deg);
  }
  75% {
    transform: translate(2px, -3px) scale(1.005, 0.995) skewX(1deg) skewY(0deg);
  }
  85% {
    transform: translate(-1px, 2px) scale(0.998, 1.002) skewX(-0.5deg) skewY(0deg);
  }
  95% {
    transform: translate(1px, -1px) scale(1.001, 0.999) skewX(0deg) skewY(0deg);
  }
  100% {
    transform: translate(0, 0) scale(1, 1) skewX(0deg) skewY(0deg);
  }
}

/* Stage 2: RGB Chromatic Aberration (Color Channel Split) */
@keyframes degauss-rgb-split {
  0% {
    filter:
      drop-shadow(0px 0px 0px rgba(255, 0, 0, 0))
      drop-shadow(0px 0px 0px rgba(0, 255, 0, 0))
      drop-shadow(0px 0px 0px rgba(0, 0, 255, 0));
  }
  5% {
    filter:
      drop-shadow(-8px -4px 2px rgba(255, 0, 0, 0.9))
      drop-shadow(0px 0px 2px rgba(0, 255, 0, 0.9))
      drop-shadow(8px 4px 2px rgba(0, 0, 255, 0.9));
  }
  10% {
    filter:
      drop-shadow(-12px -6px 3px rgba(255, 0, 0, 1))
      drop-shadow(0px 0px 3px rgba(0, 255, 0, 1))
      drop-shadow(12px 6px 3px rgba(0, 0, 255, 1));
  }
  15% {
    filter:
      drop-shadow(-10px -5px 3px rgba(255, 0, 0, 0.95))
      drop-shadow(2px 1px 2px rgba(0, 255, 0, 0.95))
      drop-shadow(10px 5px 3px rgba(0, 0, 255, 0.95));
  }
  25% {
    filter:
      drop-shadow(-6px -3px 2px rgba(255, 0, 0, 0.8))
      drop-shadow(0px 0px 2px rgba(0, 255, 0, 0.8))
      drop-shadow(6px 3px 2px rgba(0, 0, 255, 0.8));
  }
  40% {
    filter:
      drop-shadow(-3px -2px 1px rgba(255, 0, 0, 0.5))
      drop-shadow(0px 0px 1px rgba(0, 255, 0, 0.5))
      drop-shadow(3px 2px 1px rgba(0, 0, 255, 0.5));
  }
  60% {
    filter:
      drop-shadow(-1px -1px 1px rgba(255, 0, 0, 0.2))
      drop-shadow(0px 0px 0px rgba(0, 255, 0, 0.2))
      drop-shadow(1px 1px 1px rgba(0, 0, 255, 0.2));
  }
  80% {
    filter:
      drop-shadow(0px 0px 0px rgba(255, 0, 0, 0.1))
      drop-shadow(0px 0px 0px rgba(0, 255, 0, 0.1))
      drop-shadow(0px 0px 0px rgba(0, 0, 255, 0.1));
  }
  100% {
    filter:
      drop-shadow(0px 0px 0px rgba(255, 0, 0, 0))
      drop-shadow(0px 0px 0px rgba(0, 255, 0, 0))
      drop-shadow(0px 0px 0px rgba(0, 0, 255, 0));
  }
}

/* Stage 3: White Phosphor Flash (Peak Brightness) */
@keyframes degauss-white-flash {
  0%, 100% {
    background: var(--screen-background);
    filter: brightness(1) contrast(1);
  }
  8% {
    background: rgba(255, 255, 255, 0.03);
    filter: brightness(1.3) contrast(1.1);
  }
  12% {
    background: rgba(255, 255, 255, 0.08);
    filter: brightness(1.8) contrast(1.3);
  }
  16% {
    background: rgba(255, 255, 255, 0.05);
    filter: brightness(1.5) contrast(1.2);
  }
  25% {
    background: rgba(255, 255, 255, 0.02);
    filter: brightness(1.2) contrast(1.05);
  }
  40% {
    background: var(--screen-background);
    filter: brightness(1.05) contrast(1);
  }
}

/* Stage 4: Bloom Intensification */
@keyframes degauss-bloom-pulse {
  0%, 100% {
    opacity: 0.4;
    filter: blur(40px);
  }
  10% {
    opacity: 0.9;
    filter: blur(60px);
  }
  20% {
    opacity: 1.2;
    filter: blur(80px);
  }
  35% {
    opacity: 0.8;
    filter: blur(50px);
  }
  60% {
    opacity: 0.5;
    filter: blur(45px);
  }
}

/* Stage 5: Screen Vignette Pulse */
@keyframes degauss-vignette-pulse {
  0%, 100% {
    opacity: 1;
  }
  15% {
    opacity: 0.3;
  }
  30% {
    opacity: 0.6;
  }
  50% {
    opacity: 0.8;
  }
}

/* Apply Animations to Elements */
.degaussing .crt-viewport {
  animation:
    degauss-collapse-expand 1.8s cubic-bezier(0.68, -0.55, 0.265, 1.55),
    degauss-rgb-split 1.8s ease-out;
}

.degaussing .crt-screen {
  animation: degauss-white-flash 1.8s ease-in-out;
}

.degaussing .crt-bloom {
  animation: degauss-bloom-pulse 1.8s ease-in-out;
}

.degaussing .crt-vignette {
  animation: degauss-vignette-pulse 1.8s ease-in-out;
}

/* Add temporary RGB channel split overlay */
.degaussing::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 50%, rgba(255, 0, 0, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(0, 255, 0, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 50%, rgba(0, 0, 255, 0.15) 0%, transparent 50%);
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  animation: degauss-rgb-overlay 1.8s ease-out;
}

@keyframes degauss-rgb-overlay {
  0%, 100% { opacity: 0; }
  8% { opacity: 0.6; }
  15% { opacity: 0.9; }
  30% { opacity: 0.4; }
  50% { opacity: 0.1; }
}

/**
 * ==========================================================================
 * PRINT STYLES
 * ==========================================================================
 */

@media print {
  .crt-monitor,
  .crt-bezel,
  .crt-screen {
    background: white;
    box-shadow: none;
  }

  .phosphor-text,
  .phosphor-text-bright,
  .phosphor-text-dim {
    color: black;
    text-shadow: none;
  }

  .crt-vignette,
  .crt-screen.enable-scanlines::before,
  .crt-screen::after {
    display: none;
  }
}
