/* ==========================================================================
   Weekend English — The hero film
   --------------------------------------------------------------------------
   A 16-second explainer drawn by code. CSS owns the layout of every scene;
   js/film.js owns time. seek(t) only ever writes transforms, opacity, a few
   custom properties and the sheet's clip-path, so the same frame comes out
   whether you play, pause or drag the scrubber.

   Everything inside the stage is sized in --u, a container-relative unit:
   1cqi on the landscape stage, 2.1cqi on the portrait one used on phones.
   That keeps the composition identical at every width instead of reflowing.
   ========================================================================== */

.film {
    margin-top: clamp(2.5rem, 5vw, 4rem);
}

/* The frame is a size container too, so the stage's own declarations (font
   size, dot grid) can use container units: an element's cqi always refers to
   its nearest container ancestor, never to itself. */
.film__frame {
    container-type: inline-size;
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--paper-raised);
    box-shadow: var(--lift-lg);
    overflow: hidden;
}

.film__bar {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--rule);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-mute);
}

.film__dots {
    display: inline-flex;
    gap: 6px;
}

.film__dots i {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--rule-strong);
}

.film__chapter {
    flex: 1;
    min-width: 0;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 480px) {
    .film__frameno {
        display: none;
    }
}

.film__frameno {
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Stage
   -------------------------------------------------------------------------- */

.film__stage {
    --u: 1cqi;
    position: relative;
    aspect-ratio: 16 / 9;
    container-type: inline-size;
    overflow: hidden;
    background-color: var(--paper-sunk);
    background-image: radial-gradient(color-mix(in srgb, var(--rule-strong) 55%, transparent) 1px, transparent 1.2px);
    background-size: calc(2.4 * var(--u)) calc(2.4 * var(--u));
    background-position: center;
    font-size: calc(1.5 * var(--u));
    line-height: 1.35;
    color: var(--ink-body);
    user-select: none;
}

@media (max-width: 760px) {
    .film__frame {
        max-width: 30rem;
        margin-inline: auto;
    }

    .film__stage {
        --u: 2.1cqi;
        aspect-ratio: 4 / 5;
    }
}

/* The morphing sheet. Two clipped layers (an edge and a face) instead of one
   element with a border, because clip-path would cut the border off. The
   wrapper's drop-shadow is applied after the clip, so it follows the shape. */
.film__sheet-wrap {
    position: absolute;
    inset: 0;
    filter: drop-shadow(0 calc(1.2 * var(--u)) calc(1.6 * var(--u)) light-dark(rgba(20, 18, 15, 0.14), rgba(0, 0, 0, 0.55)));
    pointer-events: none;
}

.film__sheet-edge,
.film__sheet {
    position: absolute;
    inset: 0;
    clip-path: inset(50% 50% 50% 50%);
}

.film__sheet-edge {
    --bz: 0;
    background: color-mix(in srgb, light-dark(#1a1815, #2f2b26) calc(var(--bz) * 100%), var(--rule));
}

.film__sheet {
    background: var(--paper-raised);
}

/* --------------------------------------------------------------------------
   Scenes: each is positioned where its sheet should land. film.js measures
   these boxes (and their border-radius) to drive the sheet morph, so the
   layout lives in exactly one place.
   -------------------------------------------------------------------------- */

.scene {
    position: absolute;
    border-radius: calc(1.4 * var(--u));
    opacity: 0;
}

.scene--call { left: 19%; right: 19%; top: 8%;  bottom: 21%; }
.scene--tx   { left: 21%; right: 21%; top: 6%;  bottom: 19%; }
.scene--ex   { left: 7%;  right: 7%;  top: 8%;  bottom: 21%; }
.scene--pub  { left: 31%; width: 22%; top: 5%;  bottom: 5%; border-radius: calc(3.4 * var(--u)); }

@media (max-width: 760px) {
    .scene--call { left: 6%; right: 6%; top: 7%; bottom: 24%; }
    .scene--tx   { left: 6%; right: 6%; top: 5%; bottom: 20%; }
    .scene--ex   { left: 6%; right: 6%; top: 5%; bottom: 20%; }
    .scene--pub  { left: 20%; width: 60%; top: 4%; }
}

/* Every animated element starts hidden; seek() sets the real values. */
[data-k] {
    will-change: transform, opacity;
}

/* --------------------------------------------------------------------------
   Scene 1 · the lesson
   -------------------------------------------------------------------------- */

.fcall {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: calc(1.4 * var(--u));
    padding: calc(1.8 * var(--u));
}

.fcall__bar {
    display: flex;
    align-items: center;
    gap: calc(0.8 * var(--u));
    font-weight: 500;
    color: var(--ink);
}

.fcall__live {
    width: calc(0.8 * var(--u));
    height: calc(0.8 * var(--u));
    border-radius: 50%;
    background: var(--signal);
}

.fcall__title {
    flex: 1;
}

.fcall__timer {
    font-family: var(--font-mono);
    font-size: calc(1.3 * var(--u));
    color: var(--ink-mute);
    font-variant-numeric: tabular-nums;
}

.fcall__tiles {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: calc(1.2 * var(--u));
}

.fcall__tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(0.8 * var(--u));
    border-radius: calc(1 * var(--u));
    background: var(--paper-sunk);
    border: 1px solid var(--rule);
}

.favatar {
    display: grid;
    place-items: center;
    width: calc(5.6 * var(--u));
    height: calc(5.6 * var(--u));
    border-radius: 50%;
    font-family: var(--font-display);
    font-size: calc(2.4 * var(--u));
    color: #fff;
}

.favatar--c { background: light-dark(#14120f, #3d3934); }
.favatar--m { background: var(--blue); color: var(--on-blue); }

.fcall__name {
    font-size: calc(1.25 * var(--u));
    color: var(--ink-mute);
}

.fwave {
    display: flex;
    align-items: center;
    gap: calc(0.35 * var(--u));
    height: calc(3.6 * var(--u));
}

.fwave i {
    width: calc(0.5 * var(--u));
    height: 100%;
    border-radius: 99px;
    background: var(--ink-mute);
    transform: scaleY(0.12);
}

.fwave[data-wave='m'] i {
    background: var(--blue);
}

.fcall__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--u);
}

.fpill {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.35em 0.8em;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: calc(1.05 * var(--u));
    letter-spacing: 0.04em;
}

.fpill--rec {
    color: var(--signal);
    background: var(--signal-wash);
}

.fpill--rec::before {
    content: '';
    width: 0.6em;
    height: 0.6em;
    border-radius: 50%;
    background: currentColor;
}

.fcall__end {
    padding: 0.45em 1.1em;
    border-radius: 999px;
    background: var(--signal);
    color: #fff;
    font-size: calc(1.2 * var(--u));
    font-weight: 500;
}

.fcall__ended {
    position: absolute;
    left: 50%;
    top: 46%;
    translate: -50% -50%;
    padding: 0.5em 1.1em;
    border-radius: calc(0.8 * var(--u));
    background: var(--ink);
    color: var(--paper);
    font-family: var(--font-display);
    font-size: calc(2.4 * var(--u));
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Scene 2 · the transcript
   -------------------------------------------------------------------------- */

.ftx {
    position: absolute;
    inset: 0;
    padding: calc(2.2 * var(--u)) calc(2.4 * var(--u));
    display: flex;
    flex-direction: column;
    gap: calc(1.45 * var(--u));
}

.ftx__head {
    font-family: var(--font-mono);
    font-size: calc(1.05 * var(--u));
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-mute);
    padding-bottom: calc(0.6 * var(--u));
    border-bottom: 1px solid var(--rule);
}

.ftx__line {
    font-family: var(--font-display);
    font-size: calc(1.95 * var(--u));
    color: var(--ink);
    transition: none;
}

.ftx__line b {
    display: inline-block;
    min-width: calc(8.4 * var(--u));
    font-family: var(--font-mono);
    font-size: calc(0.95 * var(--u));
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--blue);
}

.ftx__line[data-who='c'] b {
    color: var(--ink-mute);
}

.ftx__line mark {
    --hl: 0;
    color: inherit;
    background: linear-gradient(color-mix(in srgb, var(--signal) 26%, transparent), color-mix(in srgb, var(--signal) 26%, transparent)) no-repeat 0 85% / calc(var(--hl) * 100%) 45%;
    border-radius: 2px;
}

.ftx__line mark.is-good {
    background-image: linear-gradient(color-mix(in srgb, var(--moss) 30%, transparent), color-mix(in srgb, var(--moss) 30%, transparent));
}

.ftx__note {
    margin-top: auto;
    font-family: var(--font-mono);
    font-size: calc(1.05 * var(--u));
    letter-spacing: 0.06em;
    color: var(--blue);
}

@media (max-width: 760px) {
    .ftx__line {
        font-size: calc(1.7 * var(--u));
    }

    .ftx__line b {
        display: block;
    }
}

/* --------------------------------------------------------------------------
   Scene 3 · the exercises written from the learner's sentences
   -------------------------------------------------------------------------- */

.fex {
    position: absolute;
    inset: 0;
    padding: calc(2.2 * var(--u));
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: calc(1.6 * var(--u));
    align-items: center;
}

.fex__card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: calc(1 * var(--u));
    min-height: calc(22 * var(--u));
    padding: calc(1.8 * var(--u)) calc(1.6 * var(--u));
    border-radius: calc(0.9 * var(--u));
    border: 1px solid var(--rule);
    background: var(--paper-raised);
    box-shadow: 0 calc(0.5 * var(--u)) calc(1.6 * var(--u)) light-dark(rgba(20, 18, 15, 0.08), rgba(0, 0, 0, 0.4));
}

