/* ===================================================================
   EXPANDABLE SECTIONS — Glass panel peek + animated expand
   Per-section color theming (warm → cool gradient)
   =================================================================== */

/* --- Section color tokens --- */
#game {
  --section-h1: #ff3366;
  --section-h2: #ff6633;
  --section-glow: rgba(255, 51, 102, 0.25);
  --section-glow-soft: rgba(255, 80, 60, 0.08);
  --section-border: rgba(255, 80, 80, 0.2);
  --section-grad: linear-gradient(135deg, #ff3366, #ff6633);
  --section-grad-wide: linear-gradient(90deg, #ff2255, #ff4444, #ff6633, #ff9933, #ffbb33);
}

#story {
  --section-h1: #ff9922;
  --section-h2: #ffd500;
  --section-glow: rgba(255, 170, 40, 0.25);
  --section-glow-soft: rgba(255, 170, 40, 0.08);
  --section-border: rgba(255, 170, 40, 0.2);
  --section-grad: linear-gradient(135deg, #ff9922, #ffd500);
  --section-grad-wide: linear-gradient(90deg, #ff7711, #ff9922, #ffbb22, #ffd500, #ffee55);
}

#weapons {
  --section-h1: #66dd44;
  --section-h2: #00cc88;
  --section-glow: rgba(80, 210, 60, 0.25);
  --section-glow-soft: rgba(80, 210, 60, 0.08);
  --section-border: rgba(80, 210, 60, 0.2);
  --section-grad: linear-gradient(135deg, #66dd44, #00cc88);
  --section-grad-wide: linear-gradient(90deg, #88ee33, #66dd44, #33cc66, #00cc88, #00bbaa);
}

#worlds {
  --section-h1: #0078ee;
  --section-h2: #0a1a60;
  --section-glow: rgba(0, 140, 255, 0.4);
  --section-glow-soft: rgba(0, 120, 238, 0.12);
  --section-border: rgba(0, 140, 255, 0.3);
  --section-grad: linear-gradient(135deg, #0078ee, #002d99);
  --section-grad-wide: linear-gradient(90deg, #30e0ff, #0078ee, #0050cc, #002d99, #0a1a60);
}

/* --- Wrapper --- */
.expandable {
  position: relative;
  scroll-margin-top: calc(var(--nav-height, 72px) + 1rem);
}

/* --- Peek header — frosted glass bar --- */
.expandable-peek {
  scroll-margin-top: calc(var(--nav-height, 72px) + 1rem);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  max-width: 560px;
  margin: 0 auto;
  padding: var(--space-sm) var(--space-lg);
  cursor: pointer;
  position: relative;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  border-radius: 16px;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(255, 255, 255, 0.03) 0%, transparent 100%),
    linear-gradient(180deg, rgba(14, 18, 30, 0.6) 0%, rgba(6, 8, 16, 0.75) 100%);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 2px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    0 8px 24px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -1px 2px rgba(0, 0, 0, 0.3);
  transition: border-color 0.4s ease, box-shadow 0.5s ease, background 0.4s ease,
              max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1), padding 0.4s ease;
  overflow: hidden;
}

/* Scan-line sweep — used by unlock animation only */
.expandable-peek::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    105deg,
    transparent 30%,
    var(--section-glow-soft) 45%,
    var(--section-glow) 50%,
    var(--section-glow-soft) 55%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

/* Hover — dim section-colored glow */
.expandable-peek:hover {
  border-color: var(--section-border);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    0 8px 24px rgba(0, 0, 0, 0.2),
    0 0 15px var(--section-glow-soft),
    0 0 30px var(--section-glow-soft),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 2px rgba(0, 0, 0, 0.3);
}

/* Title — gradient on hover using section colors */
.expandable-peek:hover .expandable-peek-title {
  background: linear-gradient(90deg, var(--section-h1), var(--section-h2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.expandable-peek-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-width: 0;
  position: relative;
  z-index: 1;
}

/* --- Icon — 3D glass SVG, no background container --- */
.expandable-peek-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: none;
  border: none;
  color: var(--section-h1, #fff);
  transition: transform 0.4s cubic-bezier(0.34, 1.3, 0.64, 1), color 0.4s ease;
}

/* Hover — icon glows in section color */
.expandable-peek:hover .expandable-peek-icon {
  transform: scale(1.15);
}

.expandable-peek-icon svg {
  width: 32px;
  height: 32px;
  overflow: visible;
  position: relative;
  z-index: 1;
  filter:
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.7))
    drop-shadow(0 0 3px var(--section-glow-soft, rgba(255, 255, 255, 0.05)));
  transition: filter 0.4s ease;
}

/* Glass body — main shape */
.expandable-peek-icon .icon-body {
  fill: currentColor;
  fill-opacity: 0.12;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition: fill-opacity 0.4s ease;
}

/* Glass highlight — top reflection */
.expandable-peek-icon .icon-gloss {
  fill: rgba(255, 255, 255, 0.2);
  stroke: none;
}

/* Inner detail lines */
.expandable-peek-icon .icon-detail {
  fill: none;
  stroke: currentColor;
  stroke-width: 0.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.5;
  transition: opacity 0.4s ease;
}

/* Hover — brighter glow on the icon */
.expandable-peek:hover .expandable-peek-icon svg {
  filter:
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6))
    drop-shadow(0 0 8px var(--section-glow, rgba(255, 255, 255, 0.15)))
    drop-shadow(0 0 14px var(--section-glow-soft, rgba(255, 255, 255, 0.08)));
}

