/* 3D layer for the whole exhibit: story, books, dominoes, globe, timeline drum.
   Load after gallery3d.css. */
html,
body {
    overflow-x: clip;
}

.section-intro {
    font-family: var(--serif);
    font-size: clamp(19px, 1.6vw, 23px);
    color: var(--c-ink-3);
    max-width: 38em;
    margin: 28px 0 28px;
}

/* Navigation fits eight sections */
@media (min-width: 901px) and (max-width: 1240px) {
    .menu {
        gap: 18px;
    }

    .menu a {
        font-size: 13px;
    }

    .brand {
        font-size: 21px;
    }
}

/* Hero leans with the cursor */
.hero-copy {
    transform: perspective(1100px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
    transition: transform .4s var(--ease);
    transform-style: preserve-3d;
}

.hero-copy .title {
    transform: translateZ(30px);
}

/* ─── The Idea (story3d.js) ─────────────────────────────────────────── */
.story-track {
    position: relative;
    height: 420vh;
    margin-top: 28px;
    width: 100vw;
    margin-left: calc(50% - 50vw);
}

.story-stage {
    position: sticky;
    top: 68px;
    height: calc(100vh - 68px);
    overflow: hidden;
    background:
        radial-gradient(ellipse at 70% 45%, #22325e 0%, #121a33 55%, #0a0f20 100%);
    color: #f6f4ee;
}

.story-stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.story-steps {
    position: absolute;
    left: max(var(--page-x), calc(50vw - var(--page-max) / 2 + var(--page-x)));
    top: 50%;
    transform: translateY(-50%);
    width: min(430px, 38vw);
    pointer-events: none;
}

.story-step {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-40%);
    opacity: 0;
    transition: opacity .6s var(--ease), transform .6s var(--ease);
}

.story-step.on {
    opacity: 1;
    transform: translateY(-50%);
}

.story-kicker {
    font-size: 11px;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: #d9c38e;
    margin: 0 0 12px;
}

.story-title {
    font-family: var(--serif);
    font-weight: 300;
    font-size: clamp(40px, 4.4vw, 64px);
    line-height: 1.02;
    margin: 0 0 18px;
    color: #fff;
}

.story-text {
    font-family: var(--serif);
    font-size: clamp(18px, 1.55vw, 22px);
    line-height: 1.55;
    color: rgba(246, 244, 238, .86);
    margin: 0;
}

.story-dots {
    position: absolute;
    right: max(20px, calc(50vw - var(--page-max) / 2 + 20px));
    top: 50%;
    transform: translateY(-50%);
    display: grid;
    gap: 14px;
}

.story-dot {
    width: 12px;
    height: 12px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(246, 244, 238, .7);
    background: transparent;
    cursor: pointer;
    transition: transform .2s, background .2s;
}

.story-dot[aria-current="true"] {
    background: #ffcf4d;
    border-color: #ffcf4d;
    transform: scale(1.35);
}

.story-hint {
    position: absolute;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 11px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: rgba(246, 244, 238, .6);
    white-space: nowrap;
    pointer-events: none;
}

.story-stage.no-webgl canvas {
    display: none;
}

/* ─── Reading Room: 3D books ────────────────────────────────────────── */
.shelf {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    justify-items: center;
    gap: 64px 32px;
    padding: 36px 0 24px;
}

.shelf > .status {
    grid-column: 1 / -1;
    justify-self: start;
}

.book3d {
    --w: 300px;
    --d: 0ms;
    position: relative;
    width: var(--w);
    height: 450px;
    perspective: 1500px;
    cursor: pointer;
}

.js .book3d {
    opacity: 0;
    transform: translateY(50px) rotateX(20deg);
    transition: opacity .8s var(--ease) var(--d), transform .8s var(--ease) var(--d);
}

.js .book3d.in {
    opacity: 1;
    transform: none;
}

.book3d::after {
    content: "";
    position: absolute;
    left: 10%;
    right: 10%;
    bottom: -28px;
    height: 24px;
    background: radial-gradient(ellipse at center, rgba(27, 27, 25, .32), transparent 70%);
    transition: transform .4s var(--ease), opacity .4s;
    pointer-events: none;
}

.book3d:hover::after {
    transform: scale(.85);
    opacity: .7;
}

.b3-inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transform: translateZ(var(--lift, 0px)) rotateX(var(--rx, 0deg)) rotateY(calc(var(--ry, 0deg) + var(--flip, 0deg)));
    transition: transform .7s cubic-bezier(.2, .8, .2, 1);
}

