/* CSS Reset & Setup */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Default Theme Variables (Matrix Theme is default) */
  --theme-color-primary: #39ff14;
  --theme-color-secondary: #008f11;
  --theme-color-glow: rgba(57, 255, 20, 0.6);
  --theme-bg-base: #020604;
  --theme-transition-speed: 0.8s;
  
  --glass-bg: rgba(10, 20, 15, 0.45);
  --glass-border: rgba(57, 255, 20, 0.2);
  --glass-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.8), 0 0 15px rgba(57, 255, 20, 0.15);
}

/* Theme Classes dynamically set on body */

/* MATRIX: Cyber Green & Black */
body.theme-matrix {
  --theme-color-primary: #39ff14;
  --theme-color-secondary: #00d911;
  --theme-color-glow: rgba(57, 255, 20, 0.7);
  --theme-bg-base: #020503;
  --glass-bg: rgba(2, 10, 5, 0.4);
  --glass-border: rgba(57, 255, 20, 0.25);
  --glass-glow: 0 0 20px rgba(57, 255, 20, 0.15), inset 0 0 10px rgba(57, 255, 20, 0.1);
}

/* STAR WARS: Crimson & Cyan Force Energies */
body.theme-star-wars {
  --theme-color-primary: #00d2ff;
  --theme-color-secondary: #ff0055;
  --theme-color-glow: rgba(0, 210, 255, 0.5);
  --theme-bg-base: #04050a;
  --glass-bg: rgba(12, 14, 24, 0.45);
  --glass-border: rgba(0, 210, 255, 0.2);
  --glass-glow: 0 0 25px rgba(0, 210, 255, 0.1), 0 0 40px rgba(255, 0, 85, 0.05);
}

/* STAR TREK: LCARS Amber & Starfleet Blue */
body.theme-star-trek {
  --theme-color-primary: #ff9900;
  --theme-color-secondary: #00a2ff;
  --theme-color-glow: rgba(255, 153, 0, 0.6);
  --theme-bg-base: #0b0e14;
  --glass-bg: rgba(15, 20, 30, 0.5);
  --glass-border: rgba(255, 153, 0, 0.25);
  --glass-glow: 0 0 30px rgba(255, 153, 0, 0.15), inset 0 0 12px rgba(0, 162, 255, 0.1);
}

/* LORD OF THE RINGS: Volcanic Gold & Ember Fire */
body.theme-lord-of-the-rings {
  --theme-color-primary: #ffa751;
  --theme-color-secondary: #ff2a00;
  --theme-color-glow: rgba(255, 42, 0, 0.85);
  --theme-bg-base: #080302;
  --glass-bg: rgba(15, 8, 5, 0.5);
  --glass-border: rgba(255, 167, 81, 0.2);
  --glass-glow: 0 0 30px rgba(255, 42, 0, 0.2), 0 0 50px rgba(255, 167, 81, 0.05);
}

/* DOCTOR WHO: TARDIS Blue & Gallifreyan Cyan */
body.theme-doctor-who {
  --theme-color-primary: #4364f7;
  --theme-color-secondary: #6fb1fc;
  --theme-color-glow: rgba(67, 100, 247, 0.7);
  --theme-bg-base: #03050f;
  --glass-bg: rgba(5, 10, 30, 0.45);
  --glass-border: rgba(67, 100, 247, 0.3);
  --glass-glow: 0 0 25px rgba(111, 177, 252, 0.15), inset 0 0 15px rgba(67, 100, 247, 0.1);
}

/* DUNE: Desert Sand Gold & Spice Blue */
body.theme-dune {
  --theme-color-primary: #e29c2b;
  --theme-color-secondary: #00d2ff;
  --theme-color-glow: rgba(226, 156, 43, 0.7);
  --theme-bg-base: #150a04;
  --glass-bg: rgba(28, 15, 8, 0.5);
  --glass-border: rgba(226, 156, 43, 0.25);
  --glass-glow: 0 0 25px rgba(226, 156, 43, 0.15), inset 0 0 10px rgba(0, 210, 255, 0.1);
}

/* BACK TO THE FUTURE: Neon Orange & Lightning Cyan */
body.theme-back-to-the-future {
  --theme-color-primary: #ff5500;
  --theme-color-secondary: #00ffff;
  --theme-color-glow: rgba(255, 85, 0, 0.7);
  --theme-bg-base: #06080e;
  --glass-bg: rgba(10, 15, 25, 0.5);
  --glass-border: rgba(255, 85, 0, 0.25);
  --glass-glow: 0 0 25px rgba(255, 85, 0, 0.15), inset 0 0 12px rgba(0, 255, 255, 0.1);
}

