/**
 * Studio Koncordia — homepage scrollytelling (page-local)
 * Three-act narrative, sticky 3D rail, progressive emphasis hooks.
 * Loaded only on index.html; does not affect other pages.
 */

/* ——— Story shell ——— */

.home-story {
  --home-rail-width: clamp(17.5rem, 36vw, 32.5rem);
  --home-sticky-top: 4.75rem;
  --home-beat-muted: var(--color-ink-muted);
  --home-beat-active: var(--color-ink);
  --home-visual-height: min(72dvh, 40rem);
  --home-draft-reveal: 0;

  position: relative;
  isolation: isolate;
  overflow-x: clip;
}

/* Draft grid/sketch — only the detail band below the asset seam; rises from bottom at compass unpin */
.home-story__draft-bg {
  --home-draft-detail-ratio: 682 / 512;

  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.home-story__draft-bg::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  aspect-ratio: var(--home-draft-detail-ratio);
  max-height: 100%;
  background-image: url("../assets/img/home-draft-background-detail.png");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center top;
  transform: translateY(calc((1 - var(--home-draft-reveal)) * 100%));
  will-change: transform;
}

/* Desktop: same reveal timing (unchanged JS), but fit the asset without cover crop/upscale */
@media (min-width: 48rem) {
  .home-story {
    /* Stop draft rise here — plain paper above, drawings below (see narrative → ways seam) */
    --home-draft-reveal-cap: 0.38;
  }

  .home-story__draft-bg::before {
    max-height: none;
    background-size: 100% auto;
    background-position: center bottom;
    transform: translateY(
      calc((1 - min(var(--home-draft-reveal), var(--home-draft-reveal-cap))) * 100%)
    );
  }
}

/* ——— Act 2 — narrative beats (pin + scroll-driven ink reveal) ——— */

.home-act--narrative {
  padding-block: 0;
  min-height: 0;
}

.home-narrative__pin {
  --home-narrative-approach: clamp(42vh, 52vh, 62vh);
  --home-narrative-pin-travel: 215vh;
  box-sizing: border-box;
  padding-top: var(--home-narrative-approach);
  height: calc(var(--home-narrative-approach) + 100vh + var(--home-narrative-pin-travel));
}

.home-narrative__stage {
  position: sticky;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  padding-block: var(--space-4);
}

.home-narrative__beats {
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-3), 2.5vh, var(--space-5));
  max-width: 40rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.home-narrative__beat {
  margin: 0;
  min-height: 0;
  display: block;
}

.home-narrative__beat p {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(1.35rem, 1.85vw + 0.65rem, 2.125rem);
  line-height: 1.28;
  letter-spacing: -0.015em;
  text-wrap: pretty;
}

.home-narrative__word {
  --word-reveal: 0;
  --word-opacity: 0;
  --word-muted-tone: color-mix(in srgb, var(--color-ink-muted) 38%, var(--color-paper));
  color: color-mix(
    in srgb,
    var(--word-muted-tone) calc((1 - var(--word-reveal)) * 100%),
    var(--color-ink) calc(var(--word-reveal) * 100%)
  );
  opacity: var(--word-opacity);
}

/* Progressive no-JS: first beat reads at full ink */
.home-story:not(.is-home-story-ready) .home-narrative__beat[data-home-emphasis-index="1"] .home-narrative__word {
  --word-reveal: 1;
  --word-opacity: 1;
}

/* Progressive no-JS: first beat at full ink, others muted */
.home-story:not(.is-home-story-ready) .home-narrative__beat[data-home-emphasis-index="1"] p {
  color: var(--color-ink);
}

.home-story:not(.is-home-story-ready) .home-narrative__beat:not([data-home-emphasis-index="1"]) p {
  color: var(--color-ink-muted);
}

.home-story.is-home-narrative-complete .home-narrative__word {
  --word-reveal: 1;
  --word-opacity: 1;
}