.book3d:hover {
    --lift: 30px;
}

.book3d.open {
    --flip: 180deg;
}

.b3-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    padding: 34px 30px 26px;
    border-radius: 2px 6px 6px 2px;
}

.b3-front {
    transform: translateZ(18px);
    background:
        radial-gradient(circle at var(--gx, 30%) var(--gy, 20%), rgba(255, 255, 255, .22), transparent 45%),
        linear-gradient(90deg, rgba(0, 0, 0, .35) 0, rgba(0, 0, 0, 0) 7%, rgba(255, 255, 255, .06) 9%, rgba(0, 0, 0, 0) 12%),
        var(--cover);
    color: #efe2bf;
    box-shadow: inset 0 0 0 10px var(--cover), inset 0 0 0 11px rgba(217, 189, 124, .7), inset 0 0 0 16px var(--cover), inset 0 0 0 17px rgba(217, 189, 124, .45);
    text-align: center;
    align-items: center;
}

.b3-author {
    font-family: var(--serif);
    font-style: italic;
    font-size: 18px;
    margin-top: 18px;
    opacity: .85;
}

.b3-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 36px;
    line-height: 1.05;
    color: #f6ecd0;
    margin: 20px 0 14px;
    text-transform: uppercase;
    letter-spacing: .02em;
    transform: translateZ(0);
}

.b3-sum {
    font-family: var(--serif);
    font-style: italic;
    font-size: 17px;
    line-height: 1.4;
    margin: 0 0 auto;
    opacity: .9;
}

.b3-front .badge {
    background: transparent;
    color: #efe2bf;
    border: 1px solid rgba(239, 226, 191, .6);
    margin: 14px 0 8px;
}

.b3-year {
    font-size: 11px;
    letter-spacing: .18em;
    text-transform: uppercase;
    opacity: .8;
}

.b3-flip {
    margin-top: 14px;
    font: 500 10px var(--sans);
    letter-spacing: .18em;
    text-transform: uppercase;
    color: inherit;
    background: transparent;
    border: 1px solid currentColor;
    padding: 9px 14px;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.b3-front .b3-flip:hover {
    background: #efe2bf;
    color: var(--cover);
}

.b3-back {
    transform: rotateY(180deg) translateZ(18px);
    background: linear-gradient(90deg, #f1ebdc, #fbf8f1 20%);
    color: var(--c-ink-2);
    border-left: 8px solid var(--cover);
    overflow-y: auto;
    padding: 26px 24px 22px;
}

.b3-kicker {
    font-size: 10px;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--c-accent);
    margin: 0 0 6px;
}

.b3-back-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 26px;
    color: var(--c-ink);
    margin: 0 0 10px;
    line-height: 1.1;
}

.b3-body {
    font-size: 14px;
    line-height: 1.6;
    margin: 0 0 10px;
}

.b3-back .exhibit-place {
    font-size: 12px;
    color: var(--c-muted-aa);
    margin: 0;
}

.b3-back .b3-flip {
    align-self: flex-start;
    color: var(--c-ink);
}

.b3-back .b3-flip:hover {
    background: var(--c-ink);
    color: var(--c-bg);
}

.b3-spine {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 36px;
    margin-left: -18px;
    transform: rotateY(-90deg) translateZ(calc(var(--w) / 2));
    background: linear-gradient(90deg, rgba(0, 0, 0, .35), rgba(255, 255, 255, .08) 50%, rgba(0, 0, 0, .35)), var(--cover);
}

