/*
 * Living Panels reader — ported from the site's episode-view component so the
 * episodes match the product reader. SCSS tokens are resolved to literals:
 *
 *   #131313 black-base   #fafafa white-base   #ffffff white
 *   #c7ffc7 green        rgba(199,255,199,.6) green-60
 *   #80ff00 green-accent rgba(255,255,255,.15) white-15
 *
 * Panels are a single vertical column. Each <section class="panel"> is a fixed
 * aspect-ratio box holding, stacked: the poster <img>, the looping <video>
 * (hidden until it actually plays, hence `.live`), any bubble/SFX overlays
 * (revealed by `.pop`), and the caption.
 *
 * State classes driven by the reader:
 *   .in       panel is meaningfully on screen
 *   .live     its video is decoding and playing — fade the video over the poster
 *   .pop      reveal the bubble/SFX overlays
 *   .speaking a voice line is playing — show the caption
 *   body.dark a `dark` panel is on screen — fade the whole page to black
 *   body.nosubs  manifest.subs === false
 */

/*
 * ---------- Global reset (from the marketing app's styles.scss) ----------
 *
 * WordPress port: scoped to `body.living-panels` (the class this template adds
 * via body_class), so the reset cannot reach anything WordPress puts outside
 * the reader.
 *
 * The scope sits inside `:where()` on purpose. A reset has to stay the weakest
 * rule on the page — plain `body.living-panels *` scores higher than the very
 * rules it is resetting, so `margin: 0` here would beat `.images-scroll`'s
 * `margin: auto` and knock the panel column out of the centre. `:where()`
 * contributes no specificity, keeping this exactly as weak as the bare `*` it
 * replaces.
 */
:where(body.living-panels),
:where(body.living-panels) * {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    border: none;
    outline: none;
    box-shadow: none;

    font-family: Kanit, sans-serif;
    font-style: normal;
    font-size: 14px;
    font-weight: 400;
    line-height: 140%;
    word-break: break-word;
}

:where(body.living-panels) *:focus {
    box-shadow: none;
    text-shadow: none;
    outline: none;
}

/* Not :where() — this one has to outrank the active theme's own body rule. */
body.living-panels {
    overflow-x: hidden;
    background: #131313;
}

.container {
    margin: auto;
    width: 100%;
    padding: 0 16px;
    /* The reader narrows the app-wide 1200px container to the panel column. */
    max-width: calc(720px + 32px);
}

.episode-view {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: #fafafa;
}

/* ---------- Header ---------- */
.header {
    background: #131313;
    color: #fafafa;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    transition: opacity 0.3s;
    opacity: 1;
}

.header.hidden {
    opacity: 0;
    pointer-events: none;
}

.header .content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: 58px;
}

.header .back-btn {
    cursor: pointer;
    flex: none;
    width: 34px;
    height: 34px;
    background: url('./prologue-assets/back.svg') center no-repeat;
    transition: transform 0.15s ease;
}

.header .back-btn:hover {
    transform: translateX(-3px);
}

.header .episode-info {
    flex: 1;
    text-align: left;
    margin-left: 8px;
    min-width: 0;
}

.header .comics-title {
    overflow: hidden;
    color: #fafafa;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    font-weight: 500;
    line-height: 120%;
    letter-spacing: 0.16px;
    margin-bottom: 2px;
}

.header .episode-index {
    color: #fafafa;
    font-family: Poppins, sans-serif;
    font-size: 12px;
    font-weight: 300;
    line-height: 120%;
    letter-spacing: 0.12px;
}

/* Hidden on mobile, where the row belongs to the title and the sound toggle. */
.header .logo {
    display: none;
    flex: none;
    background: url('./prologue-assets/logo.svg') center / contain no-repeat;
}

/*
 * The sound toggle is specific to this reader. It follows the footer buttons —
 * bordered, uppercase, transparent on the dark chrome — with the popup's own
 * icon alongside. The label carries the state, so the icon stays full colour
 * in both.
 */