.expandable-peek:hover .expandable-peek-icon .icon-body {
  fill-opacity: 0.2;
}

.expandable-peek:hover .expandable-peek-icon .icon-detail {
  opacity: 0.7;
}

/* Expanded — full bright glass icon */
.expandable.is-expanded .expandable-peek-icon svg {
  filter:
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5))
    drop-shadow(0 0 10px var(--section-glow, rgba(255, 255, 255, 0.2)))
    drop-shadow(0 0 22px var(--section-glow, rgba(255, 255, 255, 0.15)));
}

.expandable.is-expanded .expandable-peek-icon .icon-body {
  fill-opacity: 0.3;
}

.expandable.is-expanded .expandable-peek-icon .icon-detail {
  opacity: 0.9;
}

.expandable-peek-title {
  font-family: var(--font-heading);
  font-size: clamp(1rem, 2vw, 1.3rem);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0.04em;
  transition: color var(--ease-base);
  position: relative;
  z-index: 1;
}

.expandable-peek-subtitle {
  font-family: var(--font-body);
  font-size: var(--fs-small);
  color: var(--color-text-dim);
  margin-top: 0.15rem;
  position: relative;
  z-index: 1;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.3s ease;
}

.expandable.is-expanded .expandable-peek-subtitle {
  max-height: 2em;
  opacity: 1;
}

/* --- Toggle button — glass circle with section-colored fill --- */
.expandable-peek-toggle {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--color-text-dim);
  position: relative;
  z-index: 1;
  background: rgba(10, 14, 25, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.4s cubic-bezier(0.34, 1.3, 0.64, 1),
              color 0.3s ease,
              border-color 0.3s ease,
              box-shadow 0.3s ease;
  overflow: hidden;
}

/* Toggle fill layer — section gradient */
.expandable-peek-toggle::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--section-grad);
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 0;
}

.expandable-peek:hover .expandable-peek-toggle {
  color: #fff;
  border-color: var(--section-border);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.3),
    0 0 12px var(--section-glow-soft),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.expandable-peek-toggle svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  position: relative;
  z-index: 1;
  transition: transform 0.4s cubic-bezier(0.34, 1.3, 0.64, 1);
}

/* Expanded toggle — filled + rotated */
.expandable.is-expanded .expandable-peek-toggle {
  border-color: var(--section-border);
  color: var(--color-bg);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.5),
    0 0 16px var(--section-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.expandable.is-expanded .expandable-peek-toggle::before {
  opacity: 1;
}

/* Glow bloom behind expanded toggle */
.expandable.is-expanded .expandable-peek-toggle::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  background: var(--section-grad);
  filter: blur(10px);
  opacity: 0.5;
  z-index: -1;
  pointer-events: none;
}

.expandable.is-expanded .expandable-peek-toggle svg {
  transform: rotate(180deg);
}

