.unpleat-player {
    --stage-bg: #1a231e;
    position: relative;
    background: var(--stage-bg);
    border-radius: 16px;
    overflow: hidden;
    aspect-ratio: 16 / 10;
    container-type: inline-size;
}

.unpleat-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    font: 500 13px/1.5 "Segoe UI", system-ui, sans-serif;
}

.unpleat-error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: #fde68a;
    font: 500 14px/1.5 "Segoe UI", system-ui, sans-serif;
    text-align: center;
}

.unpleat-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.unpleat-camera {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.unpleat-replay {
    position: relative;
    background: #fff;
}

.unpleat-page {
    position: absolute;
    top: 0;
    left: 0;
}

.unpleat-replay iframe {
    border: 0;
    display: block;
    pointer-events: none;
}

.unpleat-cursor {
    position: absolute;
    width: 22px;
    height: 22px;
    margin: -2px 0 0 -2px;
    pointer-events: none;
    z-index: 4;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.unpleat-spot {
    position: absolute;
    border: 2px solid var(--hl, #b6d36a);
    border-radius: 8px;
    background: var(--hl-fill, rgba(217, 237, 156, 0.14));
    box-shadow: 0 0 0 4px var(--hl-soft, rgba(217, 237, 156, 0.35)), 0 4px 18px rgba(32, 42, 37, 0.12);
    opacity: 0;
    pointer-events: none;
    z-index: 2;
}

/* A callout: the rest of the page dims around the box (the shadow covers the page; the
   stage clips it), with a soft lime ring. Positioned in page coordinates like the spot. */
.unpleat-dim {
    position: absolute;
    border-radius: 10px;
    box-shadow: 0 0 0 3px var(--hl, rgba(182, 211, 106, 0.95)), 0 0 0 4000px rgba(16, 24, 19, 0.5);
    opacity: 0;
    pointer-events: none;
    z-index: 2;
}

/* A dropdown's open list, drawn by the player (browsers draw it outside the page). */
.unpleat-select {
    position: absolute;
    z-index: 3;
    box-sizing: border-box;
    padding: 4px 0;
    background: #fff;
    color: #1f1f1f;
    border: 1px solid #8f8f8f;
    border-radius: 4px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
    font-size: 14px;
    line-height: 1.45;
    text-align: left;
    pointer-events: none;
}

.unpleat-option {
    padding: 0.2em 0.75em;
    white-space: nowrap;
}

.unpleat-option.is-active {
    background: #1a73e8;
    color: #fff;
}

.unpleat-pulse {
    position: absolute;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border-radius: 50%;
    border: 3px solid var(--hl, #b6d36a);
    background: var(--hl-soft, rgba(217, 237, 156, 0.28));
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

.unpleat-caption {
    position: absolute;
    max-width: min(320px, 42%);
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(248, 247, 242, 0.97);
    color: #202a25;
    font: 500 15px/1.4 var(--font-body, "Segoe UI", system-ui, sans-serif);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    z-index: 5;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.unpleat-controls {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(32, 42, 37, 0.8);
    color: #fff;
    z-index: 6;
}

.unpleat-controls button {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    padding: 4px 8px;
}

/* Play / pause and replay: icons. */
.unpleat-controls .unpleat-icon-btn {
    display: grid;
    place-items: center;
    flex: none;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
}
.unpleat-controls .unpleat-icon-btn:hover { background: rgba(255, 255, 255, .14); }
.unpleat-controls .unpleat-icon-btn:focus-visible { outline: 2px solid var(--hl-dark, #d9ed9c); outline-offset: 1px; }
.unpleat-icon-btn svg { width: 18px; height: 18px; }
/* Play/pause in the brand colour (the project's on branded pages), its icon in the readable ink. */
.unpleat-controls .unpleat-toggle { width: 34px; height: 34px; background: var(--brand, #315e47); color: var(--brand-ink, #fff); }
.unpleat-controls .unpleat-toggle:hover { background: var(--brand-hover, #234b36); }
.unpleat-controls .unpleat-toggle svg { fill: currentColor; stroke: none; }
.unpleat-toggle svg { width: 20px; height: 20px; }

.unpleat-seek {
    flex: 1;
    accent-color: var(--hl-dark, #d9ed9c);
}

.unpleat-time {
    font-size: 12px;
    opacity: 0.8;
    min-width: 72px;
    text-align: right;
}

/* Waiting for a voice clip to load: a small spinner beside the time. */
.unpleat-buffering {
    display: none;
    flex: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: var(--hl-dark, #d9ed9c);
    border-radius: 50%;
    animation: unpleat-spin .8s linear infinite;
}
.is-buffering .unpleat-buffering { display: inline-block; }
@keyframes unpleat-spin { to { transform: rotate(360deg); } }

/* Small players (e.g. the editor's preview column): keep captions and controls in proportion. */
@container (max-width: 640px) {
    .unpleat-caption {
        max-width: 60%;
        padding: 7px 10px;
        border-radius: 9px;
        font-size: 12px;
    }

    .unpleat-controls {
        left: 8px;
        right: 8px;
        bottom: 8px;
        gap: 6px;
        padding: 4px 8px;
        font-size: 12px;
    }

    .unpleat-controls button {
        padding: 2px 4px;
    }

    .unpleat-time {
        min-width: 0;
        font-size: 11px;
    }
}

/* Voiceover subtitles, above the controls. */
.unpleat-subtitle {
    position: absolute;
    left: 50%;
    bottom: 72px;
    z-index: 5;
    max-width: 80%;
    padding: 6px 12px;
    border-radius: 6px;
    background: rgba(32, 42, 37, 0.86);
    color: #fff;
    font: 500 17px/1.4 var(--font-body, "Segoe UI", system-ui, sans-serif);
    text-align: center;
    transform: translateX(-50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.unpleat-subtitle.is-visible { opacity: 1; }
/* Pieces are short (see splitCues): even so, never more than three lines. */
.unpleat-subtitle { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; text-wrap: balance; }

.unpleat-controls .unpleat-switch {
    display: inline-flex;
    align-items: center;
    opacity: 0.45;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.unpleat-controls .unpleat-switch.is-on { opacity: 1; }

.unpleat-switch svg {
    width: 18px;
    height: 18px;
}

@container (max-width: 640px) {
    .unpleat-subtitle {
        bottom: 46px;
        max-width: 90%;
        padding: 4px 8px;
        font-size: 12px;
    }

    .unpleat-switch svg {
        width: 15px;
        height: 15px;
    }
}

/* Extra control buttons (share page): speed menu, size, fullscreen. */
.unpleat-controls .unpleat-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    font-size: 12px;
    font-weight: 600;
    opacity: 0.85;
}

.unpleat-controls .unpleat-btn:hover { opacity: 1; }
.unpleat-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.unpleat-rate { position: relative; }

.unpleat-rate-menu {
    position: absolute;
    right: -6px;
    bottom: calc(100% + 14px);
    display: grid;
    min-width: 110px;
    padding: 6px;
    border-radius: 12px;
    background: rgba(22, 28, 25, 0.96);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.unpleat-rate-menu[hidden] { display: none; }
.unpleat-controls .unpleat-rate-menu button { padding: 7px 12px; border-radius: 8px; font-size: 13px; text-align: left; }
.unpleat-controls .unpleat-rate-menu button:hover { background: rgba(255, 255, 255, 0.1); }
.unpleat-controls .unpleat-rate-menu button.is-active { color: var(--hl-dark, #d9ed9c); }

/* Fullscreen: fill the screen; the stage letterboxes the recording. */
.unpleat-player:fullscreen {
    width: 100%;
    height: 100%;
    max-width: none;
    aspect-ratio: auto;
    border-radius: 0;
}

/* Narrow players (phones): drop Replay and keep the time on one line. */
@container (max-width: 480px) {
    .unpleat-controls [data-act=replay] { display: none; }
    .unpleat-time { white-space: nowrap; }
    .unpleat-controls .unpleat-btn { min-width: 24px; }
}

/* No caption, no bubble. */
.unpleat-caption[hidden] { display: none !important; }
