/* Twitch "live now" card - home page only (loaded from MainLayout when isHome).
   A cinematic, always-dark frame: a near-black rounded slab that breaks out to
   the header width, with the 16:9 player and the metadata floating inside a
   matte. Deliberately a featured, ephemeral element. See Includes/twitch-live.html. */

.twitch-live {
    display: flex;
    flex-direction: column;
    gap: 12px;                          /* matte between the player and the metadata */
    /* Matches the hero-image width (--media-width), centred on the page; on narrow
       screens it caps to the viewport minus the same gutter as the content
       (--container-pad), so its edges line up with the hero images. */
    width: min(var(--media-width), calc(100vw - 2 * var(--container-pad)));
    margin-block: 0 60px;
    margin-left: 50%;
    transform: translateX(-50%);
    padding: 14px 14px 12px;            /* black matte around player + metadata; a hair less at
                                           the bottom so the Watch button nests concentrically into
                                           the frame's bottom-right corner (see .twitch-live-watch) */
    background: #0b0b0f;
    border-radius: 30px;               /* matches the post hero images */
    corner-shape: squircle;
}

/* Guarantee the hidden state beats the .twitch-live display rule above: the
   class and the UA `[hidden]` rule have equal specificity, so without this the
   card could show before the script reveals it. */
.twitch-live[hidden] { display: none; }

/* --- media: a wide, short "letterbox" canvas ----------------------------- */

/* The blurred thumbnail fills this canvas edge to edge; the real 16:9 player
   (.twitch-live-stage) floats centred inside it, so the sides show the blurred
   stream as ambient letterbox bars - a wide banner that stays short. */
.twitch-live-media {
    position: relative;
    aspect-ratio: 2.15 / 1;          /* wide + short letterbox - keeps the card's height down */
    overflow: hidden;                 /* clip the blurred thumbnail's overspill */
    border-radius: 16px;              /* concentric inside the 30px frame (minus the 14px matte) */
    corner-shape: squircle;
    cursor: pointer;                  /* the whole canvas starts playback */
    background: #0b0b0f;              /* dark fallback; the blurred thumbnail covers it */
    color: #fff;
}

/* Blurred live preview behind the play button - a soft ambient backdrop that
   hides the modest source resolution. The gradient shows through until it loads
   (or if it never does). Below the scrim and the overlays. */
.twitch-live-thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.15);           /* overfill so blurred edges don't reveal the box */
    filter: blur(18px);
    z-index: 0;
}
/* Gentle scrim over the preview so the LIVE badge and play button stay legible
   over bright frames. */
.twitch-live-media::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(11, 7, 20, 0.32);
    z-index: 1;
    pointer-events: none;
}

/* The real 16:9 player, centred in the canvas at its full height, so its width is
   narrower than the wide canvas → blurred letterbox bars on the sides. The play
   button centres in here; the embed fills it on click. */
.twitch-live-stage {
    position: absolute;
    top: 0;
    height: 100%;                     /* clamp to the canvas height. NOT top:0 + bottom:0 +
                                         aspect-ratio - that trio over-constrains the box, and
                                         engines disagree on which wins, leaving a sub-pixel gap
                                         at the bottom. A definite height + aspect-ratio is
                                         unambiguous: height fills, width derives from it. */
    left: 50%;
    transform: translateX(-50%);
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 10px;
    corner-shape: squircle;
    /* Transparent: the blurred thumbnail behind shows through until the embed loads. */
    z-index: 2;
}

.twitch-live-badge {
    position: absolute;
    top: 16px;
    left: 16px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #fff;
    background: #e0163a;
    border-radius: 999px;
    z-index: 3;
}
.twitch-live-badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
    animation: twitch-live-pulse 2s ease-in-out infinite;
}
@keyframes twitch-live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.twitch-live-viewers {
    position: absolute;
    top: 16px;
    right: 16px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    background: rgba(10, 8, 18, 0.6);
    border-radius: 999px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 3;
}
.twitch-live-viewers-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #e0163a;
}

.twitch-live-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: grid;
    place-items: center;
    width: 84px;
    height: 84px;
    padding: 0;
    color: #fff;
    background: #9146ff;
    border: 6px solid rgba(255, 255, 255, 0.10);
    border-radius: 50%;
    cursor: pointer;
    z-index: 2;
    transition: transform 0.18s ease, background 0.18s ease;
}
.twitch-live-play svg { margin-left: 4px; }   /* optically centre the triangle */
.twitch-live-play:hover {
    transform: translate(-50%, -50%) scale(1.06);
    background: #a970ff;
}
.twitch-live-play:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}

/* On-demand embed (injected by Task 4) fills the media surface. */
.twitch-live-embed {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    z-index: 3;
}
/* Once the player is live, the facade overlays get out of its way. */
.twitch-live-media.is-playing .twitch-live-play,
.twitch-live-media.is-playing .twitch-live-badge,
.twitch-live-media.is-playing .twitch-live-viewers {
    display: none;
}
/* Once the player owns the canvas, drop the "click to play" cursor. */
.twitch-live-media.is-playing { cursor: default; }

/* Playing: deepen the scrim so the blurred letterbox bars recede behind the
   live player (the scrim sits below the stage, so only the bars dim - the video
   itself stays untouched), and give the stage a soft shadow. Together they ramp
   the contrast from the bright video out to the dimmed bars, reading as two
   clearly separated layers rather than one flat surface. */
