/* ============================================================
   URTICA HERBAL — "The spine": mobile wayfinding
   Ported from the Fives Vault spine, restyled to the Urtica
   design system (tokens from styles/urtica.css only).

   Two pieces:
     1. a reading-progress hairline pinned under the sticky header, and
     2. an "On this page" FAB + bottom sheet built from the page's
        own top-level sections.

   Mobile-only: <=759px in CSS AND matchMedia-gated in js/spine.js
   (re-checked on resize). Reduced motion honoured in CSS + JS.
   The whole component self-disables on pages with <3 sections.
   ============================================================ */

/* Mobile gate — nothing renders at >=760px. */
@media (min-width: 760px) {
  .spine-bar,
  .spine-fab,
  .spine-sheet-root { display: none !important; }
}

/* ---- Part 1 · reading-progress hairline -------------------- */
/* `top` is a fallback only; spine.js measures .site-header__inner
   at runtime (the mobile drawer is appended to the header, so the
   header itself grows — the inner bar row is the true edge). */
.spine-bar {
  position: fixed;
  top: 76px;
  left: 0;
  height: 2px;
  width: 100%;
  background: var(--clay);
  transform: scaleX(0);
  transform-origin: left;
  z-index: 40;                 /* above content, below .site-header (50) */
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease);
  pointer-events: none;
  will-change: transform;
}
.spine-bar.is-visible { opacity: 1; }

/* ---- Part 2 · "On this page" trigger ----------------------- */
.spine-fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0;
  padding: 0.7rem 1.15rem;
  min-height: 44px;                 /* touch-target floor */
  box-sizing: border-box;
  background: var(--forest);
  color: var(--cream);
  font-family: var(--sans);
  font-size: var(--fs-caption);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  border: 1.5px solid var(--forest);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur-3) var(--ease),
              transform var(--dur-3) var(--ease);
  pointer-events: none;
}
.spine-fab.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.spine-fab:active { background: var(--forest-deep); border-color: var(--forest-deep); }
.spine-fab svg { display: block; flex: 0 0 auto; }
/* Fade the FAB away while the footer is on screen so it never
   collides with the site credit. Toggled by an IntersectionObserver
   in spine.js; wins over .is-visible (declared later, equal
   specificity). Reduced motion zeroes the duration below. */
.spine-fab.is-nearfoot {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

/* ---- Sheet root, scrim, panel ------------------------------ */
.spine-sheet-root {
  position: fixed;
  inset: 0;
  z-index: 45;                 /* above content, below the header/drawer (50) */
  visibility: hidden;
}
.spine-sheet-root.is-open { visibility: visible; }

.spine-scrim {
  position: absolute;
  inset: 0;
  background: rgba(60, 42, 28, 0.42);   /* --charcoal at 42% */
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease);
}
.spine-sheet-root.is-open .spine-scrim { opacity: 1; }

.spine-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-5) max(var(--sp-5), env(safe-area-inset-right, 0px))
           calc(var(--sp-5) + env(safe-area-inset-bottom, 0px))
           max(var(--sp-5), env(safe-area-inset-left, 0px));
  background: var(--bone);
  border-top: 1px solid var(--line);
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  transform: translateY(100%);
  transition: transform var(--dur-3) var(--ease);
}
.spine-sheet-root.is-open .spine-sheet { transform: translateY(0); }

.spine-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-3);
}
.spine-sheet-title {
  margin: 0;
  max-width: none;
  font-family: var(--sans);
  font-size: var(--fs-caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow);
  color: var(--clay-deep);
}
.spine-close {
  width: 44px;
  height: 44px;
  margin: -10px -10px -10px 0;   /* 44px hit area, edge-aligned */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--forest);
  transition: color var(--dur-2) var(--ease);
}
.spine-close:active { color: var(--clay-deep); }
.spine-close svg { display: block; }

.spine-list { display: block; }
.spine-item {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.85rem 0;
  min-height: 44px;
  text-align: left;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 400;
  line-height: var(--lh-snug);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur-3) var(--ease),
              transform var(--dur-3) var(--ease),
              color var(--dur-2) var(--ease);
}
.spine-item:first-child { border-top: 0; }
.spine-item.is-in { opacity: 1; transform: none; }
.spine-item:active { color: var(--clay-deep); }

/* the section the reader is currently in — kept live by spine.js */
.spine-item.is-current {
  color: var(--forest);
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--forest);
  padding-left: var(--sp-3);
}

/* a jumped-to section clears the sticky header + hairline
   (spine.js overwrites this with the measured value) */
.spine-anchor { scroll-margin-top: 84px; }

/* ---- Reduced motion (belt; the JS is the braces) ----------- */
@media (prefers-reduced-motion: reduce) {
  .spine-bar,
  .spine-fab,
  .spine-scrim,
  .spine-sheet,
  .spine-item {
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
  }
  .spine-item { opacity: 1 !important; transform: none !important; }
  .spine-fab.is-visible { transform: none !important; }
}
