/* ============================================================
   scroll-stage.css — the homepage's two scroll-driven pieces.
   Both are driven by scripts/scroll-stage.js and both switch off
   completely when motion is paused.

   1. Pinned work showcase (.kshow). Without the script, or with
      motion paused, the work section is the plain feature + row it
      has always been. With html.kshow-on the block becomes a tall
      track holding a sticky stage: every project is stacked in the
      same cell, the copy swaps on a class, and each browser frame is
      scrubbed into place by two numbers the script writes per frame:
        --in   0 → 1 as this project arrives
        --out  0 → 1 as the next one covers it
   2. The travelling diamond (.kgem), a fixed canvas that flies
      between .gem-dock markers. A dock is an invisible box whose
      centre and width tell the diamond where to rest and how big to
      be, so every resting place is tuned here, per breakpoint.
   ============================================================ */

/* ---------- pieces that only exist in pinned mode ---------- */
.kshow-more, .kshow-hud, .kshow-glow { display: none; }

/* ---------- diamond ---------- */
.kgem {
  position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none;
  opacity: 0; transition: opacity .7s ease; will-change: transform;
}
.kgem.is-on { opacity: 1; }
.kgem[hidden], [data-motion=reduced] .kgem { display: none; }

.gem-dock {
  position: absolute; width: var(--gem, 72px); height: var(--gem, 72px);
  pointer-events: none; visibility: hidden;
}
.khero-title, .work-head h2, .assistant-copy h2, .pricing-head h2, .kcontact .section-head h2 { position: relative; }

/* hero: large, just off the end of the headline, over the faded edge of the wall */
.khero-title .gem-dock { --gem: clamp(104px, 10.4vw, 156px); right: -12%; bottom: -5%; }
/* work heading: at the far end of the line */
.work-head h2 .gem-dock { --gem: clamp(64px, 6.4vw, 96px); right: 3%; top: 50%; translate: 0 -50%; }
/* assistant: perched above the end of the heading */
.assistant-copy h2 .gem-dock { --gem: clamp(52px, 4.6vw, 70px); right: 0; bottom: calc(100% + 4px); }
/* pricing: out in the open space beside the heading */
.pricing-head h2 .gem-dock { --gem: clamp(84px, 9vw, 132px); right: clamp(-380px, -24vw, 0px); top: 50%; translate: 0 -50%; }
/* contact: where it lands */
.kcontact .section-head h2 .gem-dock { --gem: clamp(60px, 6vw, 92px); right: 0; top: 0; }

@media (max-width: 860px) {
  .khero-title .gem-dock { --gem: 56px; right: 0; bottom: -16px; }
  .work-head h2 .gem-dock { --gem: 48px; right: 0; top: auto; bottom: 0; translate: none; }
  .assistant-copy h2 .gem-dock { --gem: 42px; }
  .pricing-head h2 .gem-dock { --gem: 48px; right: 0; top: 0; translate: none; }
  .kcontact .section-head h2 .gem-dock { --gem: 52px; }
}

/* ============================================================
   Pinned showcase
   ============================================================ */
