/* ============================================
   Chapter Game Container - Pattern Recognition Training
   ============================================ */

#chapter-game {
  width: 100%;
  max-width: 800px;
  margin: 40px auto 60px;
  padding: 60px 20px;
  display: none; /* Hidden by default - only show when game loaded */
  justify-content: center;
  align-items: center;
  min-height: 200px;
  position: relative;
  z-index: 10;
}

/* Show container only when game is loaded */
#chapter-game.has-game {
  display: flex;
}

/* Orb Container */
.orb-container {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
}

/* Base Orb Styles */
.orb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-teal, #5eead4);
  box-shadow: 0 0 20px rgba(94, 234, 212, 0.3);
  cursor: pointer;
  position: relative;
  opacity: 0.3;
  transform: scale(0.95);
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

/* Active State - Orb glowing in sequence */
.orb--active {
  opacity: 1;
  transform: scale(1.15);
  box-shadow: 0 0 40px rgba(94, 234, 212, 1);
}

/* Hover state (subtle) */
.orb:hover {
  opacity: 0.5;
}

/* ============================================
   Anomaly Types - Pattern Breaking Behaviors
   ============================================ */

/* Anomaly 1: Color Shift - Wrong color during glow */
.orb--anomaly-colorshift {
  background: #ff1493 !important; /* Brighter, more saturated pink */
  box-shadow: 0 0 60px rgba(255, 20, 147, 1) !important;
  transform: scale(1.25) !important;
}

/* Anomaly 2: Skip - Stays dim when should glow */
.orb--anomaly-skip {
  opacity: 0.15 !important; /* Even dimmer */
  transform: scale(0.8) !important; /* Smaller */
  box-shadow: none !important; /* No glow */
}

/* Anomaly 3: Double - Glows with pulsing effect */
.orb--anomaly-double {
  animation: anomaly-double-pulse 0.35s ease-in-out 3 !important;
}

@keyframes anomaly-double-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1.3); /* Larger pulse */
  }
  50% {
    opacity: 0.3; /* More dramatic fade */
    transform: scale(0.85);
  }
}

/* Anomaly 4: Early - Glows before proper turn with gold tint */
.orb--anomaly-early {
  background: #ffd700 !important; /* Gold tint */
  box-shadow: 0 0 50px rgba(255, 215, 0, 1) !important;
  transform: scale(1.2) !important;
  opacity: 1;
}

/* Anomaly 5: Late - Glows after proper turn with cyan tint */
.orb--anomaly-late {
  background: #00ffff !important; /* Cyan tint */
  box-shadow: 0 0 50px rgba(0, 255, 255, 1) !important;
  transform: scale(1.2) !important;
  opacity: 1;
}

/* ============================================
   Hit Feedback - Glow Ring on Correct Click
   ============================================ */

.orb--hit {
  animation: hit-glow 0.6s ease-out forwards !important;
}

@keyframes hit-glow {
  0% {
    box-shadow: 0 0 20px rgba(94, 234, 212, 0.4);
    transform: scale(1.0);
  }
  50% {
    box-shadow: 0 0 80px rgba(94, 234, 212, 1),
                0 0 120px rgba(94, 234, 212, 0.8);
    transform: scale(1.3);
    opacity: 1;
  }
  100% {
    box-shadow: 0 0 20px rgba(94, 234, 212, 0.3);
    transform: scale(0.95);
    opacity: 0.3;
  }
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
  #chapter-game {
    margin: 60px auto 40px;
    padding: 40px 15px;
  }

  .orb-container {
    gap: 12px;
    flex-wrap: wrap; /* Allow wrapping on tablets */
    max-width: 100%;
  }

  .orb {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 480px) {
  .orb-container {
    gap: 10px;
    flex-wrap: wrap; /* Allow wrapping on phones */
    padding: 0 10px; /* Breathing room from screen edges */
  }

  .orb {
    width: 40px;
    height: 40px;
  }
}

/* Very narrow screens (iPhone SE, small Android) */
@media (max-width: 375px) {
  .orb-container {
    gap: 8px;
  }

  .orb {
    width: 36px;
    height: 36px;
  }
}

/* ============================================
   Chapter 2: Color Sorting Puzzle
   ============================================ */

/* Sorting Container - 3 Poles */
.sorting-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 80px;
  padding: 40px 20px;
  min-height: 400px;
}

/* Individual Pole */
.sorting-pole {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  position: relative;
  padding: 0 30px; /* Wider click area without changing visual appearance */
}

/* Pole Line (Vertical) */
.pole-line {
  width: 3px;
  height: 300px;
  background: rgba(94, 234, 212, 0.3);
  border-radius: 2px;
  position: absolute;
  bottom: 0;
}