.home-story__inner {
  position: relative;
  z-index: 2;
  width: var(--container-wide);
  max-width: 100%;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--home-rail-width);
  grid-template-rows: auto auto;
  gap: clamp(var(--space-5), 4vw, var(--space-8));
  align-items: start;
}

.home-story__content {
  display: contents;
}

.home-act--hero {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
}

.home-story__rail {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
  min-width: 0;
}

.home-act--narrative {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
}

.home-visual__pin {
  position: relative;
  width: 100%;
}

/* ——— Act 1 — hero ——— */

.home-act--hero {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: var(--space-5);
  min-height: 0;
  padding: 0;
  padding-bottom: clamp(var(--space-6), 5vh, var(--space-8));
  max-width: 46rem;
}

.home-hero__eyebrow {
  margin: 0;
  font-size: calc(var(--text-micro) * 1.4);
}

.home-hero__title {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(2.21rem, 4.355vw + 0.325rem, 4.225rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  font-stretch: normal;
  color: var(--color-ink);
  text-wrap: balance;
}

.home-hero__title-continue {
  display: block;
}

.home-hero__lede {
  margin: 0;
  max-width: 42rem;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: clamp(1rem, 1.1vw + 0.85rem, var(--text-lead));
  line-height: var(--leading-body);
  letter-spacing: normal;
  color: var(--color-ink-soft);
}

.home-hero__cta {
  margin-top: var(--space-2);
}

.home-hero__cta .btn--secondary {
  font-size: var(--text-small);
  font-weight: 500;
  color: var(--color-ink-muted);
  letter-spacing: 0.06em;
}

.home-hero__cta .btn--secondary:hover,
.home-hero__cta .btn--secondary:focus-visible {
  color: var(--color-ink);
}

/* ——— Act 3 — three ways (post-narrative) ——— */

.home-ways {
  position: relative;
  z-index: 2;
  width: min(1340px, calc(100% - 2 * var(--space-gutter) + 2.5rem));
  max-width: 100%;
  margin-inline: auto;
  padding-block: clamp(var(--space-8), 14vh, 9rem) clamp(var(--space-9), 16vh, 11rem);
}

.home-ways__title {
  --ways-title-reveal: 0;

  margin: 0 0 clamp(var(--space-7), 9vh, 4.75rem);
  max-width: 14ch;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(2rem, 3.8vw + 0.5rem, 3.35rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--color-ink);
  text-wrap: balance;
  opacity: var(--ways-title-reveal);
  transform: translate3d(0, calc((1 - var(--ways-title-reveal)) * 2.25rem), 0);
  filter: blur(calc((1 - var(--ways-title-reveal)) * 5px));
  will-change: opacity, transform, filter;
}

.home-ways__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(var(--space-3), 2vw, var(--space-5));
  align-items: stretch;
}

.home-ways__card {
  --ways-card-reveal: 0;

  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 100%;
  padding: clamp(var(--space-5), 3vw, var(--space-6));
  background-color: color-mix(in srgb, var(--color-paper-raised) 88%, transparent);
  border: var(--hairline) solid var(--color-bronze-faint);
  box-shadow: 0 1.25rem 2.5rem rgba(20, 20, 18, 0.04);
  opacity: var(--ways-card-reveal);
  transform: translate3d(0, calc((1 - var(--ways-card-reveal)) * 2.5rem), 0);
  filter: blur(calc((1 - var(--ways-card-reveal)) * 4px));
  will-change: opacity, transform, filter;
}

.home-ways__card-title {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(1.2rem, 1.1vw + 0.95rem, 1.45rem);
  line-height: 1.28;
  letter-spacing: -0.015em;
  color: var(--color-ink);
  text-wrap: pretty;
}

.home-ways__card-lede {
  margin: 0;
  font-size: clamp(0.98rem, 0.35vw + 0.9rem, var(--text-body));
  line-height: var(--leading-snug);
  color: var(--color-ink-soft);
}

.home-ways__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
}

.home-ways__list li {
  position: relative;
  padding-left: 1.35rem;
  font-size: clamp(0.92rem, 0.25vw + 0.86rem, var(--text-body));
  line-height: var(--leading-snug);
  color: var(--color-ink-muted);
}

