/*
 * Video lessons: a clean video of the animation with real HTML controls on top.
 * Everything inside #lesson-stage is placed in percentages of the original 800x600
 * stage, so it follows the video at any size (and when the stage is turned on phones).
 * --u is one stage unit in CSS pixels; player.js keeps it up to date.
 */
#lesson-stage {
    --u: 1px;
    --nav-boost: 1;
    --tab-boost: 1;
    overflow: hidden;
    background: #000;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
#lesson-stage video,
#lesson-stage .vl-layer {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
}
/* Layers cover the whole stage but only their buttons take taps. */
#lesson-stage .vl-layer { pointer-events: none; }
#lesson-stage .vl-layer button { pointer-events: auto; }
#lesson-stage video { display: block; object-fit: fill; background: #000; pointer-events: none; }
#lesson-stage img { display: block; width: 100%; height: 100%; pointer-events: none; -webkit-user-drag: none; }
#lesson-stage .vl-abs { position: absolute; }
/* 16:9 lessons: the picture is one third wider than the stage and spills over both sides; the screen clips what does not fit. */
#lesson-stage.vl-wide { overflow: visible; background: transparent; }
#lesson-stage.vl-wide video { left: -16.6667%; right: auto; width: 133.3334%; }
#lesson-stage [hidden] { display: none !important; }

.vl-sr {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- buttons ---- */
#lesson-stage button {
    position: absolute;
    margin: 0; padding: 0; border: 0; background: none;
    color: inherit; font: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s ease, filter 0.1s ease, opacity 0.15s ease;
}
#lesson-stage button:focus { outline: none; }
#lesson-stage button:focus-visible {
    outline: calc(var(--u) * 3) solid #fff;
    outline-offset: calc(var(--u) * 2);
    box-shadow: 0 0 0 calc(var(--u) * 7) rgba(0, 0, 0, 0.55);
}
#lesson-stage button:disabled { cursor: default; }
@media (hover: hover) {
    #lesson-stage button:not(:disabled):hover { filter: brightness(1.12); }
}
#lesson-stage button:not(:disabled):active { transform: scale(0.92); filter: brightness(0.95); }

/* Round buttons: Back (bottom left), Play again + Next (bottom right). */
.vl-nav { position: absolute; }
.vl-nav-left  { transform-origin: 0 100%;    transform: scale(var(--nav-boost)); }
.vl-nav-right { transform-origin: 100% 100%; transform: scale(var(--nav-boost)); }
#lesson-stage .vl-round { border-radius: 50%; }
/* The last word has no "next": the original shows the button faded out. */
#lesson-stage .vl-round:disabled { opacity: 0.15; }

/* Words / E-book tabs, top right. Enlarged together on small screens. */
.vl-tabs { position: absolute; transform-origin: 100% 0; transform: scale(var(--tab-boost)); }
#lesson-stage .vl-tab { border-radius: 999px; }
#lesson-stage .vl-tab img { position: absolute; inset: 0; }
#lesson-stage .vl-tab .vl-on { opacity: 0; }
#lesson-stage .vl-tab[aria-pressed="true"] .vl-on { opacity: 1; }
#lesson-stage .vl-tab[aria-pressed="true"] .vl-off { opacity: 0; }
/* a taller, wider touch area than the pill itself */
#lesson-stage .vl-tab::after { content: ''; position: absolute; inset: -45% -5%; }

/* ---- caption ---- */
.vl-caption {
    position: absolute;
    background-color: #000;
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    -webkit-mask-position: center; mask-position: center;
    -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
}
.vl-caption.vl-said { background-color: #f00; }

/* ---- e-book ---- */
#lesson-stage .vl-entry { border-radius: calc(var(--u) * 8); }
#lesson-stage .vl-entry .vl-speaker { position: absolute; transition: transform 0.12s ease; }
@media (hover: hover) {
    #lesson-stage .vl-entry:not(:disabled):hover { filter: none; background: rgba(255, 196, 0, 0.16); }
    #lesson-stage .vl-entry:not(:disabled):hover .vl-speaker { transform: scale(1.2); }
}
#lesson-stage .vl-entry:not(:disabled):active { transform: none; filter: none; background: rgba(255, 196, 0, 0.3); }
#lesson-stage .vl-entry:not(:disabled):active .vl-speaker { transform: scale(0.9); }
#lesson-stage .vl-entry.vl-reading .vl-speaker { animation: vlPulse 0.7s ease-in-out infinite alternate; }
@keyframes vlPulse { from { transform: scale(1); } to { transform: scale(1.25); } }

/* ---- loading / resume / error ---- */
.vl-wait {
    position: absolute; left: 50%; top: 50%;
    width: calc(var(--u) * 64); height: calc(var(--u) * 64);
    margin: calc(var(--u) * -32) 0 0 calc(var(--u) * -32);
    border-radius: 50%;
    border: calc(var(--u) * 7) solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    animation: vlSpin 0.9s linear infinite;
    pointer-events: none;
    opacity: 0; transition: opacity 0.2s ease 0.25s;
}
.vl-wait.vl-show { opacity: 1; }
@keyframes vlSpin { to { transform: rotate(360deg); } }

#lesson-stage .vl-resume {
    inset: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.35);
    display: flex; align-items: center; justify-content: center;
}
#lesson-stage .vl-resume:active { transform: none; }
.vl-resume span {
    width: calc(var(--u) * 120); height: calc(var(--u) * 120);
    border-radius: 50%;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5v14l11-7z' fill='%231256c0'/%3E%3C/svg%3E") center / 62% no-repeat;
    box-shadow: 0 calc(var(--u) * 6) calc(var(--u) * 24) rgba(0, 0, 0, 0.45);
}
.vl-error {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: calc(var(--u) * 16);
    background: #1565C0; color: #fff; text-align: center;
    font-size: calc(var(--u) * 26); font-weight: 700;
    padding: calc(var(--u) * 40);
}
#lesson-stage .vl-error button {
    position: static;
    padding: calc(var(--u) * 12) calc(var(--u) * 32);
    border-radius: 999px; background: #FFD94A; color: #1a1a1a;
    font-size: calc(var(--u) * 24); font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
    #lesson-stage button, #lesson-stage .vl-entry .vl-speaker { transition: none; }
    #lesson-stage .vl-entry.vl-reading .vl-speaker { animation: none; transform: scale(1.2); }
}