.sound-toggle {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid #fafafa;
    border-radius: 4px;
    background-color: transparent;
    color: #fafafa;
    font-size: 14px;
    font-weight: 700;
    line-height: 17px;
    letter-spacing: 0.56px;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.sound-toggle::before {
    content: '';
    flex: none;
    width: 20px;
    height: 20px;
    background: url('./prologue-assets/sound.svg') center / contain no-repeat;
}

@media (hover: hover) and (pointer: fine) {
    .sound-toggle:hover {
        background-color: rgba(255, 255, 255, 0.15);
    }
}

/* ---------- Panel column ---------- */
.episode-images {
    overflow: hidden;
    margin-bottom: 60px;
}

.images-scroll {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    margin: auto;
    background-color: #ffffff;
    padding-top: 60px;
}

/* ---------- Panel media ---------- */
.panel {
    position: relative;
    width: 100%;
    /* Living panels are paced apart; the site reader butts flat images together. */
    margin: 0 0 var(--gap, 300px);
    background: #ffffff;
    overflow: hidden;
}

.panel:last-child {
    margin-bottom: 0;
}

.panel video,
.panel img {
    display: block;
    width: 100%;
    height: auto;
}

.panel video {
    position: absolute;
    inset: 0;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.35s;
}

.panel.live video {
    opacity: 1;
}

/* bubble / SFX layer: pops in when the panel enters the viewport */
.panel .ov {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.86) translateY(8px);
    transform-origin: 50% 60%;
}

/* .pop = bubbles appear: with the first spoken line when sound is on, on entry otherwise */
.panel.pop .ov {
    animation: pop 0.42s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}

