/* motion.css — linked after styles.css */
@view-transition { navigation: none; }

/* Base / Fallback (no native timeline support) */
@media screen and (orientation: portrait) and (max-width: 760px) and (min-height: 36rem) and (prefers-reduced-motion: no-preference) and (forced-colors: none) {
  .outcome-grid { display: block; }
  .outcome-card {
    position: sticky;
    top: max(8svh, 4.7rem);
    transform: none !important;
    min-height: 40svh;
    box-shadow: inset 1px 0 0 color-mix(in srgb, var(--ink) 25%, transparent), 0 -.5rem 1.6rem #100c1530;
    padding: 2.5rem 1.75rem;
  }
  .outcome-card:nth-child(2) { top: max(9.5svh, 5.45rem); }
  .outcome-card:nth-child(3) { top: max(11svh, 6.2rem); }
  .outcome-card + .outcome-card { margin-top: 20svh; }
  .outcome-grid::after { content: ''; display: block; height: 18svh; }
  .outcome-grid:has(:focus-visible) .outcome-card { position: relative; top: auto; }
}

@media (max-width: 430px) and (orientation: portrait) and (min-height: 36rem) and (prefers-reduced-motion: no-preference) and (forced-colors: none) {
  .outcome-card { grid-template-rows: auto 1fr auto; }
  .outcome-card .card-link { align-self: end; }
}

@media (orientation: landscape) and (max-width: 760px), (forced-colors: active) {
  .outcome-card { position: static !important; top: auto !important; min-height: auto !important; box-shadow: none !important; transform: none !important; }
}

@media print {
  .proof-home-heading, .outcome-card { position: static; }
  .split-heading .motion-word, .reveal-panel { animation: none !important; opacity: 1; }
}