.home-ways__list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0.05em;
  color: var(--color-bronze);
  font-size: 0.9em;
  line-height: 1;
}

.home-ways__cta {
  margin-top: auto;
  align-self: stretch;
  justify-content: center;
  width: 100%;
  min-height: 3.25rem;
  text-align: center;
}

/* Progressive no-JS: ways content readable */
.home-story:not(.is-home-story-ready) .home-ways__title,
.home-story:not(.is-home-story-ready) .home-ways__card {
  --ways-title-reveal: 1;
  --ways-card-reveal: 1;
  filter: none;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .home-ways__title,
  .home-ways__card {
    filter: none;
    will-change: auto;
  }
}

/* ——— Act 4 — Swiss market stats (post-ways) ——— */

.home-stats {
  position: relative;
  z-index: 2;
  width: min(1340px, calc(100% - 2 * var(--space-gutter) + 2.5rem));
  max-width: 100%;
  margin-inline: auto;
  padding-block: clamp(var(--space-7), 10vh, 6.5rem) clamp(var(--space-8), 12vh, 8rem);
}

.home-stats__inner {
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-7), 8vh, 4.5rem);
}

.home-stats__head {
  max-width: 18ch;
}

.home-stats__title {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(2.35rem, 4.8vw + 0.65rem, 4rem);
  line-height: 1.06;
  letter-spacing: -0.024em;
  color: var(--color-ink);
  text-wrap: balance;
}

.home-stats__title::after {
  content: "";
  display: block;
  width: clamp(3.5rem, 8vw, 5.5rem);
  height: var(--hairline);
  margin-top: clamp(var(--space-4), 2.5vh, var(--space-5));
  background: linear-gradient(
    90deg,
    var(--color-bronze) 0%,
    color-mix(in srgb, var(--color-bronze) 28%, transparent) 100%
  );
}

.home-stats__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(var(--space-5), 4vw, var(--space-7));
  align-items: start;
}

.home-stats__item {
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-4), 2.5vh, var(--space-5));
  min-width: 0;
}

.home-stats__item:first-child {
  padding-inline-start: 0;
}

.home-stats__metric {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.home-stats__metric-focus {
  display: contents;
}

.home-stats__label-focus {
  display: inline-block;
}

.home-stats__figure {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(3.25rem, 7.2vw + 0.5rem, 5.75rem);
  line-height: 0.92;
  letter-spacing: -0.035em;
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
}

.home-stats__unit {
  margin-inline-start: 0.06em;
  font-size: 0.42em;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--color-bronze);
  vertical-align: super;
}

.home-stats__fact {
  margin: 0;
  max-width: 22ch;
  font-size: clamp(1rem, 0.35vw + 0.92rem, 1.125rem);
  font-weight: 600;
  line-height: 1.5;
  color: var(--color-ink-soft);
  text-wrap: pretty;
}

.home-stats__label {
  margin: 0;
  padding-top: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: var(--tracking-nav);
  text-transform: uppercase;
  color: var(--color-bronze);
}

/* Progressive reveal — opacity/transform only (compositor-safe) */
.home-stats.is-home-stats-ready [data-home-stats-part] {
  opacity: 0;
  transform: translate3d(0, 1.25rem, 0);
  transition:
    opacity 1.15s cubic-bezier(0.22, 1, 0.36, 1),
    transform 1.15s cubic-bezier(0.22, 1, 0.36, 1);
}

.home-stats.is-home-stats-ready [data-home-stats-part^="stat-"] {
  transform: translate3d(0, 1.1rem, 0);
  transition:
    opacity 1.65s cubic-bezier(0.18, 1, 0.32, 1),
    transform 1.65s cubic-bezier(0.18, 1, 0.32, 1);
}

.home-stats.is-home-stats-ready [data-home-stats-part^="label-"] {
  transform: translate3d(0, 1rem, 0);
  transition:
    opacity 1.55s cubic-bezier(0.18, 1, 0.32, 1),
    transform 1.55s cubic-bezier(0.18, 1, 0.32, 1);
}

