/* ============================================================
   MTB LP — Motion: FROM IDEA TO STRUCTURE.
   Vocabulary: REVEAL / BUILD / SLIDE / SCALE / MASK / GRID
   - Everything below is opt-in via html.js (no JS => static, complete page)
   - prefers-reduced-motion: reduce => everything shown in its final state
   ============================================================ */

/* ---------- Scroll reveal (IntersectionObserver adds .is-visible) ---------- */
@media (prefers-reduced-motion: no-preference) {
  html.js [data-reveal] {
    opacity: 0;
    transform: translateY(var(--shift));
    transition:
      opacity var(--dur) var(--ease),
      transform var(--dur) var(--ease);
    transition-delay: calc(var(--i, 0) * 90ms);
    will-change: opacity, transform;
  }
  html.js [data-reveal].is-visible {
    opacity: 1;
    transform: none;
    will-change: auto;
  }
  html.js [data-reveal="slide"] { transform: translateX(calc(var(--shift) * -1)); }
  html.js [data-reveal="slide"].is-visible { transform: none; }

  /* BUSINESS rows: short horizontal move (24–48px) while entering */
  html.js .biz-row[data-reveal] { transform: translateX(-32px); }
  html.js .biz-row[data-reveal].is-visible { transform: none; }

  /* CTA line grows left → right after reveal */
  html.js .line-link[data-reveal] .line-link__line {
    transform: scaleX(0);
    transition: transform 0.8s var(--ease) 0.25s;
  }
  html.js .line-link[data-reveal].is-visible .line-link__line { transform: scaleX(1); }

  /* Mask reveal for headings: the heading box stays put (so it can be
     observed); each .line rises into view from below the mask. */
  html.js [data-reveal="mask"] {
    opacity: 1;
    transform: none;
    overflow: hidden;
    padding-bottom: 0.12em;
    margin-bottom: -0.12em;
  }
  html.js [data-reveal="mask"] .line {
    transform: translateY(110%);
    transition: transform 0.8s var(--ease);
  }
  html.js [data-reveal="mask"] .line:nth-child(2) { transition-delay: 80ms; }
  html.js [data-reveal="mask"] .line:nth-child(3) { transition-delay: 160ms; }
  html.js [data-reveal="mask"] .line:nth-child(4) { transition-delay: 240ms; }
  html.js [data-reveal="mask"].is-visible .line { transform: none; }

  /* Diagram CONNECT: words appear, lines draw left → right, then MTB */
  html.js [data-reveal="draw"] { opacity: 1; transform: none; }
  html.js [data-reveal="draw"] .dg-ja text { opacity: 0; transition: opacity 0.5s var(--ease); }
  html.js [data-reveal="draw"] .dg-ja text:nth-child(2) { transition-delay: 0.1s; }
  html.js [data-reveal="draw"] .dg-ja text:nth-child(3) { transition-delay: 0.2s; }
  html.js [data-reveal="draw"] .dg-ja text:nth-child(4) { transition-delay: 0.3s; }
  html.js [data-reveal="draw"] .dg-ja text:nth-child(5) { transition-delay: 0.4s; }
  html.js [data-reveal="draw"] .dg-lines path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    transition: stroke-dashoffset 0.8s var(--ease);
  }
  html.js [data-reveal="draw"] .dg-lines path:nth-child(1) { transition-delay: 0.45s; }
  html.js [data-reveal="draw"] .dg-lines path:nth-child(2) { transition-delay: 0.55s; }
  html.js [data-reveal="draw"] .dg-lines path:nth-child(3) { transition-delay: 0.65s; }
  html.js [data-reveal="draw"] .dg-lines path:nth-child(4) { transition-delay: 0.75s; }
  html.js [data-reveal="draw"] .dg-lines path:nth-child(5) { transition-delay: 0.85s; }
  html.js [data-reveal="draw"] .dg-lines path:nth-child(6) { transition-delay: 1.2s; }
  html.js [data-reveal="draw"] .dg-logo { opacity: 0; transition: opacity 0.5s var(--ease) 1.5s; }
  html.js [data-reveal="draw"].is-visible .dg-ja text { opacity: 1; }
  html.js [data-reveal="draw"].is-visible .dg-lines path { stroke-dashoffset: 0; }
  html.js [data-reveal="draw"].is-visible .dg-logo { opacity: 1; }

  /* Diagram STRUCTURE: blocks assemble one by one, then the line and MTB */
  html.js [data-reveal="build"] { opacity: 1; transform: none; }
  html.js [data-reveal="build"] .dg-block {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.5s var(--ease), transform 0.6s var(--ease);
    transition-delay: calc(var(--i, 0) * 130ms);
  }
  html.js [data-reveal="build"] .dg-lines path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    transition: stroke-dashoffset 0.7s var(--ease) 0.8s;
  }
  html.js [data-reveal="build"] .dg-logo { opacity: 0; transition: opacity 0.5s var(--ease) 1.3s; }
  html.js [data-reveal="build"].is-visible .dg-block { opacity: 1; transform: none; }
  html.js [data-reveal="build"].is-visible .dg-lines path { stroke-dashoffset: 0; }
  html.js [data-reveal="build"].is-visible .dg-logo { opacity: 1; }

  /* PROJECTS: WORD → IMAGE (mask) → INFORMATION */
  html.js [data-reveal="project"] { opacity: 1; transform: none; }
  html.js [data-reveal="project"] .project__id,
  html.js [data-reveal="project"] .project__name,
  html.js [data-reveal="project"] .project__info {
    opacity: 0;
    transform: translateY(var(--shift));
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  }
  html.js [data-reveal="project"] .project__name { transition-delay: 0.05s; }
  html.js [data-reveal="project"] .project__info { transition-delay: 0.6s; }
  html.js [data-reveal="project"] .project__media {
    clip-path: inset(0 0 100% 0);
    transition: clip-path 0.8s var(--ease) 0.4s;
  }
  html.js [data-reveal="project"].is-visible .project__id,
  html.js [data-reveal="project"].is-visible .project__name,
  html.js [data-reveal="project"].is-visible .project__info { opacity: 1; transform: none; }
  html.js [data-reveal="project"].is-visible .project__media { clip-path: inset(0 0 0 0); }

  /* HERO scroll arrow: small movement, 2 cycles then stop */
  html.js .scroll-link__arrow {
    animation: scroll-nudge 1.4s var(--ease) 2.2s 2 both;
  }
  @keyframes scroll-nudge {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(6px); }
  }
}

