/* ===== อินโทร: ประตูแห่งโชคชะตา ===== */
.gate-intro {
  --g: min(74vmin, 600px, calc((100vh - 230px) / 1.02));
  --g: min(74vmin, 600px, calc((100dvh - 230px) / 1.02));
  display: block; overflow: hidden;
  background:
    radial-gradient(60% 50% at 50% 55%, #3a1577 0%, #1a0840 45%, #07031a 80%);
  transition: opacity .6s ease, visibility .6s;
}
.gate-intro.gone { display: none; }

.vortex { position: absolute; inset: 0; width: 100%; height: 100%; }
.rays {
  position: absolute; inset: -50%;
  background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 210, 255, .10) 0 3deg, transparent 3deg 13deg);
  -webkit-mask: radial-gradient(circle at 50% 50%, #000 0, transparent 45%);
  mask: radial-gradient(circle at 50% 50%, #000 0, transparent 45%);
  animation: spin 90s linear infinite;
}

@keyframes fadeIn { to { opacity: 1; } }

.gate-stage {
  position: relative; z-index: 2; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(4px, 1.5vh, 16px); padding: 16px;
  transition: transform .75s cubic-bezier(.7, 0, .4, 1), opacity .7s ease;
}

/* ---------- หัวเรื่อง ---------- */
.gate-head { text-align: center; opacity: 0; animation: rise 1s ease .2s forwards; margin-bottom: calc(var(--g) * .1); position: relative; z-index: 3; }
.gate-eyebrow { color: #ffc4ef; letter-spacing: .08em; font-size: clamp(.75rem, 2.4vw, .95rem); text-shadow: 0 0 10px var(--pink); }
.gate-title { line-height: 1.15; }
.gate-title span {
  display: inline-block; padding: 0 .1em .2em;
  font-family: "Charm", serif; font-size: clamp(3.2rem, 11vmin, 6rem);
  background: linear-gradient(180deg, #fff 0%, #f1d4ff 35%, #c77dff 70%, #8a3fd1 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: storm 5s linear infinite;
}
.gate-title small { display: block; margin-top: .1em; font-family: "Cinzel Decorative", serif; font-size: clamp(.9rem, 2.6vmin, 1.3rem); letter-spacing: .5em; color: var(--lilac); text-shadow: 0 0 12px #b14cff; }

/* ---------- ประตูและวงเวท ---------- */
.gate { position: relative; width: var(--g); height: calc(var(--g) * .92); perspective: 1300px; transform-style: preserve-3d; flex: none; }
.gate > * { position: absolute; left: 50%; top: 50%; }

.sigil { transform: translate(-50%, -50%); opacity: 0; }
.sigil svg { width: 100%; height: 100%; display: block; }
.sigil.big { width: calc(var(--g) * 1.08); height: calc(var(--g) * 1.08); animation: sigilIn 1s cubic-bezier(.2, .9, .3, 1) .05s forwards; }
.sigil.big svg { animation: spin 70s linear infinite; }
.sigil.mid { width: calc(var(--g) * .78); height: calc(var(--g) * .78); animation: sigilIn 1s cubic-bezier(.2, .9, .3, 1) .2s forwards; }
.sigil.mid svg { animation: spin 40s linear infinite reverse; }
@keyframes sigilIn { from { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(-90deg); } to { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); } }
.sg-line { fill: none; stroke: #e3b3ff; stroke-width: .5; opacity: .75; }
.sg-glow { fill: none; stroke: #ff9ae4; stroke-width: .8; filter: drop-shadow(0 0 2px #ff7ad9); }
.sg-dash { fill: none; stroke: #9fe6ff; stroke-width: .5; stroke-dasharray: 1 2.2; }
.sg-text { fill: #ffe7a8; font-size: 4.6px; letter-spacing: 1.2px; }

.zodiac-ring {
  width: calc(var(--g) * .98); height: calc(var(--g) * .98); transform: translate(-50%, -50%);
  opacity: 0; animation: fadeIn .6s ease .35s forwards;
}
.zodiac-ring text { fill: var(--gold); font-size: 17px; letter-spacing: 4px; font-family: "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", sans-serif; filter: drop-shadow(0 0 5px rgba(245, 201, 107, .9)); }
.zodiac-ring { animation: fadeIn .6s ease .35s forwards, spinC 60s linear infinite; }
@keyframes spinC { from { transform: translate(-50%, -50%) rotate(0); } to { transform: translate(-50%, -50%) rotate(360deg); } }

/* ไพ่โคจรรอบประตู */
.card-orbit { width: 0; height: 0; transform-style: preserve-3d; animation: gateOrbit 26s linear infinite; }
@keyframes gateOrbit { from { transform: rotateX(-10deg) rotateY(0); } to { transform: rotateX(-10deg) rotateY(360deg); } }
.g-card {
  --cw: calc(var(--g) * .1);
  position: absolute; width: var(--cw); height: calc(var(--cw) * 1.6);
  left: calc(var(--cw) / -2); top: calc(var(--cw) * -.8);
  transform: rotateY(var(--a)) translateZ(calc(var(--g) * .47)) translateY(var(--y));
  border-radius: 6px; border: 1.5px solid var(--gold);
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 210, 255, .35), transparent 55%),
    linear-gradient(160deg, #5a2aa8, #1d0b48);
  box-shadow: 0 0 18px rgba(245, 201, 107, .55), inset 0 0 0 2px rgba(20, 8, 50, .8), inset 0 0 0 3px var(--gold-3);
  display: grid; place-items: center; color: #fff3c9; font-size: calc(var(--cw) * .42);
  text-shadow: 0 0 8px var(--gold);
  opacity: 0; animation: fadeIn .8s ease forwards; animation-delay: var(--d);
}

/* ตัวประตู */
.door {
  width: calc(var(--g) * .4); height: calc(var(--g) * .62);
  transform: translate(-50%, -46%) translateZ(1px);
  opacity: 0; animation: doorIn 1.2s cubic-bezier(.2, .9, .3, 1.1) .7s forwards;
}
@keyframes doorIn { from { opacity: 0; transform: translate(-50%, -30%) translateZ(1px) scale(.85); } to { opacity: 1; transform: translate(-50%, -46%) translateZ(1px); } }
.doorway {
  position: absolute; inset: 0; overflow: hidden; perspective: 700px;
  border-radius: 50% 50% 4px 4px / 34% 34% 4px 4px;
  box-shadow:
    0 0 0 calc(var(--g) * .012) var(--gold-3),
    0 0 0 calc(var(--g) * .022) #2a0f4f,
    0 0 0 calc(var(--g) * .03) var(--gold),
    0 0 50px rgba(255, 122, 217, .55), 0 0 120px rgba(177, 76, 255, .5);
}
.door-light {
  position: absolute; inset: -10%;
  background: radial-gradient(ellipse at 50% 60%, #fff 0%, #fff4d6 18%, #ffc4ef 38%, #b14cff 65%, #2a0f4f 90%);
  transition: transform 1.4s ease, filter 1.4s ease;
}
.leaf {
  position: absolute; top: 0; bottom: 0; width: 50%;
  background: linear-gradient(90deg, #2b1452, #1a0b38 60%, #12072a);
  transition: transform 1.5s cubic-bezier(.55, 0, .2, 1);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, .6);
}
.leaf.left { left: 0; transform-origin: 0 50%; }
.leaf.right { right: 0; transform-origin: 100% 50%; background: linear-gradient(270deg, #2b1452, #1a0b38 60%, #12072a); }
.leaf-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.la-frame { fill: none; stroke: var(--gold); stroke-width: 1.4; }
.la-inner { fill: none; stroke: rgba(245, 201, 107, .45); stroke-width: .8; }
.la-moon { fill: none; stroke: #ffe7a8; stroke-width: 1.6; filter: drop-shadow(0 0 3px #f5c96b); }
.la-line { fill: none; stroke: rgba(245, 201, 107, .7); stroke-width: 1; }
.la-gem { fill: #e3b3ff; stroke: #fff; stroke-width: .6; filter: drop-shadow(0 0 4px #ff7ad9); }
.handle {
  position: absolute; top: 52%; width: calc(var(--g) * .03); height: calc(var(--g) * .03); border-radius: 50%;
  border: 2px solid var(--gold); box-shadow: 0 0 8px var(--gold);
}
.leaf.left .handle { right: 12%; }
.leaf.right .handle { left: 12%; }
.seam {
  position: absolute; left: 50%; top: 6%; bottom: 0; width: 3px; margin-left: -1.5px;
  background: linear-gradient(180deg, transparent, #fff 20%, #ffc4ef 60%, transparent);
  box-shadow: 0 0 14px #fff, 0 0 30px #ff7ad9; animation: seam 2s ease-in-out infinite;
}
@keyframes seam { 50% { opacity: .45; } }
.door-arch {
  position: absolute; left: 50%; top: calc(var(--g) * -.07); transform: translateX(-50%);
  white-space: nowrap; font-size: calc(var(--g) * .035); letter-spacing: .3em; color: var(--gold-2);
  text-shadow: 0 0 10px var(--gold);
}
.door-eye { position: absolute; left: 50%; top: 9%; width: 32%; transform: translateX(-50%); z-index: 3; }
.door-eye svg { width: 100%; display: block; overflow: visible; }
.eye-lid { fill: rgba(20, 8, 50, .8); stroke: var(--gold); stroke-width: 1.6; }
.eye-iris { fill: #7ad8ff; filter: drop-shadow(0 0 4px #7ad8ff); animation: look 6s ease-in-out infinite; }
.eye-pupil { fill: #0b0620; animation: look 6s ease-in-out infinite; }
@keyframes look { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-6px); } 60% { transform: translateX(6px); } }
.steps { position: absolute; left: 50%; bottom: calc(var(--g) * -.06); transform: translateX(-50%); width: 140%; }
.steps span { display: block; height: calc(var(--g) * .022); margin: 0 auto 3px; border-radius: 4px; background: linear-gradient(180deg, #6b4fa0, #2a1650); box-shadow: 0 0 20px rgba(177, 76, 255, .5); }
.steps span:nth-child(1) { width: 80%; }
.steps span:nth-child(2) { width: 100%; }

/* มือแตะประตู */
.hand {
  left: 50%; top: 50%; width: calc(var(--g) * .15); overflow: visible;
  opacity: 0; transform-origin: 44% 0;
  transform: translateZ(160px) translate(70%, 150%) rotate(-14deg);
  transition: transform 1.1s cubic-bezier(.3, .8, .3, 1), opacity .5s ease;
  filter: drop-shadow(0 0 8px #fff) drop-shadow(0 0 22px #ff7ad9);
  pointer-events: none;
}
.hand rect, .hand ellipse { fill: url(#handG); stroke: #e3b3ff; stroke-width: 1.2; }
.hand .cuff { fill: #4b1f86; stroke: var(--gold); }
.hand .cuff-line { stroke: var(--gold); stroke-width: 1.4; }
.gate-intro.hand-in .hand { opacity: 1; transform: translateZ(160px) translate(-44%, 6%) rotate(-14deg); }
.gate-intro.tap .hand { transform: translateZ(160px) translate(-44%, 6%) rotate(-14deg) scale(.86); transition-duration: .18s; }
.gate-intro.opening .hand { opacity: 0; transform: translateZ(160px) translate(-44%, 30%) rotate(-14deg) scale(.7); transition-duration: .6s; }

.touch { left: 50%; top: 50%; width: 0; height: 0; transform: translateZ(2px) translateY(calc(var(--g) * .04)); }
.touch i {
  position: absolute; left: -12px; top: -12px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 14px #fff, 0 0 30px #ff7ad9; opacity: 0;
}
.gate-intro.tap .touch i { animation: tapRing .9s ease-out forwards; }
.gate-intro.tap .touch i:nth-child(2) { animation-delay: .12s; }
.gate-intro.tap .touch i:nth-child(3) { animation-delay: .24s; }
@keyframes tapRing { 0% { opacity: 1; transform: scale(.3); } 100% { opacity: 0; transform: scale(6); } }

.gate-flash { position: absolute; inset: 0; z-index: 6; pointer-events: none; opacity: 0; background: radial-gradient(circle at 50% 50%, #fff 0%, #ffe7f7 35%, rgba(255, 196, 239, .6) 60%, transparent 85%); transition: opacity .45s ease; }

/* ---------- ลำดับการเปิด ---------- */
.gate-intro.opening .leaf.left { transform: rotateY(-108deg); }
.gate-intro.opening .leaf.right { transform: rotateY(108deg); }
.gate-intro.opening .seam, .gate-intro.opening .door-eye { opacity: 0; transition: opacity .4s; }
.gate-intro.opening .door-light { transform: scale(1.25); filter: brightness(1.5); }
.gate-intro.opening .rays { animation-duration: 8s; }
.gate-intro.zooming .gate-stage { transform: scale(7); opacity: 0; }
.gate-intro.zooming .gate-flash { opacity: 1; }
.gate-intro.done .gate-flash { opacity: 0; }

@media (max-width: 600px) {
  .gate-intro { --g: min(96vw, calc((100dvh - 220px) / 1.02)); }
}

/* ฟอนต์ Charm: เว้นบรรทัดให้สระบนไม่ชน */
.gate-eyebrow { margin-bottom: .3em; }
.gate-title { line-height: 1.5; }
.gate-title span { padding-top: .15em; }
.gate-title span { padding: .5em .3em .25em; margin-top: -.3em; }
.gate-title span { margin-top: 0; }

/* ===== อินโทร: วงเวทหมุน แล้วเข้าสู่หน้าเข้าสู่ระบบ/สมัคร ===== */
.gate-intro { --g: min(84vmin, 640px); }
.gate { width: var(--g); height: var(--g); }
.gate-core { width: calc(var(--g) * .3); height: calc(var(--g) * .3); transform: translate(-50%, -50%); border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 244, 214, .9), rgba(255, 196, 239, .45) 40%, rgba(177, 76, 255, .2) 65%, transparent 72%);
  opacity: 0; animation: coreIn .8s ease .25s forwards, corePulse 2.4s ease-in-out 1.05s infinite; }
@keyframes coreIn { to { opacity: .85; } }
@keyframes corePulse { 50% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; } }
/* ตอนเปิด: วงเวทเร่งหมุน สว่างขึ้น แล้วซูมเข้าหาแสงกลางวง */
.gate-intro.opening .sigil.big svg { animation-duration: 4s; }
.gate-intro.opening .sigil.mid svg { animation-duration: 2.6s; }
.gate-intro.opening .sigil { filter: drop-shadow(0 0 10px #ff9ae4) brightness(1.4); transition: filter .4s; }
.gate-intro.opening .gate-core { transform: translate(-50%, -50%) scale(1.8); opacity: 1; transition: transform .5s ease; animation: none; }
.gate .gate-core { inset: auto; left: 50%; top: 50%; right: auto; bottom: auto; box-shadow: none; overflow: visible; }