.fex__src {
    align-self: flex-start;
    padding: 0.25em 0.75em;
    border-radius: 99px;
    background: var(--blue-wash);
    color: var(--blue);
    font-family: var(--font-mono);
    font-size: calc(0.95 * var(--u));
    letter-spacing: 0.04em;
}

.fex__kind {
    font-family: var(--font-mono);
    font-size: calc(1 * var(--u));
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-mute);
}

.fex__q,
.fex__prompt {
    font-size: calc(1.3 * var(--u));
    color: var(--ink-body);
}

.fex__q {
    font-family: var(--font-display);
    font-size: calc(1.6 * var(--u));
    line-height: 1.45;
    color: var(--ink);
}

.fex__gap {
    display: inline-block;
    min-width: calc(5.5 * var(--u));
    border-bottom: calc(0.2 * var(--u)) solid var(--blue);
    text-align: center;
    color: var(--blue);
}

.fex__gap span {
    display: inline-block;
}

.fex__opts {
    display: flex;
    gap: calc(0.6 * var(--u));
    margin-top: auto;
}

.fex__opts i,
.fex__tokens i {
    font-style: normal;
    font-family: var(--font-display);
    padding: 0.3em 0.6em;
    border: 1px solid var(--rule-strong);
    border-radius: calc(0.5 * var(--u));
    background: var(--paper-raised);
    white-space: nowrap;
}

