/* ============================================================================
   Voicy.ai — Shared styles for every page (home + 14 vision pages)
   - Typography tokens
   - Cross-document View Transitions (page-to-page navigation)
   - Fallback enter/leave animation for browsers without them
   ============================================================================ */

:root {
    /* Same curve as the home page's chapter slide (style.css --ease-curtain):
       moves at once, soft landing */
    --vt-ease: cubic-bezier(0.32, 0.72, 0, 1);
    --vt-ease-in: cubic-bezier(0.55, 0, 0.75, 0.25);
    --vt-dur: 600ms;
    /* old page leaving: loses most of its opacity in the first ~80ms */
    --vt-out: cubic-bezier(0, 0, 0.2, 1);

    /* ---- Colour roles (light theme) -----------------------------------------
       Space-separated RGB so Tailwind opacity modifiers work: bg-ink/10 etc.
       (mapped in tailwind.config.js). Change a role here, not in the markup. */
    --c-canvas: 255 255 255;      /* page background                         */
    --c-subtle: 246 248 250;      /* alternate section background            */
    --c-tint: 240 249 245;        /* soft mint section background            */
    --c-surface: 255 255 255;     /* cards, panels                           */
    --c-ink: 15 23 42;            /* headings          (slate-900)           */
    --c-body: 71 85 105;          /* body text         (slate-600, 7.6:1)    */
    --c-muted: 87 99 118;         /* captions, labels  (5.9:1 on white, 5.3:1 on the grey/mint bands) */
    --c-line: 226 232 240;        /* borders, dividers (slate-200)           */
    --c-brand: 4 120 87;          /* green text + buttons (emerald-700, 5.5:1) */
    --c-brand-hover: 6 95 70;     /* emerald-800                             */
    --c-accent: 16 185 129;       /* bright green: icons, highlights only    */

    --header-h: 4rem;             /* 64px on laptops, scales with root size  */
    --header-h-condensed: 3.5rem; /* after leaving the hero / scrolling      */
}

html { background-color: rgb(var(--c-canvas)); color-scheme: light; }

/* -------------------------------------------------------------------------
   Fluid sizing for large screens
   Everything is sized in rem, so the root font size scales the whole site.
   - 16px on laptops (identical to before up to ~1450x820)
   - grows to 20px on big monitors
   - capped by viewport HEIGHT too (1.95vh), so every full-screen chapter
     keeps fitting without inner scrolling on wide-but-short windows
   ------------------------------------------------------------------------- */
html {
    font-size: clamp(16px, min(1.1vw, 1.95vh), 24px);
}

/* Use the extra width on large screens instead of leaving empty margins
   (from 1700px, where there's room for the full chapter dock beside it) */
@media (min-width: 1700px) {
    /* 90rem grows with the root size, so also keep 5rem of air each side for the dock */
    .max-w-7xl { max-width: min(90rem, calc(100vw - 10rem)); }
}

.font-serif-hero { font-family: 'Playfair Display', Georgia, serif; }
.font-mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }

:focus-visible {
    outline: 2px solid #059669;
    outline-offset: 2px;
    border-radius: 6px;
}

/* -------------------------------------------------------------------------
   Top bar (home + vision pages): 64px, eases to 56px with a soft shadow once
   you leave the hero (home) or scroll down (vision pages). Toggled by
   .is-condensed from scroller.js / the vision page script.
   ------------------------------------------------------------------------- */
.site-header {
    background-color: rgb(255 255 255 / 0.82);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid rgb(var(--c-line) / 0.8);
    transition: background-color 0.4s var(--vt-ease), box-shadow 0.4s var(--vt-ease);
}
.site-header-inner {
    height: var(--header-h);
    transition: height 0.4s var(--vt-ease);
}
/* Logo: vector mark (brand green) + live wordmark, both scale with the bar */
.site-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 2.5rem;
    font-size: 1.375rem;
    color: rgb(var(--c-brand));
    text-decoration: none;
    transition: height 0.4s var(--vt-ease), font-size 0.4s var(--vt-ease);
}
.site-logo-mark { height: 100%; width: auto; flex: none; }
.site-logo-word {
    color: rgb(var(--c-ink));
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
    white-space: nowrap;
}
.site-header.is-condensed {
    background-color: rgb(255 255 255 / 0.94);
    box-shadow: 0 8px 24px -16px rgb(15 23 42 / 0.25);
}
.site-header.is-condensed .site-header-inner { height: var(--header-h-condensed); }
.site-header.is-condensed .site-logo { height: 2.25rem; font-size: 1.25rem; }
.curtain-instant .site-header,
.curtain-instant .site-header-inner,
.curtain-instant .site-logo,
.site-header.header-hold,
.site-header.header-hold .site-header-inner,
.site-header.header-hold .site-logo { transition: none; }

