/* ════════════════════════════════════════════════════════════════════
   Floating Nav — collapsible case-study sidebar
   ────────────────────────────────────────────────────────────────────
   Two independent icon-only buttons anchored top-left of the
   viewport. On hover, each expands: a hover background appears
   (macOS-style soft pill) and the label types in letter-by-letter
   from left to right, pushing whatever sits to its right.

   The "Outline" button toggles a popover with the case-study's
   section links.

   Activated by `body.case-floating-nav`. Without that class, none
   of these rules apply, so pages that haven't opted in still use
   the legacy left-rail sidebar.

   To revert from a page:
   - Remove `case-floating-nav` from <body>
   - Remove the <link> to this CSS
   - Remove the .case-fn-toolbar + .case-fn-popover markup
   - Remove the floating-nav.js <script>
   ════════════════════════════════════════════════════════════════════ */

/* ─── Hide the legacy left-rail sidebar + recentre the content ──── */
body.case-floating-nav .case-sidebar { display: none; }
body.case-floating-nav .case-page {
  /* legacy padding-left was 64px (room for the sidebar). With the
     sidebar gone, content can sit centred without that offset. */
  padding-left: 24px;
  padding-right: 24px;
  padding-top: 100px; /* clear of the floating toolbar */
}

/* ─── Toolbar — invisible flex container so the buttons can push
       each other horizontally as one expands. No background, no
       border, no shadow — the buttons themselves are the chrome.
       Anchored at top:48 so it lines up with the existing
       .case-lang-toggle / .case-theme-toggle on the same row. */
