/* ═══════════════════════════════════════════════════════════════
   flow.css — section-to-section continuity + About balance
   Loaded LAST on the portfolio page. Self-contained: removing the
   <link> restores the previous behaviour.

   Idea: every section owns its colour, and neighbouring sections
   meet on exactly the same colour. Light <-> dark changes happen in
   content-free "dusk" / "dawn" bands that scroll with the page, so
   no text ever sits on a half-faded grey wash.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --night-1: #131b27;   /* lab top (end of dusk)            */
  --night-2: #0b111a;   /* lab bottom  = systems top        */
  --night-3: #070b12;   /* systems bottom = zoom-out top    */
  --night-4: #05080e;   /* deepest sky                      */
  --band: clamp(9rem, 22vw, 15rem);        /* dusk / dawn band height */
  --flow-gutter: clamp(1.15rem, 5.4vw, 7vw);
  --fade-gap: clamp(11rem, 36vh, 21rem);  /* empty run before a scroll-linked fade */
}

/* The page-wide dark fade is replaced by section-owned colour. */
#mood-layer { display: none !important; }

/* ── ABOUT: let the story lead, cards support ─────────────────── */
.about-body {
  font-size: clamp(1rem, 0.96rem + 0.22vw, 1.085rem);
  line-height: 1.84;
  color: #37332d;
  max-width: 62ch;
}
.about-body strong { color: #14120f; }

.about-scan-item,
.acard {
  background: rgba(255, 252, 246, 0.36);
  border-color: rgba(24, 27, 32, 0.085);
  box-shadow: none;
}
.acard:hover {
  background: rgba(255, 253, 249, 0.72);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.045);
}
.about-scan-item strong,
.acard-val { font-size: .9rem; color: #26231f; }
.acard-sub { color: #6f675c; }
.about-switch {
  background: rgba(255, 252, 246, 0.5);
  box-shadow: 0 8px 18px rgba(16, 24, 40, 0.035);
}
.stats-strip {
  box-shadow: none;
  background: rgba(255, 252, 246, 0.3);
}
.stats-strip::after { content: none; }

/* ── ABOUT → LAB: dusk band ───────────────────────────────────── */
#about {
  padding-bottom: calc(var(--band) + 3.2rem);
}
#about::before {
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 248, 238, 0.78) 0%, rgba(255, 248, 238, 0) 26%),
    radial-gradient(circle at 88% 12%, rgba(242, 227, 205, 0.26) 0%, rgba(242, 227, 205, 0) 22%);
}
#about::after {
  bottom: 0;
  height: var(--band);
  background:
    radial-gradient(ellipse 62% 44% at 50% 48%, rgba(210, 186, 143, 0.1) 0%, rgba(210, 186, 143, 0) 72%),
    linear-gradient(180deg,
      rgba(19, 27, 39, 0) 0%,
      rgba(58, 60, 72, 0.07) 16%,
      rgba(48, 53, 68, 0.24) 36%,
      rgba(36, 43, 58, 0.52) 56%,
      rgba(26, 34, 47, 0.8) 74%,
      rgba(21, 29, 41, 0.95) 89%,
      var(--night-1) 100%);
}

/* 1px overlaps hide sub-pixel seams between sections */
#lab.section-lab {
  margin-top: -1px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(143, 201, 190, 0.032) 0%, rgba(143, 201, 190, 0) 28%),
    radial-gradient(ellipse at 18% 20%, rgba(210, 186, 143, 0.03) 0%, rgba(210, 186, 143, 0) 22%),
    radial-gradient(ellipse at 82% 14%, rgba(82, 95, 121, 0.05) 0%, rgba(82, 95, 121, 0) 22%),
    linear-gradient(180deg, var(--night-1) 0%, #0f1722 34%, var(--night-2) 100%);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  padding-top: clamp(4.2rem, 8vw, 6.4rem);
}
#lab.section-lab::before,
#lab.section-lab::after { content: none; }