/* Keyframes */
@keyframes scroll-bar {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes hero-ribbon-exit {
  from { transform: translateY(0) rotate(0deg); }
  to { transform: translateY(76px) rotate(-9deg); }
}

@keyframes hero-lift {
  from { translate: 0 0; }
  to { translate: 0 -0.24em; }
}

@keyframes kc-word {
  from { transform: translateY(0.68em) rotate(1.5deg); opacity: 1; }
  to { transform: none; opacity: 1; }
}

@keyframes kc-h1-word {
  from { transform: translateY(0.68em) rotate(2deg); opacity: 1; }
  to { transform: none; opacity: 1; }
}

@keyframes kc-ink-darken {
  from { color: #756a7f; transform: translateY(0.68em) rotate(1.5deg); opacity: 1; }
  to { color: var(--ink); transform: none; opacity: 1; }
}

@keyframes kc-accent-sweep {
  from { background-position: 100% 0; }
  to { background-position: 0% 0; }
}

@keyframes panel-arrive {
  from { translate: 0 1.2rem; opacity: 1; }
  to { translate: 0 0; opacity: 1; }
}

@keyframes art-arrive {
  from { transform: translateX(20px) rotate(-4deg) scale(0.92); opacity: 1; }
  to { transform: none; opacity: 1; }
}

@keyframes trace-draw {
  from { stroke-dashoffset: 0.95; }
  to { stroke-dashoffset: 0; }
}

@keyframes mark-enter {
  from { transform: rotate(-6deg) translateX(4px); opacity: 1; }
  to { transform: none; opacity: 1; }
}

/* Native Scroll-Driven Animations (Progressive Enhancement) */
@supports (animation-timeline: view()) and (animation-range: entry 0% entry 100%) {
  @media (prefers-reduced-motion: no-preference) and (forced-colors: none) {

    .scroll-progress {
      animation: scroll-bar auto linear both;
      animation-timeline: scroll(root block);
    }

    .hero { view-timeline: --kc-hero block; }
    .hero-ribbon {
      animation: hero-ribbon-exit auto linear both;
      animation-timeline: --kc-hero;
      animation-range: exit 0% exit 100%;
    }

    .hero h1.split-heading {
      animation: hero-lift auto linear both;
      animation-timeline: --kc-hero;
      animation-range: exit 0% exit 80%;
    }

    h2.split-heading,
    h3.split-heading { view-timeline: --heading-view block; }

    :is(h2,h3).split-heading .motion-word {
      animation: kc-word auto linear both;
      animation-timeline: --heading-view;
      animation-range: cover var(--kc-start, 1%) cover calc(var(--kc-start, 1%) + 20%);
    }

    :is(h2,h3).split-heading.entered .motion-word {
      animation: kc-word auto linear both;
      animation-timeline: --heading-view;
      animation-range: cover var(--kc-start, 1%) cover calc(var(--kc-start, 1%) + 20%);
    }

    .statement-grid h2.split-heading .motion-word:not(.kc-accent) {
      animation-name: kc-ink-darken;
    }
    .statement-grid h2.split-heading.entered .motion-word:not(.kc-accent) {
      animation-name: kc-ink-darken;
    }

    :is(h2,h3).split-heading .kc-accent,
    :is(h2,h3).split-heading.entered .kc-accent {
      background-image: linear-gradient(100deg, var(--kc-ink-b) 0% 18%, var(--kc-ink-a) 40% 63%, var(--kc-ink-b) 84% 100%);
      background-size: 280% 100%;
      background-position: 100% 0;
      background-clip: text;
      -webkit-background-clip: text;
      color: transparent;
      animation-name: kc-accent-sweep, kc-word;
    }

    .statement-grid h2.split-heading .motion-word.kc-accent,
    .statement-grid h2.split-heading.entered .motion-word.kc-accent {
      transition: none !important;
      color: transparent !important;
      animation-name: kc-accent-sweep, kc-word !important;
    }

    .hero h1.split-heading .kc-accent {
      background-image: linear-gradient(100deg, var(--kc-ink-b) 0% 18%, var(--kc-ink-a) 40% 63%, var(--kc-ink-b) 84% 100%);
      background-size: 280% 100%;
      background-position: 100% 0;
      background-clip: text;
      -webkit-background-clip: text;
      color: transparent;
      animation-name: kc-accent-sweep, kc-h1-word;
      animation-duration: auto, .65s;
      animation-timing-function: linear, var(--ease-out);
      animation-fill-mode: both, both;
      animation-delay: 0ms, calc(var(--delay, 0ms) + 120ms);
      animation-timeline: --kc-hero, auto;
      animation-range: exit 0% exit 85%, normal;
    }

    .proof-preview.reveal-panel {
      view-timeline: --kc-project block;
      animation: panel-arrive auto linear both;
      animation-timeline: view(block);
      animation-range: entry 0% entry 35%;
    }

    .proof-preview,
    .case-study { view-timeline: --kc-project block; }
    
    .proof-preview .project-art,
    .case-study .project-art {
      width: clamp(8rem, 13vw, 12rem);
      height: auto;
      animation: art-arrive auto linear both;
      animation-timeline: --kc-project;
      animation-range: entry 0% entry 75%;
    }

    .capability.reveal-panel,
    .case-study.reveal-panel {
      view-timeline: --panel-view block;
      animation: panel-arrive auto linear both;
      animation-timeline: --panel-view;
      animation-range: entry 0% entry 35%;
    }

    .process-list li.reveal-panel {
      view-timeline: --panel-view block;
      animation: panel-arrive auto linear both;
      animation-timeline: --panel-view;
      animation-range: entry 0% entry 35%;
    }

    @media (min-width: 761px) {
      .outcome-grid .outcome-card.reveal-panel {
        animation: panel-arrive auto linear both;
        animation-timeline: view(block);
        animation-range: entry 0% entry 35%;
      }
    }

    .outcome-card { view-timeline: --kc-service block; overflow: clip; }
    .service-mark .service-trace {
      stroke-dasharray: 1;
      animation: trace-draw auto linear both;
      animation-timeline: --kc-service;
      animation-range: cover 0% cover 34%;
    }
    .service-mark {
      animation: mark-enter auto linear both;
      animation-timeline: --kc-service;
      animation-range: cover 0% cover 34%;
    }

    .founder-panel,
    .proof-preview,
    .capability,
    .case-study { overflow: clip; }

  }
}

/* Mobile Sticky Service Cards (no animation on card box) */
@media (max-width: 760px) and (prefers-reduced-motion: no-preference) {
  .outcome-grid .outcome-card.reveal-panel,
  .outcome-grid .outcome-card.reveal-panel.entered {
    animation: none !important;
    translate: none !important;
    opacity: 1 !important;
  }
}

/* Mobile sticky card brand edge */
@media screen and (orientation: portrait) and (max-width: 760px) and (min-height: 36rem) {
  .outcome-card {
    border-left: none;
    box-shadow: inset 1px 0 0 color-mix(in srgb, var(--ink) 25%, transparent), 0 -.5rem 1.6rem #100c1530;
  }
}

/* Service Mark Layout */
.service-mark {
  float: right;
  width: clamp(2.8rem, 14vw, 4.5rem);
  max-width: 25%;
  height: auto;
  margin-left: .4rem;
  color: currentColor;
}

@media (max-width: 760px) and (min-width: 431px),
       (max-width: 1000px) and (min-width: 761px) {
  .service-mark {
    display: block;
    float: none;
    margin-left: 0;
    margin-bottom: .5rem;
    max-width: 4rem;
  }
}

@media (max-width: 430px) {
  .proof-preview .project-art,
  .case-study .project-art {
    width: 8rem;
  }
}

/* Roll Link / Button Hover & Focus */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .roll-link:hover .roll-face { animation: letter-turn .48s var(--ease-out) var(--delay) both; }
}

/* Tapped state immediate feedback */
@media (hover: none) and (prefers-reduced-motion: no-preference) {
  .button:active,
  .roll-link:active {
    transform: scale(0.97);
    transition: transform 0s;
  }
}

/* Disable auto letter roll on phone */
@media (hover: none), (pointer: coarse) {
  .roll-link.entered:not(:focus-visible) .roll-face { animation: none !important; }
}

/* Desktop Header Height Stability */
@media (min-width: 761px) and (prefers-reduced-motion: no-preference) {
  .site-header.is-scrolled .header-inner {
    min-height: 5.5rem;
    transition: min-height .35s var(--ease-out);
  }
}

/* Reduced Motion / Forced Colors / Print — Solid Readable Text */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  @supports (animation-timeline: scroll()) {
    .scroll-progress {
      animation: scroll-bar auto linear both !important;
      animation-timeline: scroll(root block) !important;
    }
  }

  h1.split-heading .motion-word,
  h2.split-heading .motion-word,
  h3.split-heading .motion-word,
  .kc-accent {
    animation: none !important;
    transform: none !important;
    opacity: 1 !important;
    background: none !important;
    color: inherit !important;
    -webkit-text-fill-color: currentColor;
  }

  .hero-ribbon { animation: none !important; transform: none !important; }
  .hero h1.split-heading { animation: none !important; translate: none !important; }
  .proof-preview.reveal-panel,
  .capability.reveal-panel,
  .case-study.reveal-panel,
  .process-list li.reveal-panel,
  .outcome-card.reveal-panel { animation: none !important; transform: none !important; translate: none !important; opacity: 1 !important; }
  .project-art { animation: none !important; transform: none !important; }
  .service-mark, .service-trace { animation: none !important; stroke-dashoffset: 0 !important; }
}

