/* ==========================================================
   TABLE SCENES — the promo recordings staged on a DM's table.
   A scene is a container (cqw = 1% of its width). Every part is
   placed in cqw by the layout; a device sizes its own details in
   em, with 1em = 1/40 of its width, so it scales as one piece.
   Layout --projector: laptop, projector and wall, phone.
   ========================================================== */

.scene {
    container: scene / inline-size;
    position: relative;
}

.scene-stage {
    --ar: 16 / 10;
    position: relative;
    aspect-ratio: var(--ar);
    overflow: hidden;
    isolation: isolate;
    border-radius: 6px;
    background: #120d08;
    box-shadow: var(--shadow-deep), 0 0 0 1px var(--line-strong);
    contain: layout paint;
}

.scene-stage > * {
    position: absolute;
}

.scene video {
    background: #000;
}

/* the width/height attributes reserve the ratio; the device sets the size */
.sc-device video,
.sc-device img {
    height: auto;
}

/* ---- Wall ---- */
.sc-wall {
    inset: 0;
    background: radial-gradient(80% 75% at 66% 24%, #3b2d1f 0%, #251a11 46%, #150f09 100%);
}

.sc-wall::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
    opacity: 0.12;
    mix-blend-mode: overlay;
}

/* ---- Table: planks converge toward a vanishing point above ---- */
.sc-table {
    left: 0;
    right: 0;
    top: var(--table-y, 64%);
    bottom: 0;
    background:
        repeating-conic-gradient(from 180deg at 50% -420%, rgba(0, 0, 0, 0.32) 0deg, rgba(0, 0, 0, 0) 0.14deg 1.9deg, rgba(0, 0, 0, 0.32) 2deg),
        repeating-conic-gradient(from 180deg at 50% -420%, rgba(255, 222, 176, 0.05) 0deg 0.35deg, transparent 0.35deg 0.8deg),
        linear-gradient(180deg, #4b3522 0%, #3b291a 22%, #2b1d12 62%, #1b120b 100%);
}

.sc-table::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 214, 160, 0.2) 0, rgba(255, 214, 160, 0) 0.45cqw, transparent 35%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---- Projection on the wall ---- */
.sc-projection {
    left: var(--px);
    top: var(--py);
    width: var(--pw);
    aspect-ratio: 404 / 540;
    z-index: 1;
    /* the whole picture is light added to the wall: black shows the wall */
    mix-blend-mode: screen;
}

.sc-projection::before {
    /* light spilling on the wall around the picture */
    content: '';
    position: absolute;
    inset: -22% -14%;
    background: radial-gradient(closest-side, rgba(255, 238, 208, 0.11), rgba(255, 238, 208, 0.03) 70%, transparent);
    transition: opacity 0.4s ease;
}

.sc-projection video,
.sc-projection img {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(1.12) contrast(1.06) saturate(1.04);
}