/* --- Expanded peek state — full width + bright glow --- */
.expandable.is-expanded .expandable-peek {
  max-width: var(--container-max);
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-color: var(--section-border);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    0 0 30px var(--section-glow),
    0 0 60px var(--section-glow),
    0 0 100px var(--section-glow-soft),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.expandable.is-expanded .expandable-peek-icon {
  transform: scale(1.15);
}

.expandable.is-expanded .expandable-peek-title {
  background: linear-gradient(90deg, var(--section-h1), var(--section-h2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* --- Body (collapsible) --- */
.expandable-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.5s ease;
  position: relative;
}


/* Corner brackets — section colored */
.expandable-body > section {
  position: relative;
}

.expandable-body > section::before,
.expandable-body > section::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border: 1px solid var(--section-border);
  pointer-events: none;
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.4s ease 0.3s, transform 0.4s cubic-bezier(0.34, 1.3, 0.64, 1) 0.3s;
}

.expandable-body > section::before {
  top: var(--space-md);
  left: var(--space-md);
  border-right: none;
  border-bottom: none;
}

.expandable-body > section::after {
  bottom: var(--space-md);
  right: var(--space-md);
  border-left: none;
  border-top: none;
}

.expandable.is-expanded .expandable-body > section::before,
.expandable.is-expanded .expandable-body > section::after {
  opacity: 1;
  transform: scale(1);
}

/* Child content — visible immediately (animations disabled) */
.expandable-body [data-animate] {
  opacity: 1;
  transform: none;
}

/* --- Preview image — hidden in compact collapsed state --- */
.expandable-peek-preview {
  flex-shrink: 0;
  width: 0;
  height: 68px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.4s ease, width 0.4s ease, border-color 0.3s ease;
  position: relative;
  z-index: 1;
}

.expandable-peek:hover .expandable-peek-preview {
  border-color: var(--section-border);
}

.expandable.is-expanded .expandable-peek-preview {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.expandable-peek-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}

.expandable-peek:hover .expandable-peek-preview img {
  transform: scale(1.08);
}

/* --- Dark background variant --- */
.expandable--dark .expandable-peek {
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(255, 255, 255, 0.02) 0%, transparent 100%),
    linear-gradient(180deg, rgba(18, 22, 38, 0.7) 0%, rgba(8, 10, 20, 0.85) 100%);
}

.expandable--dark .expandable-body {
  background: var(--color-bg-card);
}

/* --- Story variant --- */
.expandable--story {
  position: relative;
}

.expandable--story > .expandable-glow {
  position: absolute;
  inset: 0;
  background: var(--gradient-glow-purple);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.expandable--story.is-expanded > .expandable-glow {
  opacity: 0.3;
}

/* --- Ambient particles (CSS-only, inside expanded body) --- */
.expandable-particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.6s ease 0.4s;
}

.expandable.is-expanded .expandable-particles {
  opacity: 1;
}

.expandable-particle {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--section-h1);
  opacity: 0.4;
  box-shadow: 0 0 6px var(--section-glow);
}

.expandable-particle:nth-child(1) {
  top: 15%; left: 8%;
  animation: particleDrift1 8s ease-in-out infinite;
}
.expandable-particle:nth-child(2) {
  top: 40%; right: 12%;
  animation: particleDrift2 10s ease-in-out infinite;
  animation-delay: -3s;
  width: 2px; height: 2px;
}
.expandable-particle:nth-child(3) {
  bottom: 25%; left: 20%;
  animation: particleDrift3 12s ease-in-out infinite;
  animation-delay: -5s;
}
.expandable-particle:nth-child(4) {
  top: 60%; right: 25%;
  animation: particleDrift1 9s ease-in-out infinite;
  animation-delay: -2s;
  width: 2px; height: 2px;
  opacity: 0.3;
}
.expandable-particle:nth-child(5) {
  bottom: 15%; left: 60%;
  animation: particleDrift2 11s ease-in-out infinite;
  animation-delay: -7s;
}

@keyframes particleDrift1 {
  0%, 100% { transform: translate(0, 0); opacity: 0.3; }
  25% { transform: translate(15px, -20px); opacity: 0.7; }
  50% { transform: translate(-10px, -35px); opacity: 0.4; }
  75% { transform: translate(20px, -15px); opacity: 0.6; }
}

@keyframes particleDrift2 {
  0%, 100% { transform: translate(0, 0); opacity: 0.4; }
  33% { transform: translate(-20px, -15px); opacity: 0.7; }
  66% { transform: translate(10px, -30px); opacity: 0.3; }
}

@keyframes particleDrift3 {
  0%, 100% { transform: translate(0, 0); opacity: 0.2; }
  25% { transform: translate(25px, -10px); opacity: 0.5; }
  50% { transform: translate(-15px, -25px); opacity: 0.7; }
  75% { transform: translate(5px, -40px); opacity: 0.3; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .expandable-peek {
    max-width: 90%;
    padding: var(--space-sm) var(--space-md);
    gap: var(--space-sm);
    border-radius: 12px;
  }

  .expandable.is-expanded .expandable-peek {
    max-width: 100%;
    padding: var(--space-md);
  }

  .expandable-peek-preview {
    display: none;
  }

  .expandable-peek-icon {
    width: 28px;
    height: 28px;
  }

  .expandable-peek-icon svg {
    width: 24px;
    height: 24px;
  }

  .expandable-peek-subtitle {
    display: none;
  }

  .expandable-body > section::before,
  .expandable-body > section::after {
    width: 16px;
    height: 16px;
  }

  .expandable-particles {
    display: none;
  }
}