.b3-pages {
    position: absolute;
    top: 5px;
    bottom: 5px;
    left: 50%;
    width: 32px;
    margin-left: -16px;
    transform: rotateY(90deg) translateZ(calc(var(--w) / 2 - 5px));
    background: repeating-linear-gradient(90deg, #efe6cf 0 2px, #d8ccae 2px 3px);
}

/* ─── Timeline drum ─────────────────────────────────────────────────── */
.js .timeline .event {
    transform: perspective(1200px) rotateX(var(--tl-rx, 0deg)) translateZ(var(--tl-z, 0px));
    transition: opacity .6s var(--ease), background .3s ease;
    will-change: transform;
}

.js .timeline .event.in {
    opacity: var(--tl-o, 1);
    transform: perspective(1200px) rotateX(var(--tl-rx, 0deg)) translateZ(var(--tl-z, 0px));
}

.timeline .event.focus {
    background: linear-gradient(90deg, var(--c-accent-dim), transparent 70%);
}

.timeline .event.focus .event-year {
    color: var(--c-accent);
}

/* ─── Chain of Influence (chain3d.js) ───────────────────────────────── */
.chain-stage {
    position: relative;
    height: clamp(460px, 74vh, 740px);
    background: #221d18;
    border: 1px solid var(--c-ink);
    overflow: hidden;
}

.chain-stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
}

.chain-hud {
    position: absolute;
    top: 16px;
    left: 16px;
    display: grid;
    gap: 10px;
    justify-items: start;
}

.chain-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chain-hud .btn-ghost,
.journey-stage .btn-ghost {
    color: var(--c-bg);
    border-color: rgba(246, 244, 238, .7);
    background: rgba(27, 27, 25, .35);
}

.chain-slow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: rgba(246, 244, 238, .85);
    background: rgba(27, 27, 25, .45);
    padding: 6px 10px;
    cursor: pointer;
}

.chain-meter {
    --p: 0;
    position: absolute;
    top: 16px;
    right: 16px;
    width: min(260px, 40%);
    height: 34px;
    background: rgba(246, 244, 238, .12);
    border: 1px solid rgba(246, 244, 238, .5);
    overflow: hidden;
}

.chain-meter::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #9b3d3d, #26355d 35%, #b3432f 70%, #a8822e);
    transform: scaleX(var(--p));
    transform-origin: left;
    transition: transform .4s var(--ease);
}

.chain-meter span {
    position: relative;
    display: block;
    text-align: center;
    line-height: 32px;
    font-size: 11px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: #f6f4ee;
}

.chain-card {
    position: absolute;
    left: 16px;
    bottom: 16px;
    width: min(470px, calc(100% - 32px));
    background: var(--c-bg);
    border: 1px solid var(--c-ink);
    padding: 20px 22px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
}

.chain-card:empty {
    display: none;
}

.chain-reason {
    font-family: var(--serif);
    font-style: italic;
    font-size: 17px;
    color: var(--c-accent);
    margin: 0 0 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--c-border);
}

.chain-kicker {
    font-size: 10px;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--c-muted-aa);
    margin: 0 0 6px;
}

.chain-era {
    color: var(--era);
    font-weight: 500;
}

.chain-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 28px;
    color: var(--c-ink);
    margin: 0 0 8px;
    line-height: 1.1;
}

.chain-text {
    font-size: 15px;
    margin: 0 0 10px;
}

.chain-next {
    font-family: var(--serif);
    font-size: 18px;
    line-height: 1.4;
    margin: 0;
    padding: 8px 12px;
    background: var(--c-accent-dim);
    border-left: 3px solid var(--c-accent);
}

.chain-next span {
    font-style: italic;
    color: var(--c-accent);
}

.chain-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 16px;
}

.chain-item {
    display: grid;
    text-align: left;
    background: transparent;
    border: 1px solid var(--c-border);
    border-top: 4px solid var(--era);
    padding: 10px 12px;
    cursor: pointer;
    font-family: var(--sans);
    color: var(--c-ink-2);
    transition: transform .2s var(--ease), background .15s;
}

.chain-item:hover,
.chain-item[aria-current="true"] {
    background: #fff;
    transform: translateY(-3px);
}

.chain-item-year {
    font-family: var(--serif);
    font-size: 24px;
    color: var(--c-ink);
    line-height: 1;
}