@keyframes pop {
    0% {
        opacity: 0;
        transform: scale(0.86) translateY(8px);
    }
    60% {
        opacity: 1;
        transform: scale(1.04) translateY(-2px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* extra SFX layers with their own motion (overlay_NN_<anim>.png) */
.panel.pop .ov.ov-tap {
    animation:
        pop 0.42s cubic-bezier(0.2, 1.4, 0.4, 1) forwards,
        tap 0.9s ease-in-out 0.6s infinite;
}

@keyframes tap {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.65;
        transform: scale(0.96) translateY(1px);
    }
}

/* ---------- Review-only panel numbers (manifest.numbers) ---------- */
.num {
    position: absolute;
    left: 8px;
    top: 8px;
    z-index: 3;
    font:
        700 13px/1 Kanit,
        sans-serif;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    padding: 5px 8px;
    border-radius: 6px;
    pointer-events: none;
}

.num small {
    font-weight: 400;
    opacity: 0.75;
}

/* ---------- Spoken-line captions (manifest.subs) ---------- */
.cap {
    position: absolute;
    left: 10px;
    bottom: 10px;
    font-size: 11px;
    color: #fff;
    background: rgba(0, 0, 0, 0.45);
    padding: 3px 7px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.panel.speaking .cap {
    opacity: 1;
}

body.nosubs .cap {
    display: none;
}

/* ---------- Next-episode CTA ---------- */
.next-episode-block {
    padding-top: 24px;
    padding-bottom: 24px;
}

.next-episode {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    cursor: pointer;
    border: 1px solid #131313;
    border-radius: 4px;
}

.next-episode .episode-info {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
}

.next-episode .episode-thumbnail {
    border: 1px solid #131313;
    border-radius: 4px;
    width: 93px;
    height: 64px;
    overflow: hidden;
    flex: none;
}

.next-episode .episode-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.next-episode .episode-title {
    color: #131313;
    font-size: 18px;
    font-weight: 600;
    line-height: 120%;
    letter-spacing: 0.18px;
    text-align: left;
}

.next-episode .button {
    border: 1px solid #131313;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 22px 7px;
}

.next-episode.green {
    background: #c7ffc7;
    transition: background 0.15s ease;
}

.next-episode.green:hover {
    background: rgba(199, 255, 199, 0.6);
}

.next-episode.green .button {
    background: #80ff00;
}

/* ---------- Footer ---------- */
.footer {
    background: #131313;
    padding-top: 12px;
    padding-bottom: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    z-index: 100;
    transition:
        opacity 0.3s,
        transform 0.2s ease;
    will-change: transform;
}

.footer.hidden {
    opacity: 0;
    pointer-events: none;
}

.footer-controls {
    display: flex;
    justify-content: space-between;
}

.footer-controls .button {
    border: 1px solid #fafafa;
    border-radius: 4px;
    display: flex;
    background-color: transparent;
    padding: 8px;
    justify-content: center;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: #fafafa;
    font-size: 14px;
    font-weight: 500;
    line-height: 17px;
    letter-spacing: 0.56px;
    text-transform: uppercase;
}

.footer-controls .button[disabled] {
    opacity: 0.5;
}

.footer-controls .button:hover:not([disabled]) {
    cursor: pointer;
    background-color: rgba(255, 255, 255, 0.15);
}

/* ---------- Dark ending ---------- */
/* Panels flagged `dark` fade the whole page (and the gaps between panels) to black. */
html,
body,
.episode-view,
.images-scroll,
.panel,
.header {
    transition:
        background-color 1.4s ease,
        color 1.4s ease;
}

body.dark .episode-view,
body.dark .images-scroll,
body.dark .panel {
    background: #000;
}

/* ---------- First-visit sound gate ---------- */
/*
 * While the gate is up the page must not move: the choice it asks for decides
 * whether panels narrate, so scrolling past it would start the episode without
 * an answer. The class goes on <html> because that is the scrolling element —
 * `overflow: hidden` on <body> alone leaves the page scrollable. It is set in
 * the markup so it holds from first paint, before the reader boots, and dropped
 * when the gate is dismissed.
 */
html.gated,
html.gated body {
    overflow: hidden;
}

/*
 * Follows the popup convention from the marketing app (register / age-verification):
 * a dimmed full-screen wrapper, a rounded off-white card that slides in, and a
 * small round close button in the corner.
 */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.popup-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    padding: 16px;
    background: rgba(19, 19, 19, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup {
    position: relative;
    width: 100%;
    max-width: 400px;
    border-radius: 8px;
    background: #fafafa;
    padding: 24px 16px 32px;
    overflow: hidden;
    text-align: center;
    animation: slideIn 0.3s ease-out;
}

.popup .close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid #131313;
    border-radius: 50%;
    background: url('./prologue-assets/close.svg') center no-repeat;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.popup .close-button:hover {
    background-color: #c7ffc7;
}

/* Circular badge holding the same icon as the header toggle. */
.popup-icon {
    width: 200px;
    height: 200px;
    margin: 0 auto 20px;
    border-radius: 50%;
    background-color: #c7ffc7;
    background-image: url('./prologue-assets/sound.svg');
    background-position: center;
    background-repeat: no-repeat;
    background-size: 116px 98px;
}

.popup .title {
    font-size: 20px;
    font-weight: 600;
    line-height: 120%;
    letter-spacing: 0.2px;
    color: #131313;
    margin-bottom: 8px;
}

.popup .text {
    font-family: Poppins, sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 140%;
    color: #131313;
}

.popup .buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 24px;
}

/* btn-green / btn-white, matching the design system's button mixins. */
.popup .btn-green,
.popup .btn-white {
    display: flex;
    height: 50px;
    justify-content: center;
    align-items: center;
    border-radius: 50px;
    color: #131313;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    line-height: 120%;
    letter-spacing: 0.32px;
    text-transform: uppercase;
    cursor: pointer;
    will-change: background;
    transition: background 150ms linear;
}

.popup .btn-green {
    border: 1px solid #333333;
    background: #80ff00;
}

.popup .btn-white {
    border: 1px solid #131313;
    background: #fafafa;
}

/* Hover only where there is a real pointer, so taps don't stick. */
@media (hover: hover) and (pointer: fine) {
    .popup .btn-green:hover,
    .popup .btn-white:hover {
        background: #c7ffc7;
    }
}

.popup .btn-green[disabled] {
    opacity: 0.6;
    cursor: default;
}

.popup .status {
    font-size: 12px;
    color: #656565;
    min-height: 16px;
    margin-top: 12px;
}

.popup .status:empty {
    display: none;
}

/* ---------- Age verification ---------- */
/* Ported from the site's age-verification component. Reuses .popup-wrapper and
   .popup from the sound gate, which follow the same convention. */
.age-popup {
    height: 452px;
    max-width: 400px;
    padding: 0;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    text-align: left;
}

.age-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 24px 16px 32px 16px;
    background: linear-gradient(180deg, rgba(69, 0, 130, 0) 15%, rgba(69, 0, 130, 0.85) 100%);
}

.age-title {
    font-size: 20px;
    font-weight: 600;
    line-height: 125%;
    letter-spacing: 0.2px;
    color: #fafafa;
    margin-bottom: 8px;
    text-align: center;
}

.age-text {
    color: #fafafa;
    text-align: center;
    font-family: Poppins, sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 140%;
}

.age-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 24px;
    width: 100%;
}

/* btn-green / btn-white from the design system, at the popup's 48px height. */
.age-buttons .btn-agree,
.age-buttons .btn-disagree {
    display: flex;
    height: 48px;
    justify-content: center;
    align-items: center;
    border-radius: 50px;
    color: #131313;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    line-height: 120%;
    letter-spacing: 0.32px;
    text-transform: uppercase;
    cursor: pointer;
    will-change: background;
    transition: background 150ms linear;
}

.age-buttons .btn-agree {
    width: calc(100% - 81px);
    max-width: 220px;
    border: 1px solid #333333;
    background: #80ff00;
}

.age-buttons .btn-disagree {
    width: 75px;
    border: 1px solid #131313;
    background: #fafafa;
}

@media (hover: hover) and (pointer: fine) {
    .age-buttons .btn-agree:hover,
    .age-buttons .btn-disagree:hover {
        background: #c7ffc7;
    }
}

/* ---------- Swipe hint ---------- */
/* Ported from the site's swipe-hint component. Sits below the sound gate's
   z-index, so it is only ever shown once the gate has been answered. */
@keyframes handFloat {
    0%,
    100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-16px);
    }
}