/* ── LAB → SYSTEMS → ZOOM-OUT: one continuous night ───────────── */
#systems {
  margin-top: -1px;
  padding-top: clamp(4.6rem, 8vw, 7rem);
  background:
    radial-gradient(ellipse at 18% 22%, rgba(143, 201, 190, 0.04) 0%, transparent 22%),
    radial-gradient(ellipse at 82% 18%, rgba(90, 108, 142, 0.055) 0%, transparent 20%),
    linear-gradient(180deg, var(--night-2) 0%, #090e16 46%, var(--night-3) 100%);
}
#systems::before { content: none; }

/* ── ABOUT → LAB in JS mode: scroll-linked dusk ───────────────────
   Lab and Systems sit on the shared sky layer, so the whole view darkens
   together as the Lab arrives. The gap under the stats strip lets About's
   content leave the screen before the fade is half done. */
.flow-js #about { padding-bottom: clamp(3.4rem, 9vh, 5.6rem); }
/* the stats strip bows out as the dusk begins, so it never sits on grey */
.flow-js #about .stats-strip.vis { opacity: calc(1 - var(--dusk, 0) * 2.4); transition: none; }
.flow-js #about::after { content: none; }
.flow-js #lab.section-lab {
  background:
    radial-gradient(ellipse at 50% 40%, rgba(143, 201, 190, 0.032) 0%, rgba(143, 201, 190, 0) 28%),
    radial-gradient(ellipse at 18% 20%, rgba(210, 186, 143, 0.03) 0%, rgba(210, 186, 143, 0) 22%),
    radial-gradient(ellipse at 82% 14%, rgba(82, 95, 121, 0.05) 0%, rgba(82, 95, 121, 0) 22%);
}
.flow-js #lab .lab-header { opacity: calc(var(--night, 1) * var(--night, 1)); }
.flow-js #systems {
  background:
    radial-gradient(ellipse at 18% 22%, rgba(143, 201, 190, 0.04) 0%, transparent 22%),
    radial-gradient(ellipse at 82% 18%, rgba(90, 108, 142, 0.055) 0%, transparent 20%);
}

/* ── ZOOM-OUT → MOUNTAINS: scroll-linked sky crossfade ────────────
   With flow.js running, the night is one fixed layer (#flow-sky) whose
   opacity follows scroll, so the whole view lightens together and the
   "bring it back down" text changes colour with it. Without JS the
   static dawn band below is the fallback. */
#flow-sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
  background:
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(60, 78, 112, 0.1) 0%, rgba(60, 78, 112, 0) 70%),
    var(--night-3);
}

#zoom-out {
  margin-top: -1px;
  padding-bottom: calc(var(--band) + 5rem);
  background:
    linear-gradient(180deg,
      var(--night-3) 0%,
      var(--night-4) 34%,
      #080d17 calc(100% - var(--band) - 3rem),
      rgba(17, 25, 39, 0.94) calc(100% - var(--band) * 0.86),
      rgba(34, 44, 62, 0.74) calc(100% - var(--band) * 0.62),
      rgba(62, 72, 92, 0.44) calc(100% - var(--band) * 0.4),
      rgba(110, 112, 124, 0.18) calc(100% - var(--band) * 0.18),
      rgba(160, 150, 145, 0) 100%);
}
.flow-js #zoom-out {
  background: none;
  padding-bottom: clamp(4.5rem, 9vw, 6.5rem);
}
.flow-js #zoom-out .zoom-hed,
.flow-js #zoom-out .zoom-body { opacity: calc(0.25 + var(--sky, 1) * 0.75); }

.flow-js #bring-down .bring-hed {
  color: color-mix(in srgb, var(--ink) calc(var(--dawn, 1) * 100%), #f3f2ee);
}
.flow-js #bring-down .bring-body {
  color: color-mix(in srgb, var(--ink2) calc(var(--dawn, 1) * 100%), #d9dbe3);
}
.flow-js #bring-down .bring-sub {
  color: color-mix(in srgb, var(--teal) calc(var(--dawn, 1) * 100%), #8fd9cd);
}
.flow-js #bring-down .bird-container { opacity: var(--dawn, 1); }

/* Stars: sections own their colour now, so stars keep one brightness
   (script.js still writes an inline opacity from the old page-wide fade). */
.stars-layer { opacity: 0.8 !important; }
.shooting-stars,
#shooting-stars-5 { opacity: 1 !important; }
#zoom-out .stars-layer { opacity: calc(0.8 * var(--sky, 1)) !important; }
#zoom-out #shooting-stars-5 { opacity: var(--sky, 1) !important; }