.fex__opts i {
    font-size: calc(1.25 * var(--u));
}

.fex__opts i[data-k] {
    --on: 0;
    border-color: color-mix(in srgb, var(--moss) calc(var(--on) * 100%), var(--rule-strong));
    background: color-mix(in srgb, var(--moss-wash) calc(var(--on) * 100%), var(--paper-raised));
    color: color-mix(in srgb, var(--moss) calc(var(--on) * 100%), var(--ink));
}

.fex__tokens {
    display: flex;
    flex-wrap: nowrap;
    column-gap: calc(0.5 * var(--u));
    margin-top: auto;
}

.fex__tokens i {
    font-size: calc(1.15 * var(--u));
    color: var(--ink);
    box-shadow: 0 calc(0.2 * var(--u)) 0 var(--rule);
}

.fex__typed {
    margin-top: auto;
    min-height: calc(2.8 * var(--u));
    padding: calc(0.6 * var(--u)) calc(0.8 * var(--u));
    border: 1px solid var(--rule-strong);
    border-radius: calc(0.5 * var(--u));
    background: var(--paper);
    font-family: var(--font-display);
    font-size: calc(1.4 * var(--u));
    color: var(--ink);
}

.fex__caret {
    display: inline-block;
    width: 1px;
    height: 1.1em;
    margin-left: 1px;
    vertical-align: text-bottom;
    background: var(--blue);
    animation: caret 1s steps(1) infinite;
}

@keyframes caret {
    50% { opacity: 0; }
}