@media screen {
  html.kshow-on .kshow {
    --kstep: 62vh;
    position: relative;
    height: calc(100vh + (var(--kn, 6) - 1) * var(--kstep));
  }
  html.kshow-on .kshow-stage {
    position: sticky; top: 0; height: 100vh; box-sizing: border-box;
    /* full-bleed, so frames and the glow clip at the screen edge, not the column edge */
    margin-inline: calc(var(--kbleed, 0px) * -1); padding-inline: var(--kbleed, 0px);
    padding-top: calc(var(--ktop, 96px) + clamp(12px, 3vh, 36px));
    padding-bottom: clamp(16px, 4vh, 48px);
    display: grid; grid-template-columns: 84px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
    column-gap: clamp(16px, 2.4vw, 40px);
    overflow: hidden; overflow: clip;
  }
  @supports (height: 100svh) {
    html.kshow-on .kshow { --kstep: 62svh; height: calc(100svh + (var(--kn, 6) - 1) * var(--kstep)); }
    html.kshow-on .kshow-stage { height: 100svh; }
  }

  /* each project's colour, bleeding in behind its frame */
  html.kshow-on .kshow-glow {
    display: block; position: absolute; z-index: 0; pointer-events: none;
    right: -8%; top: 52%; width: min(74vw, 1040px); aspect-ratio: 1.3; translate: 0 -50%;
    color: var(--accent); background: radial-gradient(closest-side, currentColor, transparent);
    opacity: calc(.17 * var(--pre, 1)); transition: color .9s ease;
  }
  [data-theme=light] .kshow-glow { opacity: calc(.24 * var(--pre, 1)); }

  /* ---------- projects: all six in one cell ---------- */
  html.kshow-on .kwork-row { display: contents; }
  html.kshow-on .kshow-item {
    grid-area: 1 / 2; position: relative; z-index: calc(var(--ki, 0) + 1);
    min-width: 0; min-height: 0; margin: 0; padding: 0; border: 0; flex: none;
    display: grid; grid-template-columns: minmax(0, .72fr) minmax(0, 1.4fr);
    column-gap: clamp(28px, 4.4vw, 76px); align-items: center;
    pointer-events: none;
  }

  html.kshow-on .kshow-visual,
  html.kshow-on .kshow-visual:hover {
    --e: calc(1 - var(--in, 0));
    grid-column: 2; grid-row: 1; position: relative; aspect-ratio: auto;
    /* never taller than the stage has room for */
    width: min(100%, calc((100vh - var(--ktop, 96px) - 150px) * 1.6)); justify-self: end;
    border-radius: 12px; pointer-events: auto;
    transform-origin: 50% 100%;
    transform:
      translate3d(0, calc(var(--e) * var(--kdy, 100vh) + (1 - var(--pre, 1)) * 56px), 0)
      rotate(calc(var(--e) * 2.4deg))
      scale(calc((1 - var(--out, 0) * .08) * (.92 + var(--pre, 1) * .08)));
    transition: border-color .3s, box-shadow .45s var(--ease);
    box-shadow: 0 44px 90px -54px #000;
    will-change: transform;
  }
  html.kshow-on .kshow-visual:hover { border-color: var(--accent-border, var(--accent)); }
  html.kshow-on .kshow-visual img,
  html.kshow-on .kshow-visual:hover img { transform: scale(calc(1.07 - var(--in, 0) * .07)); transition: none; }
  /* the frame underneath dims as the next one slides over it */
  html.kshow-on .kshow-visual::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: var(--bg); opacity: calc(var(--out, 0) * .62);
  }
  html.kshow-on .is-below .kshow-visual, html.kshow-on .is-buried .kshow-visual { visibility: hidden; }

  html.kshow-on .kshow-copy {
    grid-column: 1; grid-row: 1; padding: 0; max-width: 30rem;
    opacity: 0; transform: translate3d(0, 28px, 0);
    transition: opacity .3s ease, transform .6s var(--ease);
  }
  html.kshow-on .is-past .kshow-copy { transform: translate3d(0, -28px, 0); }
  html.kshow-on .is-active .kshow-copy { opacity: 1; transform: none; pointer-events: auto; transition-delay: .1s; }
  html.kshow-on .kshow-more { display: block; }

  /* the row's cards take on the feature's type */
  html.kshow-on .kshow-copy .project-category {
    font-size: .75rem; letter-spacing: 0; text-transform: none; color: var(--text-dim); margin: 0 0 12px;
  }
  html.kshow-on .kshow-copy h3 {
    font-size: clamp(2.1rem, 3.5vw, 3.3rem); font-weight: 500; letter-spacing: -.05em; line-height: 1; margin: 6px 0 18px;
  }
  html.kshow-on .kshow-copy h3 a { display: inline; }
  html.kshow-on .kshow-copy h3 a span { display: none; }
  html.kshow-on .kshow-copy .feature-lede { display: block; font-size: 1.05rem; line-height: 1.6; max-width: 40ch; margin: 0; }
  html.kshow-on .kshow-copy .feature-facts { display: grid; margin: 24px 0 28px; }

  /* ---------- rail: where you are, and the diamond's track ---------- */
  html.kshow-on .kshow-hud {
    display: flex; flex-direction: column; grid-area: 1 / 1; align-self: center;
    position: relative; z-index: 8; height: min(46vh, 340px); margin: 0;
    opacity: var(--pre, 1);
  }
  .kshow-count { display: none; margin: 0; }
  .kshow-rail { position: relative; flex: 1; margin-left: 24px; }
  .kshow-rail::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 1px; background: var(--border-2); }
  .kshow-fill {
    position: absolute; left: 0; top: 0; bottom: 0; width: 1px; background: var(--accent);
    transform-origin: 50% 0; transform: scaleY(var(--kp, 0));
  }
  .kshow-rail .kshow-marker { --gem: 42px; left: 0; top: calc(var(--kp, 0) * 100%); translate: -50% -50%; }
  .kshow-rail ol { list-style: none; margin: 0; padding: 0; height: 100%; display: flex; flex-direction: column; justify-content: space-between; }
  .kshow-rail li { height: 0; display: flex; align-items: center; }
  .kshow-rail button {
    appearance: none; position: relative; background: none; border: 0; margin: 0; cursor: pointer;
    padding: 12px 8px 12px 32px; font: .68rem var(--mono); letter-spacing: .1em; color: var(--text-dim);
    transition: color .3s ease;
  }
  .kshow-rail button::before {
    content: ""; position: absolute; left: -3px; top: 50%; width: 7px; height: 7px; border-radius: 50%; translate: 0 -50%;
    background: var(--bg); border: 1px solid var(--border-2); box-sizing: border-box;
    transition: background .3s ease, border-color .3s ease;
  }
  .kshow-rail button.is-done::before { background: var(--accent); border-color: var(--accent); }
  .kshow-rail button:hover, .kshow-rail button[aria-current] { color: var(--accent-text, var(--accent)); }

  /* ---------- short screens: trim the copy so it all still fits on the stage ---------- */
  html.kshow-on.kshow-tight .kshow-copy .feature-facts { display: none; }
  html.kshow-on.kshow-tight .kshow-copy .feature-lede { margin-bottom: 24px; }

  /* ---------- stacked layout: frame above, copy below, frames arrive from the side ---------- */
  @media (max-width: 960px) {
    html.kshow-on .kshow { --kstep: 58vh; }
    @supports (height: 100svh) { html.kshow-on .kshow { --kstep: 58svh; } }
    html.kshow-on .kshow-stage {
      grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); row-gap: 14px;
      padding-top: calc(var(--ktop, 62px) + 12px); padding-bottom: 12px;
    }
    html.kshow-on .kshow-glow { right: -30%; top: 34%; width: 150vw; }
    html.kshow-on .kshow-item {
      grid-area: 2 / 1; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
      row-gap: 16px; align-items: start;
    }
    html.kshow-on .kshow-visual,
    html.kshow-on .kshow-visual:hover {
      grid-column: 1; grid-row: 1; justify-self: center;
      width: min(100%, calc((48vh - 40px) * 1.6)); width: min(100%, calc((48svh - 40px) * 1.6));
      transform-origin: 50% 50%;
      transform:
        translate3d(calc(var(--e) * 104vw), calc((1 - var(--pre, 1)) * 40px), 0)
        rotate(calc(var(--e) * 3deg))
        scale(calc((1 - var(--out, 0) * .1) * (.94 + var(--pre, 1) * .06)));
    }
    html.kshow-on .kshow-copy { grid-column: 1; grid-row: 2; max-width: none; overflow: hidden; }
    html.kshow-on .kshow-copy .project-category { margin-bottom: 6px; }
    html.kshow-on .kshow-copy h3 { font-size: clamp(1.8rem, 7.4vw, 2.5rem); margin: 2px 0 10px; }
    html.kshow-on .kshow-copy .feature-lede {
      font-size: 1rem; line-height: 1.5; max-width: 46ch;
      display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden;
    }
    html.kshow-on .kshow-copy .feature-facts { display: none; }
    html.kshow-on .kshow-copy .btn { margin-top: 16px; }
    html.kshow-on.kshow-tight .kshow-stage { row-gap: 10px; padding-top: calc(var(--ktop, 62px) + 8px); }
    html.kshow-on.kshow-tight .kshow-item { row-gap: 12px; }
    html.kshow-on.kshow-tight .kshow-visual,
    html.kshow-on.kshow-tight .kshow-visual:hover { width: min(100%, calc((40vh - 40px) * 1.6)); width: min(100%, calc((40svh - 40px) * 1.6)); }
    html.kshow-on.kshow-tight .kshow-copy h3 { font-size: 1.7rem; margin-bottom: 8px; }
    html.kshow-on.kshow-tight .kshow-copy .feature-lede { -webkit-line-clamp: 3; margin-bottom: 0; }
    html.kshow-on.kshow-tight .kshow-copy .btn { margin-top: 12px; }

    html.kshow-on .kshow-hud { flex-direction: row; align-items: center; gap: 18px; height: 34px; align-self: auto; }
    .kshow-count { display: flex; align-items: baseline; gap: 6px; font-size: .7rem; letter-spacing: .1em; color: var(--text-dim); }
    .kshow-count b { font-weight: 500; color: var(--accent-text, var(--accent)); }
    .kshow-rail { margin: 0 18px 0 0; height: 34px; }
    .kshow-rail::before { top: 50%; bottom: auto; right: 0; width: auto; height: 1px; }
    .kshow-fill { top: 50%; bottom: auto; right: 0; width: auto; height: 1px; transform-origin: 0 50%; transform: scaleX(var(--kp, 0)); }
    .kshow-rail .kshow-marker { --gem: 30px; left: calc(var(--kp, 0) * 100%); top: 50%; }
    .kshow-rail ol { flex-direction: row; }
    .kshow-rail li { width: 0; height: 100%; justify-content: center; }
    .kshow-rail button { flex: none; width: 30px; height: 34px; padding: 0; font-size: 0; }
    .kshow-rail button::before { left: 50%; translate: -50% -50%; }
  }
}