@media (forced-colors: active) {
  .kc-accent,
  h1.split-heading .accent-word .motion-word,
  h2.split-heading .accent-word .motion-word,
  h3.split-heading .accent-word .motion-word {
    background: none !important;
    color: CanvasText !important;
  }
  .scroll-progress { display: none; }
}

@media print {
  .split-heading .motion-word,
  .reveal-panel,
  .kc-accent,
  .project-art,
  .service-mark,
  .hero-ribbon {
    animation: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
  .scroll-progress { display: none; }
}

/* Palette Inheritance (Ink A/B) */
:root, html, body {
  --kc-ink-a: var(--paper);
  --kc-ink-b: var(--violet-bright);
}

.section-paper, .capability, .proof-preview-light, .case-study:not(.case-study-dark) {
  --kc-ink-a: var(--ink);
  --kc-ink-b: var(--violet-text);
}

.case-study-violet, .founder-panel, .proof-preview-violet {
  --kc-ink-a: var(--ink);
  --kc-ink-b: var(--violet-text);
}

.contact-direct, .case-study-dark {
  --kc-ink-a: var(--paper);
  --kc-ink-b: var(--violet-bright);
}

/* H1 Time-based Animations (Fallback & Native) */
@media (prefers-reduced-motion: no-preference) and (forced-colors: none) {
  h1.split-heading .motion-word {
    animation: kc-h1-word .65s var(--ease-out) var(--delay, 0ms) both;
  }

  /* H1 Accent Words */
  h1.split-heading:not(.hero h1) .kc-accent {
    background-image: linear-gradient(100deg, var(--kc-ink-b) 0% 18%, var(--kc-ink-a) 40% 63%, var(--kc-ink-b) 84% 100%);
    background-size: 280% 100%;
    background-position: 100% 0;
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    animation-name: kc-accent-sweep, kc-h1-word;
    animation-duration: .65s, .65s;
    animation-timing-function: linear, var(--ease-out);
    animation-fill-mode: both, both;
    animation-delay: calc(var(--delay, 0ms) + 120ms), var(--delay, 0ms);
  }

  /* Statement Grid H2 Darken (Fallback) */
  .statement-grid h2.split-heading .motion-word:not(.kc-accent) {
    color: #756a7f;
    transition: color .23s ease;
  }
}

@media print {
  .split-heading .motion-word,
  .accent-word .motion-word {
    color: inherit !important;
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
    animation: none !important;
  }
}

@media (max-width:760px) and (hover:hover) {
  .roll-link.entered:not(:hover):not(:focus-visible) .roll-face {
    animation: none;
  }
}

/* Service Verb Treatment */
@supports (animation-timeline: view()) and (animation-range: entry 0% entry 100%) {
  @media screen and (prefers-reduced-motion: no-preference) and (forced-colors: none) {
    .outcome-card .service-verb {
      background-image: linear-gradient(100deg, var(--ink) 0% 18%, var(--violet-text) 40% 63%, var(--ink) 84% 100%);
      background-size: 280% 100%;
      background-position: 100% 0;
      background-clip: text;
      -webkit-background-clip: text;
      color: transparent;
      animation: kc-accent-sweep auto linear both;
      animation-timeline: --kc-service;
      animation-range: cover 0% cover 44%;
    }

    .outcome-card:first-child .service-verb {
      background-image: linear-gradient(100deg, var(--ink) 0% 18%, var(--ink-soft) 40% 63%, var(--ink) 84% 100%);
    }
  }
}

/* Descender clipping fix */
.split-heading .motion-word.kc-accent {
  padding-block: .2em;
  margin-block: -.2em;
}
.service-verb {
  padding-block: .2em;
}

/* Mobile header scroll offset and compact nav */
@media (max-width: 760px) {
  .site-header { position: sticky; top: 0; }
  main[id], main [id] {scroll-margin-top:3.25rem;}
}

@media (max-width: 364px) {
  .site-header .header-inner {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    padding-block: .5rem;
    gap: .6rem;
    min-height: 4rem;
  }
  .site-header.is-scrolled .header-inner {
    min-height: 4rem;
  }
  .site-header .brand-name {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .site-header .primary-nav {
    justify-content: flex-end;
    gap: clamp(.55rem, 2.5vw, 1rem);
    width: auto;
  }
}
