/* ==========================================================================
   EPIC MOTION: the third animation level, on public pages only.
   Each page opens with its own curtain, titles arrive letter by letter,
   and sections land harder. Nothing here applies unless <html> has .epic.
   ========================================================================== */

.epic {
    --a-epic-blur: 12px;
    --a-epic-side: 240px;
    --a-epic-ease: cubic-bezier(.16, 1, .3, 1);
    --a-epic-spring: cubic-bezier(.3, 1.6, .45, 1);
}

/* Covers the page from the first paint until the curtain exists. */
.epic-cover::after { content: ''; position: fixed; inset: 0; z-index: 94; background: var(--a-bg); }

/* --- Page opener --------------------------------------------------------- */
.a-open { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; overflow: hidden; cursor: pointer; }
.a-open-panels { position: absolute; inset: 0; display: grid; }
.a-open-panels i { display: block; background: var(--a-bg); will-change: transform; }
.a-open-text { position: relative; display: grid; justify-items: center; gap: 12px; padding: 24px; text-align: center; color: var(--a-ink); }
.a-open-brand { font-family: var(--a-head); font-size: 15px; font-weight: 500; letter-spacing: .3em; color: var(--a-accent); animation: a-fade .5s ease both; }
.a-open-name { font-family: var(--a-head); font-size: clamp(52px, 13vw, 170px); font-weight: 700; line-height: 1.25; background: var(--a-title-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; animation: a-open-name .8s var(--a-epic-ease) both; }
.a-open-line { width: min(46vw, 420px); height: 2px; background: var(--a-title-gradient); transform-origin: center; animation: a-open-line .7s var(--a-epic-ease) .1s both; }

.a-open.is-leaving { pointer-events: none; }
.a-open.is-leaving .a-open-text { animation: a-open-text-out .42s ease-in both; }

@keyframes a-open-name { from { opacity: 0; transform: scale(1.5); letter-spacing: .12em; filter: blur(var(--a-epic-blur)); } to { opacity: 1; transform: none; letter-spacing: 0; filter: none; } }
@keyframes a-open-line { from { transform: scaleX(0); } to { transform: none; } }
@keyframes a-open-text-out { to { opacity: 0; transform: scale(.82); filter: blur(var(--a-epic-blur)); } }

/* Home: an iris opens from the middle. */
.a-open[data-mode="iris"] .a-open-panels { display: block; }
.a-open[data-mode="iris"] .a-open-panels i { position: absolute; left: 50%; top: 50%; width: 0; height: 0; border-radius: 50%; background: none; box-shadow: 0 0 0 300vmax var(--a-bg), 0 0 60px 12px var(--a-accent); transform: translate(-50%, -50%); will-change: width, height; }
.a-open[data-mode="iris"].is-leaving .a-open-panels i { animation: a-iris .95s cubic-bezier(.7, 0, .2, 1) .12s forwards; }
@keyframes a-iris { to { width: 260vmax; height: 260vmax; } }

/* Work: tall shutters lift one after another. */
.a-open[data-mode="shutter"] .a-open-panels { grid-template-columns: repeat(7, 1fr); }
.a-open[data-mode="shutter"] .a-open-panels i { margin-right: -1px; transform-origin: top; }
.a-open[data-mode="shutter"].is-leaving .a-open-panels i { animation: a-lift .7s cubic-bezier(.7, 0, .2, 1) calc(var(--n) * 55ms + 120ms) forwards; }
@keyframes a-lift { to { transform: scaleY(0); } }

/* Life: bands slide away in turn, like turning through pages. */
.a-open[data-mode="sweep"] .a-open-panels { grid-template-rows: repeat(8, 1fr); }
.a-open[data-mode="sweep"] .a-open-panels i { margin-bottom: -1px; }
.a-open[data-mode="sweep"].is-leaving .a-open-panels i { animation: a-sweep-l .75s cubic-bezier(.7, 0, .2, 1) calc(var(--n) * 45ms + 120ms) forwards; }
.a-open[data-mode="sweep"].is-leaving .a-open-panels i:nth-child(even) { animation-name: a-sweep-r; }
@keyframes a-sweep-l { to { transform: translateX(-101%); } }
@keyframes a-sweep-r { to { transform: translateX(101%); } }

/* Gallery: a wall of tiles spins away. */
.a-open[data-mode="tiles"] .a-open-panels { grid-template: repeat(4, 1fr) / repeat(6, 1fr); }
.a-open[data-mode="tiles"] .a-open-panels i { margin: 0 -1px -1px 0; }
.a-open[data-mode="tiles"].is-leaving .a-open-panels i { animation: a-tile .62s cubic-bezier(.6, 0, .3, 1) calc(var(--d) * 1ms + 120ms) forwards; }
@keyframes a-tile { to { transform: scale(0) rotate(120deg); } }

/* Profile: two doors part. */
.a-open[data-mode="doors"] .a-open-panels { grid-template-columns: 1fr 1fr; }
.a-open[data-mode="doors"].is-leaving .a-open-panels i { animation: a-sweep-l .9s cubic-bezier(.7, 0, .2, 1) .12s forwards; box-shadow: 2px 0 26px var(--a-accent); }
.a-open[data-mode="doors"].is-leaving .a-open-panels i:last-child { animation-name: a-sweep-r; box-shadow: -2px 0 26px var(--a-accent); }

/* Links: strips fold away from the centre outward. */
.a-open[data-mode="fan"] .a-open-panels { grid-template-columns: repeat(7, 1fr); }
.a-open[data-mode="fan"] .a-open-panels i { margin-right: -1px; }
.a-open[data-mode="fan"].is-leaving .a-open-panels i { animation: a-fold .6s cubic-bezier(.7, 0, .2, 1) calc(var(--d) * 1ms + 120ms) forwards; }
@keyframes a-fold { to { transform: scaleX(0); } }

/* Support: columns rise out of the way with a gold edge. */
.a-open[data-mode="rise"] .a-open-panels { grid-template-columns: repeat(7, 1fr); }
.a-open[data-mode="rise"] .a-open-panels i { margin-right: -1px; }
.a-open[data-mode="rise"].is-leaving .a-open-panels i { box-shadow: 0 6px 22px var(--a-accent); animation: a-rise-out .78s cubic-bezier(.7, 0, .2, 1) calc(var(--d) * 1ms + 120ms) forwards; }
@keyframes a-rise-out { to { transform: translateY(-104%); } }

/* Theme change: the page's own curtain plays backward to close, then opens as usual. */
.a-open-panels i { transition: background-color .25s ease, box-shadow .25s ease; }
.a-open.is-closing { pointer-events: none; }
.a-open[data-mode="iris"].is-closing .a-open-panels i { animation: a-iris .66s cubic-bezier(.7, 0, .2, 1) reverse both; }
.a-open[data-mode="shutter"].is-closing .a-open-panels i { animation: a-lift .46s cubic-bezier(.7, 0, .2, 1) calc(var(--n) * 30ms) reverse both; }
.a-open[data-mode="sweep"].is-closing .a-open-panels i { animation: a-sweep-l .48s cubic-bezier(.7, 0, .2, 1) calc(var(--n) * 24ms) reverse both; }
.a-open[data-mode="sweep"].is-closing .a-open-panels i:nth-child(even) { animation-name: a-sweep-r; }
.a-open[data-mode="tiles"].is-closing .a-open-panels i { animation: a-tile .4s cubic-bezier(.6, 0, .3, 1) calc(var(--d) * .8ms) reverse both; }
.a-open[data-mode="doors"].is-closing .a-open-panels i { animation: a-sweep-l .62s cubic-bezier(.7, 0, .2, 1) reverse both; }
.a-open[data-mode="doors"].is-closing .a-open-panels i:last-child { animation-name: a-sweep-r; }
.a-open[data-mode="fan"].is-closing .a-open-panels i { animation: a-fold .42s cubic-bezier(.7, 0, .2, 1) calc(var(--d) * .8ms) reverse both; }
.a-open[data-mode="rise"].is-closing .a-open-panels i { animation: a-rise-out .46s cubic-bezier(.7, 0, .2, 1) calc(var(--d) * .8ms) reverse both; }
.a-open-theme { font-size: clamp(72px, 14vw, 150px); color: var(--a-accent); filter: drop-shadow(0 0 28px rgba(var(--a-glow), .7)); animation: a-theme-icon .62s var(--a-epic-spring) .3s both; }
@keyframes a-theme-icon { from { opacity: 0; transform: scale(.2) rotate(-160deg); } to { opacity: 1; transform: none; } }

/* --- Particles and the shockwave ----------------------------------------- */
#a-fx { position: fixed; inset: 0; z-index: 96; width: 100%; height: 100%; pointer-events: none; }
.a-ring { position: fixed; z-index: 96; width: 40px; height: 40px; margin: -20px 0 0 -20px; border: 2px solid var(--a-accent); border-radius: 50%; pointer-events: none; animation: a-ring 1.1s var(--a-epic-ease) forwards; }
@keyframes a-ring { from { opacity: .9; transform: scale(.2); } to { opacity: 0; transform: scale(26); } }

/* --- Titles, letter by letter -------------------------------------------- */
.epic .a-hero h1, .epic .a-head h1, .epic .a-error h1 { animation: none; }
.a-chars { perspective: 900px; }
.a-chars-word { display: inline-block; white-space: nowrap; }
.a-char { display: inline-block; transform-origin: 50% 100%; animation: a-char-in .95s var(--a-epic-spring) calc(var(--i) * var(--a-char-gap, 30ms)) both paused; }
.a-chars.is-playing .a-char { animation-play-state: running; }
@keyframes a-char-in {
    from { opacity: 0; transform: translateY(.9em) rotateX(-85deg) scale(.6); filter: blur(var(--a-epic-blur)); }
    to { opacity: 1; transform: none; filter: none; }
}

/* --- Page entrance waits for the curtain --------------------------------- */
.epic .a-hero-status, .epic .a-head > .a-mono, .epic .a-error > .a-mono { animation: a-epic-drop .9s var(--a-epic-ease) .1s both; }
.epic .a-hero .a-lede, .epic .a-head-text, .epic .a-error .a-lede { animation: a-epic-focus 1.1s var(--a-epic-ease) .55s both; }
.epic .a-hero-cta, .epic .a-error .a-btn { animation: a-epic-pop .9s var(--a-epic-spring) .8s both; }
.epic .a-hero-meta { animation: a-epic-focus 1s var(--a-epic-ease) 1s both; }
.epic .a-links-intro { animation: a-epic-side 1.1s var(--a-epic-ease) .1s both; }
.epic .a-nav { animation: a-epic-drop .9s var(--a-epic-ease) .15s backwards; }
.epic #atlas-butterfly { animation: a-epic-wings 1.8s var(--a-epic-ease) .1s both; }
.epic-opening .a-hero-status, .epic-opening .a-head > .a-mono, .epic-opening .a-error > .a-mono,
.epic-opening .a-hero .a-lede, .epic-opening .a-head-text, .epic-opening .a-error .a-lede,
.epic-opening .a-hero-cta, .epic-opening .a-error .a-btn, .epic-opening .a-hero-meta,
.epic-opening .a-links-intro, .epic-opening .a-nav, .epic-opening #atlas-butterfly { animation-play-state: paused; }

@keyframes a-epic-drop { from { opacity: 0; transform: translateY(-60px); } to { opacity: 1; transform: none; } }
@keyframes a-epic-focus { from { opacity: 0; transform: translateY(30px) scale(1.06); filter: blur(var(--a-epic-blur)); } to { opacity: 1; transform: none; filter: none; } }
@keyframes a-epic-pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }
@keyframes a-epic-side { from { opacity: 0; transform: translateX(calc(var(--a-epic-side) * -1)) rotate(-3deg); } to { opacity: 1; transform: none; } }
@keyframes a-epic-wings { from { opacity: 0; transform: scale(.5) rotate(-12deg); } to { opacity: 1; transform: none; } }

