/* WaifuHunt Gacha 3D
 * - Stage: persistent WebGL canvas behind hero content (idle visible).
 * - Pull: stage promotes to fullscreen + overlay backdrop / reveal card.
 * - В idle никакие слои не должны блокировать клики (pointer-events: none).
 */

/* ---------- Stage (всегда живой canvas) ---------- */

/* ВАЖНО: .wh-hero-25d имеет class .wh-reveal с transform — это создаёт
   containing block для position:fixed детей и ломает fullscreen pull mode.
   Сбрасываем transform/animation на hero, когда 3D готов. */
body.wh-page-index.is-gacha-3d-ready .wh-hero-25d,
body.wh-page-index.is-gacha-3d-ready .wh-hero-25d.wh-reveal,
body.wh-page-index.is-gacha-3d-ready .wh-hero-25d.wh-reveal.is-visible {
  transform: none !important;
  animation: none !important;
  filter: none !important;
  perspective: none !important;
  opacity: 1 !important;
}

.gacha-3d-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
  contain: size layout paint;
}

body.is-gacha-3d-ready .gacha-3d-stage {
  opacity: 1;
}

.gacha-3d-stage.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9000;
  opacity: 1 !important;
  pointer-events: none;
}

.gacha-3d-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  pointer-events: none;
  background: transparent;
}

/* Гасим старый 2D cabinet-фон когда 3D готов — чтобы canvas был доминирующим
   слоем. Используем повышенную специфичность (3 класса), чтобы перебить
   inline override-блок в index.html. */

body.wh-page-index.is-gacha-3d-ready .wh-hero-25d {
  background:
    linear-gradient(90deg, rgba(5,6,14,0.95), rgba(5,6,14,0.5) 30%, rgba(5,6,14,0.05) 60%, rgba(5,6,14,0.10)),
    radial-gradient(ellipse at 70% 55%, rgba(255,79,163,0.22), transparent 48%),
    radial-gradient(ellipse at 30% 60%, rgba(134,97,255,0.18), transparent 50%),
    radial-gradient(circle at 50% 30%, rgba(255,214,107,0.10), transparent 38%),
    #07091a !important;
}

body.wh-page-index.is-gacha-3d-ready .wh-hero-25d-bg {
  opacity: 0.30 !important;
  filter: brightness(0.55) saturate(1.0) blur(8px) !important;
  transition: opacity 0.6s ease, filter 0.6s ease;
}

body.wh-page-index.is-gacha-3d-ready .wh-hero-25d-cards {
  opacity: 0.5 !important;
}

/* Защита от runaway expand (наблюдалось 16M-pixel hero на production
   из-за feedback loop между grid layout и canvas sizing). Жёстко клампим
   hero высоту через max-height + height: auto. БЕЗ `contain: layout`
   — оно ломает fullscreen pull (создаёт containing block для fixed). */
body.wh-page-index.is-gacha-3d-ready .wh-hero-25d {
  height: auto !important;
  max-height: 100vh !important;
}

body.wh-page-index.is-gacha-3d-ready .wh-hero-content {
  position: relative;
}

/* Pull mode НЕ скрывает hero content через visibility — это рискованно
   (если cleanup упадёт, hero застрянет невидимым). Вместо этого
   используем opaque scene.background на canvas + fullscreen stage,
   что визуально полностью перекрывает hero без disabling его CSS. */

/* ---------- Loading overlay (3D init) ---------- */

.gacha-3d-loading {
  position: fixed;
  inset: 0;
  z-index: 8500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255,79,163,0.18), transparent 45%),
    radial-gradient(ellipse at 50% 55%, rgba(134,97,255,0.16), transparent 55%),
    linear-gradient(180deg, #050610 0%, #07091a 60%, #050610 100%);
  opacity: 1;
  transition: opacity 0.6s ease, visibility 0s linear 0.6s;
  overflow: hidden;
}

body.is-gacha-3d-ready .gacha-3d-loading {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s ease, visibility 0s linear 0.5s;
}