.sc-projection::after {
    /* soft edges, a hot spot in the middle, the wall's grain through the light */
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(70% 70% at 50% 45%, rgba(255, 248, 232, 0.07), transparent 70%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
    box-shadow: inset 0 0 1.4cqw 0.5cqw rgba(21, 15, 9, 0.85);
    opacity: 0.9;
    mix-blend-mode: soft-light;
}

.scene.is-dark .sc-projection::before {
    opacity: 0.25;
}

/* ---- Beam from the lens to the wall ---- */
.sc-beam,
.sc-dust {
    inset: 0;
    z-index: 2;
    pointer-events: none;
    clip-path: polygon(var(--beam));
}

.sc-beam {
    background: radial-gradient(75cqw 60cqw at var(--lens), rgba(255, 241, 214, 0.34), rgba(255, 241, 214, 0.12) 32%, rgba(255, 241, 214, 0.03) 66%, transparent 86%);
    mix-blend-mode: screen;
    animation: beam-flicker 5.5s steps(1, end) infinite;
    transition: opacity 0.35s ease;
}

.scene.is-dark .sc-beam {
    opacity: 0.22;
    animation: none;
}

@keyframes beam-flicker {
    0%, 100% { opacity: 1; }
    12% { opacity: 0.93; }
    13% { opacity: 1; }
    47% { opacity: 0.96; }
    48% { opacity: 1; }
    81% { opacity: 0.92; }
    82% { opacity: 1; }
}

.sc-dust i {
    position: absolute;
    width: 0.32cqw;
    height: 0.32cqw;
    min-width: 2px;
    min-height: 2px;
    border-radius: 50%;
    background: rgba(255, 244, 222, 0.75);
    filter: blur(0.5px);
    opacity: 0;
    animation: mote 16s linear infinite;
}

.sc-dust i:nth-child(1) { left: 58%; top: 58%; animation-delay: 0s; }
.sc-dust i:nth-child(2) { left: 64%; top: 46%; animation-delay: -3s; animation-duration: 19s; }
.sc-dust i:nth-child(3) { left: 52%; top: 40%; animation-delay: -7s; }
.sc-dust i:nth-child(4) { left: 70%; top: 52%; animation-delay: -11s; animation-duration: 21s; }
.sc-dust i:nth-child(5) { left: 61%; top: 34%; animation-delay: -5s; animation-duration: 14s; }
.sc-dust i:nth-child(6) { left: 75%; top: 42%; animation-delay: -9s; }
.sc-dust i:nth-child(7) { left: 55%; top: 50%; animation-delay: -13s; animation-duration: 18s; }
.sc-dust i:nth-child(8) { left: 67%; top: 61%; animation-delay: -2s; animation-duration: 23s; }

@keyframes mote {
    0% { opacity: 0; transform: translate3d(0, 0, 0); }
    15% { opacity: 0.9; }
    50% { opacity: 0.35; }
    85% { opacity: 0.8; }
    100% { opacity: 0; transform: translate3d(2.2cqw, -5cqw, 0); }
}

.sc-lens {
    left: var(--lens-x);
    top: var(--lens-y);
    width: 2.4cqw;
    height: 1.2cqw;
    z-index: 4;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(255, 250, 235, 0.95), rgba(255, 236, 200, 0.45) 45%, transparent);
    mix-blend-mode: screen;
    transition: opacity 0.35s ease;
}

.scene.is-dark .sc-lens {
    opacity: 0.4;
}

/* ---- Devices: 1em = 1/40 of the device's width ---- */
.sc-device {
    left: var(--x);
    top: var(--y);
    width: var(--w);
    font-size: calc(var(--w) / 40);
    z-index: 5;
}

/* Laptop, seen from the DM's chair */
.sc-laptop {
    transform: perspective(180cqw) rotateY(var(--turn, 7deg));
    transform-origin: 50% 100%;
}

.sc-laptop .sc-screen {
    position: relative;
    padding: 0.8em 0.8em 1.5em;
    border-radius: 1.1em 1.1em 0.25em 0.25em;
    background: linear-gradient(180deg, #1d1d22, #0d0d10);
    box-shadow: inset 0 0 0 0.1em #3c3c45, 0 2em 3.5em -0.5em rgba(0, 0, 0, 0.7);
}

.sc-laptop .sc-screen::before {
    /* camera */
    content: '';
    position: absolute;
    top: 0.28em;
    left: 50%;
    width: 0.26em;
    height: 0.26em;
    transform: translateX(-50%);
    border-radius: 50%;
    background: #2b2f3a;
}

.sc-laptop video,
.sc-laptop img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 0.15em;
}

.sc-laptop .sc-screen::after {
    /* glass reflection */
    content: '';
    position: absolute;
    inset: 0.8em 0.8em 1.5em;
    background: linear-gradient(115deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0) 38%);
    pointer-events: none;
}

