/* Section separation, direction B — "Surfaces and chapters".
   Home page of index.html (also the index-sep-b.html proposal), loaded after every other stylesheet.

   Every home section is a sheet: full bleed, large rounded top corners and a soft shadow cast upwards
   onto the sheet below it. All sheets share one palette: the site's neutral green-grey surfaces
   (alternating a step lighter / darker so neighbours part) and the same soft white light from the top;
   each section's own glow stays in the ladybird's olive, red and mint. The sheets follow the app's order
   (hero → 1 Stacking → 2 Edit → 3 Retouch → 4 Export); a glass navigator at the bottom of the screen says which
   chapter you are in and how far through it.
   With motion allowed (html.sb-pin, set by js/sep-b.js) a sheet pins once its end reaches the bottom
   of the screen and the next sheet slides up over it while it recedes (a little smaller, dimmer).
   Each slot is one screen taller than its sheet and the next slot starts one screen earlier, so the
   page keeps its length and the pinned sheet lets go as soon as it is fully covered.
   Without JS or with reduced motion the sheets simply follow each other, the next one's rounded top
   overlapping the end of the previous one. No divider lines anywhere. */

#page-home.page--home {   /* beats the page's inline <style>, which comes after the stylesheet links */
  --sb-r: clamp(28px, 3.6vw, 52px);               /* sheet corner */
  --sb-pad-top: clamp(104px, 10vw, 152px);        /* calm space above each heading */
  --sb-pad-end: clamp(96px, 9vw, 136px);          /* every chapter ends on calm space */
  --sb-slide: 100svh;                             /* how long a sheet stays pinned while the next covers it */
  /* Surfaces: the site's own green-grey (--bg #0b0c0c, --surface #141615), alternating so neighbours part. */
  --sb-a: #121514;
  --sb-b: #151817;
  --sb-light: radial-gradient(90% 520px at 50% 0, #e8f2e612, transparent 70%);   /* same top light on every sheet */
  padding-bottom: clamp(20px, 3vw, 36px);
}

/* ---------- Slots and sheets ---------- */

.sb-slot {
  position: relative;
  margin-inline: calc(var(--gutter) * -1);        /* full bleed: the page's own gutter is given back inside */
}
.sb-slot:nth-child(1) { z-index: 1; }
.sb-slot:nth-child(2) { z-index: 2; }
.sb-slot:nth-child(3) { z-index: 3; }
.sb-slot:nth-child(4) { z-index: 4; }
.sb-slot:nth-child(5) { z-index: 5; }
.sb-slot + .sb-slot { margin-top: calc(var(--sb-r) * -1); }

/* Hero: the base surface. It already bleeds to the edges by itself; inside a full-bleed slot it must not. */
.sb-slot > .hero { margin: 0; max-width: none; background: var(--bg); }
/* The Stacking sheet's rounded top overlaps the hero by --sb-r: give that back, plus real room under the buttons. */
#page-home .sb-slot > .hero { padding-bottom: calc(var(--sb-r) + clamp(64px, 9vh, 112px)); }

.sb-slot > .stk,
.sb-slot > .cx {
  margin: 0;
  /* gutter × 2 = the page's gutter + the section's own, so every section keeps its exact content width */
  padding: var(--sb-pad-top) calc(var(--gutter) * 2) var(--sb-pad-end);
  border-radius: var(--sb-r) var(--sb-r) 0 0;
  /* No overflow clip here: a rounded clip around the glass (backdrop-filter) cards made Chrome split every
     sheet into a stack of sheet-sized layers (~1.7 GB of raster at 2x), and tiles that were not ready in
     time showed as blank rectangles while scrolling. The glows are clipped on their own instead (below). */
  box-shadow:
    0 -28px 70px -18px #000000b3,                 /* cast up onto the sheet underneath */
    inset 0 1px 0 #ffffff12;                      /* the lit top edge of the glass */
}

/* One palette: the same top light on every sheet, surfaces alternating a step. */
.sb-slot > .stk {
  --bg: var(--sb-a);                              /* the timeline's node rings punch out the surface colour */
  background: var(--sb-light), var(--sb-a);
}
.sb-slot > .ce  { background: var(--sb-light), var(--sb-b); }
.sb-slot > .rd  { background: var(--sb-light), var(--sb-a); }
.sb-slot > .exc { background: var(--sb-light), var(--sb-b); }

/* Retouch's glow was the frame map's viridis (purple + teal), which read blue against the rest.
   It now takes the ladybird glow that Stacking and Export use, so the whole page stays in one light. */