.gacha-3d-loading-orb {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,0.85), rgba(255,79,163,0.85) 35%, rgba(156,102,255,0.55) 70%, transparent 95%);
  box-shadow:
    0 0 60px rgba(255,79,163,0.55),
    0 0 140px rgba(156,102,255,0.45),
    inset 0 0 30px rgba(255,255,255,0.45);
  animation: gacha3dOrbPulse 1.6s ease-in-out infinite;
}

@keyframes gacha3dOrbPulse {
  0%, 100% { transform: scale(0.86); filter: brightness(1); }
  50%      { transform: scale(1.06); filter: brightness(1.25); }
}

.gacha-3d-loading-rings {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.gacha-3d-loading-rings span {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  border: 1px solid rgba(255,79,163,0.32);
  transform: translate(-50%, -50%);
  animation: gacha3dRingExpand 2.4s linear infinite;
}

.gacha-3d-loading-rings span:nth-child(1) {
  width: 140px;
  height: 140px;
  animation-delay: 0s;
}
.gacha-3d-loading-rings span:nth-child(2) {
  width: 220px;
  height: 220px;
  animation-delay: 0.6s;
  border-color: rgba(156,102,255,0.28);
}
.gacha-3d-loading-rings span:nth-child(3) {
  width: 320px;
  height: 320px;
  animation-delay: 1.2s;
  border-color: rgba(255,214,107,0.22);
}

@keyframes gacha3dRingExpand {
  0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0.0; }
  20%  { opacity: 0.85; }
  100% { transform: translate(-50%, -50%) scale(1.4); opacity: 0; }
}

.gacha-3d-loading-label {
  color: rgba(255,255,255,0.92);
  font-size: clamp(14px, 1.6vw, 18px);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-shadow: 0 0 24px rgba(255,79,163,0.5);
  z-index: 1;
}

.gacha-3d-loading-sub {
  color: rgba(255,255,255,0.55);
  font-size: clamp(11px, 1.1vw, 13px);
  letter-spacing: 0.12em;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .gacha-3d-loading-orb,
  .gacha-3d-loading-rings span {
    animation: none;
  }
}

/* Vignette остаётся выше canvas (z-index 2 в существующем стиле) — даёт
   приятную радиальную окантовку поверх 3D. */

/* ---------- Pull overlay: backdrop + reveal ---------- */

.gacha-3d-overlay {
  position: fixed;
  inset: 0;
  z-index: 9100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.32s ease;
  display: block;
  isolation: isolate;
}

.gacha-3d-overlay.hidden {
  display: none;
  pointer-events: none;
}

.gacha-3d-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.gacha-3d-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(7,8,18,0.0) 0%, rgba(5,6,14,0.55) 55%, rgba(2,3,8,0.92) 100%),
    linear-gradient(180deg, rgba(7,8,18,0.32), rgba(5,6,14,0.62) 60%, rgba(3,4,10,0.86) 100%);
  opacity: 0;
  transition: opacity 0.42s ease, backdrop-filter 0.42s ease;
}

.gacha-3d-overlay.is-active .gacha-3d-backdrop {
  opacity: 1;
}