@keyframes swipeFadeIn {
    from {
        opacity: 0;
        transform: scale(0.88);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes swipeFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.88);
    }
}

.swipe-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    pointer-events: none;
    animation: swipeFadeIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.swipe-overlay.leaving {
    animation: swipeFadeOut 0.2s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

.swipe-card {
    position: relative;
    pointer-events: auto;
    border-radius: 8px;
    background: rgba(19, 19, 19, 0.9);
    padding: 20px 33px 18px 33px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    cursor: pointer;
    max-width: 150px;
    user-select: none;
}

.swipe-card .arrow-wrap {
    height: 118px;
    background: url('./prologue-assets/swipe-arrow.svg') top center / 15px 118px no-repeat;
}

.swipe-card .hand-wrap {
    width: 50px;
    height: 50px;
    position: absolute;
    right: 20px;
    top: 70px;
    background: url('./prologue-assets/swipe-hand.svg') center / 50px 50px no-repeat;
    animation: handFloat 1.3s ease-in-out infinite;
}

.swipe-card .swipe-label {
    color: #fafafa;
    text-align: center;
    font-family: Poppins, sans-serif;
    font-size: 14px;
    font-weight: 500;
    line-height: 120%;
    letter-spacing: 0.56px;
    text-transform: uppercase;
}

/* ---------- Desktop ---------- */
@media screen and (min-width: 767px) {
    .header .content {
        height: 64px;
    }

    .header .logo {
        display: block;
        width: 60px;
        height: 48px;
    }

    .sound-toggle {
        margin-right: 16px;
    }

    .popup .title {
        font-size: 24px;
        line-height: 125%;
        letter-spacing: 0.28px;
    }

    .images-scroll {
        max-width: 720px;
    }

    .next-episode-block {
        padding-bottom: 56px;
    }

    .footer-controls {
        gap: 40px;
        justify-content: center;
    }
}