.sb-slot > .rd::before {
  background: url("../assets/algorithms/ladybird-glow.webp") center / cover;
  filter: blur(80px) saturate(1.1);
  opacity: .22;
  -webkit-mask-image: radial-gradient(closest-side, #000 25%, transparent);
  mask-image: radial-gradient(closest-side, #000 25%, transparent);
}
/* Glows fill the sheet rather than stop at a hard band. They reach 10% past each side, so each one clips
   itself back to the sheet's edges (10% of the sheet = 1/12 of the 120%-wide glow) and its rounded top. */
.sb-slot > .stk::before { inset: 0 -10% 0; }
.sb-slot > .cx::before { inset: 8% -10% 0; }
.sb-slot > .rd::before, .sb-slot > .exc::before { inset: 4% -10% 4%; }
.sb-slot > .stk::before,
.sb-slot > .cx::before { clip-path: inset(0 calc(100% / 12) round var(--sb-r) var(--sb-r) 0 0); }
.sb-slot--last > .cx::before { clip-path: inset(0 calc(100% / 12) round var(--sb-r)); }

/* Baked glows. The live glows (blur 80–90px + saturate + mask over a sheet-sized box, defined in
   stacking-timeline.css, home-edit.css, sep-b.css .rd and home-export.css) cost the GPU a full re-blur on
   every frame while a covered sheet recedes: Edit→Retouch ran at ~94 fps with 84 frames over 20 ms.
   Design/Mockups/bake_glows.mjs renders each one once into assets/glows/*.webp (same box, opacity 1) and
   stamps the ?v= below. RE-RUN IT whenever a glow source changes (ladybird-glow.webp, the Edit gradients,
   the filter/mask/inset rules). html.glow-live switches these off; the bake script uses it. */
html:not(.glow-live) #page-home .sb-slot > .stk::before,
html:not(.glow-live) #page-home .sb-slot > #home-edit::before,
html:not(.glow-live) #page-home .sb-slot > #home-retouch::before,
html:not(.glow-live) #page-home .sb-slot > #home-export::before {
  background-position: 0 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  filter: none;
  -webkit-mask-image: none;
  mask-image: none;
}
html:not(.glow-live) #page-home .sb-slot > .stk::before { background-image: url("../assets/glows/stacking.webp?v=46f71e6e"); }
html:not(.glow-live) #page-home .sb-slot > #home-edit::before { background-image: url("../assets/glows/edit.webp?v=a85a7f7d"); }
html:not(.glow-live) #page-home .sb-slot > #home-retouch::before { background-image: url("../assets/glows/retouch.webp?v=095d8c3a"); }
html:not(.glow-live) #page-home .sb-slot > #home-export::before { background-image: url("../assets/glows/export.webp?v=874c5925"); }

/* The last chapter closes as a card; the footer sits on the page below it. */
.sb-slot--last > .cx { border-radius: var(--sb-r); }
body:has(#page-home:not([hidden])) .footer { border-top: 0; }

/* ---------- Section navigator (js/sep-b.js) ----------
   A glass pill at the bottom of the screen, in the top bar's language: Stacking · Edit · Retouch.
   The lozenge sits on the chapter you are in; the line under each name fills as you read through it.
   It comes up when the Stacking sheet reaches mid-screen and goes away as the last chapter ends. */

.sb-nav {
  position: fixed; z-index: 45;
  left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; padding: 4px;
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-highlight), 0 12px 32px #00000059, 0 1px 2px #00000066;
  opacity: 0; visibility: hidden;
  transform: translate(-50%, 18px);
  transition: opacity .3s ease, transform .45s cubic-bezier(.3, 1.25, .4, 1), visibility 0s linear .45s;
}
.sb-nav[hidden] { display: none; }
.sb-nav.is-on { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }

.sb-nav__thumb {
  position: absolute; left: 0; top: 4px;
  height: 36px; width: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff29, #ffffff17);
  box-shadow: inset 0 1px 0 #ffffff38, inset 0 -1px 0 #ffffff0a, 0 2px 8px #0000004d;
}
.sb-nav.is-ready .sb-nav__thumb {
  transition: transform .42s cubic-bezier(.3, 1.25, .4, 1), width .42s cubic-bezier(.3, 1.25, .4, 1);
}

.sb-nav button {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 16px;
  border: 0; border-radius: 999px; background: none;
  color: var(--muted);
  font: inherit; font-size: 13.5px; font-weight: 500; letter-spacing: -.005em;
  white-space: nowrap; cursor: pointer;
  transition: color .2s;
}
.sb-nav button:hover,
.sb-nav button[aria-current] { color: var(--text); }
.sb-nav button:focus-visible { outline-offset: -2px; }
.sb-nav em { font: 600 10.5px var(--mono); font-style: normal; opacity: .55; }
/* Reading progress through this chapter */
.sb-nav i {
  position: absolute; left: 16px; right: 16px; bottom: 5px;
  height: 2px; border-radius: 1px;
  background: #ffffff14; overflow: hidden;
}
.sb-nav i::after {
  content: ""; position: absolute; inset: 0;
  background: currentColor; opacity: .55;
  transform-origin: 0 50%; transform: scaleX(var(--p, 0));
}

/* ---------- Motion: pin, slide over, recede (js/sep-b.js) ---------- */

.sb-pin .sb-slot:not(.sb-slot--last) { padding-bottom: var(--sb-slide); }
.sb-pin .sb-slot + .sb-slot { margin-top: calc(var(--sb-slide) * -1 - var(--sb-r)); }

.sb-pin .sb-slot:not(.sb-slot--last) > * {
  position: sticky;
  /* Tall sheets pin with their end on the bottom of the screen; short ones pin at the top. */
  top: min(0px, calc(100svh - var(--sb-h, 100svh)));
}
/* While the next sheet rises, js/sep-b.js scales and dims the covered one (inline transform/opacity). */
.sb-pin .sb-slot > .is-covered {
  transform-origin: 50% max(50%, calc(var(--sb-h, 100svh) - 50svh));   /* the middle of what is on screen */
  will-change: transform, opacity;
}
.sb-pin .sb-slot > .is-buried { will-change: auto; }

@media (max-width: 720px) {
  #page-home.page--home {
    --sb-r: 28px;
    --sb-pad-top: 88px;
    --sb-pad-end: 80px;
  }
  .sb-nav { bottom: calc(12px + env(safe-area-inset-bottom)); }
  .sb-nav button { padding: 0 12px; font-size: 12.5px; gap: 6px; }
  .sb-nav i { left: 12px; right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .sb-nav, .sb-nav.is-ready .sb-nav__thumb { transition: none; }
}
