/* The Theatre (static/js/theatre.js): pick a film in three taps */

/* ── Banner on the Personalised tab ── */
.th-banner {
    position: relative; overflow: hidden; isolation: isolate;
    margin: 6px var(--side-pad) 26px; padding: 26px 28px;
    border-radius: var(--radius-lg, 18px);
    border: 1px solid rgba(129, 140, 248, 0.28);
    background:
        radial-gradient(120% 140% at 0% 0%, rgba(99, 102, 241, 0.32), transparent 55%),
        radial-gradient(80% 120% at 100% 100%, rgba(103, 232, 249, 0.12), transparent 60%),
        linear-gradient(135deg, #141629 0%, #0d0f18 100%);
    display: flex; align-items: center; justify-content: space-between; gap: 22px; flex-wrap: wrap;
}
.th-banner:empty { display: none; }
/* A slow spotlight sweeping across the stage */
.th-banner-glow {
    position: absolute; z-index: -1; top: -60%; left: -30%; width: 60%; height: 220%;
    background: radial-gradient(closest-side, rgba(199, 210, 254, 0.16), transparent);
    animation: thSweep 9s ease-in-out infinite alternate; pointer-events: none;
}
@keyframes thSweep { to { left: 75%; } }
.th-kicker {
    display: inline-flex; align-items: center; gap: 8px; margin-bottom: 8px;
    font-size: 0.72rem; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; color: #a5b4fc;
}
.th-banner h3 { font-size: 1.45rem; letter-spacing: -0.4px; margin: 0 0 4px; }
.th-banner p { color: var(--text-dim); margin: 0; font-size: 0.95rem; }
.th-banner-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Buttons ── */
.th-btn {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 10px 18px;
    border-radius: 999px; border: 1px solid var(--border-strong, rgba(255,255,255,.14));
    background: rgba(255, 255, 255, 0.05); color: var(--text, #e2e4e9);
    font: 600 0.92rem var(--font-body, Inter, system-ui, sans-serif); cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.th-btn:hover { background: rgba(255, 255, 255, 0.1); transform: translateY(-1px); }
.th-btn:active { transform: translateY(0) scale(0.98); }
.th-btn-primary {
    border-color: transparent; color: #fff;
    background: linear-gradient(180deg, #6f73f5 0%, #4f46e5 100%);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}
.th-btn-primary:hover { background: linear-gradient(180deg, #7c80f7 0%, #5a52ec 100%); }
.th-btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim, #8b90a0); }
.th-btn-season { border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.07); text-align: left; }
.th-btn-season .i { color: #fbbf24; }
.th-btn-season span { display: flex; flex-direction: column; line-height: 1.15; }
.th-btn-season small { font-weight: 500; font-size: 0.72rem; color: var(--text-dim, #8b90a0); }

/* ── The panel ── */
.theatre-panel {
    width: min(920px, 100%); max-width: 920px !important; max-height: min(88vh, 860px);
    display: flex; flex-direction: column; overflow: hidden !important;
    background:
        radial-gradient(90% 60% at 50% -10%, rgba(99, 102, 241, 0.22), transparent 70%),
        rgba(14, 16, 24, 0.97) !important;
}
.th-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; flex: none; }
.th-icon-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border, rgba(255,255,255,.08));
    background: rgba(255, 255, 255, 0.05); color: var(--text, #e2e4e9); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.th-icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.th-dots { display: flex; gap: 6px; }
.th-dots i { width: 22px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); transition: background 0.3s, width 0.3s; }
.th-dots i.done { background: rgba(129, 140, 248, 0.6); }
.th-dots i.on { background: #818cf8; width: 34px; box-shadow: 0 0 10px rgba(129, 140, 248, 0.7); }
.th-body { flex: 1; overflow-y: auto; padding: 10px 28px 28px; -webkit-overflow-scrolling: touch; }

/* ── A question ── */
.th-q { text-align: center; animation: thIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes thIn { from { opacity: 0; transform: translateY(10px); } }
.th-q-kicker { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: #a5b4fc; margin-bottom: 8px; }
.th-q h2, .th-res-head h2 { font-size: clamp(1.4rem, 3.4vw, 2rem); letter-spacing: -0.6px; margin: 0 0 6px; }
.th-note { display: inline-flex; align-items: center; gap: 6px; color: #fbbf24; font-size: 0.85rem; margin-top: 2px; }
.th-options {
    display: grid; gap: 12px; margin: 22px auto 4px; max-width: 760px;
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
}
.th-opt {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    min-height: 116px; padding: 16px 12px; border-radius: 18px; cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.08); background: rgba(255, 255, 255, 0.035); color: var(--text, #e2e4e9);
    font: 600 0.95rem var(--font-body, Inter, system-ui, sans-serif);
    transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.th-opt:hover, .th-opt:focus-visible {
    transform: translateY(-3px); border-color: rgba(129, 140, 248, 0.55);
    background: rgba(99, 102, 241, 0.1); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 24px rgba(99, 102, 241, 0.2);
    outline: none;
}
.th-opt:active { transform: scale(0.97); }
.th-opt.picked { border-color: #818cf8; background: rgba(99, 102, 241, 0.18); }
.th-opt-ico {
    width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.35rem; color: #c7d2fe;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.3), rgba(99, 102, 241, 0.06) 70%);
    box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.25);
}
.th-opt-label { line-height: 1.25; }
.th-opt.seasonal { border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.06); }
.th-opt.seasonal .th-opt-ico { color: #fbbf24; background: radial-gradient(circle, rgba(251, 191, 36, 0.28), rgba(251, 191, 36, 0.05) 70%); box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.35); }
.th-opt.seasonal::after {
    content: 'In season'; position: absolute; top: 8px; right: 10px;
    font-size: 0.6rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: #fbbf24;
}

/* ── Loading / errors ── */
.th-loading { min-height: 340px; display: flex; align-items: center; justify-content: center; }
.th-error, .th-empty { text-align: center; color: var(--text-dim, #8b90a0); padding: 50px 10px; line-height: 1.6; }

/* ── Results ── */
.th-res-head { text-align: center; animation: thIn 0.35s ease both; }
.th-why { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 6px; }
.th-why span { padding: 4px 11px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; color: #c7d2fe; background: rgba(99, 102, 241, 0.14); border: 1px solid rgba(129, 140, 248, 0.25); }
.th-results { display: grid; gap: 18px; margin: 22px 0 8px; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); }
.th-card {
    text-align: left; background: none; border: 0; padding: 0; color: inherit; cursor: pointer;
    animation: thCard 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes thCard { from { opacity: 0; transform: translateY(14px) scale(0.97); } }
.th-poster {
    position: relative; aspect-ratio: 2 / 3; border-radius: 14px; overflow: hidden;
    background: linear-gradient(135deg, #1c2030, #12141d); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.th-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.th-card:hover .th-poster, .th-card:focus-visible .th-poster { transform: translateY(-4px); box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 0 0 2px #818cf8; }
.th-card:focus-visible { outline: none; }
.th-foryou, .th-rating {
    position: absolute; display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px;
    font-size: 0.68rem; font-weight: 800; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.th-foryou { top: 8px; left: 8px; background: rgba(99, 102, 241, 0.85); color: #fff; }
.th-rating { bottom: 8px; right: 8px; background: rgba(0, 0, 0, 0.65); color: #fbbf24; }
.th-card-title { margin-top: 9px; font-weight: 700; font-size: 0.92rem; line-height: 1.25; }
.th-card-meta { margin-top: 3px; font-size: 0.78rem; color: var(--text-dim, #8b90a0); }
.th-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; }
.th-actions-left { justify-content: flex-start; }

/* ── Spotlight: one film ── */
.th-spot { position: relative; border-radius: 18px; overflow: hidden; margin-top: 6px; animation: thIn 0.5s ease both; }
.th-spot-art {
    position: absolute; inset: 0; background: #0f1117 center / cover no-repeat; opacity: 0.45;
    -webkit-mask: linear-gradient(180deg, #000 0%, transparent 100%); mask: linear-gradient(180deg, #000 0%, transparent 100%);
}
.th-spot-body { position: relative; display: flex; gap: 26px; padding: 30px; align-items: flex-end; }
.th-spot-poster { width: 180px; border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 40px rgba(99, 102, 241, 0.3); flex: none; }
.th-spot-text { min-width: 0; }
.th-spot-text h2 { font-size: clamp(1.6rem, 4vw, 2.4rem); letter-spacing: -0.8px; margin: 0 0 6px; }
.th-spot-text p { color: rgba(226, 228, 233, 0.8); line-height: 1.55; margin: 12px 0 0; max-width: 560px; }

/* ── Phones: a tall sheet, two option columns, thumb-sized buttons ── */
@media (max-width: 760px), (pointer: coarse) and (max-width: 1100px) {
    .th-banner { padding: 20px; margin-bottom: 20px; }
    .th-banner h3 { font-size: 1.25rem; }
    .th-banner-actions, .th-banner-actions .th-btn { width: 100%; }
    .th-banner-actions .th-btn { justify-content: center; }
    #theatreModal .theatre-panel {
        height: calc(100dvh - var(--safe-t, 0px) - var(--safe-b, 0px) - 32px) !important; max-height: none !important;
    }
    .th-body { padding: 6px 16px calc(24px + var(--safe-b, 0px)); }
    .th-options { grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
    .th-opt { min-height: 100px; font-size: 0.9rem; border-radius: 16px; }
    .th-opt-ico { width: 42px; height: 42px; font-size: 1.2rem; }
    .th-results { grid-template-columns: 1fr 1fr; gap: 12px; }
    .th-actions .th-btn { flex: 1 1 100%; justify-content: center; }
    .th-spot-body { flex-direction: column; align-items: flex-start; padding: 20px; gap: 16px; }
    .th-spot-poster { width: 130px; }
}

@media (prefers-reduced-motion: reduce) {
    .th-banner-glow, .th-q, .th-card, .th-spot, .th-res-head { animation: none !important; }
}

/* Pick up where you left off */
.th-resume-sub { color: var(--text-dim, #8b90a0); margin: 0 0 10px; }
.th-resume-posters { display: flex; justify-content: center; margin: 26px 0 8px; height: 170px; }
.th-resume-posters img {
    width: 110px; height: 165px; object-fit: cover; border-radius: 12px; margin: 0 -18px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); border: 2px solid rgba(14, 16, 24, 0.9);
    transform: rotate(calc((var(--i) - 2) * 6deg)) translateY(calc(var(--i) * 2px));
    animation: thCard 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(var(--i) * 60ms);
}
@media (max-width: 760px) { .th-resume-posters img { width: 86px; height: 129px; margin: 0 -16px; } .th-resume-posters { height: 140px; } }

/* Icons inside the round badges: no trailing text, so no text spacing (it pushed them off-centre) */
.th-opt-ico .i { margin: 0; vertical-align: middle; display: block; }

/* ── Desktop: all 8 films and the buttons fit without scrolling ── */
/* The action buttons stick to the bottom of the panel, so they're never cut off */
.th-actions-bar {
    position: sticky; bottom: -28px; z-index: 3; margin: 18px -28px -28px; padding: 16px 28px 20px;
    background: linear-gradient(180deg, rgba(14, 16, 24, 0) 0%, rgba(14, 16, 24, 0.94) 34%, rgba(14, 16, 24, 0.98) 100%);
}
.th-actions-bar .th-actions { margin-top: 0; }
/* Desktop: one long row of posters that scrolls sideways and keeps loading more */
@media (min-width: 761px) {
    .theatre-panel { width: min(1180px, 94vw); max-width: 1180px !important; max-height: min(90vh, 820px); }
    .th-res-head h2 { font-size: 1.7rem; }
    .th-rail-wrap { position: relative; margin: 18px -28px 0; }
    .th-results {
        display: flex !important; gap: 18px; margin: 0; padding: 10px 28px 18px;
        overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; scroll-padding: 0 28px;
        scrollbar-width: none; overscroll-behavior-x: contain;
        -webkit-mask: linear-gradient(90deg, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
                mask: linear-gradient(90deg, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
    }
    .th-results::-webkit-scrollbar { display: none; }
    .th-results .th-card { flex: 0 0 172px; scroll-snap-align: start; }
    .th-rail-nav {
        position: absolute; top: 40%; z-index: 4; width: 46px; height: 46px; margin-top: -23px; border-radius: 50%;
        border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(14, 16, 24, 0.85); color: #fff; cursor: pointer;
        display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
        backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); transition: opacity 0.2s ease, transform 0.15s ease, background 0.2s ease;
    }
    .th-rail-nav:hover { background: #4f46e5; transform: scale(1.06); }
    .th-rail-nav.prev { left: 10px; }
    .th-rail-nav.next { right: 10px; }
    .th-rail-wrap.at-start .th-rail-nav.prev, .th-rail-wrap.at-end .th-rail-nav.next { opacity: 0; pointer-events: none; }
    /* Endless row: "Show me others" is less needed but stays for a clean re-roll */
}
@media (min-width: 761px) and (max-height: 760px) {
    .th-results .th-card { flex-basis: 140px; }
}
.th-rail-more, .th-rail-end {
    flex: 0 0 150px; display: flex; align-items: center; justify-content: center; text-align: center;
    color: var(--text-dim, #8b90a0); font-size: 0.85rem; padding: 0 10px; aspect-ratio: 2 / 3;
}
.th-rail-more .loading { width: 34px !important; height: 34px !important; }
@media (max-width: 760px), (pointer: coarse) and (max-width: 1100px) {
    .th-rail-nav { display: none; }
    .th-rail-more, .th-rail-end { grid-column: 1 / -1; aspect-ratio: auto; padding: 20px 0; }
}

/* Cards: keyboard focus, and a still variant for ones swapped in later */
.th-card { position: relative; outline: none; }
.th-card:focus-visible .th-poster { box-shadow: 0 0 0 2px #818cf8; }
.th-card-still { animation: none; }

/* Beta: thumbs down on each film */
.th-beta {
    display: inline-block; margin-left: 10px; padding: 3px 9px; border-radius: 999px; vertical-align: middle;
    font-size: 0.62rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
    color: #fbbf24; background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.35);
}
.th-beta-hint { margin-top: 10px; font-size: 0.8rem; color: var(--text-dim, #8b90a0); }
.th-beta-hint .i { width: 1em; height: 1em; }
.th-down {
    position: absolute; top: 8px; right: 8px; z-index: 2; width: 34px; height: 34px; border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.22); background: rgba(10, 11, 16, 0.72); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 0.85rem;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    opacity: 0; transform: scale(0.85); transition: opacity 0.18s ease, transform 0.18s ease, background 0.2s ease;
}
.th-card:hover .th-down, .th-card:focus-within .th-down { opacity: 1; transform: none; }
.th-down:hover { background: #ef4444; border-color: transparent; }
@media (hover: none) { .th-down { opacity: 1; transform: none; } }
.th-card.th-gone { pointer-events: none; animation: thGone 0.26s ease forwards; }
@keyframes thGone { to { opacity: 0; transform: scale(0.88) translateY(8px); filter: blur(3px); } }

@media (max-width: 760px), (pointer: coarse) and (max-width: 1100px) {
    .th-actions-bar { bottom: calc(-24px - var(--safe-b, 0px)); margin: 14px -16px calc(-24px - var(--safe-b, 0px)); padding: 14px 16px calc(16px + var(--safe-b, 0px)); }
}
/* Phones: the buttons sit after the films (pinned, they covered half the screen), compact two-up */
@media (max-width: 760px), (pointer: coarse) and (max-width: 1100px) {
    .th-actions-bar { position: static; margin: 20px 0 0; padding: 0; background: none; }
    .th-actions-bar .th-actions { gap: 8px; }
    .th-actions-bar .th-btn { flex: 1 1 calc(50% - 4px); justify-content: center; min-height: 46px; padding: 10px 12px; font-size: 0.86rem; }
    .th-actions-bar .th-btn-primary { flex-basis: 100%; }
    .th-actions-bar .th-btn-ghost { flex-basis: 100%; }
}

/* ── Server page: Theatre tuning ── */
.tt { padding: 0 var(--side-pad, 20px) 40px; }
.tt-panel h3 { display: flex; align-items: center; gap: 8px; }
.tt-panel h3 .th-beta { margin-left: 2px; }
.tt-saved { margin-left: auto; font-size: 0.75rem; font-weight: 600; color: #6fdc8c; opacity: 0; transition: opacity 0.25s; }
.tt-saved.show { opacity: 1; }
.tt-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.tt-sub { font-weight: 700; font-size: 0.9rem; margin-bottom: 10px; }
.tt-label { display: block; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); margin: 16px 0 8px; }
.tt-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tt-chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--border-strong); background: rgba(255, 255, 255, 0.04); color: var(--text);
    font: 600 0.8rem var(--font-body); transition: background 0.15s, border-color 0.15s;
}
.tt-chip:hover { border-color: rgba(129, 140, 248, 0.6); }
.tt-chip.on { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.6); color: #fca5a5; text-decoration: line-through; }
.tt-chip .i { margin-right: 0; width: 0.9em; height: 0.9em; }
.tt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 16px; }
.tt-field { display: flex; flex-direction: column; gap: 5px; font-size: 0.78rem; color: var(--text-dim); }
.tt-field select, .tt-field input {
    padding: 9px 10px; border-radius: 10px; border: 1px solid var(--border-strong);
    background: rgba(15, 17, 23, 0.8); color: var(--text); font: 500 0.85rem var(--font-body);
}
.tt-toggle { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 0.85rem; cursor: pointer; }
.tt-toggle input { width: 18px; height: 18px; accent-color: #6366f1; }
.tt-conf { display: flex; align-items: center; gap: 12px; font-size: 0.82rem; }
.tt-conf-bar { flex: 1; max-width: 200px; height: 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.tt-conf-bar i { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #67e8f9); border-radius: 8px; transition: width 0.4s; }
.tt-counts { margin-top: 6px; font-size: 0.8rem; }
.tt-feats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tt-feat { position: relative; padding: 5px 9px; margin-bottom: 5px; border-radius: 8px; font-size: 0.8rem; overflow: hidden; background: rgba(255, 255, 255, 0.03); }
.tt-feat span { position: relative; z-index: 1; }
.tt-feat i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 8px; }
.tt-feat.pos i { background: rgba(70, 211, 105, 0.22); }
.tt-feat.neg i { background: rgba(239, 68, 68, 0.22); }
.tt-list { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; }
.tt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
.tt-row em { font-style: normal; color: var(--text-dim); font-size: 0.75rem; margin-left: 6px; }
.tt-row button { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: transparent; color: #c7d2fe; font: 600 0.75rem var(--font-body); cursor: pointer; }
.tt-reset { margin-top: 18px; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(239, 68, 68, 0.4); background: transparent; color: #fca5a5; font: 600 0.8rem var(--font-body); cursor: pointer; }
.tt-reset:hover { background: rgba(239, 68, 68, 0.12); }
@media (max-width: 860px) { .tt-cols, .tt-feats { grid-template-columns: 1fr; } }
