/* ============================================================================
   PurrCine — Cinematic Theme System (v2)
   ----------------------------------------------------------------------------
   Five fully-tokenised themes, one shared glassmorphism layer, and a set of
   extremely lightweight seasonal characters.

   Design mandates honoured here:
     • relative units only (rem / em / vw / vh / dvh / clamp) → 320px → 8K
     • GPU-only animation properties (transform / opacity / filter) → no layout
       thrashing, no battery drain on older mobile chipsets
     • decorative assets are tiny, pointer-events:none, and capped at 0.15–0.20
       opacity so they never compete with text or video playback
     • every glass surface ships a solid fallback for legacy mobile browsers
   ========================================================================== */

/* ------------------------------------------------------------------ tokens */
:root {
    /* shared geometry */
    --th-radius: 1rem;
    --th-radius-sm: 0.75rem;
    --th-radius-pill: 999px;
    --th-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --th-header-h: 4.25rem;

    /* glass tokens (dark, expensive-looking) */
    --th-glass: rgba(255, 255, 255, 0.03);
    --th-glass-strong: rgba(10, 10, 16, 0.72);
    --th-glass-border: rgba(255, 255, 255, 0.09);
    --th-blur: 12px;

    /* text */
    --th-text: #f4f5f9;
    --th-muted: rgba(244, 245, 249, 0.62);
    --th-faint: rgba(244, 245, 249, 0.38);

    /* default theme values (also injected inline by PHP) */
    --theme-accent: #00f0ff;
    --theme-accent-2: #7c5cff;
    --theme-bg: #0b0c10;
    --theme-glow: rgba(0, 240, 255, 0.26);
    --theme-gold: #d4af37;
    --theme-surface: #111319;
    --theme-surface-2: #16181f;
    --theme-line: rgba(255, 255, 255, 0.08);
}

/* Re-map the global design tokens to whichever theme is active. */
body[data-theme] {
    --gold: var(--theme-accent);
    --violet: var(--theme-accent-2);
    --accent: var(--theme-accent);
    --grad: linear-gradient(120deg, var(--theme-accent), var(--theme-accent-2));
    --theme-soft: color-mix(in srgb, var(--theme-accent) 18%, transparent);
    --pc-accent: var(--theme-accent);
    --pc-accent-2: var(--theme-accent-2);
    --pc-grad: linear-gradient(120deg, var(--theme-accent), var(--theme-accent-2));
    color: var(--th-text);
}

/* ------------------------------------------------------------------ per-theme tokens */
body[data-theme="default"] {
    --theme-bg: #0b0c10;
    --theme-accent: #00f0ff;
    --theme-accent-2: #7c5cff;
    --theme-glow: rgba(0, 240, 255, 0.24);
    --theme-surface: #101218;
    --theme-surface-2: #15181f;
    --theme-line: rgba(0, 240, 255, 0.14);
}

body[data-theme="halloween"] {
    --theme-bg: #0a0604;
    --theme-accent: #ff5500;
    --theme-accent-2: #9b5cff;
    --theme-glow: rgba(255, 85, 0, 0.26);
    --theme-surface: #120b06;
    --theme-surface-2: #1a1008;
    --theme-line: rgba(255, 85, 0, 0.18);
}

body[data-theme="christmas"] {
    --theme-bg: #06100a;
    --theme-accent: #e60026;
    --theme-accent-2: #d4af37;
    --theme-glow: rgba(230, 0, 38, 0.22);
    --theme-surface: #08150d;
    --theme-surface-2: #0c1d12;
    --theme-line: rgba(212, 175, 55, 0.18);
}

body[data-theme="newyear"] {
    --theme-bg: #0a0a0f;
    --theme-accent: #d4af37;
    --theme-accent-2: #7b61ff;
    --theme-glow: rgba(212, 175, 55, 0.24);
    --theme-surface: #101017;
    --theme-surface-2: #15151e;
    --theme-line: rgba(212, 175, 55, 0.18);
}

