/* ============================================================
   Reader — shared slider + full-size lightbox component
   Used by: brand-assets.html (style guide), onboarding.html (dashboard
   screens). Behavior lives in assets/js/reader.js. Consumes tokens from
   main.css only.

   Per-page knobs (set on the .reader element or an ancestor):
     --reader-aspect  frame aspect ratio          (default 1512 / 917)
     --reader-fit     object-fit for the image    (default cover)
     --reader-bg      frame background            (default --bg-light-purple)
   ============================================================ */

/* Style-guide reader ------------------------------------------
   A branded "document viewer": titled top bar, a full-bleed slide
   frame you click to open full-size, and a numbered section roadmap
   (TOC) below. Reuses tokens only. */
.reader {
    position: relative;
    isolation: isolate;
}

/* Soft brand glow behind the window */
.reader__glow {
    position: absolute;
    inset: -14% -10% -22%;
    z-index: -1;
    background:
        radial-gradient(46% 55% at 74% 26%, rgba(119, 82, 254, 0.42), transparent 72%),
        radial-gradient(40% 50% at 20% 88%, rgba(131, 91, 255, 0.30), transparent 70%);
    filter: blur(28px);
    pointer-events: none;
}

.reader__window {
    position: relative;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(119, 82, 254, 0.12);
    box-shadow: 0 30px 60px rgba(119, 82, 254, 0.20), 0 10px 24px rgba(16, 24, 40, 0.06);
    overflow: hidden;
}

/* Top bar — reads like an app/document header */
.reader__bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(119, 82, 254, 0.10);
    background: linear-gradient(90deg, rgba(119, 82, 254, 0.06), rgba(119, 82, 254, 0) 62%);
}

.reader__badge {
    flex: none;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--bg-soft-purple);
    color: var(--color-primary);
}

.reader__badge svg { width: 16px; height: 16px; }