/* ── MOUNTAINS → WATER: water rises through the mist ──────────── */
.deep-section.dark-section {
  margin-top: calc(var(--band) * -0.62);
  padding-top: clamp(12.5rem, 22vw, 19rem);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.22) calc(var(--band) * 0.22), rgba(0, 0, 0, 0.72) calc(var(--band) * 0.5), #000 calc(var(--band) * 0.8));
          mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.22) calc(var(--band) * 0.22), rgba(0, 0, 0, 0.72) calc(var(--band) * 0.5), #000 calc(var(--band) * 0.8));
}
.deep-section.dark-section::before { content: none; }
.deep-section__bg {
  background-size: auto, auto, auto, cover;
  background-position: 0 0, 56% 7%, 44% 42%, 60% 0%;
}

/* ── WATER → GALLERY → WRITING → WORKSPACE ───────────────────────
   Order in index.html: deep-dive, gallery-wall, blog, dashboard. */
.deep-section::after {
  background: linear-gradient(180deg, rgba(7, 11, 18, 0) 0%, rgba(7, 11, 18, 0.72) 55%, var(--night-3) 100%);
}
#gallery-wall {
  margin-top: -1px;
  padding-bottom: calc(var(--band) + 3.6rem);
  background: linear-gradient(180deg, var(--night-3) 0%, #05080e 22%, #040508 100%);
  /* no-JS fallback: the dark chamber dissolves into the page before Writing */
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 calc(100% - var(--band)), rgba(0, 0, 0, 0.72) calc(100% - var(--band) * 0.62), rgba(0, 0, 0, 0.26) calc(100% - var(--band) * 0.28), transparent 100%);
          mask-image: linear-gradient(180deg, #000 0%, #000 calc(100% - var(--band)), rgba(0, 0, 0, 0.72) calc(100% - var(--band) * 0.62), rgba(0, 0, 0, 0.26) calc(100% - var(--band) * 0.28), transparent 100%);
}
#gallery-wall::before {
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 16rem);
          mask-image: linear-gradient(180deg, transparent 0%, #000 16rem);
}
/* JS mode: the gallery sits on the shared sky layer, which fades out with
   scroll as Writing arrives (same mechanism as sky -> mountains). */