body[data-theme="valentine"] {
    --theme-bg: #12050b;
    --theme-accent: #ff007f;
    --theme-accent-2: #ff7ab8;
    --theme-glow: rgba(255, 0, 127, 0.24);
    --theme-surface: #1a0812;
    --theme-surface-2: #220b18;
    --theme-line: rgba(255, 0, 127, 0.18);
}

/* ------------------------------------------------------------------ canvas */
body[data-theme] {
    background-color: var(--theme-bg);
    transition: background-color 0.6s var(--th-ease);
}

body[data-theme]::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background:
        radial-gradient(80rem 45rem at 10% -12%, var(--theme-glow), transparent 62%),
        radial-gradient(60rem 40rem at 102% -4%, color-mix(in srgb, var(--theme-accent-2) 16%, transparent), transparent 60%),
        linear-gradient(180deg, var(--theme-bg) 0%, #050507 100%);
    transition: background 0.6s var(--th-ease);
}

/* subtle vignette so text always sits on a darker bed */
body[data-theme]::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(120% 90% at 50% 8%, transparent 42%, rgba(0, 0, 0, 0.55) 100%);
}

/* ------------------------------------------------------------------ glass surfaces */
body[data-theme] .site-header,
body[data-theme] .mobile-nav,
body[data-theme] .notif-dropdown,
body[data-theme] .user-dropdown,
body[data-theme] .search-panel,
body[data-theme] .dropdown-panel {
    background: var(--th-glass-strong);
    border: 1px solid var(--th-glass-border);
    -webkit-backdrop-filter: blur(var(--th-blur)) saturate(150%);
    backdrop-filter: blur(var(--th-blur)) saturate(150%);
}

/* legacy fallback: browsers without backdrop-filter get an opaque panel */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    body[data-theme] .site-header,
    body[data-theme] .mobile-nav,
    body[data-theme] .notif-dropdown,
    body[data-theme] .user-dropdown,
    body[data-theme] .search-panel {
        background: color-mix(in srgb, var(--theme-bg) 94%, #000);
    }
}

body[data-theme] .site-header { box-shadow: 0 1px 0 var(--theme-line); }

/* ------------------------------------------------------------------ accent surfaces */
body[data-theme] .btn-primary {
    background: var(--grad);
    color: #0a0a0d;
    box-shadow: 0 0.75rem 1.9rem -0.9rem var(--theme-glow);
    transition: transform 0.25s var(--th-ease), box-shadow 0.25s var(--th-ease), filter 0.25s ease;
}
body[data-theme] .btn-primary:hover { filter: brightness(1.08); }

body[data-theme] .brand-word span,
body[data-theme] .grad-text {
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

body[data-theme] .section-link:hover,
body[data-theme] .genre-chip:hover,
body[data-theme] .type-pill.active,
body[data-theme] .drama-filter.active {
    color: var(--theme-accent);
    border-color: color-mix(in srgb, var(--theme-accent) 55%, transparent);
}

body[data-theme] .hero-v3-badge,
body[data-theme] .card-badge {
    background: var(--grad);
    color: #0a0a0d;
}

body[data-theme] .rating-pill { color: var(--theme-accent); }

body[data-theme] .movie-card:hover,
body[data-theme] .movie-card:focus-within {
    border-color: color-mix(in srgb, var(--theme-accent) 45%, transparent);
    box-shadow: 0 1.4rem 2.6rem -1.4rem var(--theme-glow);
}

body[data-theme] .purr-bg-vignette {
    background: radial-gradient(circle at 50% 112%, var(--theme-glow), transparent 55%);
}

/* seasonal ribbon on the home page */
.season-ribbon {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.9rem;
    border-radius: var(--th-radius-pill);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--theme-accent);
    background: color-mix(in srgb, var(--theme-accent) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--theme-accent) 35%, transparent);
}

