/* ──────────────────────────────────────────────────────────────────────────
   TheaterPlayer — cinematic chrome for the /tutorials/{appId} surface.
   Adapted from the Movie Library reference; uses the host's --tp-accent.
   ────────────────────────────────────────────────────────────────────── */

.tp-stage {
    --tp-accent: #E8B53A;
    --tp-accent-soft: color-mix(in srgb, var(--tp-accent) 18%, transparent);
    --tp-accent-ink: oklch(0.22 0.02 70);
    --tp-bg: #11100d;
    --tp-ff-sans: 'Inter', ui-sans-serif, system-ui, sans-serif;
    --tp-ff-display: 'Fraunces', 'Inter', serif;
    --tp-ff-mono: 'JetBrains Mono', ui-monospace, monospace;
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--tp-bg);
    overflow: hidden;
    isolation: isolate;
    font-family: var(--tp-ff-sans);
    color: rgba(255, 255, 255, 0.92);
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
}

.tp-stage.tp-fullscreen { border-radius: 0; }

/* The actual media — video / iframe / div holder for YT/Vimeo */
.tp-stage .tp-media-host { position: absolute; inset: 0; z-index: 1; }
.tp-stage .tp-media-host > * {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: #000;
    display: block;
    object-fit: contain;
}

/* Click shield to capture taps anywhere on the surface */
.tp-shield {
    position: absolute;
    inset: 0;
    z-index: 2;
}

/* Loading + error states */
.tp-spinner {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.tp-stage.tp-buffering .tp-spinner { display: flex; }
.tp-spinner-ring {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.18);
    border-top-color: var(--tp-accent);
    animation: tp-spin 0.85s linear infinite;
}
@keyframes tp-spin { to { transform: rotate(360deg); } }

.tp-error {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;
}
.tp-stage.tp-errored .tp-error { display: flex; }
.tp-error-msg { font-size: 14px; color: rgba(255,255,255,0.7); margin: 0; max-width: 360px; }
.tp-error-retry {
    padding: 8px 18px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.18);
    background: transparent;
    color: white;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.tp-error-retry:hover { background: rgba(255,255,255,0.08); }

/* ───── Overlay (top crumbs, big play, bottom controls) ───── */
.tp-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding: 28px 32px;
    background: linear-gradient(to bottom,
        rgba(0,0,0,0.45) 0%,
        transparent 22%,
        transparent 55%,
        rgba(0,0,0,0.7) 100%);
    pointer-events: none;
    transition: opacity 0.24s ease, transform 0.24s ease;
}
.tp-overlay > * { pointer-events: auto; }
.tp-stage.tp-playing.tp-idle .tp-overlay { opacity: 0; transform: translateY(6px); pointer-events: none; }
.tp-stage.tp-playing.tp-idle { cursor: none; }

