/* ==========================================
   THE DESCENT — Hall of Records
   CSS-3D corridor: sandstone colonnade, torchlight,
   hieroglyph friezes, a golden runner to the sun-disk.
   Reuses style.css tokens; default (no JS) = realm grid.
   ========================================== */

.descent-page {
    --corridor-half: 600px;
    --corridor-rise: 340px;
    /* Egyptian palette */
    --sand:     #c9a25a;
    --sand-lit: #ecce8c;
    --ochre:    #b5762e;
    --torch:    #ff9a45;
    --lapis:    #2a5da8;
    --tomb:     #0b0808;
    min-height: 100%;
}

/* --- Default: hide 3D, show grid --- */
.descent-track,
.descent-viewport,
.descent-ui { display: none; }
.descent-fallback { display: block; }

/* --- Enhanced: 3D on, grid off --- */
.descent-page.enhanced .descent-track,
.descent-page.enhanced .descent-viewport,
.descent-page.enhanced .descent-ui { display: block; }
.descent-page.enhanced .descent-fallback { display: none; }

/* ==========================================
   SCROLL DRIVER + STAGE
   ========================================== */

.descent-track { height: 760vh; pointer-events: none; }

.descent-viewport {
    position: fixed;
    inset: 0;
    z-index: 3;
    overflow: hidden;
    perspective: 880px;
    perspective-origin: 50% 46%;
}

.corridor {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    will-change: transform;
}

/* Tomb darkening that deepens as you descend (JS sets opacity) */
.drain-veil {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: var(--tomb);
    opacity: 0;
}

/* ==========================================
   WALLS — carved sandstone with hieroglyph frieze
   ========================================== */

.wall {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 26000px;
    height: 1480px;
    margin: -740px 0 0 -13000px;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='110' viewBox='0 0 320 110'%3E%3Cg fill='none' stroke='%23c9a84c' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' opacity='0.4'%3E%3Ccircle cx='50' cy='34' r='12'/%3E%3Cpath d='M50 46 V92 M34 60 H66'/%3E%3Cpath d='M138 60 Q160 44 182 60 Q160 76 138 60 Z'/%3E%3Ccircle cx='160' cy='60' r='5'/%3E%3Cpath d='M160 76 q-4 14 -18 14'/%3E%3Ccircle cx='265' cy='54' r='12'/%3E%3Cpath d='M265 30 v-8 M265 86 v8 M241 54 h-8 M289 54 h8'/%3E%3C/g%3E%3C/svg%3E") repeat-x left 32%,
        repeating-linear-gradient(0deg, rgba(0,0,0,0.16) 0 2px, transparent 2px 118px),
        linear-gradient(180deg,
            rgba(201,162,90,0.34) 0%,
            rgba(150,104,52,0.22) 40%,
            rgba(40,26,16,0.4) 72%,
            rgba(12,9,8,0.62) 100%);
    background-size: 300px 100px, auto, auto;
    backface-visibility: hidden;
}

.wall-left  { transform: translateX(calc(var(--corridor-half) * -1)) rotateY(90deg); }
.wall-right { transform: translateX(var(--corridor-half)) rotateY(-90deg); }

/* ==========================================
   FLOOR — slab seams + golden runner to the chamber
   ========================================== */

.floor,
.ceiling {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 26000px;
    height: 1160px;
    margin: -580px 0 0 -13000px;
    backface-visibility: hidden;
}

.floor {
    transform: translateY(var(--corridor-rise)) rotateX(90deg);
    background:
        linear-gradient(180deg,
            rgba(10,7,12,0.6) 0%,
            rgba(181,118,46,0.10) 38%,
            rgba(255,176,86,0.34) 50%,
            rgba(181,118,46,0.10) 62%,
            rgba(10,7,12,0.6) 100%),
        repeating-linear-gradient(90deg, rgba(0,0,0,0.32) 0 3px, transparent 3px 300px);
}