/* ============================================================================
   SEASONAL CHARACTER LAYER
   One fixed, pointer-transparent stage. Only the characters themselves accept
   pointer events, everything else passes through to the page.
   ========================================================================== */
.purr-seasonal {
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: none;
    overflow: hidden;
    contain: strict;
}
.purr-seasonal > * { pointer-events: auto; }

/* -------------------------------------------------- Halloween: peeking ghost */
.purr-ghost {
    position: absolute;
    left: 0;
    bottom: clamp(4rem, 12vh, 9rem);
    width: clamp(3.4rem, 5.2vw, 4.6rem);
    height: clamp(4.4rem, 6.8vw, 6rem);
    margin-left: -2.1rem;                 /* only a sliver peeks out */
    opacity: 0.15;                        /* mandated watermark cap */
    cursor: pointer;
    border: 0;
    padding: 0;
    background: none;
    -webkit-tap-highlight-color: transparent;
    filter: drop-shadow(0 0.7rem 1.4rem rgba(155, 92, 255, 0.35));
    transform: translate3d(0, 0, 0);
    transition: opacity 0.45s var(--th-ease), transform 0.45s var(--th-ease), filter 0.45s var(--th-ease);
    animation: th-ghost-bob 7s ease-in-out infinite;
    will-change: transform, opacity;
}
.purr-ghost:hover,
.purr-ghost:focus-visible,
.purr-ghost.is-peek {
    opacity: 0.5;
    transform: translate3d(1.5rem, -0.6rem, 0);
    filter: drop-shadow(0 1rem 2rem rgba(155, 92, 255, 0.55));
    outline: none;
}
.purr-ghost .ghost-body {
    position: absolute;
    inset: 0;
    border-radius: 48% 48% 22% 22%;
    background: radial-gradient(62% 58% at 42% 28%, #ffffff, #e9e2ff 58%, #c8b4ff);
    clip-path: polygon(0 0, 100% 0, 100% 76%, 86% 92%, 72% 76%, 58% 92%, 44% 76%, 30% 92%, 16% 76%, 0 92%);
    box-shadow: inset -0.4rem -0.6rem 1rem rgba(120, 90, 190, 0.28);
}
.purr-ghost .ghost-eye {
    position: absolute;
    top: 34%;
    width: 14%;
    height: 20%;
    border-radius: 50%;
    background: #2a1640;
    animation: th-ghost-blink 5.5s infinite;
}
.purr-ghost .ghost-eye.l { left: 26%; }
.purr-ghost .ghost-eye.r { left: 56%; }
.purr-ghost .ghost-mouth {
    position: absolute;
    top: 58%;
    left: 42%;
    width: 18%;
    height: 11%;
    border-radius: 0 0 1rem 1rem;
    background: #2a1640;
    opacity: 0.85;
}
.purr-ghost .ghost-boo {
    position: absolute;
    top: -1.6rem;
    left: 50%;
    transform: translate3d(-50%, 0.3rem, 0) scale(0.85);
    opacity: 0;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    color: #d9c7ff;
    white-space: nowrap;
    transition: opacity 0.3s ease, transform 0.3s var(--th-ease);
    pointer-events: none;
}
.purr-ghost:hover .ghost-boo,
.purr-ghost:focus-visible .ghost-boo {
    opacity: 1;
    transform: translate3d(-50%, 0, 0) scale(1);
}

/* the "poof" — scale up, drift up, fade + blur, then the node is removed */
.purr-ghost.is-poof,
.purr-snowman.is-poof {
    animation: none;
    pointer-events: none;
    opacity: 0 !important;
    transform: translate3d(2.5rem, -5rem, 0) scale(1.35);
    filter: blur(0.6rem) drop-shadow(0 0 0 transparent);
    transition: opacity 0.55s ease, transform 0.55s var(--th-ease), filter 0.55s ease;
}

@keyframes th-ghost-bob {
    0%, 100% { translate: 0 0; rotate: -2deg; }
    50%      { translate: 0.4rem -0.7rem; rotate: 2deg; }
}
@keyframes th-ghost-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    95%           { transform: scaleY(0.08); }
}

