/* ============================================================
   How It Works — sticky tower / scrolling copy section
   Namespaced with "hiw-" prefix. Uses the site's own CSS custom
   properties so this respects the light/dark theme toggle.

   IMPORTANT: this page does NOT use CSS position:sticky for the
   image column. This site's global `overflow-x: hidden` on both
   <html> and <body> causes both to compute overflow-y:auto,
   which makes <body> the nearest "scroll container" ancestor for
   sticky purposes — but the actual scroll position lives at the
   document level, not on body's own scrollTop. That mismatch
   silently breaks position:sticky (verified: the frame's screen
   position moved with scroll instead of staying pinned). The fix
   is a small scroll-driven position:fixed toggle in
   how-it-works-tower.js instead — see .hiw-visual-frame.is-pinned
   / .is-bottomed below, which that script applies.
   ============================================================ */

.hiw-layout {
  display: flex;
  align-items: flex-start;
  max-width: 1320px;
  margin: 0 auto;
  padding: 1rem 2rem 4rem;
  gap: 4vw;
  position: relative; /* containing block for the "bottomed" state */
}

.hiw-visual-col {
  flex: 0 0 33%;
  max-width: 33%;
  height: calc(100vh - var(--nav-h, 74px) - 48px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  /* position:relative is load-bearing: it's what makes .hiw-visual-frame's
     width:100% resolve to THIS column's width rather than .hiw-layout's
     full width once the frame goes position:absolute in the "bottomed"
     state. Because of that, "bottom" for .is-bottomed can't just be a flat
     CSS 0 — this column sits at the very top of the (much taller) layout,
     so bottom:0 here would park the frame back at the top of the page
     instead of the bottom of the section. how-it-works-tower.js computes
     an explicit pixel bottom offset for exactly this reason — see
     updatePin()'s "is-bottomed" branch (fixed 2026-08-23: the image
     appeared to vanish once it un-pinned, leaving a blank gap where the
     fixed image used to be — it had jumped off-screen to the top). */
}

.hiw-visual-frame {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card), 0 18px 40px -18px rgba(20, 40, 32, .3);
  border: 1px solid var(--border);
  background: var(--surface);
}

/* Applied by JS while the tower section is mid-scroll: pins the frame
   to the viewport at a fixed screen position. Left/width are set inline
   by JS (measured from the column), since position:fixed can't resolve
   percentage sizes against a flex ancestor. */
.hiw-visual-frame.is-pinned {
  position: fixed;
  top: calc(var(--nav-h, 74px) + 24px);
  height: calc(100vh - var(--nav-h, 74px) - 48px);
}

/* Applied by JS once the text column has scrolled past the tower
   entirely: settles the frame at the bottom of .hiw-layout instead of
   continuing to float over whatever content comes after the tower. */
.hiw-visual-frame.is-bottomed {
  position: absolute;
  bottom: 4rem; /* sits on .hiw-layout's bottom padding line, level with the end of the text */
  top: auto;
  height: calc(100vh - var(--nav-h, 74px) - 48px);
}
/* While bottomed, the column stops being the frame's positioning parent so
   the frame is placed against .hiw-layout (position:relative) instead. */
.hiw-visual-col.hiw-col-released { position: static; }

/* PAN MODE: the image fills the frame's width (so it renders much larger
   than the old shrink-to-fit-viewport-height mode) and is consequently
   taller than the frame. JS translates it vertically so the floor being
   discussed is always centered in view — the frame acts as a window
   gliding up and down the tower. */
.hiw-visual-frame img {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  transition: transform .55s cubic-bezier(.22,.61,.36,1);
  will-change: transform;
}

.hiw-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hiw-spotlight {
  position: absolute;
  left: 0;
  right: 0;
  box-shadow: 0 0 0 2000px rgba(1, 3, 40, .45);
  border-top: 2px solid var(--teal);
  border-bottom: 2px solid var(--teal);
  transition: top .45s cubic-bezier(.22,.61,.36,1),
              height .45s cubic-bezier(.22,.61,.36,1),
              opacity .3s ease;
  opacity: 0;
}
.hiw-spotlight.is-active { opacity: 1; }

.hiw-floor-chip {
  position: absolute;
  left: 12px;
  top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill, 999px);
  padding: 6px 13px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--teal-text, var(--teal));
  box-shadow: var(--shadow-card);
}

.hiw-text-col {
  flex: 0 0 63%;
  max-width: 63%;
  padding-top: 8px;
}