@media (max-width: 760px) {
    .fex {
        grid-template-columns: 1fr;
        align-content: center;
        gap: calc(0.9 * var(--u));
        padding: calc(1.6 * var(--u));
    }

    .fex__card {
        min-height: 0;
        gap: calc(0.6 * var(--u));
        padding: calc(1.1 * var(--u)) calc(1.3 * var(--u));
    }

    .fex__q {
        font-size: calc(1.45 * var(--u));
    }

    .fex__prompt {
        display: none;
    }
}

/* --------------------------------------------------------------------------
   Scene 4 · on the learner's phone
   -------------------------------------------------------------------------- */

.fpub {
    position: absolute;
    inset: calc(0.7 * var(--u));
    padding: calc(4.2 * var(--u)) calc(1.4 * var(--u)) calc(1.4 * var(--u));
    display: flex;
    flex-direction: column;
    gap: calc(1.2 * var(--u));
    border-radius: calc(2.8 * var(--u));
}

.fpub__notch {
    position: absolute;
    top: calc(1.3 * var(--u));
    left: 50%;
    width: 32%;
    height: calc(1.6 * var(--u));
    margin-left: -16%;
    border-radius: 99px;
    background: #0b0a09;
}

.fpub__note {
    display: flex;
    flex-direction: column;
    gap: calc(0.25 * var(--u));
    padding: calc(1.1 * var(--u)) calc(1.2 * var(--u));
    border-radius: calc(1.2 * var(--u));
    background: var(--ink);
    color: var(--paper);
    box-shadow: 0 calc(0.8 * var(--u)) calc(2 * var(--u)) light-dark(rgba(20, 18, 15, 0.25), rgba(0, 0, 0, 0.6));
}

.fpub__app {
    font-family: var(--font-mono);
    font-size: calc(0.85 * var(--u));
    letter-spacing: 0.06em;
    opacity: 0.7;
}

.fpub__note b {
    font-weight: 500;
    font-size: calc(1.25 * var(--u));
    color: inherit;
    line-height: 1.25;
}

.fpub__note span:last-child {
    font-size: calc(1 * var(--u));
    opacity: 0.75;
}

.fpub__list {
    list-style: none;
    display: grid;
    gap: calc(0.7 * var(--u));
}

.fpub__list li {
    display: flex;
    align-items: center;
    gap: calc(0.7 * var(--u));
    padding: calc(0.8 * var(--u)) calc(1 * var(--u));
    border-radius: calc(0.8 * var(--u));
    border: 1px solid var(--rule);
    background: var(--paper-sunk);
    font-size: calc(1.1 * var(--u));
    color: var(--ink);
    line-height: 1.25;
}

.fpub__list i {
    flex-shrink: 0;
    width: calc(0.9 * var(--u));
    height: calc(0.9 * var(--u));
    border-radius: 50%;
    background: var(--blue);
}

.fpub__zero {
    position: absolute;
    left: calc(100% + 5 * var(--u));
    top: 26%;
    width: calc(34 * var(--u));
    display: flex;
    align-items: center;
    gap: calc(1.6 * var(--u));
}

.fpub__num {
    font-family: var(--font-display);
    font-size: calc(13 * var(--u));
    line-height: 0.8;
    color: var(--blue);
    font-variant-numeric: tabular-nums;
}

.fpub__unit {
    font-family: var(--font-display);
    font-size: calc(2 * var(--u));
    line-height: 1.2;
    color: var(--ink);
}

@media (max-width: 760px) {
    .fpub__zero {
        left: 50%;
        top: calc(100% + 2.4 * var(--u));
        width: max-content;
        translate: -50% 0;
        gap: calc(1 * var(--u));
    }

    .fpub__num {
        font-size: calc(7 * var(--u));
    }

    .fpub__unit {
        font-size: calc(1.5 * var(--u));
    }
}

/* --------------------------------------------------------------------------
   Subtitle track: words are spans so seek() can lift them in one by one.
   -------------------------------------------------------------------------- */

.film__caption {
    position: absolute;
    left: 6%;
    right: 6%;
    bottom: 5.5%;
    text-align: center;
    font-family: var(--font-display);
    font-size: calc(1.9 * var(--u));
    line-height: 1.25;
    color: var(--ink);
    text-wrap: balance;
}

.film__caption .cw {
    display: inline-block;
    white-space: pre;
}

/* In the last scene the phone sits where the subtitle would, so the line
   moves beside it, under the zero. */