.case-fn-toolbar {
  position: fixed;
  top: 48px;
  left: 24px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ─── Single button (back or outline) ──────────────────────────────
   IMPORTANT: transitions live on the :hover state, NOT the base.
   That means hover-IN is animated, but unhover is INSTANT — when the
   visitor sweeps the cursor between buttons, the leaving button
   snaps shut immediately while the incoming button animates open.
   Mixed transitions during sweeps were what felt "not smooth". */
.case-fn-btn {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2px;
  text-decoration: none;
  line-height: 1;
  /* No transition on the base — unhover is instant. */
  /* Backdrop blur — the top-fade gradient is short (56px, no solid
     plateau) so most of the button sits over un-overlaid content.
     Blurring whatever scrolls behind keeps the buttons legible
     against busy content without needing a heavy solid background.
     macOS-toolbar glass. */
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.case-fn-btn:hover,
.case-fn-btn:focus-visible,
.case-fn-btn.is-active {
  background: rgba(0, 0, 0, 0.06);
  outline: 0;
  gap: 6px;
  /* Hover-in: smooth ease-out for background + gap. */
  transition: background 260ms cubic-bezier(0.33, 1, 0.68, 1),
              gap        260ms cubic-bezier(0.33, 1, 0.68, 1);
}
[data-theme="dark"] .case-fn-btn:hover,
[data-theme="dark"] .case-fn-btn:focus-visible,
[data-theme="dark"] .case-fn-btn.is-active {
  background: rgba(255, 255, 255, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .case-fn-btn:hover,
  :root:not([data-theme="light"]) .case-fn-btn:focus-visible,
  :root:not([data-theme="light"]) .case-fn-btn.is-active {
    background: rgba(255, 255, 255, 0.08);
  }
}

.case-fn-btn-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.case-fn-btn-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* ─── Label — typewriter expand on hover, smooth collapse on unhover
   ─────────────────────────────────────────────────────────────────
   Each letter is its own <span>. `--i` is the letter index (set
   inline). On hover the wrapper's max-width grows AND each letter
   fades+slides in with a `--i`-scaled delay (typewriter).
   On UNHOVER both the wrapper and the letters use simpler
   transitions with no delay, so the whole label fades out together
   and the slot collapses cleanly — no "letters disappearing one by
   one in reverse" feel that the symmetric version had. */

/* ── Base / unhover state — NO transition (instant snap-back) ──── */
.case-fn-btn-label {
  display: inline-flex;
  overflow: hidden;
  max-width: 0;
  white-space: nowrap;
}
.case-fn-btn-label > span {
  display: inline-block;
  opacity: 0;
}

/* ── Hover / focus / active — animated open + letter stagger ──── */
.case-fn-btn:hover .case-fn-btn-label,
.case-fn-btn:focus-visible .case-fn-btn-label,
.case-fn-btn.is-active .case-fn-btn-label {
  max-width: 220px;
  transition: max-width 320ms cubic-bezier(0.2, 0, 0, 1);
}
.case-fn-btn:hover .case-fn-btn-label > span,
.case-fn-btn:focus-visible .case-fn-btn-label > span,
.case-fn-btn.is-active .case-fn-btn-label > span {
  opacity: 1;
  transition: opacity 200ms cubic-bezier(0.2, 0, 0, 1);
  transition-delay: calc(var(--i, 0) * 28ms);
}

/* ─── The popover ─────────────────────────────────────────────────
   Slides in from off-screen left (its full width + a buffer) so it
   reads as "emerging from the page edge", not just fading nearby.
   Aligned at left:60px so it sits under the Outline button's left
   edge (the toolbar's 2nd button), not flush with Back. */
.case-fn-popover {
  position: fixed;
  /* Toolbar sits at top:48, button height ~32 → popover at ~92px. */
  top: 92px;
  left: 60px;
  z-index: 99;
  min-width: 240px;
  background: var(--bg);
  border: 1px solid rgb(218 218 218 / 14%);
  border-radius: 12px;
  box-shadow:
    0 1px 2px  rgb(0 0 0 / 3%),
    0 16px 36px rgb(0 0 0 / 5%);
  padding: 6px;
  opacity: 0;
  /* -100% of its own width + the 60px gap to viewport edge = fully
     off-screen to the left. The "hiding behind the page edge" feel. */
  transform: translateX(calc(-100% - 70px));
  transform-origin: top left;
  pointer-events: none;
  transition:
    opacity   260ms ease,
    transform 360ms cubic-bezier(0.2, 0, 0, 1);
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
}
.case-fn-popover.is-open {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.case-fn-popover-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.case-fn-popover-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  text-decoration: none;
  letter-spacing: 0.2px;
  transition: background 150ms ease;
}

/* Section title — separate span so the active state can bump weight
   without re-flowing the icon column. */
.case-fn-popover-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  transition: color 180ms ease, font-weight 180ms ease;
}

/* ─── Top-of-viewport scroll-progress strip ───────────────────────
   2px bar pinned to the very top edge of the page. Always visible
   regardless of whether the popover is open. Fills left → right
   with mint as the visitor scrolls deeper into the case study.
   --scroll-progress (0..1) is set by JS via RAF on scroll. */
.case-fn-top-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  z-index: 101; /* above the toolbar */
  pointer-events: none;
}
.case-fn-top-progress-fill {
  display: block;
  height: 100%;
  background: #5a9072;
  transform-origin: left center;
  transform: scaleX(var(--scroll-progress, 0));
  transition: transform 80ms linear;
  will-change: transform;
}
/* Hover — subtle bg shift + text brightens to full --text. */
.case-fn-popover-link:hover {
  background: var(--bg2);
}
.case-fn-popover-link:hover .case-fn-popover-text { color: var(--text); }
.case-fn-popover-link:hover .case-fn-popover-icon { color: var(--text2); }

/* Active — typographic only. Title goes weight 600 + full text color.
   No accent bar, no filled pill, no progress hairline. */
.case-fn-popover-link.is-active .case-fn-popover-text {
  color: var(--text);
  font-weight: 600;
}
.case-fn-popover-link.is-active .case-fn-popover-icon { color: var(--text); }

/* ─── Section icon — leading the link label ─────────────────────── */
.case-fn-popover-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text3); /* muted by default */
  transition: color 180ms ease;
}
.case-fn-popover-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ─── Top fade overlay — soft scroll-into-chrome ────────────────
   When the visitor scrolls, a gradient strip fades content into the
   page background just before it slips behind the floating-nav
   chrome. Sits *below* the toolbar (z-index 99 vs the toolbar's 100)
   and *above* the page content via pointer-events:none.

   Why scroll-gated instead of always-on: at scrollY=0 there's nothing
   above the viewport to fade. An always-visible gradient would tint
   the very top of the hero, which looks like a bug. We fade the
   gradient IN once the visitor has scrolled past ~8px.

   The mobile backdrop strip (`.case-fn-toolbar::before`, defined in
   the mobile media query) is independent of this — it stays solid so
   the toolbar buttons always sit on a clean color, regardless of
   scroll state. This fade layer is *additional*, providing the soft
   transition below the chrome.

   Inspired by the modern `animation-timeline: scroll()` mask pattern,
   but implemented with a JS class toggle so it works everywhere
   today (Firefox doesn't ship scroll-driven animations yet). */
body.case-floating-nav::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  /* No solid plateau. The previous design had ~32px of fully opaque
     overlay before the fade started, which read as a "white block"
     in screenshots. Here the ease-out fade begins from the very top
     edge: 100% bg at exactly 0px, immediately transitioning down.
     Total height 56px so the visible fade region is short and feels
     like content "scrolls past the chrome" rather than into a zone.
     `backdrop-filter: blur` on the toolbar buttons (defined in
     `.case-fn-btn`) keeps them legible against the now-mostly-
     transparent overlay. */
  height: 56px;
  background: linear-gradient(180deg,
    var(--bg)                                                 0%,
    color-mix(in srgb, var(--bg) 78%, transparent)            28%,
    color-mix(in srgb, var(--bg) 48%, transparent)            55%,
    color-mix(in srgb, var(--bg) 18%, transparent)            80%,
    transparent                                              100%
  );
  z-index: 99;
  pointer-events: none;
  opacity: 0;
  transition: opacity 320ms cubic-bezier(0.2, 0, 0, 1);
  will-change: opacity;
}
body.case-floating-nav.is-fn-scrolled::after { opacity: 1; }

/* Bottom fade — mirror of the top, also no plateau. Auto-disables at
   page end (handled in floating-nav.js) so content doesn't dissolve
   before leaving the viewport. */
body.case-floating-nav::before {
  content: '';
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: linear-gradient(0deg,
    var(--bg)                                                 0%,
    color-mix(in srgb, var(--bg) 70%, transparent)            30%,
    color-mix(in srgb, var(--bg) 38%, transparent)            60%,
    color-mix(in srgb, var(--bg) 12%, transparent)            85%,
    transparent                                              100%
  );
  z-index: 99;
  pointer-events: none;
  opacity: 0;
  transition: opacity 320ms cubic-bezier(0.2, 0, 0, 1);
  will-change: opacity;
}
body.case-floating-nav.is-fn-bottom-fade::before { opacity: 1; }

/* ─── Lang / theme toggle parity ─────────────────────────────────
   Apply the floating-nav's icon weight to the existing case-study
   toggles so all top-row chrome reads as one set on both desktop
   and mobile. The toggles' base CSS (in case.css) lives outside this
   component; these scoped overrides only fire when the page opts
   into `body.case-floating-nav`. */
body.case-floating-nav .case-theme-toggle svg {
  width: 16px;
  height: 16px;
  /* Toggle icons use a 24×24 viewBox at 16×16, so stroke 1.5 renders
     as ~1.0 visual — thinner than the floating-nav icons (1.6 in a
     16×16 viewBox = 1.6 visual). 2.4 brings them to ~1.6 visual. */
  stroke-width: 2.4;
}
body.case-floating-nav .case-lang-toggle {
  font-weight: 600;
}

/* ─── Switch-button tooltip ────────────────────────────────────────
   Optional one-off nudge anchored under the "View full case study"
   button. JS sets `--anchor-left` (px from viewport left) and toggles
   `.is-visible` after a delay. Dismissed on any click, on hover of the
   switch button, or after the visitor scrolls. Suppressed for the rest
   of the session via sessionStorage. */
.case-fn-tooltip {
  position: fixed;
  top: var(--anchor-top, 88px);
  left: var(--anchor-left, 120px);
  z-index: 102;
  background: #1a1a1a;
  color: #fff;
  border-radius: 8px;
  box-shadow:
    0 1px 2px  rgb(0 0 0 / 12%),
    0 12px 28px rgb(0 0 0 / 18%);
  padding: 8px 12px;
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top left;
  transition:
    opacity   260ms cubic-bezier(0.2, 0, 0, 1),
    transform 260ms cubic-bezier(0.2, 0, 0, 1);
}
.case-fn-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
/* Arrow pointing up at the icon. Solid black diamond rotated 45°,
   half-clipped behind the tooltip body so only the top triangle pokes
   out. `--arrow-offset` lets JS slide the arrow under the icon center
   independently of where the tooltip body lands. */
.case-fn-tooltip::after {
  content: '';
  position: absolute;
  top: -4px;
  left: var(--arrow-offset, 16px);
  width: 10px;
  height: 10px;
  background: #1a1a1a;
  transform: rotate(45deg);
  border-radius: 2px 0 0 0;
}

/* Dark mode — invert so the tooltip stays high-contrast against the
   dark page background. A black-on-black tooltip blends in; flipping
   to a light surface with dark text gives the same "pops out from the
   page" feel both themes share. */
[data-theme="dark"] .case-fn-tooltip,
:root:not([data-theme="light"]) .case-fn-tooltip {
  background: #f4f4f4;
  color: #1a1a1a;
  box-shadow:
    0 1px 2px  rgb(0 0 0 / 24%),
    0 12px 28px rgb(0 0 0 / 32%);
}
[data-theme="dark"] .case-fn-tooltip::after,
:root:not([data-theme="light"]) .case-fn-tooltip::after {
  background: #f4f4f4;
}

/* ─── Paywall feedback — shake the wall when a locked visitor tries
   to jump to a section via the outline. Pairs with JS that prevents
   scroll, scrolls the wall into view, and replays this animation.
   The translate sequence uses GPU-only transform, so it's smooth
   even on mid-tier phones. */
@keyframes case-fn-paywall-shake {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-8px); }
  30%      { transform: translateX( 7px); }
  45%      { transform: translateX(-5px); }
  60%      { transform: translateX( 4px); }
  75%      { transform: translateX(-2px); }
  90%      { transform: translateX( 1px); }
}
.pw-paywall.case-fn-bump {
  animation: case-fn-paywall-shake 520ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* ─── Mobile — the floating nav now replaces the legacy sticky
   mobile header. Toolbar stays visible (icon-only — hover-typewriter
   is disabled because tapped :hover sticks and looks broken on touch),
   popover is positioned to fit narrow viewports, and the legacy
   `.case-mobile-header` / `.case-mobile-menu` are hidden whenever
   `case-floating-nav` is opted in. */
@media (max-width: 768px) {
  /* Hide the legacy mobile chrome — floating nav takes over. */
  body.case-floating-nav .case-mobile-header,
  body.case-floating-nav .case-mobile-menu { display: none !important; }

  /* Tighter offsets for phones. Both toolbar AND lang/theme toggles
     align to top:14px so left- and right-side chrome sit on the
     same horizontal line. */
  .case-fn-toolbar { top: 14px; left: 16px; }

  /* Mobile sticky header backdrop — a full-width strip that sits
     behind the toolbar buttons (and the lang/theme toggles on the
     right) so scrolling content doesn't read through. Implemented as
     a pseudo on the toolbar to avoid extra markup. z-index sits one
     step below the toolbar's stacking context so the buttons stay
     above. A 1px hairline at the bottom adds depth without weight. */
  .case-fn-toolbar::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg);
    box-shadow: 0 1px 0 rgb(0 0 0 / 5%);
    z-index: -1;
    pointer-events: none;
  }
  [data-theme="dark"] .case-fn-toolbar::before,
  :root:not([data-theme="light"]) .case-fn-toolbar::before {
    box-shadow: 0 1px 0 rgb(255 255 255 / 6%);
  }

  /* Re-anchor the lang / theme toggles. With the hamburger gone they
     can sit at the edge; aligned to the toolbar's top:14px so both
     sides of the header sit on the same horizontal baseline. */
  body.case-floating-nav .case-lang-toggle,
  body.case-floating-nav .case-theme-toggle {
    top: 14px !important;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
  }
  body.case-floating-nav .case-lang-toggle  { right: 56px !important; font-size: 13px !important; }
  body.case-floating-nav .case-theme-toggle { right: 16px !important; }
  /* (Icon-weight / font-weight parity is handled by the unscoped
     rules above this @media block, so the same look applies on
     desktop too — only positioning differs by breakpoint.) */

  /* Tooltip — now SHOWN on mobile. The button labels are icon-only on
     touch (no hover), so the tooltip is the only way new visitors
     learn there's a full version. Wraps to multiple lines on narrow
     viewports instead of overflowing. */
  .case-fn-tooltip {
    max-width: calc(100vw - 32px);
    white-space: normal;
    line-height: 1.4;
  }
  .case-fn-popover {
    top: 60px;
    left: 52px;
    min-width: 220px;
    max-width: calc(100vw - 68px);
  }

  /* Disable the typewriter label expansion on touch — there's no real
     hover, and the post-tap "stuck" hover state looks broken. */
  .case-fn-btn:hover,
  .case-fn-btn:focus-visible,
  .case-fn-btn.is-active {
    gap: 0;
    background: transparent;
    transition: none;
  }
  /* But keep the Outline button's active background while popover is
     open — so the visitor sees which button opened it. */
  .case-fn-btn.case-fn-menu.is-active {
    background: rgba(0, 0, 0, 0.06);
  }
  [data-theme="dark"] .case-fn-btn.case-fn-menu.is-active,
  :root:not([data-theme="light"]) .case-fn-btn.case-fn-menu.is-active {
    background: rgba(255, 255, 255, 0.08);
  }
  .case-fn-btn:hover .case-fn-btn-label,
  .case-fn-btn:focus-visible .case-fn-btn-label,
  .case-fn-btn.is-active .case-fn-btn-label {
    max-width: 0;
  }

  /* (Tooltip stays visible on mobile — see wrapping rules below.) */

  /* Clear the fixed toolbar so the article starts below it. */
  body.case-floating-nav .case-page { padding-top: 60px; }
}