/* -------------------------------------------------------------------------
   Cross-document View Transitions (Chrome/Edge 126+, Safari 18.2+)
   page-transitions.js tags each navigation with a type:
     open  : home -> vision page   (card artwork morphs into the page hero)
     close : vision page -> home   (hero artwork morphs back into its card)
     next / prev : vision -> vision (directional slide; header stays put)
   ------------------------------------------------------------------------- */
@view-transition {
    navigation: auto;
}

/* The top bar is the same size on every page, so it stays anchored while the
   page underneath it changes. The logo and the Let's Talk button are the same
   on both pages and are captured on their own, so they never flicker; only
   the links in between swap, quickly (old ones out in 120ms, new ones in by
   200ms), so the two sets never read as doubled text. */
.site-header { view-transition-name: site-header; }
.site-header .site-logo { view-transition-name: site-logo; }
.site-header .site-cta { view-transition-name: site-cta; }
::view-transition-group(site-header) { z-index: 50; animation-duration: 320ms; }
::view-transition-group(site-logo),
::view-transition-group(site-cta) { z-index: 51; animation-duration: 320ms; }
::view-transition-old(site-header) { animation: 120ms ease-out both vt-fade-out; }
::view-transition-new(site-header) { animation: 200ms ease-out both vt-fade-in; }

/* Shared artwork / category chip morph */
::view-transition-group(vision-visual),
::view-transition-group(vision-category) {
    z-index: 40;
    animation-duration: 640ms;
    animation-timing-function: var(--vt-ease);
}
/* Chip travels above the artwork, matching how it sits on the card */
::view-transition-group(vision-category) { z-index: 41; }
::view-transition-old(vision-visual),
::view-transition-new(vision-visual) {
    animation-duration: 640ms;
    height: 100%;
    object-fit: contain;
}

/* Page bodies. One rule for every navigation: the new page is solid from the
   first frame and sits *under* the old one, which fades away on top. There
   is never a moment where two half-transparent pages are mixed (the washed
   out, blank-looking middle of a plain cross-fade). Motion comes from the
   artwork morph and the new page's own staggered entrance ([data-enter]). */
::view-transition-old(root) { z-index: 1; animation: 180ms var(--vt-out) both vt-fade-out; }
::view-transition-new(root) { animation: none; }

/* open: home steps back slightly as it fades */
html:active-view-transition-type(open)::view-transition-old(root) {
    animation: 180ms var(--vt-out) both vt-recede;
}
/* close: the vision page sinks slightly as it fades; home is already there */
html:active-view-transition-type(close)::view-transition-old(root) {
    animation: 180ms var(--vt-out) both vt-drop;
}

/* next / prev between vision pages: the old page leaves sideways, the new one
   glides in from the other side underneath it */
html:active-view-transition-type(next)::view-transition-old(root) { animation: 180ms var(--vt-out) both vt-out-left; }
html:active-view-transition-type(next)::view-transition-new(root) { animation: 520ms var(--vt-ease) both vt-in-right; }
html:active-view-transition-type(prev)::view-transition-old(root) { animation: 180ms var(--vt-out) both vt-out-right; }
html:active-view-transition-type(prev)::view-transition-new(root) { animation: 520ms var(--vt-ease) both vt-in-left; }

@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in { from { opacity: 0; } }
/* Small distances: the page only hints at depth; the artwork carries the move */
@keyframes vt-recede { to { opacity: 0; transform: scale(0.98); } }
@keyframes vt-drop { to { opacity: 0; transform: translateY(12px); } }
@keyframes vt-out-left { to { opacity: 0; transform: translateX(-40px); } }
@keyframes vt-in-right { from { transform: translateX(40px); } }
@keyframes vt-out-right { to { opacity: 0; transform: translateX(40px); } }
@keyframes vt-in-left { from { transform: translateX(-40px); } }