.twitch-live-media.is-playing::after {
    background: rgba(0, 0, 0, 0.5);
}
.twitch-live-media.is-playing .twitch-live-stage {
    /* Solid dark surface the moment play is clicked. The class (and this shadow)
       apply instantly, but the Twitch iframe takes a beat to load - without a
       background the stage stays transparent and the shadow appears to be cast
       by nothing. This also reads as a clean loading backdrop the player fades
       into. */
    background: #18181b;
    box-shadow: 0 0 50px 25px rgba(0, 0, 0, 0.55);
}

/* --- bar ----------------------------------------------------------------- */

.twitch-live-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 1px 4px;                 /* 4px sides align the metadata with the player edges; the
                                         1px top/bottom leaves the button equally spaced above and
                                         below (the rest of its breathing room is the frame gap +
                                         padding, tuned so top gap == bottom gap == 18px) */
}
.twitch-live-avatar-wrap {
    position: relative;
    flex: 0 0 auto;
    height: 56px;                     /* avatar (46) + the LIVE badge's 10px overhang, so
                                         the wrap IS the unit and centres (with the text) as one.
                                         This drives the bar's height, so a smaller avatar tightens
                                         the whole metadata section. */
    line-height: 0;                   /* no descender gap under the avatar */
    text-decoration: none;            /* it's a link to the owner's Twitch */
}
/* No hover state on the avatar link - suppress the global a:hover underline that
   would otherwise strike through the LIVE badge. */
.twitch-live .twitch-live-avatar-wrap:hover { text-decoration: none; }
.twitch-live-avatar {
    display: block;
    position: relative;
    top: -2px;                        /* optical nudge up; the wrap (and its centring) is unchanged */
    width: 46px;
    height: 46px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.08);  /* dark placeholder while the avatar loads */
}
/* Twitch-style LIVE badge straddling the bottom of the avatar - the persistent
   live indicator (the in-video badge is covered once the player opens). */
.twitch-live-avatar-badge {
    position: absolute;
    bottom: -1px;                     /* just below the wrap's base - a hair lower on the avatar */
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 6px;
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 1;
    color: #fff;
    background: #e0163a;
    border-radius: 5px;
    border: 2px solid #0b0b0f;        /* cutout ring matching the frame */
}
.twitch-live-meta {
    flex: 1 1 auto;
    min-width: 0;                     /* let the ellipsis engage */
}
.twitch-live-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.6;
    color: #f5f5f7;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.twitch-live-sub {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: rgba(235, 235, 245, 0.62);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.twitch-live-channel { font-weight: 600; }

/* Title and channel are links to Twitch - keep their resting appearance (inherit the
   title/subtitle colour; two classes to beat `.container a`'s link colour) and tint
   Twitch purple on hover, matching the card's buttons. */
.twitch-live .twitch-live-title-link,
.twitch-live .twitch-live-channel {
    color: inherit;
    text-decoration: none;
    transition: color 0.15s ease;
}
.twitch-live .twitch-live-title-link:hover,
.twitch-live .twitch-live-channel:hover {
    color: #9146ff;
}

/* Scoped two classes deep so the white text beats any `.container a` link
   colour without needing !important. */
.twitch-live .twitch-live-watch {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 18px;
    font-size: 0.92rem;
    font-weight: 700;
    color: #fff;
    background: #9146ff;
    border-radius: 12px;              /* 30px frame radius − 18px gap = 12px → concentric with the
                                         frame's bottom-right corner */
    corner-shape: squircle;          /* match the frame's squircle so the nesting is a true concentric */
    text-decoration: none;
    transition: background 0.18s ease;
}
.twitch-live .twitch-live-watch:hover { background: #a970ff; }
.twitch-live-watch svg { width: 20px; height: 20px; }

/* --- narrow screens ------------------------------------------------------ */

@media (max-width: 560px) {
    /* Narrow columns: drop the letterbox. A 16:9 canvas + the 16:9 stage means the
       stage spans the full width (no pillarbox bars) - the video just fills it. */
    .twitch-live-media { aspect-ratio: 16 / 9; }
    /* Avatar + title/subtitle stay on one row (flex-basis:0 stops the nowrap title
       from giving the meta a huge basis that bumps it onto its own line); the button
       drops to a full-width row below. Two classes are needed so this flex beats the
       base `.twitch-live .twitch-live-watch { flex: 0 0 auto }`. */
    .twitch-live-bar { flex-wrap: wrap; }
    .twitch-live-meta { flex-basis: 0; }
    .twitch-live .twitch-live-watch {
        flex: 1 0 100%;
        order: 3;
        justify-content: center;
    }
}

/* --- responsive: card bottom gap ----------------------------------------- */

/* Tablet/phone: halve the card's bottom gap (60px -> 30px). The TOP gap is set
   for all article pages in site.css (body:has(article) main .container). */
@media (max-width: 1000px) {
    .twitch-live { margin-block: 0 30px; }
}

/* --- reduced motion ------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    .twitch-live-badge-dot { animation: none; }
    .twitch-live-play,
    .twitch-live .twitch-live-watch,
    .twitch-live .twitch-live-title-link,
    .twitch-live .twitch-live-channel { transition: none; }
    .twitch-live-play:hover { transform: translate(-50%, -50%); }
}