.sc-laptop-base {
    position: relative;
    height: 1.25em;
    margin: 0 -2.3em;
    background: linear-gradient(180deg, #5a5a63 0%, #34343b 35%, #1c1c21 100%);
    clip-path: polygon(1.5% 0, 98.5% 0, 100% 70%, 98.8% 100%, 1.2% 100%, 0 70%);
}

.sc-laptop-base::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 7em;
    height: 0.4em;
    transform: translateX(-50%);
    border-radius: 0 0 0.4em 0.4em;
    background: #2a2a30;
}

.sc-laptop::after {
    /* the screen's cool light on the table */
    content: '';
    position: absolute;
    left: 8%;
    right: 8%;
    top: 100%;
    height: 7em;
    margin-top: -1em;
    background: radial-gradient(closest-side, rgba(150, 178, 255, 0.16), transparent);
    mix-blend-mode: screen;
    pointer-events: none;
}

/* Projector from behind: light leaves on the far side */
.sc-projector {
    aspect-ratio: 40 / 15;
    z-index: 4;
}

.sc-projector::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 1.6em 1.6em 1.2em 1.2em;
    background:
        linear-gradient(180deg, #67625a 0%, #4a4640 22%, #2d2a26 23%, #1e1c19 100%);
    box-shadow: inset 0 0.15em 0 rgba(255, 255, 255, 0.18), 0 1.6em 2.4em -0.4em rgba(0, 0, 0, 0.75);
}

.sc-projector::after {
    /* vents */
    content: '';
    position: absolute;
    left: 16%;
    right: 30%;
    top: 42%;
    height: 34%;
    border-radius: 0.3em;
    background: repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.6) 0 0.45em, rgba(255, 255, 255, 0.04) 0.45em 1.1em);
}

.sc-projector i {
    position: absolute;
    right: 10%;
    top: 52%;
    width: 0.9em;
    height: 0.9em;
    border-radius: 50%;
    background: #8fd383;
    box-shadow: 0 0 1.2em #8fd383;
}

/* Phone on a little stand */
.sc-phone {
    transform: perspective(120cqw) rotateY(var(--turn, -10deg));
}

.sc-phone .sc-screen {
    position: relative;
    padding: 1.9em;
    border-radius: 6.2em;
    background: #0c0c0f;
    box-shadow: inset 0 0 0 0.35em #43434c, 0 3em 5em -1em rgba(0, 0, 0, 0.75);
}

.sc-phone .sc-screen::before {
    /* dynamic island */
    content: '';
    position: absolute;
    top: 3.4em;
    left: 50%;
    width: 9em;
    height: 2.5em;
    transform: translateX(-50%);
    border-radius: 2em;
    background: #050506;
    z-index: 1;
}

.sc-phone video,
.sc-phone img {
    width: 100%;
    aspect-ratio: 430 / 932;
    object-fit: cover;
    border-radius: 4.4em;
}