.ceiling {
    transform: translateY(calc(var(--corridor-rise) * -1)) rotateX(-90deg);
    background:
        repeating-linear-gradient(90deg, rgba(0,0,0,0.4) 0 3px, transparent 3px 300px),
        linear-gradient(0deg, rgba(42,93,168,0.12) 0%, rgba(8,5,14,0) 65%);
}

/* ==========================================
   COLONNADE — sandstone columns (built by JS)
   ========================================== */

.column {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 88px;
    height: 740px;
    margin: -370px 0 0 -44px;
    border-radius: 7px 7px 0 0;
    background:
        repeating-linear-gradient(90deg, rgba(0,0,0,0.14) 0 2px, transparent 2px 11px),
        linear-gradient(90deg,
            rgba(46,30,16,0.7) 0%,
            var(--sand) 26%,
            var(--sand-lit) 50%,
            var(--sand) 74%,
            rgba(46,30,16,0.7) 100%);
    box-shadow: inset 0 0 22px rgba(0,0,0,0.45);
    backface-visibility: hidden;
}

.column .cap {
    position: absolute;
    top: -38px; left: -16px; right: -16px;
    height: 50px;
    border-radius: 10px 10px 3px 3px;
    background: linear-gradient(180deg, var(--sand-lit), var(--ochre));
    box-shadow: 0 5px 12px rgba(0,0,0,0.45);
}

.column .cap::before {     /* abacus block atop the capital */
    content: "";
    position: absolute;
    top: -12px; left: 8px; right: 8px;
    height: 12px;
    background: linear-gradient(180deg, var(--sand-lit), var(--ochre));
    border-radius: 3px;
}

