/* Video feature: the player, its cards and the admin video page. */

.player { display: block; margin: 16px 0; }
.player-box {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius);
    background: #000;
    user-select: none;
    -webkit-user-select: none;
    /* A long press is 2x (js/player.js): no iPhone callout over it. */
    -webkit-touch-callout: none;
}
.player-box video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; touch-action: manipulation; }
/* In full screen Chrome keeps a caption on one line, so a long line is cut at the sides: let it wrap. */
.player-box video::-webkit-media-text-track-display { white-space: normal !important; }
/* «حجم الترجمة» (js/player.js sets data-caption-size). ::cue font-size works in Chrome and in WebKit; a size on the
   text track display box itself breaks WebKit's cue backgrounds. An iPhone's own caption style (Settings) can win. */
.player[data-caption-size="small"] .player-box video::cue { font-size: 85%; }
.player[data-caption-size="large"] .player-box video::cue { font-size: 130%; }
/* In full screen, while the bar shows, the captions move up by its height (js/player.js sets it), so it never covers them. */
.player-box video::-webkit-media-text-track-container { transition: transform .25s var(--ease-out); }
.player.is-full:not(.is-idle) .player-box video::-webkit-media-text-track-container { transform: translateY(calc(-1 * var(--player-bar-height, 0px))); }
/* Full screen is the whole player, dark in both themes (is-full, set by js/player.js for the Fullscreen API and for
   the iPhone way below): the video fills it and the controls float over it (.player-overlay below). The bar and the
   folded chapter list under the video go; their parts move into the overlay. */
.player.is-full {
    position: relative;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    background: var(--console);
    color: var(--on-console);
}
.player.is-full .player-box { flex: 1 1 auto; min-height: 0; aspect-ratio: auto; border-radius: 0; }
.player.is-full > .player-bar, .player.is-full > .player-chapters { display: none; }
.player.is-full .player-select { border-color: color-mix(in srgb, var(--on-console) 22%, transparent); background: var(--console-2); color: var(--on-console); }
.player.is-full.is-idle, .player.is-full.is-idle video { cursor: none; }
.player.is-full .player-message {
    position: absolute;
    top: 8px;
    inset-inline: 8px;
    z-index: 7;
    margin: 0;
    padding: 8px 12px;
    border-inline-start: 4px solid var(--danger);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--console) 92%, transparent);
    color: var(--on-console);
}
/* The iPhone has no full screen for an element: the player covers the whole screen above everything (the page under
   it does not scroll), inside the safe areas. On an upright phone it turns 90 degrees clockwise (data-rotated), so
   the video fills the screen sideways: its width is the screen's height, and the safe areas turn with it. */
.player.is-pseudo {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.player.is-pseudo[data-rotated] {
    width: 100vh;
    width: 100dvh;
    height: 100vw;
    height: 100dvw;
    padding: env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left) env(safe-area-inset-top);
    transform-origin: top left;
    transform: translateX(100vw) rotate(90deg);
    transform: translateX(100dvw) rotate(90deg);
}
/* Safari letterboxes a page in landscape and paints the side strips with the page background: dark, like the player. */
html.has-player-full, html.has-player-full body { overflow: hidden; background: var(--console); }

/* The full screen controls, like YouTube: a bar at the bottom (play, the time, the timeline, the gear, leave) over a
   dark fade, and the gear's sheet above it (the speed, the quality, the chapters; it scrolls). Dark in both themes,
   so they read on any picture; under the watermark. Hidden (is-idle) they take no taps, so a tap reaches the video. */