.sc-phone::after {
    /* stand */
    content: '';
    position: absolute;
    left: 18%;
    right: 18%;
    top: 92%;
    height: 9em;
    z-index: -1;
    border-radius: 1em 1em 1.6em 1.6em;
    background: linear-gradient(180deg, #5b3f27, #3a2717);
    box-shadow: 0 2em 3em -1em rgba(0, 0, 0, 0.7);
}

/* Candle with a living flame */
.sc-candle {
    left: var(--cx);
    top: var(--cy);
    width: 1.5cqw;
    height: 4.2cqw;
    z-index: 3;
    border-radius: 0.25cqw 0.25cqw 0.15cqw 0.15cqw;
    background: linear-gradient(90deg, #b9a47e, #f1e4c6 42%, #c9b58f);
    box-shadow: 0 0.6cqw 1cqw rgba(0, 0, 0, 0.5);
}

.sc-candle::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 96%;
    width: 0.95cqw;
    height: 1.9cqw;
    margin-left: -0.475cqw;
    border-radius: 50% 50% 46% 46% / 64% 64% 36% 36%;
    background: radial-gradient(ellipse at 50% 72%, #fffbe8 0%, #ffd77a 30%, #ff9a3a 62%, rgba(255, 120, 40, 0) 72%);
    transform-origin: 50% 100%;
    animation: flame 2.2s ease-in-out infinite alternate;
}

.sc-candle::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 100%;
    width: 26cqw;
    height: 26cqw;
    margin: 0 0 -13cqw -13cqw;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(255, 176, 86, 0.2), rgba(255, 176, 86, 0.06) 55%, transparent);
    mix-blend-mode: screen;
    animation: glow 3.3s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes flame {
    0% { transform: scale(1, 1) rotate(-2deg); }
    35% { transform: scale(0.94, 1.08) rotate(2deg); }
    70% { transform: scale(1.04, 0.95) rotate(-1deg); }
    100% { transform: scale(0.97, 1.05) rotate(1.5deg); }
}

@keyframes glow {
    from { opacity: 0.8; }
    to { opacity: 1; }
}

/* Dice */
.sc-die {
    left: var(--x);
    top: var(--y);
    width: var(--w);
    z-index: 6;
    filter: drop-shadow(0 0.5cqw 0.5cqw rgba(0, 0, 0, 0.6));
    transform: rotate(var(--r, 0deg));
}

/* Hand-written labels with arrows */
.sc-label {
    left: var(--x);
    top: var(--y);
    z-index: 7;
    display: flex;
    align-items: center;
    gap: 0.4cqw;
    font-family: var(--font-hand);
    font-size: clamp(14px, 2.1cqw, 27px);
    font-weight: 600;
    line-height: 1;
    color: var(--gold-soft);
    white-space: nowrap;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9);
    pointer-events: none;
}

.sc-label svg {
    width: clamp(26px, 4.6cqw, 60px);
    height: auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.9));
}

.sc-label svg.flip {
    transform: scaleX(-1);
}