.hiw-intro {
  padding-bottom: 4vh;
  margin-bottom: 4vh;
  border-bottom: 1px solid var(--border);
}
.hiw-intro .page-title {
  margin-top: 8px !important;
}

.hiw-floor-block {
  min-height: 66vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5vh 0;
  border-bottom: 1px solid var(--border);
}
.hiw-floor-block:last-child { border-bottom: none; }

.hiw-floor-block h2 {
  font-family: 'Young Serif', Georgia, serif;
  font-weight: 400;
  font-size: clamp(22px, 2.2vw, 28px);
  line-height: 1.2;
  margin: 4px 0 14px;
  color: var(--text);
}
.hiw-floor-block p {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text-dim);
  max-width: 54ch;
  margin: 0 0 12px;
}
.hiw-floor-block ul {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  max-width: 54ch;
}
.hiw-floor-block li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 9px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-dim);
}
.hiw-floor-block li strong { color: var(--text); }
.hiw-floor-block li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal-light);
  border: 1.5px solid var(--teal);
}

.hiw-floor-block.is-current h2 { color: var(--teal-text, var(--teal)); }

/* ---------- Mobile-only per-floor image/text switcher ----------
   .hiw-mobile-switch is a small self-contained card, one per floor,
   inserted as the first child of each .hiw-floor-block. It auto-cycles
   between that floor's cropped tower-illustration slice (pre-cropped
   into images/hiw-floor-*.png at build time, from the same data-top/
   data-bottom bounds the desktop spotlight uses) and a condensed one-
   line summary of that floor's text — a slow crossfade, driven by
   how-it-works-tower.js, no scrolling or dragging required. Hidden
   entirely on desktop, where the existing sticky tower + full text
   already does the job. ---------- */
.hiw-mobile-switch { display: none; }

@media (max-width: 860px) {
  .hiw-layout {
    flex-direction: column;
    padding: 0.5rem 1rem 2.5rem;
    gap: 0;
  }
  /* The shared sticky image column is a desktop-only concept on mobile —
     each floor now carries its own switcher instead. */
  .hiw-visual-col { display: none; }
  .hiw-text-col { max-width: 100%; flex: none; padding-top: 0; }

  /* The original label/heading/paragraph/list are still the source of
     truth for desktop and are read by screen readers on mobile too, but
     visually replaced by the condensed switcher card. */
  .hiw-floor-block > .label,
  .hiw-floor-block > h2,
  .hiw-floor-block > p,
  .hiw-floor-block > ul {
    display: none;
  }

  /* !important overrides the inline min-height:126vh some floor blocks carry
     for the desktop pin/pan scroll distance (see index.html) — irrelevant on
     mobile now that floors use the card switcher instead of scroll panning. */
  .hiw-floor-block { min-height: 0 !important; padding: 14px 0; }

  .hiw-mobile-switch {
    display: block;
    position: relative;
    width: 100%;
    height: 200px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    background: #F3EEE0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  /* Small tap hint so the card reads as interactive rather than a static
     image — reader taps to flip between illustration and summary text,
     at their own pace (no auto-cycle). */
  .hiw-mobile-switch::after {
    content: "⇄ tap to flip";
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 1;
    background: rgba(20, 20, 16, .55);
    color: #fff;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    letter-spacing: .03em;
    padding: 4px 8px;
    border-radius: var(--radius-pill, 999px);
    pointer-events: none;
  }
  .hiw-mobile-switch.is-text-active::after {
    background: rgba(20, 20, 16, .12);
    color: var(--text-dim);
  }
  .hiw-switch-image,
  .hiw-switch-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .8s ease;
  }
  .hiw-switch-image { opacity: 1; }
  .hiw-switch-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }
  .hiw-switch-text {
    opacity: 0;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    background: var(--surface);
    padding: 20px 22px;
    box-sizing: border-box;
    text-align: left;
  }
  .hiw-switch-text h3 {
    font-family: 'Young Serif', Georgia, serif;
    font-weight: 400;
    font-size: 17px;
    line-height: 1.25;
    color: var(--text);
    margin: 0 0 8px;
  }
  .hiw-switch-text p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dim);
    margin: 0;
  }
  .hiw-mobile-switch.is-text-active .hiw-switch-image { opacity: 0; }
  .hiw-mobile-switch.is-text-active .hiw-switch-text { opacity: 1; }
}