.player-overlay { display: none; }
.player.is-full .player-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
    color: var(--on-console);
}
.player-controls {
    padding: 28px 8px 4px;
    background: linear-gradient(transparent, color-mix(in srgb, var(--console) 88%, transparent));
    pointer-events: auto;
    transition: opacity .25s var(--ease-out), visibility 0s;
}
.player.is-idle .player-controls { opacity: 0; visibility: hidden; transition: opacity .25s var(--ease-out), visibility 0s .25s; }
/* Just after a tap showed them (js/player.js), the bar takes no taps, so that tap and a second tap of a seek reach the video. */
.player.is-revealing .player-controls { pointer-events: none; }
.player-controls .player-track { margin: 0; color: var(--on-console); }
.player-controls-row { display: flex; align-items: center; gap: 4px; }
.player-icon, .player-controls .player-fullscreen.btn, .player-controls .player-captions.btn {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 48px;
    height: 48px;
    min-height: 48px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
    color: inherit;
    cursor: pointer;
}
.player-icon:hover, .player-controls .player-fullscreen.btn:hover, .player-controls .player-captions.btn:hover { transform: none; background: color-mix(in srgb, var(--on-console) 14%, transparent); }
.player-icon:focus-visible, .player-controls .player-fullscreen.btn:focus-visible, .player-controls .player-captions.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.player-play[data-state="playing"] .player-play-icon, .player-play[data-state="paused"] .player-pause-icon { display: none; }
.player-gear { margin-inline-start: auto; }
/* In the bar the captions button comes just before the gear, so it takes the gear's gap. */
.player-controls .player-captions { margin-inline-start: auto; }
.player-controls .player-captions + .player-gear { margin-inline-start: 0; }
.player-gear[aria-expanded="true"] { background: color-mix(in srgb, var(--on-console) 18%, transparent); }
.player-gear[aria-expanded="true"] .icon { transform: rotate(45deg); }
.player-gear .icon { transition: transform .2s var(--ease-out); }
.player-time { padding-inline: 4px; font: 600 var(--fs-sm)/1 var(--font-title); white-space: nowrap; text-shadow: 0 0 3px #000; }
/* The full screen and captions buttons are text buttons under the video and icons in the bar (their text stays for
   screen readers). Captions on: the button is filled under the video and underlined in the bar, like YouTube. */
.player-fullscreen-icon, .player-captions-icon { display: none; }
.player-controls .player-fullscreen-icon, .player-controls .player-captions-icon { display: block; }
.player-captions[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.player-controls .player-captions[aria-pressed="true"] { background: transparent; color: inherit; box-shadow: inset 0 -3px 0 var(--accent); }
.player-controls .player-fullscreen-text, .player-controls .player-captions-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.player-sheet {
    flex: 0 1 auto;
    align-self: flex-end;
    width: min(340px, calc(100% - 16px));
    min-height: 0;
    margin: 8px;
    padding: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid color-mix(in srgb, var(--on-console) 18%, transparent);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--console) 95%, transparent);
    box-shadow: var(--shadow-2);
    pointer-events: auto;
    animation: player-sheet .18s var(--ease-out) both;
}
.player-sheet:focus { outline: none; }
.player-sheet-settings { display: grid; gap: 6px; }
.player-sheet .player-setting { display: flex; justify-content: space-between; gap: 12px; min-height: 48px; padding-inline: 4px; font: 700 var(--fs-sm)/1.3 var(--font-title); }
.player-sheet .player-select { min-width: 8.5rem; }
.player-sheet-title { margin: 10px 4px 2px; color: var(--on-console-muted); font: 700 var(--fs-sm)/1.3 var(--font-title); }
.player-sheet ol { margin: 0; padding: 0; list-style: none; }
@keyframes player-sheet {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
/* Over the full screen controls and the message, so they never hide it. */
.player-mark {
    position: absolute;
    top: 8%;
    left: 8%;
    z-index: 8;
    pointer-events: none;
    direction: ltr;
    font-family: var(--font-code);
    font-size: clamp(.75rem, 2.2vw, 1.1rem);
    letter-spacing: .08em;
    color: #fff;
    opacity: .35;
    text-shadow: 0 0 3px #000;
}
/* The turned player is as wide as the screen is high. */
.player[data-rotated] .player-mark { font-size: clamp(.75rem, 2.2vh, 1.1rem); }
.player-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}
.player-setting { display: inline-flex; align-items: center; gap: 8px; font-size: .95rem; }
.player-select {
    min-height: 44px;
    padding: 4px 10px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
.player .btn-small { min-height: 44px; padding: 6px 16px; }
.player-fullscreen { margin-inline-start: auto; }
/* A phone has no room for the three in one row: speed and full screen first, then the quality. */
@media (max-width: 30em) {
    .player-setting-quality { order: 1; }
}

/* Before the first tap: the poster (or a dark screen) and one big play button. Nothing downloads before it. */
.player-start {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    width: 100%;
    border: 0;
    background: radial-gradient(circle at 50% 50%, rgba(10, 18, 32, .15), rgba(10, 18, 32, .65));
    color: #fff;
    font: 700 1.1rem/1.3 var(--font-title);
    cursor: pointer;
}
.player-start:focus-visible { box-shadow: inset var(--focus-ring); border-radius: var(--radius); }
.player-start-label { padding: 2px 14px; border-radius: var(--radius-pill); background: rgba(10, 18, 32, .7); }
.player-message { margin: 8px 0 0; color: var(--danger); }

/* «من الأول» next to the resume chip: a corner of the start screen, so it never covers the big play button. */
.player-restart {
    position: absolute;
    top: 10px;
    inset-inline-start: 10px;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 6px 16px;
    border: 2px solid color-mix(in srgb, var(--on-console) 55%, transparent);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--navy) 75%, transparent);
    color: var(--on-console);
    font: 700 var(--fs-sm)/1.2 var(--font-title);
    cursor: pointer;
}
.player-restart:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Double tap on a side (or a key): how far it went, on that side, for a moment. Also in full screen. */
.player-ripple {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 36%;
    pointer-events: none;
    background: color-mix(in srgb, var(--on-console) 16%, transparent);
}
.player-ripple[data-side="back"] { left: 0; border-radius: 0 50% 50% 0 / 0 50% 50% 0; }
.player-ripple[data-side="forward"] { right: 0; border-radius: 50% 0 0 50% / 50% 0 0 50%; }
.player-ripple.is-on { animation: player-ripple .35s var(--ease-out) both; }
.player-ripple-text {
    padding: 4px 14px;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--navy) 75%, transparent);
    color: var(--on-console);
    font: 700 var(--fs-lg)/1.3 var(--font-title);
}
@keyframes player-ripple {
    from { opacity: 0; transform: scale(.9); }
    to { opacity: 1; transform: none; }
}