/* ---- Controls (scenes and single video cards) ---- */
.sc-toggle,
.sc-play {
    position: absolute;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(237, 199, 138, 0.35);
    background: rgba(15, 11, 7, 0.72);
    color: var(--gold-soft);
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.sc-toggle {
    right: 12px;
    bottom: 12px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
}

.sc-toggle:hover,
.sc-play:hover {
    background: rgba(30, 22, 14, 0.9);
    border-color: var(--gold);
}

.sc-toggle .icon {
    width: 18px;
    height: 18px;
}

.sc-toggle .i-play,
.is-paused .sc-toggle .i-pause {
    display: none;
}

.is-paused .sc-toggle .i-play {
    display: block;
}

.sc-play {
    left: 50%;
    top: 50%;
    display: none;
    gap: 0.6rem;
    padding: 0.85rem 1.4rem;
    transform: translate(-50%, -50%);
    border-radius: 999px;
    font-family: var(--font-display);
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sc-play .icon {
    width: 18px;
    height: 18px;
}

.needs-play .sc-play {
    display: flex;
}

.needs-play .sc-toggle {
    display: none;
}

/* ---- Chapters ---- */
.chapters {
    margin-top: 1.1rem;
}

.chapter-now {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.8rem;
    min-height: 1.6em;
    margin-bottom: 0.9rem;
}

.chapter-title {
    font-family: var(--font-display);
    font-size: 1.12rem;
    font-weight: 400;
    color: var(--ink);
}

.chapter-line {
    font-size: 0.9rem;
    color: var(--ink-dim);
}

.chapter-list {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
    list-style: none;
}

.chapter-list button {
    position: relative;
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.6rem 0.7rem;
    border: 1px solid var(--line);
    background: rgba(34, 26, 18, 0.7);
    color: var(--ink-dim);
    font-size: 0.76rem;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.chapter-list button:hover {
    border-color: var(--line-strong);
    color: var(--ink);
}

.chapter-list button[aria-current="true"] {
    border-color: var(--gold);
    color: var(--gold-soft);
    background: rgba(217, 169, 107, 0.08);
}

.chapter-num {
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--gold);
    opacity: 0.8;
}

.chapter-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: rgba(85, 67, 44, 0.5);
}

.chapter-bar i {
    position: absolute;
    inset: 0;
    background: var(--gold);
    transform: scaleX(var(--p, 0));
    transform-origin: left;
}

/* ==========================================================
   LAYOUT A — projector scene in the Second Screen section
   ========================================================== */
.scene--projector {
    margin-bottom: 2.6rem;
}

.scene--projector .scene-stage {
    --ar: 16 / 10;
    --table-y: 64%;
    --px: 55.1cqw;
    --py: 2cqw;
    --pw: 27.8cqw;
    --lens-x: 69cqw;
    --lens-y: 43.6cqw;
    --lens: 69% 69.8%;
    --beam: 69% 69.8%, 55.1% 62.6%, 55.1% 3.2%, 82.9% 3.2%, 82.9% 62.6%;
}

.scene--projector .sc-laptop { --x: 4cqw; --y: 27.5cqw; --w: 40cqw; }
.scene--projector .sc-projector { --x: 62cqw; --y: 43.2cqw; --w: 14cqw; }
.scene--projector .sc-phone { --x: 87.5cqw; --y: 33.5cqw; --w: 7.2cqw; }
.scene--projector .sc-candle { --cx: 47.4cqw; --cy: 35.6cqw; }
.scene--projector .die-1 { --x: 56cqw; --y: 52.5cqw; --w: 3.4cqw; --r: -12deg; }
.scene--projector .die-2 { --x: 60.4cqw; --y: 54.6cqw; --w: 2.7cqw; --r: 18deg; }
.scene--projector .label-dm { --x: 6cqw; --y: 21.2cqw; }
.scene--projector .label-wall { --x: 36cqw; --y: 8.5cqw; }
.scene--projector .label-phone { --x: 71.5cqw; --y: 52.2cqw; }

/* ==========================================================
   Narrow scenes: taller stage, the wall picture on top
   ========================================================== */
@container scene (max-width: 460px) {
    .scene--projector .scene-stage {
        --ar: 4 / 5;
        --table-y: 62%;
        --px: 30.5cqw;
        --py: 4cqw;
        --pw: 39cqw;
        --lens-x: 83cqw;
        --lens-y: 88.6cqw;
        --lens: 83% 70.9%;
        --beam: 83% 70.9%, 30.5% 44.8%, 30.5% 3.2%, 69.5% 3.2%, 69.5% 44.8%;
    }

    .scene--projector .sc-laptop { --x: 4cqw; --y: 69cqw; --w: 64cqw; --turn: 5deg; }

    .scene--projector .sc-projector { --x: 72cqw; --y: 88cqw; --w: 22cqw; }

    .scene--projector .die-1 { --x: 76cqw; --y: 104cqw; --w: 6.4cqw; }

    .scene--projector .die-2 { --x: 85cqw; --y: 108cqw; --w: 5.2cqw; }

    .scene--projector .label-dm { --x: 6cqw; --y: 60.5cqw; }

    .scene--projector .label-wall { --x: 50cqw; --y: 58cqw; }

    /* the wall is above the label here: point the arrow up */
    .scene--projector .label-wall svg { transform: rotate(-62deg); }

    .scene--projector .sc-phone,
    .scene--projector .sc-candle,
    .scene--projector .label-phone {
        display: none;
    }

    .chapter-list {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
        padding-bottom: 2px;
    }

    .chapter-list li {
        flex: 0 0 9.5rem;
        scroll-snap-align: start;
    }
}

/* ---- Reduced motion: still scenes, nothing drifts ---- */
@media (prefers-reduced-motion: reduce) {
    .sc-dust,
    .sc-candle::before,
    .sc-candle::after {
        animation: none;
    }

    .sc-dust {
        display: none;
    }

    .sc-beam {
        animation: none;
    }
}
