/*
 * Analyze wayfinding (2026-10) - where am I in the story, and through
 * which lens? Loaded only by index.html, next to analyze_scenes.css. The
 * behaviour: analyze_scenes.js tracks the chapter in view (aria-current,
 * --rail-progress); analyze_wayfinding.js runs the horizon dock.
 *
 *   Chapter rail  xl+ left gutter: one icon per scene (partials/
 *                 _scene_icons.html) on a reading thread that fills in
 *                 the horizon accent down to the chapter in view.
 *   Horizon dock  the Three Horizons cards, condensed: pinned under the
 *                 nav once the cards scroll away, so the horizon in force
 *                 is always in sight and one tap from changing.
 *
 * Unlayered like its sibling (outranks Tailwind utilities, so it only
 * targets its own classes). Colours come from --scene-accent and the
 * --color-horizon-* tokens: nothing here hard-codes a horizon.
 */

/* ------------------------------------------------------------------
   Chapter rail (xl+ only: below that the page shell has no gutter and
   the icons would sit on content). Labels stay in the a11y tree; they
   just fade in on hover/focus.
   ------------------------------------------------------------------ */
.scene-rail { display: none; }
@media (min-width: 1280px) {
    .scene-rail {
        display: block;
        position: fixed;
        left: 0.6rem;
        top: 50%;
        transform: translateY(-50%);
        z-index: 15;
        /* A <nav>, so tailwind_input.css's site-wide `nav { overflow-x: clip }`
           (meant for the top bar) would slice the current icon's scale + glow
           at this 36px box and hide every hover label beside it. Fixed in the
           gutter, the rail can't widen the page; both axes visible is safe. */
        overflow: visible;
    }
}
.scene-rail ol {
    --rail-progress: 0; /* 0..1: how far down the chapters the reader is */
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
/* The reading thread: a faint line through every icon, lit in the
   horizon accent from the first chapter down to the one in view. */
.scene-rail ol::before,
.scene-rail ol::after {
    content: "";
    position: absolute;
    left: calc(50% - 0.5px);
    top: 1.125rem;
    width: 1px;
}
.scene-rail ol::before {
    bottom: 1.125rem;
    background: rgb(148 163 184 / 0.18);
}
.scene-rail ol::after {
    height: calc((100% - 2.25rem) * var(--rail-progress));
    background: var(--scene-accent);
    box-shadow: 0 0 8px color-mix(in srgb, var(--scene-accent) 70%, transparent);
    transition: height 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.scene-rail a {
    position: relative;
    z-index: 1; /* over the thread */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem; /* 36px - well past WCAG 2.2 2.5.8's 24px minimum */
    height: 2.25rem;
    border-radius: 9999px;
    border: 1px solid rgb(148 163 184 / 0.18);
    background: var(--color-base);
    color: rgb(148 163 184);
    transition: color 0.25s ease, border-color 0.25s ease, background-color 0.25s ease,
        box-shadow 0.25s ease, transform 0.25s ease;
}
.scene-rail a:hover {
    color: rgb(241 245 249);
    border-color: rgb(148 163 184 / 0.45);
}
.scene-rail a:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
.scene-rail a[aria-current="true"] {
    color: var(--scene-accent);
    border-color: color-mix(in srgb, var(--scene-accent) 60%, transparent);
    background: color-mix(in srgb, var(--scene-accent) 14%, var(--color-base));
    box-shadow: 0 0 20px -4px color-mix(in srgb, var(--scene-accent) 70%, transparent);
    transform: scale(1.1);
}
.scene-rail-icon,
.scene-rail-icon svg {
    display: block;
    width: 1.1rem;
    height: 1.1rem;
}
.scene-rail .scene-rail-label {
    position: absolute;
    left: 2.85rem;
    white-space: nowrap;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    border: 1px solid var(--color-border);
    background: var(--color-panel);
    font-size: 0.72rem;
    font-weight: 600;
    color: rgb(226 232 240);
    opacity: 0;
    transform: translateX(-0.35rem);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.scene-rail a:hover .scene-rail-label,
.scene-rail a:focus-visible .scene-rail-label {
    opacity: 1;
    transform: none;
}

/* ------------------------------------------------------------------
   Horizon dock - pinned under the nav (its top follows the nav's live
   height, --nav-h) and centred on the story column (--dock-x, measured
   by analyze_wayfinding.js: the watchlist rail can take the right-hand side).
   analyze_scenes.css reserves its room (--dock-space) for focus/jumps.
   ------------------------------------------------------------------ */
.horizon-dock {
    --dock-ease: cubic-bezier(0.22, 1, 0.36, 1);
    position: fixed;
    top: calc(var(--nav-h, 4rem) + 0.5rem);
    left: var(--dock-x, 50%);
    z-index: 25; /* under the nav and its menus (z-30), over scenes and rail */
    display: flex;
    align-items: center;
    max-width: calc(100vw - 1.5rem);
    padding: 0.25rem;
    border-radius: 9999px;
    border: 1px solid color-mix(in srgb, var(--scene-accent) 35%, var(--color-border));
    background: color-mix(in srgb, var(--color-panel) 80%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    backdrop-filter: blur(14px) saturate(1.4);
    box-shadow: 0 16px 36px -18px rgb(0 0 0 / 0.8),
        0 0 30px -12px color-mix(in srgb, var(--scene-accent) 60%, transparent);
    opacity: 0;
    transform: translate(-50%, -0.6rem);
    transition: opacity 0.25s ease, transform 0.4s var(--dock-ease);
}
.horizon-dock[hidden] { display: none; }
.horizon-dock.is-docked {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* The chapter in view, and a jump to any other - section navigation at
   every width (the rail itself only fits xl+ gutters). A disclosure: the
   button names the chapter (icon only on phones), the list drops below. */
.horizon-dock-chapters {
    position: relative;
    display: flex;
    margin-right: 0.25rem;
    padding-right: 0.25rem;
    border-right: 1px solid rgb(148 163 184 / 0.18);
}
.horizon-dock-chapter {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 2.25rem;
    padding: 0 0.6rem;
    border-radius: 9999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    white-space: nowrap;
    color: rgb(203 213 225);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.horizon-dock-chapter:hover,
.horizon-dock-chapter[aria-expanded="true"] { background: rgb(148 163 184 / 0.12); color: #fff; }
.horizon-dock-chapter:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.horizon-dock-chapter-now { display: inline-flex; align-items: center; gap: 0.5rem; }
.horizon-dock-chapter .scene-rail-icon,
.horizon-dock-chapter .scene-rail-icon svg {
    width: 0.95rem;
    height: 0.95rem;
    color: var(--scene-accent);
}
.horizon-dock-caret {
    width: 0.8rem;
    height: 0.8rem;
    color: rgb(148 163 184);
    transition: transform 0.2s ease;
}
.horizon-dock-chapter[aria-expanded="true"] .horizon-dock-caret { transform: rotate(180deg); }

.horizon-dock-menu {
    position: absolute;
    top: calc(100% + 0.65rem);
    left: -0.25rem;
    min-width: 14rem;
    padding: 0.35rem;
    border-radius: 1rem;
    border: 1px solid color-mix(in srgb, var(--scene-accent) 35%, var(--color-border));
    /* Fully opaque: even 6% show-through ghosts a scene's big headings
       across the rows (opaque + opaque mixes stay opaque). No backdrop
       blur either - nested in the dock's, it would sample nothing. */
    background: linear-gradient(180deg, color-mix(in srgb, var(--scene-accent) 7%, var(--color-panel)), var(--color-panel));
    box-shadow: 0 18px 40px -16px rgb(0 0 0 / 0.85);
}
.horizon-dock-menu[hidden] { display: none; }
.horizon-dock-menu a {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 2.75rem; /* 44px rows: thumbs, not cursors */
    padding: 0 0.8rem;
    border-radius: 0.65rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: rgb(203 213 225);
}
.horizon-dock-menu a:hover { background: rgb(148 163 184 / 0.1); color: #fff; }
.horizon-dock-menu a:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
.horizon-dock-menu .scene-rail-icon { color: rgb(148 163 184); }
.horizon-dock-menu a[aria-current="true"] {
    color: #fff;
    background: color-mix(in srgb, var(--scene-accent) 16%, transparent);
}
.horizon-dock-menu a[aria-current="true"] .scene-rail-icon { color: var(--scene-accent); }

.horizon-dock-pills {
    position: relative;
    display: flex;
    gap: 0.125rem;
}
.horizon-dock-pill {
    position: relative;
    z-index: 1; /* over the glide */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.25rem; /* 36px targets */
    padding: 0 0.9rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    color: rgb(203 213 225);
    cursor: pointer;
    transition: color 0.25s ease;
}
/* Each horizon keeps its own colour, active or not - --hz drives the
   pill's icon and score, and the glide's tint while it sits there (the
   glide is decoration: data-glide, never a control's data-horizon). */
.horizon-dock-pill[data-horizon="day"],
.horizon-dock-glide[data-glide="day"] { --hz: var(--color-horizon-day); }
.horizon-dock-pill[data-horizon="swing"],
.horizon-dock-glide[data-glide="swing"] { --hz: var(--color-horizon-swing); }
.horizon-dock-pill[data-horizon="invest"],
.horizon-dock-glide[data-glide="invest"] { --hz: var(--color-horizon-invest); }
.horizon-dock-pill:hover,
.horizon-dock-pill[aria-pressed="true"] { color: #fff; }
.horizon-dock-pill:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
.horizon-dock-icon { display: flex; color: var(--hz); }
.horizon-dock-icon svg { width: 0.95rem; height: 0.95rem; }
.horizon-dock-score {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--hz) 70%, #fff);
}
.horizon-dock-score:empty { display: none; }

/* The active-pill highlight glides to the chosen pill on a switch
   (position + width from analyze_wayfinding.js), recolouring as it goes. */
.horizon-dock-glide {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 0;
    border-radius: 9999px;
    background: color-mix(in srgb, var(--hz, var(--scene-accent)) 22%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hz, var(--scene-accent)) 65%, transparent),
        0 0 18px -4px color-mix(in srgb, var(--hz, var(--scene-accent)) 75%, transparent);
    transition: transform 0.45s var(--dock-ease), width 0.45s var(--dock-ease),
        background-color 0.45s ease, box-shadow 0.45s ease;
}
.horizon-dock-glide.is-instant { transition: none; }

/* How far through the story the reader is, in the horizon's colour. */
.horizon-dock-progress {
    position: absolute;
    left: 1.25rem;
    right: 1.25rem;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--scene-accent);
    transform-origin: left center;
    transform: scaleX(var(--read, 0));
    pointer-events: none;
}

@media (max-width: 639px) {
    /* Edge to edge, less room on the right for the watchlist rail's peek
       tab (1.75rem, 2.75rem on touch - style.css): the two sit side by
       side instead of the tab covering the last pill. */
    .horizon-dock {
        left: 0.75rem;
        right: 3.25rem;
        max-width: none;
        transform: translateY(-0.6rem);
    }
    .horizon-dock.is-docked { transform: none; }
    .horizon-dock-pills { flex: 1; }
    .horizon-dock-pill {
        flex: 1 1 auto;
        gap: 0.25rem;
        padding: 0 0.35rem;
        font-size: 0.75rem;
    }
    /* Room for the chapter button: it shrinks to its icon (the name stays
       in its accessible name), and the scores stay on the cards. */
    .horizon-dock-chapter { gap: 0.25rem; padding: 0 0.45rem; }
    .horizon-dock-chapter-name {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .horizon-dock-score { display: none; }
}

/* ------------------------------------------------------------------
   Reduced motion + print
   ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    .scene-rail a,
    .scene-rail ol::after,
    .scene-rail .scene-rail-label,
    .horizon-dock,
    .horizon-dock-pill,
    .horizon-dock-glide,
    .horizon-dock-chapter,
    .horizon-dock-caret { transition: none; }
    .scene-rail a[aria-current="true"] { transform: none; }
}
@media print {
    .scene-rail,
    .horizon-dock { display: none !important; }
}