.column .base {
    position: absolute;
    bottom: -24px; left: -12px; right: -12px;
    height: 32px;
    border-radius: 4px;
    background: linear-gradient(180deg, var(--sand), #4a3018);
}

/* ==========================================
   TORCHES — flickering wall light (built by JS)
   ========================================== */

.torch {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
    margin: -100px 0 0 -100px;
    border-radius: 50%;
    background: radial-gradient(circle,
        rgba(255,214,150,0.7) 0%,
        rgba(255,140,55,0.38) 34%,
        rgba(255,110,40,0.1) 60%,
        transparent 72%);
    animation: torch-flicker 1.7s ease-in-out infinite;
}

/* brightness-only flicker — opacity is owned by JS (depth fade), transform by JS */
@keyframes torch-flicker {
    0%, 100% { filter: brightness(0.82); }
    28%      { filter: brightness(1.2); }
    52%      { filter: brightness(0.7); }
    78%      { filter: brightness(1.05); }
}

/* ==========================================
   LIVING FLAME — mounted on each column
   (children inherit the column's depth-faded opacity)
   ========================================== */

.flame {
    position: absolute;
    top: 24px;
    left: 50%;
    width: 26px;
    height: 44px;
    margin-left: -13px;
    background: linear-gradient(to top, #ffe06a 0%, #ff9a3c 50%, #ff5a2a 100%);
    clip-path: polygon(50% 0%, 68% 32%, 80% 64%, 64% 88%, 50% 100%, 36% 88%, 20% 64%, 32% 32%);
    transform-origin: 50% 100%;
    filter: drop-shadow(0 0 14px rgba(255,140,50,0.9));
    animation: flame-dance 0.42s ease-in-out infinite alternate;
}

.flame-glow {
    position: absolute;
    top: 2px;
    left: 50%;
    width: 120px;
    height: 120px;
    margin-left: -60px;
    border-radius: 50%;
    background: radial-gradient(circle,
        rgba(255,196,120,0.55) 0%,
        rgba(255,140,55,0.28) 38%,
        transparent 70%);
    animation: flame-glow-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes flame-dance {
    0%   { transform: scaleY(1) scaleX(1) translateY(0) skewX(-3deg) rotate(-1deg); }
    100% { transform: scaleY(1.18) scaleX(0.9) translateY(-3px) skewX(4deg) rotate(2deg); }
}

@keyframes flame-glow-pulse {
    0%   { filter: brightness(0.82); transform: scale(0.96); }
    100% { filter: brightness(1.18); transform: scale(1.08); }
}

/* ==========================================
   DUST MOTES — adrift in the light
   ========================================== */

.motes {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.mote {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,214,150,0.7);
    box-shadow: 0 0 6px rgba(255,180,90,0.6);
    opacity: 0;
    animation-name: mote-drift;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

@keyframes mote-drift {
    0%   { transform: translate(0, 0);        opacity: 0; }
    12%  { opacity: 0.7; }
    88%  { opacity: 0.5; }
    100% { transform: translate(26px, -130px); opacity: 0; }
}

/* ==========================================
   CHAMBER BLOOM — light grows as you approach (JS opacity)
   ========================================== */

.chamber-glow {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(circle at 50% 46%,
        rgba(255,222,160,0.6) 0%,
        rgba(255,176,86,0.3) 7%,
        rgba(255,150,70,0.1) 16%,
        transparent 30%);
}

/* active tablet's sigil breathes */
.panel.is-active .panel-sigil {
    animation: sigil-breathe 2.4s ease-in-out infinite;
}

@keyframes sigil-breathe {
    0%, 100% { filter: drop-shadow(0 0 16px rgba(255,154,69,0.7)); transform: scale(1); }
    50%      { filter: drop-shadow(0 0 28px rgba(255,206,120,1)); transform: scale(1.1); }
}

/* ==========================================
   REALM PANELS — carved stone cartouche tablets
   ========================================== */

.panel {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 460px;
    min-height: 290px;
    margin: -150px 0 0 -230px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2.6rem 2rem;
    text-align: center;
    text-decoration: none;
    color: var(--cosmic-white);
    border: 2px solid var(--sacred-gold);
    border-radius: 10px;
    background:
        radial-gradient(130% 80% at 50% 0%, rgba(255,176,80,0.20), transparent 62%),
        linear-gradient(180deg, #3e2d1a 0%, #2a1e12 58%, #1d150d 100%);
    box-shadow:
        0 26px 60px rgba(0,0,0,0.6),
        inset 0 0 0 4px rgba(12,9,8,0.7),
        inset 0 0 0 6px rgba(255,207,90,0.45),
        inset 0 0 40px rgba(0,0,0,0.4);
    transition: border-color var(--dur-mid) var(--ease-glide),
                box-shadow var(--dur-mid) var(--ease-glide);
    will-change: opacity, filter;
}

.panel[data-depth="1"] { --z: -900px; }
.panel[data-depth="2"] { --z: -1800px; }
.panel[data-depth="3"] { --z: -2700px; }
.panel[data-depth="4"] { --z: -3600px; }
.panel[data-depth="5"] { --z: -4500px; }
.panel[data-depth="6"] { --z: -5400px; }

.panel-left  { transform: translate3d(calc(var(--corridor-half) * -0.7), 0, var(--z)) rotateY(30deg); }
.panel-right { transform: translate3d(calc(var(--corridor-half) *  0.7), 0, var(--z)) rotateY(-30deg); }

.panel:hover,
.panel:focus-visible {
    border-color: #ffe39a;
    box-shadow:
        0 0 44px rgba(255,170,70,0.4),
        inset 0 0 0 4px rgba(12,9,8,0.7),
        inset 0 0 0 6px var(--sacred-gold),
        inset 0 0 40px rgba(0,0,0,0.45);
    outline: none;
}

.panel.is-active {
    border-color: #ffe39a;
    box-shadow:
        0 0 64px rgba(255,176,80,0.5),
        inset 0 0 0 4px rgba(12,9,8,0.7),
        inset 0 0 0 6px var(--sacred-gold),
        inset 0 0 40px rgba(0,0,0,0.4);
}

.panel:focus-visible { outline: 2px solid var(--cosmic-white); outline-offset: 4px; }

.panel-sigil {
    color: var(--sacred-gold);
    font-size: 3rem;
    line-height: 1;
    filter: drop-shadow(0 0 16px rgba(255,154,69,0.7));
}

.panel-name {
    font-family: 'Cinzel', serif;
    font-size: 1.55rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--sacred-gold);
}

.panel-line {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.18rem;
    line-height: 1.5;
    color: var(--warm-peach);
    opacity: 0.92;
    max-width: 22ch;
}

/* ==========================================
   THE CHAMBER LIGHT — radiant sun-disk
   ========================================== */

.void-ember {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff6dc 0%, var(--sacred-gold) 32%, var(--golden-orange) 62%, transparent 76%);
    box-shadow: 0 0 70px 24px rgba(255,176,80,0.55), 0 0 150px 60px rgba(255,207,90,0.32);
    transform: translateZ(-6300px);
    animation: ember-breathe 4.5s var(--ease-glide) infinite;
}

/* sun rays */
.void-ember::before {
    content: "";
    position: absolute;
    inset: -70px;
    border-radius: 50%;
    background: repeating-conic-gradient(from 0deg,
        rgba(255,207,90,0.55) 0deg 3deg, transparent 3deg 13deg);
    -webkit-mask: radial-gradient(circle, transparent 32%, #000 36%, #000 66%, transparent 70%);
            mask: radial-gradient(circle, transparent 32%, #000 36%, #000 66%, transparent 70%);
    animation: ray-spin 50s linear infinite;
}

@keyframes ember-breathe {
    0%, 100% { transform: translateZ(-6300px) scale(1);    opacity: 0.92; }
    50%      { transform: translateZ(-6300px) scale(1.28); opacity: 1; }
}

@keyframes ray-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ==========================================
   THE DOOR AT THE END — an arch the ember shines through
   ========================================== */

.beyond-door {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 360px;
    height: 520px;
    margin: -300px 0 0 -180px;     /* sit on the floor, arch up */
    transform: translateZ(-6150px);
    border: 7px solid var(--sacred-gold);
    border-bottom: none;
    border-radius: 180px 180px 0 0;
    background: linear-gradient(180deg, rgba(255,207,90,0.06), rgba(12,9,8,0.0));
    box-shadow:
        0 0 60px rgba(255,176,80,0.5),
        inset 0 0 60px rgba(255,176,80,0.35);
    text-decoration: none;
}

/* doorway frame inner trim */
.beyond-door::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 1px solid rgba(255,222,160,0.6);
    border-bottom: none;
    border-radius: 170px 170px 0 0;
}

/* ==========================================
   CROSS-OVER CTA — fades in at the end (JS opacity)
   ========================================== */

.beyond-cta {
    position: absolute;
    left: 50%;
    bottom: 7.5rem;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.95rem 1.8rem;
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--deep-night);
    background: linear-gradient(135deg, var(--sacred-gold), var(--golden-orange));
    border-radius: 50px;
    text-decoration: none;
    box-shadow: 0 0 34px rgba(255,176,80,0.55), 0 12px 30px rgba(0,0,0,0.5);
    opacity: 0;                 /* JS reveals near the chamber */
    pointer-events: none;
    transition: transform var(--dur-mid) var(--ease-out-expo), box-shadow var(--dur-mid) var(--ease-out-expo);
}

.beyond-cta.is-open { pointer-events: auto; }
.beyond-cta:hover { transform: translateX(-50%) translateY(-3px); box-shadow: 0 0 50px rgba(255,200,110,0.7), 0 16px 40px rgba(0,0,0,0.6); }
.beyond-cta:focus-visible { outline: 2px solid var(--cosmic-white); outline-offset: 4px; }

.beyond-cta .cta-sigil { color: var(--deep-night); font-size: 1.3rem; line-height: 0; display: inline-flex; }
.beyond-cta .cta-sigil .sigil { stroke-width: 5; }

/* ==========================================
   FOG — torch-warm haze pinned to the chamber
   ========================================== */

.fog {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    background: radial-gradient(circle at 50% 46%,
        rgba(255,196,110,0.12) 0%,
        rgba(40,26,14,0) 26%,
        rgba(12,8,6,0.22) 72%,
        rgba(8,5,6,0.6) 100%);
}

/* ==========================================
   TITLE + MOUTH / VOID LINES
   ========================================== */

.hall-kicker {
    position: absolute;
    top: 8%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    font-family: 'Cinzel', serif;
    font-size: clamp(0.95rem, 0.7rem + 1.4vw, 1.5rem);
    font-weight: 600;
    letter-spacing: 0.42em;
    text-indent: 0.42em;
    text-transform: uppercase;
    color: var(--sacred-gold);
    text-shadow: 0 0 28px rgba(255,154,69,0.6);
    white-space: nowrap;
    pointer-events: none;
}

.hall-kicker::before,
.hall-kicker::after {
    content: "";
    display: inline-block;
    width: clamp(18px, 5vw, 46px);
    height: 1px;
    vertical-align: middle;
    margin: 0 0.9em;
    background: linear-gradient(90deg, transparent, var(--sacred-gold));
    opacity: 0.7;
}
.hall-kicker::after { transform: scaleX(-1); }

.mouth-line,
.void-line {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    width: min(620px, 84vw);
    text-align: center;
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: var(--text-lead);
    line-height: 1.6;
    color: var(--cosmic-white);
    text-shadow: 0 0 24px rgba(0,0,0,0.8);
    pointer-events: none;
}

.mouth-line { bottom: 15%; }
.void-line  { top: 30%; transform: translate(-50%, -50%); opacity: 0; color: var(--sand-lit); }

/* ==========================================
   FIXED UI
   ========================================== */

.descent-ui { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
.descent-ui a { pointer-events: auto; }

.skip-link {
    position: absolute;
    top: 1.6rem; right: 1.8rem;
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--warm-peach);
    text-decoration: none;
    opacity: 0.7;
    transition: color var(--dur-fast) ease, opacity var(--dur-fast) ease;
}
.skip-link:hover, .skip-link:focus-visible { color: var(--sacred-gold); opacity: 1; }

.progress {
    position: absolute;
    left: 0; bottom: 0;
    width: 100%; height: 2px;
    background: rgba(255,207,90,0.12);
}
.progress-bar {
    display: block;
    height: 100%; width: 100%;
    transform: scaleX(0);
    transform-origin: left center;
    background: linear-gradient(90deg, var(--ochre), var(--sacred-gold));
    box-shadow: 0 0 12px rgba(255,154,69,0.7);
    will-change: transform;
}

.scroll-hint {
    position: absolute;
    bottom: 2.2rem; left: 50%;
    transform: translateX(-50%);
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--warm-peach);
    opacity: 0.7;
    animation: hint-float 3.2s ease-in-out infinite;
}
@keyframes hint-float {
    0%, 100% { transform: translate(-50%, 0); }
    50%      { transform: translate(-50%, -6px); }
}

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* ==========================================
   FALLBACK GRID (the realm hub)
   ========================================== */

.descent-fallback {
    position: relative;
    z-index: 2;
    max-width: 900px;
    margin: 0 auto;
    padding: 14vh 6vw 12vh;
    text-align: center;
}
.fallback-title {
    font-family: 'Cinzel', serif;
    font-size: var(--text-hero);
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--cosmic-white);
    text-shadow: 0 0 24px var(--golden-orange);
    margin-bottom: 0.6rem;
}
.fallback-sub {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: var(--text-lead);
    color: var(--warm-peach);
    margin-bottom: 3rem;
    opacity: 0.9;
}

/* ==========================================
   GUARDS — force fallback on mobile / reduced-motion
   ========================================== */

@media (prefers-reduced-motion: reduce) {
    .descent-page.enhanced .descent-track,
    .descent-page.enhanced .descent-viewport,
    .descent-page.enhanced .descent-ui { display: none; }
    .descent-page.enhanced .descent-fallback { display: block; }
    .void-ember, .void-ember::before, .scroll-hint, .torch,
    .flame, .flame-glow, .mote { animation: none; }
}

@media (max-width: 820px), (pointer: coarse) {
    .descent-page.enhanced .descent-track,
    .descent-page.enhanced .descent-viewport,
    .descent-page.enhanced .descent-ui { display: none; }
    .descent-page.enhanced .descent-fallback { display: block; }
}