/* The chapter timeline: one part per chapter, left to right like the video's own timeline, filled as it plays. A
   finger drags along it (an upright scroll still scrolls the page; in full screen nothing scrolls). */
.player-track {
    position: relative;
    display: flex;
    align-items: center;
    gap: 3px;
    height: 44px;
    margin-top: 2px;
    padding: 0 4px;
    direction: ltr;
    cursor: pointer;
    touch-action: pan-y;
}
.player.is-full .player-track { touch-action: none; }
/* Above the finger or the pointer on the timeline: the chapter and the time there. */
.player-bubble {
    position: absolute;
    bottom: calc(100% - 6px);
    left: 0;
    z-index: 2;
    display: grid;
    justify-items: center;
    gap: 2px;
    max-width: min(240px, 80%);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--console) 92%, transparent);
    box-shadow: var(--shadow-2);
    color: var(--on-console);
    white-space: nowrap;
    pointer-events: none;
    transform: translateX(-50%);
}
.player-bubble-title { max-width: 100%; overflow: hidden; text-overflow: ellipsis; font: 700 var(--fs-sm)/1.3 var(--font-title); }
.player-bubble-time { font: 600 var(--fs-xs)/1 var(--font-title); }
.player-seg {
    position: relative;
    flex: 1 1 0;
    height: 6px;
    overflow: hidden;
    border-radius: 3px;
    background: color-mix(in srgb, currentColor 25%, transparent);
}
.player-seg-fill {
    position: absolute;
    inset: 0;
    background: var(--s, var(--primary));
    transform: scaleX(var(--p, 0));
    transform-origin: left;
}

/* A play or pause from a tap, a click or a key: the new state's icon in the middle, fading, like YouTube. With
   reduced motion it stays still for a moment (js/player.js hides it). It takes no taps. */
.player-flash {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    margin: -38px 0 0 -38px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--console) 60%, transparent);
    color: var(--on-console);
    pointer-events: none;
}
.player-flash[data-state="playing"] .player-flash-pause, .player-flash[data-state="paused"] .player-flash-play { display: none; }
.player-flash.is-on { animation: player-flash .6s var(--ease-out) both; }
@keyframes player-flash {
    from { opacity: 1; transform: scale(.8); }
    to { opacity: 0; transform: scale(1.25); }
}
@media (prefers-reduced-motion: reduce) {
    .player-flash.is-on { animation: none; }
}
/* A long press plays at 2x: a small label at the top while the finger is down. */
.player-boost {
    position: absolute;
    top: 12px;
    left: 50%;
    z-index: 3;
    padding: 4px 14px;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--console) 75%, transparent);
    color: var(--on-console);
    font: 700 var(--fs-sm)/1.3 var(--font-title);
    pointer-events: none;
    transform: translateX(-50%);
}
/* The video waits for data. Under the takeover and stop box (js/player.js hides it there too). */
.player-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border: 4px solid color-mix(in srgb, var(--on-console) 30%, transparent);
    border-top-color: var(--on-console);
    border-radius: 50%;
    pointer-events: none;
    animation: player-spin .8s linear infinite;
}
@keyframes player-spin { to { transform: rotate(360deg); } }
/* The end of the video: the quiz, the next lesson and play again, over the video (dark in both themes). In full screen
   it stays above the bar, which keeps its taps. */