.reader__section {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader__count {
    flex: none;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.reader__count b { color: var(--color-primary); }
.reader__count-sep { margin: 0 2px; opacity: 0.6; }

.reader__expand {
    flex: none;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    border: 1px solid var(--border-light);
    background: var(--bg-white);
    color: var(--color-primary);
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.reader__expand svg { width: 15px; height: 15px; }

.reader__expand:hover {
    border-color: var(--color-primary);
    background: var(--bg-light-purple);
    transform: translateY(-1px);
}

/* Autoplay progress line — shown only while auto-advancing (JS hides it
   on manual interaction; reduced-motion never shows it). */
.reader__progress {
    height: 3px;
    background: rgba(119, 82, 254, 0.12);
    overflow: hidden;
    border-radius: 2px;
}

.reader__progress span {
    display: block;
    height: 100%;
    background: var(--color-primary);
    transform: scaleX(0);
    transform-origin: left center;
}

@media (prefers-reduced-motion: reduce) {
    .reader__progress { display: none; }
}

/* Slide frame */
.reader-frame {
    position: relative;
    aspect-ratio: var(--reader-aspect, 1512 / 917);
    overflow: hidden;
    background: var(--reader-bg, var(--bg-light-purple));
}

.reader-frame picture,
.reader-frame img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    /* cover for full-bleed artwork; contain when the slide is a UI capture
       that must not be cropped (see onboarding.html) */
    object-fit: var(--reader-fit, cover);
}

.reader-slide {
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.reader-slide.is-active {
    opacity: 1;
    pointer-events: auto;
}

/* Click-to-open overlay + hint */
.reader__open {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 16px;
    border: none;
    background: transparent;
    cursor: zoom-in;
}

.reader__open::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(0deg, rgba(41, 29, 76, 0.28), transparent 42%);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.reader__hint {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 100px;
    background: rgba(41, 29, 76, 0.78);
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
    opacity: 0;
    translate: 0 8px;
    transition: opacity 0.25s ease, translate 0.25s ease;
}

.reader__hint svg { width: 15px; height: 15px; }

.reader:hover .reader__open::after,
.reader__open:focus-visible::after { opacity: 1; }

.reader:hover .reader__hint,
.reader__open:focus-visible .reader__hint { opacity: 1; translate: 0 0; }

/* Prev / next arrows overlaid on the frame */
.reader__nav {
    position: absolute;
    top: 50%;
    z-index: 3;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(119, 82, 254, 0.16);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    color: var(--color-primary);
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.reader__nav svg { width: 18px; height: 18px; }
.reader__nav--prev { left: 12px; }
.reader__nav--next { right: 12px; }

.reader__nav:hover {
    background: #fff;
    border-color: var(--color-primary);
    transform: translateY(-50%) scale(1.06);
}

/* Shared visible focus ring for reader controls */
.reader__expand:focus-visible,
.reader__open:focus-visible,
.reader__nav:focus-visible,
.reader:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Section roadmap (table of contents) — a numbered stepper that
   doubles as navigation. Horizontal filmstrip; active scrolls in. */
.reader__toc {
    display: flex;
    gap: 6px;
    padding: 12px;
    border-top: 1px solid rgba(119, 82, 254, 0.10);
    overflow-x: auto;
    scrollbar-width: none;
    scroll-behavior: smooth;
}

.reader__toc::-webkit-scrollbar { display: none; }

.reader-toc-step {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 6px;
    border-radius: 100px;
    border: 1px solid transparent;
    background: var(--bg-light-purple);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.reader-toc-step__num {
    flex: none;
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(119, 82, 254, 0.14);
    color: var(--color-primary);
    font-size: 0.68rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.reader-toc-step:hover {
    color: var(--text-primary);
    border-color: rgba(119, 82, 254, 0.28);
}

.reader-toc-step.is-active {
    background: var(--color-primary);
    color: #fff;
}

.reader-toc-step.is-active .reader-toc-step__num {
    background: rgba(255, 255, 255, 0.24);
    color: #fff;
}

.reader-toc-step:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ------------------------------------------------------------
   FULL-SIZE READER (lightbox)
   ------------------------------------------------------------ */
.reader-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 3vw, 40px);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.reader-lightbox[hidden] { display: none; }
.reader-lightbox.is-open { opacity: 1; }

.reader-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(41, 29, 76, 0.82);
    backdrop-filter: blur(6px);
}

.reader-lightbox__dialog {
    position: relative;
    z-index: 1;
    width: min(1200px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transform: scale(0.98);
    transition: transform 0.2s ease;
}

.reader-lightbox.is-open .reader-lightbox__dialog { transform: scale(1); }

.reader-lightbox__bar {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
}

.reader-lightbox__step {
    flex: none;
    padding: 4px 10px;
    border-radius: 100px;
    background: rgba(255, 255, 255, 0.14);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.reader-lightbox__title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-lightbox__count {
    flex: none;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    font-variant-numeric: tabular-nums;
}

.reader-lightbox__count b { color: #fff; }

.reader-lightbox__close {
    flex: none;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease;
}

.reader-lightbox__close svg { width: 18px; height: 18px; }
.reader-lightbox__close:hover { background: rgba(255, 255, 255, 0.2); }

.reader-lightbox__stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reader-lightbox__pic { display: block; }

.reader-lightbox__pic img {
    display: block;
    max-width: 100%;
    max-height: 78vh;
    width: auto;
    height: auto;
    border-radius: var(--radius-md);
    background: #fff;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
}

.reader-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.4);
    /* Dark frosted disc so the white arrow stays visible whether it sits
       over a white guide page or the dark backdrop. */
    background: rgba(41, 29, 76, 0.55);
    backdrop-filter: blur(8px);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.reader-lightbox__nav svg { width: 22px; height: 22px; }
.reader-lightbox__nav--prev { left: 8px; }
.reader-lightbox__nav--next { right: 8px; }
.reader-lightbox__nav:hover {
    background: rgba(41, 29, 76, 0.85);
    border-color: #fff;
    transform: translateY(-50%) scale(1.06);
}

.reader-lightbox__close:focus-visible,
.reader-lightbox__nav:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .reader-slide,
    .reader-lightbox,
    .reader-lightbox__dialog,
    .reader__hint,
    .reader__open::after { transition: none; }
}


/* ---- Narrow screens ---- */
@media (max-width: 560px) {
    .reader__bar { padding: 10px 12px; gap: 8px; }
    .reader__section { font-size: 0.82rem; }
    .reader__nav { width: 34px; height: 34px; }
    .reader__nav svg { width: 16px; height: 16px; }
    .reader__toc { padding: 10px; }
    .reader-toc-step { font-size: 0.74rem; }

    .reader-lightbox__step { display: none; }
    .reader-lightbox__pic img { max-height: 72vh; }
    .reader-lightbox__nav { width: 40px; height: 40px; }
}