.home-stats.is-home-stats-visible [data-home-stats-part="title"] {
  opacity: 1;
  transform: none;
  transition-delay: 0ms;
}

.home-stats.is-home-stats-visible [data-home-stats-part="stat-1"] {
  opacity: 1;
  transform: none;
  transition-delay: 780ms;
}

.home-stats.is-home-stats-visible [data-home-stats-part="stat-2"] {
  opacity: 1;
  transform: none;
  transition-delay: 1080ms;
}

.home-stats.is-home-stats-visible [data-home-stats-part="stat-3"] {
  opacity: 1;
  transform: none;
  transition-delay: 1380ms;
}

.home-stats.is-home-stats-visible [data-home-stats-part="label-1"] {
  opacity: 1;
  transform: none;
  transition-delay: 1780ms;
}

.home-stats.is-home-stats-visible [data-home-stats-part="label-2"] {
  opacity: 1;
  transform: none;
  transition-delay: 2080ms;
}

.home-stats.is-home-stats-visible [data-home-stats-part="label-3"] {
  opacity: 1;
  transform: none;
  transition-delay: 2380ms;
}

.home-stats:not(.is-home-stats-ready) [data-home-stats-part] {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .home-stats.is-home-stats-ready [data-home-stats-part] {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

@media (min-width: 48rem) {
  .home-stats {
    /* Full-viewport stage: title enters sooner after the narrative */
    min-height: max(40rem, 92svh);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    box-sizing: border-box;
    margin-top: clamp(var(--space-4), 3.5vh, 3rem);
    padding-block: clamp(var(--space-6), 6vh, 4.75rem) clamp(var(--space-8), 9vh, 7rem);
  }

  .home-stats__inner {
    width: 100%;
    flex: 0 0 auto;
    align-items: center;
    text-align: center;
    gap: clamp(var(--space-8), 9vh, 5rem);
  }

  .home-stats__head {
    max-width: none;
    width: 100%;
  }

  .home-stats__title {
    font-size: clamp(2.3rem, 3.45vw + 0.5rem, 3.85rem);
    text-wrap: nowrap;
    white-space: nowrap;
  }

  .home-stats__title::after {
    margin-inline: auto;
    width: clamp(4rem, 8.5vw, 6rem);
    margin-top: clamp(var(--space-4), 2.8vh, var(--space-6));
  }

  .home-stats__grid {
    width: 100%;
    max-width: 62rem;
    margin-inline: auto;
    align-items: stretch;
    gap: clamp(var(--space-6), 5vw, var(--space-8));
  }

  .home-stats__item {
    align-items: center;
    text-align: center;
    padding-inline: clamp(var(--space-2), 1.5vw, var(--space-4));
  }

  .home-stats__item:first-child {
    padding-inline-start: clamp(var(--space-2), 1.5vw, var(--space-4));
  }

  .home-stats__metric {
    align-items: center;
    flex: 1 1 auto;
    width: 100%;
    gap: 0;
  }

  .home-stats__metric-focus {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: var(--space-4);
    transform-origin: center center;
    backface-visibility: hidden;
    transition: transform 0.5s cubic-bezier(0.2, 1, 0.34, 1);
    will-change: transform;
  }

  .home-stats__label-focus {
    display: inline-block;
    transform-origin: center center;
    backface-visibility: hidden;
    transition: transform 0.5s cubic-bezier(0.2, 1, 0.34, 1);
    will-change: transform;
  }

  @media (hover: hover) {
    .home-stats__item {
      isolation: isolate;
      cursor: default;
    }

    .home-stats__item:hover {
      z-index: 1;
    }

    .home-stats__item:hover .home-stats__metric-focus {
      transform: scale(1.06);
    }

    .home-stats__item:hover .home-stats__label-focus {
      transform: scale(1.085);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .home-stats__metric-focus,
    .home-stats__label-focus {
      transition: none;
    }

    .home-stats__item:hover .home-stats__metric-focus,
    .home-stats__item:hover .home-stats__label-focus {
      transform: none;
    }
  }

  .home-stats__figure {
    text-align: center;
    font-size: clamp(3.5rem, 7.8vw + 0.55rem, 6.35rem);
  }

  .home-stats__fact {
    width: 100%;
    max-width: none;
    margin-top: 1lh;
    margin-inline: auto;
    font-size: clamp(1.06rem, 0.42vw + 0.96rem, 1.22rem);
    line-height: 1.52;
    text-wrap: pretty;
    min-height: calc(2 * 1lh);
  }

  .home-stats__label {
    margin-top: auto;
    width: 100%;
    min-height: 2.85rem;
    padding-top: clamp(var(--space-4), 2.4vh, var(--space-5));
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-size: 0.875rem;
    letter-spacing: 0.14em;
    color: var(--color-ink);
  }

  .home-stats__unit {
    font-size: 0.62em;
    vertical-align: super;
  }
}

/* ——— Sticky 3D visual rail ——— */

.home-visual {
  position: sticky;
  top: var(--home-sticky-top);
  height: var(--home-visual-height);
  display: grid;
  place-items: center;
  width: 100%;
}

.home-visual__mount,
.home-visual__fallback {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
}

.home-visual__mount {
  position: relative;
  overflow: hidden;
}

.home-visual__mount canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.home-visual__fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.72;
}

.home-visual__fallback-img {
  /* Kept a little narrower than the rail so the mark reads at a similar weight
     to the 3D compass and never crowds the headline on narrow screens. */
  width: min(86%, 16rem);
  height: auto;
  object-fit: contain;
}

/*
 * Visibility is driven solely by data-home-visual-state, which is present in the
 * markup from the first paint. The static mark therefore shows without JS, while
 * the GLB downloads, and whenever the 3D path fails — never a blank rail.
 */
.home-visual[data-home-visual-state="ready"] .home-visual__mount:not(:empty) ~ .home-visual__fallback {
  display: none;
}

.home-visual.is-loading .home-visual__mount canvas {
  opacity: 0;
}

.home-visual.is-ready .home-visual__mount canvas {
  opacity: 1;
  transition: opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.home-visual[data-home-visual-state="fallback"] .home-visual__mount {
  display: none;
}

.home-visual__fallback[hidden] {
  display: none;
}

/* Scroll-driven pose hooks (set by home-scroll.js via custom properties) */
.home-visual {
  --home-visual-rotate-x: 0deg;
  --home-visual-rotate-y: 0deg;
  --home-visual-rotate-z: 0deg;
  --home-visual-translate-y: 0%;
}

.home-visual__mount {
  transform: rotateX(var(--home-visual-rotate-x)) rotateY(var(--home-visual-rotate-y))
    rotateZ(var(--home-visual-rotate-z)) translateY(var(--home-visual-translate-y));
  transform-style: preserve-3d;
  will-change: transform;
}

/* Story progression (values set by home-scroll.js on [data-home-story]) */
.home-story[data-home-story-progress] {
  --home-story-progress: 0;
  --home-narrative-reveal: 0;
  --home-draft-reveal: 0;
}

/* ——— Tablet ——— */

@media (max-width: 63.99rem) and (min-width: 48rem) {
  .home-story {
    --home-rail-width: clamp(12.5rem, 34vw, 18rem);
    --home-visual-height: min(58dvh, 28rem);
  }

  .home-ways__grid {
    grid-template-columns: 1fr;
  }

  .home-act--hero {
    max-width: none;
    padding-inline-end: var(--space-2);
  }

  .home-act--narrative {
    min-height: 0;
  }

  .home-narrative__pin {
    --home-narrative-approach: clamp(38vh, 48vh, 56vh);
    --home-narrative-pin-travel: 190vh;
  }

  .home-narrative__beats {
    gap: var(--space-3);
  }

  .home-narrative__beat p {
    font-size: clamp(1.2rem, 4.8vw, 1.65rem);
    line-height: 1.3;
  }
}
