/* Styled YouTube player: markup in src/_includes/video-player.njk, behaviour
   in /js/video-player.js. Control bar ported from the sales deck's video
   slide.

     resting  - title and blurb above a 16:9 frame; the frame shows a poster
                with a solid play button centred on it
     playing  - the poster and play button fall away and the clip runs in the
                frame, with our own control bar standing in for YouTube's

   The control-bar fade (and the scrim over image posters) are neutral
   legibility overlays, not brand gradients. The progress bar is the only
   brand ramp, which R2 allows. */

.video-player {
    container-type: inline-size;
    display: grid;
    grid-template-areas:
        'title'
        'copy'
        'stage';
}

.video-title {
    grid-area: title;
    margin: 0;
    color: var(--text-primary);
    text-wrap: balance;
}

/* Sized like .section-tagline, the site's usual subhead. */
.video-description {
    grid-area: copy;
    max-width: 800px;
    margin: 20px auto 0;
    font-size: 24px;
    line-height: 1.5;
    text-align: center;
    color: var(--text-secondary);
    text-wrap: balance;
}

/* ---------- Frame ---------- */

.video-stage {
    grid-area: stage;
    container-type: inline-size;
    position: relative;
    isolation: isolate;
    aspect-ratio: 16 / 9;
    margin-top: 48px;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface-card);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
}

.video-player.is-live .video-stage {
    cursor: default;
    background: var(--bg-deepest);
}

.video-embed {
    position: absolute;
    inset: 0;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.video-embed iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    /* Backs up the inert attribute: clicks never reach YouTube. */
    pointer-events: none;
}

.video-player.is-live .video-embed,
.video-player.is-fallback .video-embed {
    opacity: 1;
}

/* Autoplay was refused (some mobile browsers), so YouTube's own play button
   is the only way in. See enterFallback() in video-player.js. */
.video-player.is-fallback .video-embed iframe {
    pointer-events: auto;
}

/* ---------- Poster ---------- */