.gacha-3d-overlay.is-revealing .gacha-3d-backdrop {
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* ============================================================
   Reveal card — tarot-style portal по дизайн-прототипу.
   Палитра: --magenta #ff6bd6 / --violet #a040ff / --gold #d4a657
   Шрифты: Cinzel display, Cormorant italic accents, Inter body.
   ============================================================ */
.gacha-3d-reveal-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(420px, 86vw);
  max-height: 88vh;
  transform: translate(-50%, -46%) scale(0.86);
  /* dark obsidian fill + inner purple glow per user spec */
  background:
    radial-gradient(ellipse at 50% 30%, rgba(217, 70, 239, 0.18), transparent 55%),
    linear-gradient(160deg, #1a0d24 0%, #0d0612 60%, #060309 100%);
  /* gold border with inner purple glow */
  border: 1px solid rgba(201, 168, 76, 0.6);
  border-radius: 18px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  box-shadow:
    0 30px 80px rgba(124, 58, 237, 0.40),
    0 0 60px rgba(217, 70, 239, 0.30),
    inset 0 0 0 1px rgba(201, 168, 76, 0.22),
    inset 0 0 60px rgba(124, 58, 237, 0.20);
  display: flex;
  flex-direction: column;
  transition: opacity 0.42s ease, transform 0.5s cubic-bezier(0.2, 1.2, 0.4, 1);
}

.gacha-3d-reveal-card.is-shown {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

/* Tarot card corners — золотые ornaments (#c9a84c) */
.gacha-3d-reveal-card::before,
.gacha-3d-reveal-card::after {
  content: "";
  position: absolute;
  width: 36px;
  height: 36px;
  border: 1.5px solid rgba(201, 168, 76, 0.78);
  pointer-events: none;
  z-index: 2;
}
.gacha-3d-reveal-card::before {
  top: 14px;
  left: 14px;
  border-right: none;
  border-bottom: none;
}
.gacha-3d-reveal-card::after {
  bottom: 14px;
  right: 14px;
  border-left: none;
  border-top: none;
}

.gacha-3d-reveal-img {
  width: 100%;
  height: 280px;
  max-height: 56%;
  object-fit: cover;
  display: block;
  background: radial-gradient(ellipse at 50% 50%, rgba(124, 58, 237, 0.4), rgba(10, 6, 18, 0.95));
  filter: saturate(1.05) brightness(0.95);
  position: relative;
  z-index: 1;
}

.gacha-3d-reveal-copy {
  padding: 22px 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: #e9d8ff;
  position: relative;
  z-index: 1;
  text-align: center;
}

.gacha-3d-reveal-kicker {
  font-family: 'Cinzel', 'Cormorant', Georgia, serif;
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: #c9a84c;
  font-weight: 500;
}

.gacha-3d-reveal-title {
  margin: 2px 0 0;
  font-family: 'Cinzel', Georgia, serif;
  font-size: clamp(24px, 3.2vw, 34px);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #f5d076;
  text-shadow:
    0 0 24px rgba(201, 168, 76, 0.45),
    0 0 60px rgba(124, 58, 237, 0.32);
}

.gacha-3d-reveal-text {
  margin: 6px 0 14px;
  font-family: 'Cormorant', Georgia, serif;
  font-style: italic;
  font-size: 15px;
  line-height: 1.5;
  color: #b69dcf;
}

.gacha-3d-reveal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.gacha-3d-reveal-cta-primary,
.gacha-3d-reveal-cta-secondary {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 11px 22px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform 0.2s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
  user-select: none;
}

.gacha-3d-reveal-cta-primary {
  /* user spec: magenta #d946ef → violet #7c3aed gradient */
  background: linear-gradient(135deg, #d946ef, #7c3aed);
  color: #fff;
  box-shadow: 0 8px 24px rgba(217, 70, 239, 0.4), 0 0 0 1px rgba(217, 70, 239, 0.55) inset;
}
.gacha-3d-reveal-cta-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(217, 70, 239, 0.6), 0 0 0 1px rgba(217, 70, 239, 0.85) inset;
}

.gacha-3d-reveal-cta-secondary {
  background: rgba(124, 58, 237, 0.10);
  color: #e9d8ff;
  border-color: rgba(201, 168, 76, 0.5);
}
.gacha-3d-reveal-cta-secondary:hover {
  background: rgba(124, 58, 237, 0.20);
  border-color: rgba(201, 168, 76, 0.85);
}

@media (max-width: 600px) {
  .gacha-3d-reveal-img { height: 200px; }
  .gacha-3d-reveal-copy { padding: 18px 20px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .gacha-3d-overlay,
  .gacha-3d-backdrop,
  .gacha-3d-reveal-card,
  .gacha-3d-stage {
    transition-duration: 0.18s;
  }
}