/* Object Stack Container */
.pole-stack {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 2;
  padding-bottom: 10px;
}

/* Sorting Objects (Circles) */
.sorting-object {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  transition: all 0.3s ease;
  opacity: 0.6;
  box-shadow: 0 0 15px rgba(94, 234, 212, 0.2);
}

/* Color Variants */
.sorting-object--teal {
  background: var(--accent-teal, #5eead4);
}

.sorting-object--gold {
  background: #ffd700;
}

.sorting-object--pink {
  background: #ff1493;
}

/* Top Object (Clickable) */
.sorting-object--top {
  cursor: pointer;
  opacity: 0.8;
}

.sorting-object--top:hover {
  opacity: 1;
  transform: scale(1.1);
  box-shadow: 0 0 30px currentColor;
}

/* Selected State */
.sorting-object--selected {
  opacity: 1 !important;
  transform: scale(1.15) !important;
  box-shadow: 0 0 40px currentColor !important;
  animation: pulse-select 0.8s ease-in-out infinite;
}

@keyframes pulse-select {
  0%, 100% { transform: scale(1.15); }
  50% { transform: scale(1.25); }
}

/* Win State */
.sorting-object--win {
  animation: win-pulse 1s ease-in-out infinite;
}

@keyframes win-pulse {
  0%, 100% {
    opacity: 0.8;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
    box-shadow: 0 0 50px currentColor;
  }
}

/* ============================================
   Chapter 2 Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
  .sorting-container {
    gap: 60px;
    min-height: 350px;
  }

  .pole-line {
    height: 250px;
  }

  .sorting-object {
    width: 50px;
    height: 50px;
  }
}

@media (max-width: 480px) {
  .sorting-container {
    gap: 40px;
    min-height: 300px;
    padding: 30px 10px;
  }

  .pole-line {
    height: 200px;
  }

  .sorting-object {
    width: 40px;
    height: 40px;
  }

  .pole-stack {
    gap: 6px;
  }
}

@media (max-width: 375px) {
  .sorting-container {
    gap: 30px;
  }

  .sorting-object {
    width: 35px;
    height: 35px;
  }
}

/* ============================================
   Chapter 3: Sensitivity - Particle Collision
   ============================================ */

/* Particle Container (transparent, no background) */
.particle-container {
  position: relative;
  width: 100%;
  height: 500px;
  overflow: hidden;
}

/* Base Particle */
.particle {
  position: absolute;
  width: 30px;
  height: 30px;
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 0.7;
}

/* Shape: Circle */
.particle--circle {
  border-radius: 50%;
}

/* Shape: Square */
.particle--square {
  border-radius: 3px;
}

/* Shape: Triangle */
.particle--triangle {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-bottom: 26px solid; /* height * sqrt(3)/2 for equilateral */
  background: transparent !important; /* Override background, use border-bottom-color */
}

/* Color: Teal */
.particle--teal.particle--circle,
.particle--teal.particle--square {
  background: var(--accent-teal, #5eead4);
  box-shadow: 0 0 10px rgba(94, 234, 212, 0.4);
}

.particle--teal.particle--triangle {
  border-bottom-color: var(--accent-teal, #5eead4);
  filter: drop-shadow(0 0 10px rgba(94, 234, 212, 0.4));
}

/* Color: Gold */
.particle--gold.particle--circle,
.particle--gold.particle--square {
  background: #ffd700;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.particle--gold.particle--triangle {
  border-bottom-color: #ffd700;
  filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.4));
}

/* Color: Pink */
.particle--pink.particle--circle,
.particle--pink.particle--square {
  background: #ff1493;
  box-shadow: 0 0 10px rgba(255, 20, 147, 0.4);
}

.particle--pink.particle--triangle {
  border-bottom-color: #ff1493;
  filter: drop-shadow(0 0 10px rgba(255, 20, 147, 0.4));
}

/* Colliding State (subtle pulse) */
.particle--colliding {
  opacity: 1;
  animation: particle-collide-pulse 0.6s ease-in-out infinite;
}

@keyframes particle-collide-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Correct Detection Feedback */
.particle--correct {
  opacity: 1 !important;
  transform: scale(1.3) !important;
  animation: particle-correct-flash 0.6s ease-out forwards !important;
}

@keyframes particle-correct-flash {
  0% { opacity: 1; }
  50% { opacity: 1; box-shadow: 0 0 30px currentColor; }
  100% { opacity: 0.7; transform: scale(1); }
}

/* Incorrect Detection Feedback */
.particle--incorrect {
  animation: particle-incorrect-shake 0.4s ease-out forwards !important;
}

@keyframes particle-incorrect-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Hover Effect */
.particle:hover {
  opacity: 1;
  transform: scale(1.1);
}

/* ============================================
   Chapter 3 Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
  .particle-container {
    height: 400px;
  }

  .particle {
    width: 25px;
    height: 25px;
  }

  .particle--triangle {
    border-left: 12.5px solid transparent;
    border-right: 12.5px solid transparent;
    border-bottom: 21.6px solid;
  }
}

@media (max-width: 480px) {
  .particle-container {
    height: 350px;
  }

  .particle {
    width: 20px;
    height: 20px;
  }

  .particle--triangle {
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 17.3px solid;
  }
}

/* ============================================
   Chapter 4: Calibration - Threshold Training
   ============================================ */

/* Calibration Container */
.calibration-container {
  position: relative;
  width: 100%;
  height: 500px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: none; /* Transparent - shows page background */
}

/* Center Point */
.calibration-center {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-teal, #5eead4);
  box-shadow: 0 0 15px rgba(94, 234, 212, 0.8);
  z-index: 10;
}

/* Threshold Rings (Static) */
.calibration-ring {
  position: absolute;
  border: 2px solid #ffd700;
  border-radius: 50%;
  opacity: 0.4;
  pointer-events: none;
  z-index: 5;
}

.calibration-ring--inner {
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.calibration-ring--outer {
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

/* Waves Container */
.calibration-waves {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Wave (Expanding Circle) */
.calibration-wave {
  position: absolute;
  border: 3px solid var(--accent-teal, #5eead4);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.7;
  box-shadow: 0 0 15px rgba(94, 234, 212, 0.5);
  transition: opacity 0.1s ease;
  pointer-events: all;
}

.calibration-wave:hover {
  opacity: 1;
  box-shadow: 0 0 25px rgba(94, 234, 212, 0.8);
}

/* Trauma Event Wave (Pink) */
.calibration-wave--trauma {
  border-color: #ff1493;
  box-shadow: 0 0 20px rgba(255, 20, 147, 0.6);
  animation: trauma-pulse 0.4s ease-in-out 3;
}

@keyframes trauma-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Captured Wave (Success) */
.calibration-wave--captured {
  border-color: #00ff00 !important;
  box-shadow: 0 0 40px rgba(0, 255, 0, 1) !important;
  animation: wave-capture 0.6s ease-out forwards !important;
}

@keyframes wave-capture {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
    box-shadow: 0 0 60px rgba(0, 255, 0, 1);
  }
  100% {
    opacity: 0;
    transform: scale(0.8);
  }
}

/* Failed Wave (Miss) */
.calibration-wave--failed {
  border-color: #ff0000 !important;
  animation: wave-fail 0.4s ease-out !important;
}

@keyframes wave-fail {
  0%, 100% { opacity: 0.7; }
  50% {
    opacity: 1;
    box-shadow: 0 0 30px rgba(255, 0, 0, 0.8);
  }
}

/* Noise Overlay (Visual Distortion for Maladaptive Processing) */
.calibration-noise {
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, transparent 30%, rgba(255, 20, 147, 0.1) 100%);
  opacity: 0;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.5s ease, backdrop-filter 0.5s ease;
}

/* ============================================
   Chapter 4 Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
  .calibration-container {
    height: 400px;
  }

  .calibration-ring--inner {
    width: 120px !important;
    height: 120px !important;
  }

  .calibration-ring--outer {
    width: 200px !important;
    height: 200px !important;
  }
}

@media (max-width: 480px) {
  .calibration-container {
    height: 350px;
  }

  .calibration-ring--inner {
    width: 100px !important;
    height: 100px !important;
  }

  .calibration-ring--outer {
    width: 170px !important;
    height: 170px !important;
  }

  .calibration-wave {
    border-width: 2px;
  }
}

/* ============================================
   Conditional Game Positioning by Chapter
   ============================================ */

/* Enable flexbox on all chapters to control element order */
.reader-main {
  display: flex;
  flex-direction: column;
}

/* Default order for all chapters: content → game → navigation → footer */
.chapter-content {
  order: 0;
}

#chapter-game {
  order: 1; /* Game appears after content */
  margin: 40px auto 40px;
}

.chapter-navigation {
  order: 2; /* Navigation appears after game */
}

.reader-footer {
  order: 3; /* Footer always last */
}

/* ============================================
   Intro Inline Game Container (Mid-Content)
   ============================================ */

/* Intro game appears within content flow (not at bottom) */
#intro-game-inline {
  width: 100%;
  max-width: 800px;
  margin: 20px auto 20px;
  padding: 20px 20px;
  display: none;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  position: relative;
  z-index: 10;
}

#intro-game-inline.has-game {
  display: flex;
}