.video-poster {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Only image posters get a scrim, so the play button reads on any photo. */
.video-scrim {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(6, 9, 15, 0.4);
}

.video-poster,
.video-scrim {
    transition: opacity 0.3s ease;
}

.video-player.is-live .video-poster,
.video-player.is-live .video-scrim,
.video-player.is-fallback .video-poster,
.video-player.is-fallback .video-scrim {
    opacity: 0;
    pointer-events: none;
}

/* ---------- Play button ---------- */

/* Sits in the frame's grid cell, dead centre, above the poster. Only the
   button itself takes clicks; everywhere else falls through to the frame. */
.video-cue {
    --play-size: clamp(56px, 8.7cqw, 96px);
    grid-area: stage;
    place-self: center;
    position: relative;
    z-index: 1;
    pointer-events: none;
    transition:
        opacity 0.3s ease,
        visibility 0.3s;
}

.video-play {
    position: relative;
    display: block;
    width: var(--play-size);
    height: var(--play-size);
    border-radius: 50%;
    pointer-events: auto;
    transition: transform 0.25s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Two hairline rings mark the button as the node the poster's lines run
   into. Strokes, not a glow. */
.video-play::before,
.video-play::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    border: 1px solid var(--glow-cyan-40);
    transition:
        inset 0.25s cubic-bezier(0.25, 1, 0.5, 1),
        border-color 0.25s ease;
}

.video-play::before {
    inset: calc(var(--play-size) * -0.16);
}

.video-play::after {
    inset: calc(var(--play-size) * -0.34);
    border-color: var(--glow-cyan-15);
}

.video-play svg {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
}

.video-play circle {
    fill: var(--el-cyan);
    transition: fill 0.2s ease;
}

.video-play path {
    fill: var(--bg-main);
}

.video-stage:hover ~ .video-cue .video-play,
.video-play:hover,
.video-play:focus-visible {
    transform: scale(1.06);
}

.video-stage:hover ~ .video-cue .video-play::after,
.video-play:hover::after,
.video-play:focus-visible::after {
    border-color: var(--glow-cyan-30);
}

.video-stage:hover ~ .video-cue .video-play circle,
.video-play:hover circle,
.video-play:focus-visible circle {
    fill: var(--success);
}

/* Hangs below the button without moving it off centre. */
.video-cue-label {
    position: absolute;
    top: calc(100% + var(--play-size) * 0.34 + 14px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: baseline;
    gap: 8px;
    white-space: nowrap;
}

.video-cue-text {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-primary);
}

.video-length {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* In a small frame the label crowds the poster; the button says enough. */
@container (max-width: 600px) {
    .video-cue-label {
        display: none;
    }
}

.video-player.has-image-poster .video-cue-label {
    padding: 4px 10px;
    border-radius: 4px;
    background: rgba(6, 9, 15, 0.75);
}

/* Between the click and YouTube's first frame the poster and button stay
   put: the triangle gives way to the inner ring turning into a spinner. Once
   the clip is running, poster and button fade out as the video fades in. */
.video-play path {
    transition: opacity 0.2s ease;
}

.video-player.is-loading .video-stage {
    cursor: progress;
}

.video-player.is-loading .video-play path {
    opacity: 0;
}

.video-player.is-loading .video-play::before {
    border: 2px solid transparent;
    border-top-color: var(--el-cyan);
    border-right-color: var(--el-cyan);
    animation: video-play-spin 0.8s linear infinite;
}

@keyframes video-play-spin {
    to {
        transform: rotate(360deg);
    }
}

.video-player.is-live .video-cue,
.video-player.is-fallback .video-cue {
    opacity: 0;
    visibility: hidden;
}

/* ---------- Control bar ---------- */

.video-controls {
    position: absolute;
    z-index: 5;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 40px 16px 12px;
    background: linear-gradient(to top, rgba(6, 9, 15, 0.9) 0%, rgba(6, 9, 15, 0) 100%);
    cursor: default;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.25s ease,
        visibility 0.25s;
}

.video-player.is-live .video-controls {
    opacity: 1;
    visibility: visible;
}

/* Fade the bar once the clip is running and the pointer settles, unless a
   keyboard user is working it. */
.video-player.is-live.is-playing.is-idle .video-controls:not(:has(:focus-visible)) {
    opacity: 0;
}

.video-toggle,
.video-fullscreen {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    padding: 7px;
    background: none;
    border: 0;
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    transition: color 0.2s ease;
}

.video-toggle svg,
.video-fullscreen svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.video-toggle:hover,
.video-fullscreen:hover {
    color: var(--el-cyan);
}

.video-fullscreen[hidden] {
    display: none;
}

.video-toggle .video-toggle-pause,
.video-player.is-playing .video-toggle .video-toggle-play {
    display: none;
}

.video-player.is-playing .video-toggle .video-toggle-pause {
    display: block;
}

/* The hit area is taller than the track it draws. */
.video-scrub {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    touch-action: none;
}

.video-track {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(245, 245, 245, 0.22);
    transition: height 0.2s ease;
}

.video-scrub:hover .video-track,
.video-scrub:focus-visible .video-track,
.video-scrub.is-dragging .video-track {
    height: 6px;
}

.video-progress {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--gradient-cta);
}

.video-time {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ---------- Full screen ---------- */

.video-stage:fullscreen {
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
}

.video-stage:-webkit-full-screen {
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 1024px) {
    .video-description {
        font-size: 20px;
    }

    .video-stage {
        margin-top: 40px;
    }
}

@media (max-width: 768px) {
    .video-title {
        font-size: 32px;
        line-height: 40px;
    }

    .video-stage {
        margin-top: 32px;
    }

    .video-cue-label {
        top: calc(100% + var(--play-size) * 0.2);
    }

    .video-controls {
        gap: 8px;
        padding: 32px 8px 6px;
    }

    .video-time {
        font-size: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .video-player *,
    .video-player *::before,
    .video-player *::after {
        transition-duration: 0s !important;
    }

    /* Slower, but it keeps turning: it's a status, not decoration. */
    .video-player.is-loading .video-play::before {
        animation-duration: 2.4s;
    }
}