.flow-js #gallery-wall {
  background: none;
  -webkit-mask-image: none;
          mask-image: none;
  padding-bottom: clamp(5rem, 14vh, 8rem);
}
.flow-js #gallery-wall .stars-layer { opacity: calc(0.8 * var(--sky, 1)) !important; }
.flow-js #gallery-wall .shooting-stars { opacity: var(--sky, 1) !important; }
.flow-js #blog:not(.blog-dark) .sec-label {
  color: color-mix(in srgb, var(--ink3) calc(var(--dawn, 1) * 100%), #c9ccd6);
}
.flow-js #blog:not(.blog-dark) .blog-hed {
  color: color-mix(in srgb, var(--ink) calc(var(--dawn, 1) * 100%), #f3f2ee);
}
.flow-js #blog:not(.blog-dark) .blog-intro {
  color: color-mix(in srgb, var(--ink2) calc(var(--dawn, 1) * 100%), #d9dbe3);
}
#blog {
  margin-top: 0;
  padding-top: clamp(3.4rem, 6vw, 4.6rem);
}
#blog::before { content: none; }
#dashboard {
  margin-top: 0;
  padding-top: calc(var(--band) + 4.6rem);
  background: #06070c;
  /* dusk: the workspace rises out of the page after Writing */
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.26) calc(var(--band) * 0.3), rgba(0, 0, 0, 0.74) calc(var(--band) * 0.64), #000 var(--band));
          mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.26) calc(var(--band) * 0.3), rgba(0, 0, 0, 0.74) calc(var(--band) * 0.64), #000 var(--band));
}
footer { background: #08080f; }

/* ── Phones (360 – 430 px wide) ───────────────────────────────── */
@media (max-width: 600px) {
  #about,
  #systems,
  #zoom-out { padding-left: var(--flow-gutter); padding-right: var(--flow-gutter); }

  #about { padding-top: clamp(3.6rem, 14vw, 5rem); }

  .about-top { margin-bottom: 1.8rem; }
  .about-switch { width: 100%; justify-content: space-between; }
  .about-switch-btn { flex: 1; padding: .66rem .4rem; font-size: clamp(.86rem, 3.7vw, .98rem); }

  .about-hed { font-size: clamp(1.9rem, 8.4vw, 2.5rem); margin-bottom: 1.25rem; }

  /* three summary chips become one quiet list instead of three tall boxes */
  .about-scan-band {
    grid-template-columns: 1fr;
    gap: 0;
    border-top: 1px solid rgba(24, 27, 32, 0.1);
    margin-bottom: 1.6rem;
  }
  .about-scan-item {
    display: grid;
    grid-template-columns: 6.2rem 1fr;
    gap: .8rem;
    align-items: baseline;
    padding: .8rem 0;
    border: 0;
    border-bottom: 1px solid rgba(24, 27, 32, 0.1);
    border-radius: 0;
    background: none;
  }
  .about-scan-label { margin-bottom: 0; }

  .about-body { line-height: 1.78; }
  .about-body p { margin-bottom: 1.15rem; }

  /* side cards: two per row so the section is not a long stack */
  .about-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem;
  }
  .acard { padding: .82rem .85rem; border-radius: 14px; }
  .acard-val { font-size: clamp(.8rem, 3.5vw, .9rem); }
  .acard-sub { font-size: .72rem; }

  .stats-strip { margin-left: 0; margin-right: 0; border-radius: 24px; }
  .snum { font-size: clamp(1.9rem, 8.6vw, 2.45rem); }

  .zoom-hed { font-size: clamp(2.7rem, 13.5vw, 3.9rem); }
  #zoom-out { min-height: 0; padding-top: clamp(4.5rem, 20vw, 6.5rem); }

  .bring-hed { font-size: clamp(2rem, 9.6vw, 2.9rem); }
  .bring-sub { font-size: clamp(1.5rem, 7vw, 2rem); margin-bottom: 1.6rem; }
  .bring-body { font-size: clamp(.94rem, 4vw, 1rem); margin-bottom: 3rem; }
}

@media (max-width: 374px) {
  .about-cards { grid-template-columns: 1fr; }
}

/* ── Phones: no light flash on a fast fling ──────────────────────
   On touch screens a fling scrolls on the compositor, ahead of flow.js,
   so for a few frames the night layer can still be faded out (or clipped)
   while dark sections are already on screen, and the cream page showed
   through them. Parts of a section that can never be on screen during a
   fade get their own solid night, so they no longer depend on the script:
     - Systems, Apps, Map, Gallery, Writing: always full night.
     - Lab: its fade runs while its top edge is on screen, so everything
       more than one screen below that edge is always full night.
     - Zoom-out: its fade runs while its bottom edge is on screen, so
       everything more than one screen above that edge is full night.
   The fixed layer also reaches below the screen, so the address bar
   sliding away can't open a gap under it. */
#flow-sky { bottom: -20vh; }
@media (hover: none), (pointer: coarse) {
  html.flow-js #systems,
  html.flow-js #apps,
  html.flow-js #atlas,
  html.flow-js #gallery-wall,
  html.flow-js #blog { background-color: var(--night-3); }   /* html. beats the later apps/atlas/writing sheets */
  html.flow-js #lab.section-lab {
    background:
      radial-gradient(ellipse at 50% 40%, rgba(143, 201, 190, 0.032) 0%, rgba(143, 201, 190, 0) 28%),
      radial-gradient(ellipse at 18% 20%, rgba(210, 186, 143, 0.03) 0%, rgba(210, 186, 143, 0) 22%),
      radial-gradient(ellipse at 82% 14%, rgba(82, 95, 121, 0.05) 0%, rgba(82, 95, 121, 0) 22%),
      linear-gradient(180deg, transparent 0, transparent 100vh, var(--night-3) 100vh);
  }
  html.flow-js #zoom-out {
    background: linear-gradient(180deg, var(--night-3) 0, var(--night-3) calc(100% - 100vh), transparent calc(100% - 100vh));
  }
}
html.flow-night-root { background-color: #040508; }