.chain-item-title {
    font-size: 13px;
    margin-top: 4px;
}

.chain-stage.no-webgl,
.journey-stage.no-webgl {
    height: auto;
    min-height: 120px;
}

.chain-stage.no-webgl canvas,
.journey-stage.no-webgl canvas {
    display: none;
}

.chain-stage.no-webgl .chain-card {
    position: static;
    width: auto;
}

/* ─── Journey globe (journey3d.js) ──────────────────────────────────── */
.journey-stage {
    position: relative;
    height: clamp(480px, 78vh, 780px);
    background: radial-gradient(ellipse at 60% 50%, #1c2a52 0%, #0b1024 70%);
    border: 1px solid var(--c-ink);
    overflow: hidden;
}

.journey-stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
}

#journey-play {
    position: absolute;
    top: 16px;
    left: 16px;
}

.journey-card {
    position: absolute;
    right: 16px;
    bottom: 16px;
    width: min(380px, calc(100% - 32px));
    background: var(--c-bg);
    border: 1px solid var(--c-ink);
    padding: 20px 22px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .4);
    animation: g3d-in .35s var(--ease);
}

.journey-kicker {
    font-size: 10px;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--c-muted-aa);
    margin: 0 0 4px;
}

.journey-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 34px;
    color: var(--c-ink);
    margin: 0 0 8px;
    line-height: 1.05;
}

.journey-what {
    font-size: 15px;
    margin: 0 0 12px;
}

.journey-why {
    font-family: var(--serif);
    font-size: 18px;
    line-height: 1.4;
    margin: 0;
    padding: 8px 12px;
    background: var(--c-accent-dim);
    border-left: 3px solid var(--c-accent);
}

.journey-why span {
    font-style: italic;
    color: var(--c-accent);
}

.journey-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 14px;
}

.journey-stop {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.journey-stop:hover strong,
.journey-stop[aria-current="true"] strong {
    color: var(--c-accent);
}

.journey-stop[aria-current="true"] .stop-year {
    color: #9b3d3d;
}

/* Archive book leans with the cursor */
.book {
    perspective: 1800px;
}

.spread[data-tilt] {
    transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
    transition: transform .4s var(--ease);
}

/* ─── Small screens ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .story-track {
        height: 380vh;
    }

    .story-stage {
        top: 68px;
    }

    .story-steps {
        left: 20px;
        right: 20px;
        top: auto;
        bottom: 56px;
        width: auto;
        transform: none;
    }

    .story-step,
    .story-step.on {
        top: auto;
        bottom: 0;
        transform: none;
        background: rgba(10, 15, 32, .72);
        padding: 16px 18px;
        backdrop-filter: blur(4px);
    }

    .story-step:not(.on) {
        transform: translateY(12px);
    }

    .story-title {
        font-size: 32px;
        margin-bottom: 8px;
    }

    .story-text {
        font-size: 16px;
    }

    .story-dots {
        right: 14px;
        top: 24px;
        transform: none;
        grid-auto-flow: column;
    }

    .story-hint {
        bottom: 14px;
        width: calc(100% - 40px);
        font-size: 9px;
        text-align: center;
        white-space: normal;
    }
}

@media (max-width: 760px) {
    .shelf {
        grid-template-columns: 1fr;
    }

    .book3d {
        --w: min(300px, calc(100vw - 48px));
    }

    .chain-stage,
    .journey-stage {
        height: auto;
    }

    .chain-stage canvas,
    .journey-stage canvas {
        height: 62vh;
        min-height: 400px;
    }

    .chain-card,
    .journey-card {
        position: static;
        width: auto;
        border: 0;
        border-top: 1px solid var(--c-ink);
        box-shadow: none;
        animation: none;
    }

    .chain-meter {
        top: 10px;
        right: 10px;
        width: 44%;
    }

    .chain-hud {
        top: 56px;
        left: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {

    .hero-copy,
    .spread[data-tilt],
    .b3-inner,
    .story-step,
    .js .book3d {
        transition: none;
    }

    .js .book3d {
        opacity: 1;
        transform: none;
    }

    .journey-card {
        animation: none;
    }
}