@media (min-width: 761px) {
    .film__caption.is-side {
        left: 58%;
        right: 6%;
        top: 58%;
        bottom: auto;
        text-align: left;
    }
}

@media (max-width: 760px) {
    .film__caption {
        bottom: 4%;
        font-size: calc(1.75 * var(--u));
    }

    .scene--pub {
        bottom: 30%;
    }
}

/* Without JavaScript there is no clock, so show the final frame as a still
   and drop the controls that would do nothing. */
html:not(.js) .scene:not(.scene--pub),
html:not(.js) .film__sheet-wrap,
html:not(.js) .film__controls,
html:not(.js) .film__chapters,
html:not(.js) .film__bar {
    display: none;
}

html:not(.js) .scene--pub {
    opacity: 1;
    background: var(--paper-raised);
    border: 0.7cqi solid #1a1815;
}

/* --------------------------------------------------------------------------
   Controls
   -------------------------------------------------------------------------- */

.film__controls {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.film__play {
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    cursor: pointer;
    transition: background-color var(--fast), border-color var(--fast), transform 260ms var(--spring);
}

.film__play:hover {
    background: var(--blue);
    border-color: var(--blue);
    color: var(--on-blue);
}

.film__play:active {
    transform: scale(0.94);
}

.film__play svg {
    width: 1rem;
    height: 1rem;
    grid-area: 1 / 1;
}

.film__play[aria-pressed='true'] .i-play,
.film__play[aria-pressed='false'] .i-pause {
    display: none;
}

.film__scrub {
    --p: 0;
    position: relative;
    flex: 1;
    height: 2.75rem;
    display: flex;
    align-items: center;
}

.film__scrub::before {
    /* track, with a tick at every chapter boundary */
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 99px;
    background:
        repeating-linear-gradient(90deg, transparent 0 calc(100% / 4 - 2px), var(--paper) calc(100% / 4 - 2px) calc(100% / 4)),
        var(--rule);
}

.film__fill {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 99px;
    background: var(--blue);
    transform-origin: left;
    transform: scaleX(var(--p));
    pointer-events: none;
}

.film__scrub input {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    margin: 0;
    background: transparent;
    appearance: none;
    cursor: pointer;
}

.film__scrub input::-webkit-slider-runnable-track {
    height: 3px;
    background: transparent;
}

.film__scrub input::-moz-range-track {
    height: 3px;
    background: transparent;
}

.film__scrub input::-webkit-slider-thumb {
    appearance: none;
    width: 15px;
    height: 15px;
    margin-top: -6px;
    border-radius: 50%;
    background: var(--blue);
    border: 3px solid var(--paper);
    box-shadow: 0 0 0 1px var(--blue);
}

.film__scrub input::-moz-range-thumb {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--blue);
    border: 3px solid var(--paper);
    box-shadow: 0 0 0 1px var(--blue);
}

.film__scrub input:focus-visible {
    outline: none;
}

.film__scrub input:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 1px var(--blue), 0 0 0 5px var(--blue-wash);
}

.film__time {
    font-size: 0.75rem;
    color: var(--ink-mute);
    white-space: nowrap;
}

.film__chapters {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    margin-top: var(--space-3);
    border-top: 1px solid var(--rule);
}

.film__chapters button {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    padding: 0.7rem 0.5rem 0.2rem 0;
    border: 0;
    background: none;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-mute);
    text-align: left;
    cursor: pointer;
    position: relative;
    transition: color var(--fast);
}

.film__chapters button::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0.5rem;
    top: -1px;
    height: 2px;
    background: var(--blue);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform var(--med);
}

.film__chapters button span {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: var(--blue);
}

.film__chapters button:hover,
.film__chapters button[aria-current='true'] {
    color: var(--ink);
}

.film__chapters button[aria-current='true']::before {
    transform: scaleX(1);
}

.film__credit {
    margin-top: var(--space-4);
    font-size: 0.8125rem;
    color: var(--ink-mute);
    max-width: 60ch;
}

@media (max-width: 760px) {
    .film__chapters {
        grid-template-columns: repeat(2, 1fr);
        max-width: 30rem;
        margin-inline: auto;
    }

    .film__controls,
    .film__credit {
        max-width: 30rem;
        margin-inline: auto;
    }

    .film__credit {
        margin-top: var(--space-4);
    }
}