/* -------------------------------------------------- Christmas: snowman */
.purr-snowman {
    position: absolute;
    right: clamp(0.75rem, 2vw, 1.5rem);
    bottom: clamp(3.5rem, 10vh, 7rem);
    width: clamp(3rem, 4.6vw, 4rem);
    height: clamp(4.2rem, 6.4vw, 5.6rem);
    opacity: 0.2;
    cursor: pointer;
    border: 0;
    padding: 0;
    background: none;
    -webkit-tap-highlight-color: transparent;
    transform: translate3d(0, 0, 0);
    transition: opacity 0.4s var(--th-ease), transform 0.4s var(--th-ease);
    animation: th-snowman-sway 8s ease-in-out infinite;
    will-change: transform, opacity;
}
.purr-snowman:hover,
.purr-snowman:focus-visible { opacity: 0.55; transform: scale(1.05); outline: none; }
.purr-snowman .sm-ball {
    position: absolute;
    left: 50%;
    translate: -50% 0;
    border-radius: 50%;
    background: radial-gradient(60% 60% at 38% 30%, #ffffff, #dbe7ff 70%, #b9c9e8);
    box-shadow: inset -0.35rem -0.45rem 0.9rem rgba(120, 140, 180, 0.35);
}
.purr-snowman .sm-ball.b1 { width: 62%; height: 42%; bottom: 0; }
.purr-snowman .sm-ball.b2 { width: 46%; height: 32%; bottom: 36%; }
.purr-snowman .sm-ball.b3 { width: 36%; height: 25%; bottom: 64%; }
.purr-snowman .sm-eye {
    position: absolute; top: 74%; width: 5%; height: 4%;
    border-radius: 50%; background: #1b2230;
}
.purr-snowman .sm-eye.l { left: 38%; }
.purr-snowman .sm-eye.r { left: 56%; }
.purr-snowman .sm-nose {
    position: absolute; top: 79%; left: 50%; width: 16%; height: 4%;
    background: #ff8a3d; border-radius: 0.25rem; translate: -40% 0; rotate: 8deg;
}
.purr-snowman .sm-hat {
    position: absolute; top: 47%; left: 50%; translate: -50% 0;
    width: 48%; height: 5%; background: #c0392b; border-radius: 0.2rem;
}
.purr-snowman .sm-hat::before {
    content: ""; position: absolute; left: 18%; bottom: 100%;
    width: 64%; height: 150%; background: #c0392b; border-radius: 0.25rem 0.25rem 0 0;
}
@keyframes th-snowman-sway {
    0%, 100% { rotate: -2deg; }
    50%      { rotate: 2deg; }
}

/* -------------------------------------------------- Christmas: drifting snow */
.purr-flake {
    position: absolute;
    top: -1.5rem;
    width: 0.22rem;
    height: 0.22rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    opacity: 0.18;                     /* watermark cap */
    animation: th-flake-fall linear infinite;
    will-change: transform, opacity;
}
@keyframes th-flake-fall {
    0%   { transform: translate3d(0, -6vh, 0); opacity: 0; }
    12%  { opacity: 0.18; }
    100% { transform: translate3d(2.5rem, 108vh, 0); opacity: 0; }
}

/* -------------------------------------------------- Valentine: soft hearts */
.purr-heart {
    position: absolute;
    bottom: -2rem;
    font-size: 0.7rem;
    line-height: 1;
    color: #ff4f92;
    opacity: 0.15;                     /* watermark cap */
    animation: th-heart-rise linear infinite;
    will-change: transform, opacity;
    user-select: none;
}
@keyframes th-heart-rise {
    0%   { transform: translate3d(0, 0, 0) scale(0.6); opacity: 0; }
    14%  { opacity: 0.15; }
    100% { transform: translate3d(1.2rem, -104vh, 0) scale(1); opacity: 0; }
}

/* -------------------------------------------------- New Year: real fireworks */
/* Each .purr-firework is a tiny burst: a core flash plus 12 sparks placed on a
   circle with per-spark --a (angle) and --d (distance) custom properties. */
.purr-firework {
    position: absolute;
    width: 0.18rem;
    height: 0.18rem;
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    animation: th-firework-cycle 6s ease-out infinite;
    will-change: transform, opacity;
}
.purr-firework .fw-core {
    position: absolute;
    inset: -0.28rem;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, var(--fw, #d4af37) 55%, transparent 72%);
    animation: th-firework-core 6s ease-out infinite;
}
.purr-firework .fw-spark {
    position: absolute;
    top: 0;
    left: 0;
    width: 0.14rem;
    height: 0.14rem;
    border-radius: 50%;
    background: var(--fw, #d4af37);
    box-shadow: 0 0 0.35rem var(--fw, #d4af37);
    transform: rotate(calc(var(--a) * 1deg)) translate3d(0, 0, 0);
    opacity: 0;
    animation: th-firework-spark 6s ease-out infinite;
    animation-delay: var(--delay, 0s);
    will-change: transform, opacity;
}
@keyframes th-firework-cycle {
    0%, 62%, 100% { opacity: 0; }
    63%           { opacity: 0.85; }
    78%           { opacity: 0.5; }
    88%           { opacity: 0; }
}
@keyframes th-firework-core {
    0%, 62%, 100% { transform: scale(0.2); opacity: 0; }
    64%           { transform: scale(1.4); opacity: 0.9; }
    76%           { transform: scale(0.6); opacity: 0; }
}
@keyframes th-firework-spark {
    0%, 62%, 100% { transform: rotate(calc(var(--a) * 1deg)) translate3d(0, 0, 0) scale(0.4); opacity: 0; }
    66%           { transform: rotate(calc(var(--a) * 1deg)) translate3d(0, calc(var(--d) * -0.55), 0) scale(1); opacity: 0.95; }
    82%           { transform: rotate(calc(var(--a) * 1deg)) translate3d(0, calc(var(--d) * -1), 0) scale(0.55); opacity: 0.35; }
    92%           { transform: rotate(calc(var(--a) * 1deg)) translate3d(0, calc(var(--d) * -1.25), 0) scale(0.2); opacity: 0; }
}

/* -------------------------------------------------- responsive scaling */
@media (max-width: 768px) {
    .purr-ghost {
        width: clamp(2.6rem, 9vw, 3.2rem);
        height: clamp(3.4rem, 11.5vw, 4.2rem);
        margin-left: -1.5rem;
        bottom: clamp(4.5rem, 14vh, 7rem);
    }
    .purr-snowman {
        width: clamp(2.4rem, 8vw, 3rem);
        height: clamp(3.4rem, 11vw, 4.2rem);
        bottom: clamp(4.5rem, 13vh, 6.5rem);
    }
    .purr-flake { width: 0.18rem; height: 0.18rem; }
    .purr-heart { font-size: 0.6rem; }
}

/* -------------------------------------------------- motion safety */
@media (prefers-reduced-motion: reduce) {
    .purr-ghost,
    .purr-snowman,
    .purr-flake,
    .purr-heart,
    .purr-firework,
    .purr-firework .fw-core,
    .purr-firework .fw-spark {
        animation: none !important;
    }
    .purr-ghost, .purr-snowman { opacity: 0.15; }
    .purr-flake, .purr-heart, .purr-firework { display: none; }
    body[data-theme] * { scroll-behavior: auto !important; }
}

/* -------------------------------------------------- print */
@media print {
    .purr-seasonal { display: none !important; }
    body[data-theme]::before,
    body[data-theme]::after { display: none !important; }
}