/* -------------------------------------------------------------------------
   Fallback for browsers without cross-document transitions (e.g. Firefox):
   page-transitions.js fades the page out before navigating.
   ------------------------------------------------------------------------- */
html.is-leaving body {
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 200ms ease-in, transform 200ms ease-in;
}

/* Staggered content entrance on vision pages (also plays inside a view transition) */
@keyframes vt-item-in {
    from { opacity: 0; translate: 0 16px; }
    to   { opacity: 1; translate: 0 0; }
}
/* Same rhythm as the home page's chapter entrance (0.7s, 45ms steps) */
[data-enter] {
    animation: vt-item-in 0.7s var(--vt-ease) both;
    /* --enter-base is raised by page-transitions.js when the page arrives
       through an open/close morph, so it starts once the old page is gone */
    animation-delay: calc(var(--enter-i, 0) * 45ms + var(--enter-base, 120ms));
}

/* While the artwork is morphing in from its card, it shouldn't also fade in */
html:active-view-transition-type(open) #vision-visual,
html:active-view-transition-type(close) #vision-visual {
    animation: none;
}

/* -------------------------------------------------------------------------
   Story loops: the vision page hero artwork plays a short scripted story
   (assets/js/story.js; beats declared in scripts/svg_animations.py).
   Without .is-story (cards on home, reduced motion) the artwork shows its
   finished picture: everything except [data-tmp] helpers.
   ------------------------------------------------------------------------- */
svg:not(.is-story) [data-tmp] { display: none; }

svg.is-story [data-s] {
    opacity: 0;
    transition: opacity 0.5s var(--vt-ease), transform 0.6s var(--vt-ease);
    transition-delay: var(--d, 0ms);
}
svg.is-story [data-s]:not([data-fx]) { transform: translateY(8px); }
svg.is-story [data-s][data-fx="pop"] {
    transform: scale(0.6);
    transform-box: fill-box;
    transform-origin: center;
    transition-timing-function: var(--vt-ease), cubic-bezier(0.34, 1.56, 0.64, 1);
}
svg.is-story [data-s][data-fx="left"]  { transform: translateX(-28px); }
svg.is-story [data-s][data-fx="right"] { transform: translateX(28px); }
/* "fade" never touches transform: some parts keep an SVG transform attribute
   (e.g. rotated labels) that a CSS transform would override */
svg.is-story [data-s].is-on { opacity: 1; }
svg.is-story [data-s]:not([data-fx="fade"]).is-on { transform: none; }

svg.is-story.is-resetting [data-s] { transition-duration: 0.4s; transition-delay: 0ms; }
svg.is-story.is-instant [data-s] { transition: none; }

/* Looping parts only move during their beats, and nothing moves while paused */
svg.is-story [data-run]:not(.is-run),
svg.is-story [data-run]:not(.is-run) *,
svg.is-story.is-paused * { animation-play-state: paused; }

/* Helpers used inside the stories */
@keyframes story-ping {
    from { opacity: 0.55; transform: scale(0.92); }
    to   { opacity: 0; transform: scale(1.18); }
}
.story-ping { animation: story-ping 1.4s cubic-bezier(0, 0, 0.2, 1) infinite; transform-box: fill-box; transform-origin: center; }
.story-ping.is-late { animation-delay: 0.7s; }
@keyframes story-blink { 50% { opacity: 0.2; } }
.story-blink { animation: story-blink 1s steps(1) infinite; }

/* Caption with step dots under the hero artwork */
.story-caption {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    min-height: 1.75rem;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: rgb(var(--c-body));
    text-align: center;
}
.story-dots { display: inline-flex; gap: 0.3rem; flex-shrink: 0; }
.story-dots i {
    width: 0.375rem; height: 0.375rem; border-radius: 999px;
    background: rgb(var(--c-line));
    transition: width 0.3s var(--vt-ease), background-color 0.3s var(--vt-ease);
}
.story-dots i.is-on { width: 1rem; background: rgb(var(--c-brand)); }
.story-text { transition: opacity 0.18s ease, transform 0.3s var(--vt-ease); }
.story-text.is-swapping { opacity: 0; transform: translateY(3px); }

@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }
    [data-enter] { animation: none !important; }
    .site-header, .site-header-inner, .site-logo { transition: none; }
    html.is-leaving body { transition: none; }
}