/* INTERSTELLAR: Deep Cosmic Purple & Glowing Accretion Gold */
body.theme-interstellar {
  --theme-color-primary: #8e2de2;
  --theme-color-secondary: #f9d423;
  --theme-color-glow: rgba(142, 45, 226, 0.7);
  --theme-bg-base: #03010a;
  --glass-bg: rgba(12, 5, 28, 0.5);
  --glass-border: rgba(142, 45, 226, 0.25);
  --glass-glow: 0 0 25px rgba(142, 45, 226, 0.15), inset 0 0 10px rgba(249, 212, 35, 0.1);
}

/* Global Styles */
body {
  overflow: hidden;
  background-color: var(--theme-bg-base);
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  cursor: crosshair;
  transition: background-color var(--theme-transition-speed) ease;
}

#background-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* Cyber overlays */
.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.04),
    rgba(0, 255, 0, 0.01),
    rgba(0, 0, 255, 0.04)
  );
  background-size: 100% 4px, 6px 100%;
  z-index: 2;
  pointer-events: none;
}

.overlay-vignette {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle,
    rgba(0, 0, 0, 0) 30%,
    rgba(0, 0, 0, 0.7) 100%
  );
  z-index: 3;
  pointer-events: none;
}



.hidden {
  display: none !important;
}

/* Main Console Container */
.console-wrapper {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  width: 100%;
  max-width: 600px;
  padding: 20px;
}

/* 1. Central Portal Aperture */
.portal-aperture {
  position: relative;
  width: 260px;
  height: 260px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.portal-aperture:hover {
  transform: scale(1.05);
}

.aperture-core {
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.9), 0 0 40px var(--theme-color-glow);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: box-shadow 0.6s ease;
}

/* Rotating Vortex Layers inside Aperture */
.vortex-layer {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  opacity: 0.7;
}

.layer-1 {
  background: radial-gradient(circle, transparent 20%, var(--theme-color-primary) 70%, transparent 95%);
  mask-image: repeating-conic-gradient(from 0deg, black 0deg 15deg, transparent 15deg 30deg);
  -webkit-mask-image: repeating-conic-gradient(from 0deg, black 0deg 15deg, transparent 15deg 30deg);
  animation: rotate-clockwise 12s linear infinite;
}

.layer-2 {
  background: radial-gradient(circle, transparent 10%, var(--theme-color-secondary) 60%, transparent 90%);
  mask-image: repeating-conic-gradient(from 45deg, black 0deg 20deg, transparent 20deg 40deg);
  -webkit-mask-image: repeating-conic-gradient(from 45deg, black 0deg 20deg, transparent 20deg 40deg);
  animation: rotate-counter-clockwise 8s linear infinite;
  opacity: 0.5;
}

.layer-3 {
  background: radial-gradient(circle, transparent 30%, #ffffff 80%, transparent 90%);
  mask-image: repeating-conic-gradient(from 90deg, black 0deg 10deg, transparent 10deg 25deg);
  -webkit-mask-image: repeating-conic-gradient(from 90deg, black 0deg 10deg, transparent 10deg 25deg);
  animation: rotate-clockwise 5s linear infinite;
  opacity: 0.35;
}

/* Concentric Aperture Rings */
.aperture-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  transition: border-color 0.6s ease, box-shadow 0.6s ease;
}

.aperture-ring.outer {
  width: 260px;
  height: 260px;
  border-width: 2px;
  border-style: dashed;
  animation: rotate-clockwise 60s linear infinite;
}

.aperture-ring.middle {
  width: 210px;
  height: 210px;
  border-width: 1px;
  border-style: solid;
  border-top-color: transparent;
  border-bottom-color: transparent;
  animation: rotate-counter-clockwise 20s linear infinite;
}

.aperture-ring.inner {
  width: 180px;
  height: 180px;
  border-width: 2px;
  border-style: double;
  border-left-color: transparent;
  border-right-color: transparent;
  animation: rotate-clockwise 15s linear infinite;
}

/* 2. Control Deck (Main Menu Triggers) */
.control-deck {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-glow);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  padding: 15px 30px;
  border-radius: 100px;
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: center;
  transition: border-color 0.6s ease, box-shadow 0.6s ease;
}

/* Control Deck Node Button */
.deck-node {
  position: relative;
  background: transparent;
  border: none;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  outline: none;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.deck-node::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.3s ease;
}

.deck-node:hover {
  transform: scale(1.15) translateY(-5px);
}