/* --- Scroll entrances, each movement pushed further ---------------------- */
.epic [data-rise]:not(.is-done) { transition-duration: 1.1s, 1.35s, 1.1s; transition-timing-function: var(--a-epic-ease); }
.epic [data-rise=""], .epic [data-rise="up"] { transform: translateY(120px) scale(.92); filter: blur(var(--a-epic-blur)); }
.epic [data-rise="left"] { transform: translateX(calc(var(--a-epic-side) * -1)) rotate(-4deg); }
.epic [data-rise="right"] { transform: translateX(var(--a-epic-side)) rotate(4deg); }
.epic [data-rise="zoom"] { transform: translate(var(--ex, 0), var(--ey, 0)) scale(.3) rotate(var(--er, -8deg)); filter: blur(var(--a-epic-blur)); }
.epic [data-rise="flip"] { transform: perspective(900px) rotateX(78deg) translateY(100px); }
.epic [data-rise="blur"] { filter: blur(34px); transform: scale(1.3); }
.epic [data-rise="pop"] { transform: translate(var(--ex, 0), var(--ey, 140px)) scale(.25) rotate(var(--er, 12deg)); }
.epic [data-rise="pop"]:not(.is-done) { transition-timing-function: var(--a-epic-ease), var(--a-epic-spring), var(--a-epic-ease); }

/* The toggle shows which level is on. */
.atlas button#motion-toggle.is-epic { align-self: center; aspect-ratio: 1; height: auto; border-radius: 50%; color: var(--a-on-accent); background: var(--a-title-gradient); box-shadow: 0 0 18px rgba(var(--a-glow), .55) !important; }

/* Phones: shorter travel and no blur, so scrolling stays smooth. */
@media (max-width: 960px) {
    .epic { --a-epic-blur: 0px; --a-epic-side: 70px; }
    .epic [data-rise="blur"] { filter: none; }
    .a-open[data-mode="tiles"] .a-open-panels { grid-template: repeat(6, 1fr) / repeat(4, 1fr); }
    .a-open[data-mode="shutter"] .a-open-panels, .a-open[data-mode="fan"] .a-open-panels, .a-open[data-mode="rise"] .a-open-panels { grid-template-columns: repeat(7, 1fr); }
}