/* ---------- OPENING: M → T → B build, then copy, then label ---------- */
@media (prefers-reduced-motion: no-preference) {
  html.js.opening .hero__glyph {
    animation: build-in 0.55s var(--ease) both;
  }
  html.js.opening .hero__glyph--m { animation-delay: 0.25s; }
  html.js.opening .hero__glyph--t { animation-delay: 0.45s; }
  html.js.opening .hero__glyph--b { animation-delay: 0.65s; }
  html.js.opening .hero__glyph--inc { animation-delay: 0.85s; }

  html.js.opening .hero__copy .line,
  html.js.opening .hero__copy-ja {
    animation: reveal-up 0.6s var(--ease) both;
  }
  html.js.opening .hero__copy .line:nth-child(1) { animation-delay: 1.2s; }
  html.js.opening .hero__copy .line:nth-child(2) { animation-delay: 1.3s; }
  html.js.opening .hero__copy .line:nth-child(3) { animation-delay: 1.4s; }
  html.js.opening .hero__copy-ja { animation-delay: 1.55s; }

  html.js.opening .hero__label,
  html.js.opening .hero__foot,
  html.js.opening .site-header {
    animation: fade-in 0.5s var(--ease) both;
    animation-delay: 1.6s;
  }

  @keyframes build-in {
    from { opacity: 0; transform: translateY(40px); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes reveal-up {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
}

/* ---------- Reduced motion: complete state, no smooth scroll ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================
   Scroll-linked choreography (progressive enhancement)
   Only when: JS on, motion allowed, browser supports scroll-driven animations.
   ============================================================ */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {

    /* HERO → ABOUT: the decorative MTB grows and fades inside the clipped hero
       while the white ABOUT enters from below. */
    html.js .hero { view-timeline: --hero block; }
    html.js .hero__logo {
      transform-origin: 50% 100%;
      animation: hero-exit linear both;
      animation-timeline: --hero;
      animation-range: exit 0% exit 100%;
    }
    html.js .hero__copy,
    html.js .hero__foot,
    html.js .hero__label {
      animation: hero-fade linear both;
      animation-timeline: --hero;
      animation-range: exit 0% exit 55%;
    }
    @keyframes hero-exit { to { transform: scale(1.18) translateY(-3%); opacity: 0.2; } }
    @keyframes hero-fade { to { opacity: 0; } }

    /* VISION: BUILD A BETTER TOMORROW. completes, then settles back so the eye
       moves to the Japanese line. */
    html.js .vision__head .display {
      transform-origin: 0 0;
      animation: vision-settle linear both;
      animation-timeline: view();
      animation-range: cover 58% cover 88%;
    }
    @keyframes vision-settle { to { transform: scale(0.9); opacity: 0.5; } }
  }

  /* HOW WE WORK pin build — PC only (≥1024×800), never with reduced motion.
     .how__stage becomes 320svh tall; .how__sticky pins for the middle ~52%
     of its view timeline (cover 24%–76%). */
  @media (min-width: 1024px) and (min-height: 800px) and (prefers-reduced-motion: no-preference) {
    html.js .how { timeline-scope: --how; }
    html.js .how__stage { view-timeline: --how block; height: 320svh; margin-top: var(--s-6); }
    html.js .how__sticky {
      position: sticky;
      top: 0;
      height: 100svh;
      display: grid;
      grid-template-rows: auto 1fr;
      padding-top: calc(var(--header-h) + var(--s-2));
      overflow: hidden;
    }
    html.js .how__stage-label { display: block; grid-row: 1; }
    html.js .how__steps,
    html.js .how__assembly { grid-area: 2 / 1; align-self: center; margin: 0; }

    /* compact rows so five stages fit in one viewport */
    html.js .how__steps .step { padding-block: 14px; }
    html.js .how__steps .step__word { font-size: clamp(40px, 4.4vw, 68px); }
    html.js .how__steps .step__ja { font-size: 18px; margin-top: 4px; }
    html.js .how__steps .step__desc { font-size: 15px; line-height: 1.6; padding-top: 0.15em; }

    /* 1) stages construct one by one */
    html.js .how__steps .step[data-reveal] {
      transition: none;
      animation: how-step linear both;
      animation-timeline: --how;
      animation-range: cover calc(25% + var(--i, 0) * 5%) cover calc(29% + var(--i, 0) * 5%);
    }
    /* 2) list steps aside, the STRUCTURE diagram takes its place */
    html.js .how__steps {
      animation: how-list-out linear both;
      animation-timeline: --how;
      animation-range: cover 53% cover 58%;
    }
    html.js .how__assembly {
      animation: how-diagram-in linear both;
      animation-timeline: --how;
      animation-range: cover 56% cover 60%;
    }
    html.js .diagram--structure .dg-block {
      transition: none;
      animation: how-block linear both;
      animation-timeline: --how;
      animation-range: cover calc(58% + var(--i, 0) * 2.4%) cover calc(61% + var(--i, 0) * 2.4%);
    }
    /* 3) the line connects and MTB appears */
    html.js .diagram--structure .dg-lines path {
      transition: none;
      animation: how-line linear both;
      animation-timeline: --how;
      animation-range: cover 70% cover 74%;
    }
    html.js .diagram--structure .dg-logo {
      transition: none;
      animation: how-logo linear both;
      animation-timeline: --how;
      animation-range: cover 73% cover 76%;
    }
    @keyframes how-step { from { opacity: 0; transform: translateY(32px); } to { opacity: 1; transform: none; } }
    @keyframes how-list-out { from { opacity: 1; visibility: visible; } to { opacity: 0; visibility: hidden; } }
    @keyframes how-diagram-in { from { opacity: 0; visibility: hidden; } to { opacity: 1; visibility: visible; } }
    @keyframes how-block { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
    @keyframes how-line { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
    @keyframes how-logo { from { opacity: 0; } to { opacity: 1; } }
  }
}