.player-end {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    padding: 12px;
    background: color-mix(in srgb, var(--navy) 90%, transparent);
    color: var(--on-console);
    text-align: center;
}
.player.is-full:not(.is-idle) .player-end { padding-bottom: calc(12px + var(--player-bar-height, 0px)); }
.player-end-title { margin: 0; font: 700 var(--fs-md)/1.3 var(--font-title); }
.player-end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.player-end .btn { width: auto; min-height: 44px; padding: 6px 16px; }
.player-end .btn-on-dark {
    --btn-bg: var(--console-2);
    --btn-fg: var(--on-console);
    --btn-border: color-mix(in srgb, var(--on-console) 30%, transparent);
    --btn-edge: var(--console-edge);
}
.player-end-next { margin: 0; max-width: 40ch; overflow: hidden; color: var(--on-console-muted); font-size: var(--fs-sm); text-overflow: ellipsis; white-space: nowrap; }
/* A phone's small player has room for the buttons only. */
@media (max-width: 30em) {
    .player:not(.is-full) .player-end-next { display: none; }
}

/* The chapter list under the player: the current one is marked, a tap seeks (and starts the video). */
.player-chapters {
    margin-top: 8px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, currentColor 6%, transparent);
}
.player-chapters summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
    min-height: 44px;
    padding: 6px 12px;
    cursor: pointer;
    font: 700 var(--fs-sm)/1.4 var(--font-title);
    list-style: none;
}
.player-chapters summary::-webkit-details-marker { display: none; }
/* The fold sign: a small chevron at the end of the line that turns when the list opens. */
.player-chapters summary::after {
    content: "";
    width: 8px;
    height: 8px;
    margin-inline-start: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform .2s var(--ease-out);
}
.player-chapters[open] summary::after { transform: rotate(-135deg); }
.player-chapters summary:focus-visible, .player-chapter:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.player-chapter-now { font: 400 var(--fs-sm)/1.4 var(--font-text); color: color-mix(in srgb, currentColor 80%, transparent); }
.player-chapters ol { margin: 0; padding: 0 4px 6px; list-style: none; }
.player-chapter {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 6px 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}
.player-chapter:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
.player-chapter[aria-current="true"] { background: color-mix(in srgb, var(--s, var(--primary)) 24%, transparent); font-weight: 700; }
.player-chapter .num { min-width: 3.5em; font-family: var(--font-title); }

/* One stream at a time: another device of the account is playing (dark over the video in both themes). */
.player-takeover {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 12px;
    padding: 16px;
    background: color-mix(in srgb, var(--navy) 90%, transparent);
    color: var(--on-console);
    text-align: center;
}
.player-takeover[hidden] { display: none; }
.player-takeover-text { margin: 0; max-width: 32ch; font: 700 var(--fs-md)/1.4 var(--font-title); }
.player-takeover .btn { width: auto; }

.video-card { margin: 16px 0; text-align: center; }
.video-card p { margin: 0 0 12px; }
.video-locked { border-color: var(--accent); background: var(--accent-soft); }
.video-locked-title { font-family: var(--font-title); font-size: 1.15rem; }
.video-soon { color: var(--text-muted); }
.video-soon p { margin: 0; }

/* Admin video page */
.upload-form { max-width: 560px; margin-bottom: 24px; }
.upload-progress { width: 100%; height: 12px; margin-bottom: 8px; accent-color: var(--turquoise); }
.upload-status { min-height: 1.7em; margin: 0 0 12px; }
.error-text {
    max-width: 480px;
    max-height: 200px;
    overflow: auto;
    margin: 6px 0 0;
    padding: 8px;
    border-radius: 8px;
    background: var(--danger-soft);
    font-size: .8rem;
    white-space: pre-wrap;
}