.deck-node:hover::before {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.deck-node:active {
  transform: scale(0.95);
}

/* Glowing selector ring when active */
.node-ring {
  position: absolute;
  top: -6px;
  left: -6px;
  right: -6px;
  bottom: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  opacity: 0;
  transition: all 0.5s ease;
}

.deck-node.active .node-ring {
  border-color: var(--theme-color-primary);
  box-shadow: 0 0 15px var(--theme-color-glow);
  opacity: 1;
  animation: pulse-ring 2.5s infinite;
}

/* Icons styling inside selector nodes */
.node-icon {
  position: relative;
  z-index: 2;
  pointer-events: none;
  transition: filter 0.3s ease;
}

/* Dual Pills (Matrix style) */
.dual-pills {
  display: flex;
  gap: 6px;
  transform: rotate(-35deg);
}

.pill {
  width: 10px;
  height: 24px;
  border-radius: 100px;
  position: relative;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
  animation: float-pills 4s ease-in-out infinite alternate;
}

.pill.red {
  background: linear-gradient(to bottom, #ff3366, #990022);
  animation-delay: 0.2s;
}

.pill.blue {
  background: linear-gradient(to bottom, #00d2ff, #004e7a);
}

/* Specific details for themes when active */
.deck-node:hover .node-icon,
.deck-node.active .node-icon {
  filter: drop-shadow(0 0 6px var(--theme-color-primary));
}

/* Lord of the Rings Ring Spin Animation */
.theme-trigger[data-theme="lord-of-the-rings"].active .node-icon {
  animation: spin-slow 20s linear infinite;
}

/* 3. Sub-Console Dials */
.sub-deck {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-glow);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  padding: 15px 25px;
  border-radius: 20px;
  display: flex;
  gap: 35px;
  justify-content: center;
  align-items: center;
  transition: all 0.6s ease;
}

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

.dial {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle, #2d3748 40%, #1a202c 100%);
  border: 2px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 0.05);
  transition: border-color 0.4s ease;
}

.dial:hover {
  border-color: var(--theme-color-primary);
}

.dial-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 18px;
  background: var(--theme-color-primary);
  box-shadow: 0 0 6px var(--theme-color-glow);
  transform-origin: bottom center;
  transform: translate(-50%, -100%) rotate(0deg);
  border-radius: 20px;
  pointer-events: none;
  transition: transform 0.1s linear, background-color 0.4s ease;
}

.dial-label-light {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--theme-color-secondary);
  box-shadow: 0 0 2px var(--theme-color-glow);
  transition: background-color 0.5s ease, box-shadow 0.5s ease;
}

.dial:hover + .dial-label-light {
  background: var(--theme-color-primary);
  box-shadow: 0 0 8px var(--theme-color-glow);
}

/* Animations */
@keyframes rotate-clockwise {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes rotate-counter-clockwise {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}

@keyframes spin-slow {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes pulse-ring {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.08);
    opacity: 0.7;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

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

/* Mobile Responsiveness */
@media (max-width: 600px) {
  .console-wrapper {
    gap: 30px;
    transform: scale(0.9);
  }

  .portal-aperture {
    width: 220px;
    height: 220px;
  }

  .aperture-core {
    width: 130px;
    height: 130px;
  }

  .aperture-ring.outer { width: 220px; height: 220px; }
  .aperture-ring.middle { width: 180px; height: 180px; }
  .aperture-ring.inner { width: 150px; height: 150px; }

  .control-deck {
    padding: 10px 20px;
    gap: 10px;
  }

  .deck-node {
    width: 58px;
    height: 58px;
  }

  .node-ring {
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
  }


}

/* Glitch Overload Styles & Animations */
.overlay-glitch {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 99;
  pointer-events: none;
  background: transparent;
  opacity: 0;
  transition: opacity 0.3s ease;
}

body.overload-active .overlay-glitch {
  opacity: 1;
  animation: glitch-screen-color 0.15s infinite;
}

body.overload-active .console-wrapper {
  animation: shake 0.1s infinite;
}

body.overload-active {
  animation: chromatic-glitch 0.2s infinite;
}

body.system-shutdown {
  background-color: #000000 !important;
  transition: background-color 0.5s ease-in;
}

body.system-shutdown * {
  opacity: 0 !important;
  transition: opacity 0.5s ease-in;
}

@keyframes shake {
  0% { transform: translate(2px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -2px) rotate(-1deg); }
  20% { transform: translate(-3px, 0px) rotate(1deg); }
  30% { transform: translate(0px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(-3px, 1px) rotate(0deg); }
  70% { transform: translate(2px, 1px) rotate(-1deg); }
  80% { transform: translate(-1px, -1px) rotate(1deg); }
  90% { transform: translate(2px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -2px) rotate(-1deg); }
}

@keyframes glitch-screen-color {
  0% { background-color: rgba(255, 0, 0, 0.08); }
  20% { background-color: rgba(0, 255, 255, 0.08); }
  40% { background-color: rgba(255, 0, 255, 0.08); }
  60% { background-color: rgba(0, 255, 0, 0.08); }
  80% { background-color: rgba(255, 255, 0, 0.08); }
  100% { background-color: rgba(255, 0, 0, 0.08); }
}

@keyframes chromatic-glitch {
  0% { filter: contrast(1) hue-rotate(0deg); }
  50% { filter: contrast(1.3) hue-rotate(15deg) saturate(1.5); }
  100% { filter: contrast(1) hue-rotate(0deg); }
}