/* Top row: crumbs + episode chip */
.tp-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: rgba(255,255,255,0.92);
}
.tp-crumbs { display: flex; gap: 10px; align-items: center; font-size: 13px; pointer-events: none; }
.tp-crumb-genre {
    font-family: var(--tp-ff-mono);
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    padding: 5px 10px;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 999px;
    background: rgba(0,0,0,0.2);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.tp-crumb-sep { opacity: 0.4; }
.tp-crumb-title { opacity: 0.88; font-weight: 500; }
.tp-chip {
    font-family: var(--tp-ff-mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.15);
    pointer-events: none;
}

/* Big center play */
.tp-play-big {
    justify-self: center;
    align-self: center;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: rgba(255,255,255,0.95);
    color: #0a0a0a;
    display: grid;
    place-items: center;
    transition: transform 0.2s ease, background 0.2s ease, opacity 0.25s ease;
    box-shadow: 0 16px 40px rgba(0,0,0,0.45);
    border: 0;
    padding: 0;
    cursor: pointer;
}
.tp-play-big svg { width: 28px; height: 28px; fill: currentColor; stroke: none; margin-left: 3px; }
.tp-play-big:hover { transform: scale(1.06); background: white; }
.tp-stage.tp-playing .tp-play-big { opacity: 0; transform: scale(0.7); pointer-events: none; }

/* Bottom area: chapter line + scrubber + controls */
.tp-bottom { color: white; display: flex; flex-direction: column; gap: 14px; }

.tp-chapter-line { display: flex; align-items: flex-end; gap: 18px; padding: 0 4px; }
.tp-chapter-num {
    font-family: var(--tp-ff-mono);
    font-size: 48px;
    line-height: 0.9;
    font-weight: 300;
    opacity: 0.55;
    letter-spacing: -0.02em;
}
.tp-chapter-title-wrap { flex: 1; min-width: 0; }
.tp-chapter-eyebrow {
    font-family: var(--tp-ff-mono);
    font-size: 10px;
    letter-spacing: 0.2em;
    opacity: 0.55;
    text-transform: uppercase;
    margin-bottom: 2px;
}
.tp-chapter-title {
    font-size: 22px;
    font-weight: 500;
    letter-spacing: -0.01em;
    text-wrap: balance;
}

/* Scrubber */
.tp-scrub {
    position: relative;
    padding: 14px 4px 8px;
    cursor: pointer;
}
.tp-scrub-track { position: relative; height: 4px; }
.tp-scrub-chapters { display: flex; gap: 3px; height: 100%; }
.tp-scrub-segment {
    background: rgba(255,255,255,0.15);
    height: 100%;
    border-radius: 2px;
    position: relative;
    overflow: hidden;
    transition: transform 0.15s ease, background 0.15s ease;
    flex: 1;
}
.tp-scrub:hover .tp-scrub-segment { transform: scaleY(1.4); }
.tp-scrub-segment.tp-done    { background: rgba(255,255,255,0.5); }
.tp-scrub-segment.tp-current { background: rgba(255,255,255,0.25); }
.tp-scrub-segment:hover { background: rgba(255,255,255,0.35); }
.tp-scrub-segment.tp-current:hover { background: rgba(255,255,255,0.4); }
.tp-scrub-fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--tp-accent);
    border-radius: 2px;
    transition: width 0.15s linear;
}
.tp-scrub-thumb {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 14px;
    height: 14px;
    background: var(--tp-accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 0 var(--tp-accent-soft);
    transition: transform 0.2s ease, box-shadow 0.2s ease, left 0.15s linear;
    pointer-events: none;
}
.tp-scrub:hover .tp-scrub-thumb,
.tp-scrub.tp-dragging .tp-scrub-thumb {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 8px var(--tp-accent-soft);
}
.tp-scrub-hover {
    position: absolute;
    top: -4px;
    left: 0;
    transform: translate(-50%, -100%);
    padding: 4px 8px;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 4px;
    font-family: var(--tp-ff-mono);
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.tp-scrub:hover .tp-scrub-hover { opacity: 1; }

/* Control bar */
.tp-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
}
.tp-ctl-group { display: flex; align-items: center; gap: 4px; }
.tp-ctl {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: rgba(255,255,255,0.85);
    transition: background 0.15s ease, color 0.15s ease;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
}
.tp-ctl:hover { background: rgba(255,255,255,0.1); color: white; }
.tp-ctl:focus-visible { outline: 2px solid var(--tp-accent); outline-offset: 1px; }
.tp-ctl[disabled] { opacity: 0.35; cursor: not-allowed; }
.tp-ctl[disabled]:hover { background: transparent; color: rgba(255,255,255,0.85); }
.tp-ctl[aria-pressed="true"] { color: var(--tp-accent); }
.tp-ctl svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}
.tp-ctl.tp-ctl-primary {
    background: var(--tp-accent);
    color: var(--tp-accent-ink);
    width: 44px;
    height: 44px;
    margin: 0 8px;
}
.tp-ctl.tp-ctl-primary:hover {
    background: var(--tp-accent);
    filter: brightness(1.08);
    color: var(--tp-accent-ink);
}
.tp-ctl.tp-ctl-primary svg { fill: currentColor; stroke: none; width: 18px; height: 18px; }

.tp-time {
    font-family: var(--tp-ff-mono);
    font-size: 12px;
    opacity: 0.7;
    margin-left: 12px;
    display: flex;
    gap: 6px;
    font-variant-numeric: tabular-nums;
}
.tp-time-sep { opacity: 0.4; }

.tp-vol { display: flex; align-items: center; gap: 8px; }
.tp-vol-track {
    width: 90px;
    height: 4px;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.tp-vol-fill {
    height: 100%;
    background: rgba(255,255,255,0.85);
    transition: width 0.12s linear;
}

/* Speed menu */
.tp-speed-menu {
    position: absolute;
    bottom: 64px;
    right: 24px;
    background: rgba(12, 14, 18, 0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    min-width: 96px;
    box-shadow: 0 18px 40px -10px rgba(0,0,0,0.6);
    z-index: 7;
}
.tp-stage.tp-speed-open .tp-speed-menu { display: flex; }
.tp-speed-opt {
    background: transparent;
    border: 0;
    color: white;
    text-align: left;
    padding: 8px 12px;
    border-radius: 7px;
    font-size: 13px;
    font-family: var(--tp-ff-mono);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background 0.12s ease;
}
.tp-speed-opt:hover { background: rgba(255,255,255,0.10); }
.tp-speed-opt[aria-pressed="true"] {
    color: var(--tp-accent);
    background: rgba(255,255,255,0.06);
    font-weight: 600;
}

/* Compact responsive — narrower viewports get a smaller bottom area */
@media (max-width: 900px) {
    .tp-overlay { padding: 18px 16px; gap: 8px; grid-row-gap: 8px; }
    .tp-chapter-num { font-size: 36px; }
    .tp-chapter-title { font-size: 17px; }
    .tp-play-big { width: 64px; height: 64px; }
    .tp-play-big svg { width: 22px; height: 22px; }
    .tp-vol-track { width: 60px; }
    .tp-time { margin-left: 6px; font-size: 11px; }
    .tp-ctl { width: 36px; height: 36px; }
    .tp-ctl.tp-ctl-primary { width: 40px; height: 40px; }
}
@media (max-width: 600px) {
    .tp-crumb-title { display: none; }
    .tp-vol-track { display: none; }
    .tp-ctl-cc, .tp-ctl-pip { display: none; }
}
