/* ==========================================================
   Motion + scroll story layer (round 2, 2026-12-03)
   - Everything moving lives behind `html.m-on` (set in <head> only when the
     visitor has not asked for reduced motion), so without JS or with
     reduced motion the page shows its final, static state.
   - Scroll-linked effects use CSS scroll-driven animations (compositor only:
     transform / opacity / individual translate-scale-rotate). Browsers
     without them get IntersectionObserver reveals (html:not(.m-sdt)).
   ========================================================== */

/* ---------- page-to-page crossfade (View Transitions, cross-document) ---------- */
@view-transition { navigation: auto; }
.site-header { view-transition-name: site-header; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .32s; }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }

/* ==========================================================
   CASE STORIES: pinned screen + rows (layout works with or without motion)
   ========================================================== */
.f-case { overflow: clip; }
.f-case-visual { display: block; padding: 0; min-height: 0; max-height: none; overflow: visible; }
.f-pin { position: sticky; top: 100px; height: min(calc(100svh - 132px), 700px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 28px 24px; }
.f-stage { position: relative; height: calc(100% - 40px); max-height: 600px; aspect-ratio: 420 / 912; border-radius: 26px; overflow: hidden; background: #0f0f14; box-shadow: 0 40px 70px -32px #1b0f5a80, 0 12px 28px #0000001f; }
.f-case--violet .f-stage { aspect-ratio: 420 / 746; }
.f-scr { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top; opacity: 0; }
.f-scr.is-on { opacity: 1; }
.f-pin-meta { display: flex; align-items: center; gap: 12px; min-height: 22px; color: var(--f-ink); }
.f-case--night .f-pin-meta { color: #fff; }
.f-dots { display: inline-flex; gap: 6px; }
.f-dots i { display: block; width: 6px; height: 6px; border-radius: 99px; background: currentColor; opacity: .28; transition: width .45s cubic-bezier(.2, .7, .2, 1), opacity .45s; }
.f-dots i.is-on { width: 24px; opacity: 1; }
.f-pin-label { font-size: 13px; font-weight: 600; letter-spacing: 0; }
.f-case-visual .f-shot { display: none; } /* old 2-shot layout */

/* the rows become chapters once motion.js runs the story (.m-story) */
.f-case.m-story .f-row { transition: opacity .45s ease; }
.f-case.m-story .f-row:not(.is-on) { opacity: .38; }
.f-case.m-story .f-row.is-on dt { color: var(--f-violet); }
@media (min-width: 900px) {
  .f-case { align-items: stretch; }
  .f-case.m-story .f-row { min-height: max(36vh, 260px); align-content: center; }
  .f-case.m-story .f-row:last-child { min-height: max(30vh, 220px); }
}
@media (max-width: 899px) {
  /* phone: the screen strip sticks under the header while the chapters scroll beneath it */
  .f-case-visual { position: sticky; top: var(--m-hdr, 72px); z-index: 2; }
  .f-pin { position: static; height: auto; padding: 18px 16px 14px; gap: 12px; }
  .f-stage { height: min(34svh, 290px); max-height: none; border-radius: 18px; }
  .f-case.m-story .f-row { min-height: 26svh; align-content: start; padding-top: 22px; }
  .f-case.m-story .f-row:last-child { min-height: 0; }
}

/* ==========================================================
   APPS: swipe rail on phones
   ========================================================== */
.f-rail-meta { display: none; }
@media (max-width: 640px) {
  .portfolio-design .r-apps-grid { display: grid; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 84%; gap: 12px; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none; margin-inline: -20px; padding: 4px 20px 6px; scroll-padding-inline: 20px; scroll-timeline: --rail inline; }
  .portfolio-design .r-apps-grid::-webkit-scrollbar { display: none; }
  .portfolio-design .r-app { scroll-snap-align: start; }
  .f-rail-meta { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: 13px; color: #6f6f6f; }
  #apps .f-wrap { timeline-scope: --rail; }
  .f-rail-bar { position: relative; flex: 0 0 72px; height: 3px; border-radius: 3px; background: #e3e3df; overflow: hidden; }
  .f-rail-bar i { position: absolute; inset: 0; background: var(--f-ink); transform-origin: left; transform: scaleX(.12); }
  [dir="rtl"] .f-rail-bar i { transform-origin: right; }
}

/* ==========================================================
   MOTION (only with html.m-on)
   ========================================================== */
@keyframes m-rise { from { opacity: 0; translate: 0 26px; } to { opacity: 1; translate: 0 0; } }
@keyframes m-word { from { opacity: .12; translate: 0 .42em; filter: blur(10px); } to { opacity: 1; translate: 0 0; filter: blur(0); } }
@keyframes m-pop { from { opacity: 0; scale: .9; } to { opacity: 1; scale: 1; } }

/* hero entrance (time-based, on load) */
.m-on .f-kicker { animation: m-rise .7s cubic-bezier(.2, .7, .2, 1) both; }
.m-on .f-h1-name { animation: m-rise .7s .08s cubic-bezier(.2, .7, .2, 1) both; }
.m-on .m-w { display: inline-block; animation: m-word .9s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--i) * 55ms + 140ms); }
.m-on .f-hero .f-lead { animation: m-rise .8s .45s cubic-bezier(.2, .7, .2, 1) both; }
.m-on .f-hero .f-actions { animation: m-rise .8s .58s cubic-bezier(.2, .7, .2, 1) both; }
.m-on .f-hero .f-proof { animation: m-rise .8s .7s cubic-bezier(.2, .7, .2, 1) both; }
.m-on .f-hero-visual { animation: m-pop 1s .2s cubic-bezier(.2, .7, .2, 1) both; }

/* screens crossfade between chapters */
.m-on .f-scr { scale: 1.05; transition: opacity .6s ease, scale .9s cubic-bezier(.2, .7, .2, 1); }
.m-on .f-scr.is-on { scale: 1; }

/* pointer spotlight on cards (desktop pointers only; motion.js sets --mx/--my) */
@media (hover: hover) and (pointer: fine) {
  .m-on .r-app, .m-on .f-skills-list a, .m-on .f-hire { position: relative; isolation: isolate; }
  .m-on .r-app::after, .m-on .f-skills-list a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0; transition: opacity .3s; background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%), #5b3fd61f, transparent 65%); z-index: -1; }
  .m-on .f-skills-list a::after { background: radial-gradient(280px circle at var(--mx, 50%) var(--my, 50%), #8b74ff40, transparent 65%); }
  .m-on .r-app:hover::after, .m-on .f-skills-list a:hover::after { opacity: 1; }
}

/* ---------- scroll-driven (Chrome/Edge 115+, Safari 26+) ---------- */
@supports (animation-timeline: view()) and (animation-range: 0% 100%) {

  /* reading progress hairline */
  .m-on .site-wrapper::before { content: ""; position: fixed; top: 0; inset-inline: 0; height: 3px; z-index: 10001; background: linear-gradient(90deg, #5b3fd6, #a48bff); transform-origin: left; scale: 0 1; pointer-events: none; animation: m-progress linear both; animation-timeline: scroll(root); }
  [dir="rtl"].m-on .site-wrapper::before { transform-origin: right; background: linear-gradient(270deg, #5b3fd6, #a48bff); }
  @keyframes m-progress { to { scale: 1 1; } }

  /* hero: the three screens fan out as the hero leaves (desktop) */
  @media (min-width: 900px) {
    .m-on .f-hero { view-timeline: --hero block; }
    .m-on .f-phone--l { animation: f-float-l 8s ease-in-out infinite, m-fan-l linear both; animation-timeline: auto, --hero; animation-range: normal, exit 0% exit 90%; }
    .m-on .f-phone--r { animation: f-float-r 9s ease-in-out infinite, m-fan-r linear both; animation-timeline: auto, --hero; animation-range: normal, exit 0% exit 90%; }
    .m-on .f-phone--c { animation: f-float 7s ease-in-out infinite, m-fan-c linear both; animation-timeline: auto, --hero; animation-range: normal, exit 0% exit 90%; }
    .m-on .f-hero-copy { animation: m-hero-copy linear both; animation-timeline: --hero; animation-range: exit 10% exit 100%; }
  }
  @keyframes m-fan-l { to { translate: -70px 60px; rotate: -7deg; } }
  @keyframes m-fan-r { to { translate: 70px 60px; rotate: 7deg; } }
  @keyframes m-fan-c { to { scale: 1.08; translate: 0 -30px; } }
  @keyframes m-hero-copy { to { opacity: .2; translate: 0 -40px; } }

  /* phone hero image: settles back as you scroll away */
  @media (max-width: 899px) {
    .m-on .f-hero { view-timeline: --hero block; }
    .m-on .f-phone--c { animation: m-pop 1s .2s cubic-bezier(.2, .7, .2, 1) both, m-hero-img linear both; animation-timeline: auto, --hero; animation-range: normal, exit 0% exit 100%; }
    .m-on .f-hero-visual { animation: none; }
  }
  @keyframes m-hero-img { to { scale: .9; opacity: .55; } }

  /* section titles fill with ink as they cross the screen */
  .m-on .f-head h2, .m-on .f-about h2 {
    color: transparent; -webkit-background-clip: text; background-clip: text;
    background-image: linear-gradient(to right, var(--f-ink) 50%, #c8c8c4 50%); background-size: 200% 100%; background-position: 100% 0;
    animation: m-fill linear both; animation-timeline: view(); animation-range: entry 30% cover 42%;
  }
  [dir="rtl"].m-on .f-head h2, [dir="rtl"].m-on .f-about h2 { background-image: linear-gradient(to left, var(--f-ink) 50%, #c8c8c4 50%); background-position: 0 0; animation-name: m-fill-rtl; }
  .m-on .f-skills h2 { color: transparent; -webkit-background-clip: text; background-clip: text; background-image: linear-gradient(to right, #fff 50%, #5c5c66 50%); background-size: 200% 100%; background-position: 100% 0; animation: m-fill linear both; animation-timeline: view(); animation-range: entry 30% cover 45%; }
  [dir="rtl"].m-on .f-skills h2 { background-image: linear-gradient(to left, #fff 50%, #5c5c66 50%); background-position: 0 0; animation-name: m-fill-rtl; }
  @keyframes m-fill { to { background-position: 0 0; } }
  @keyframes m-fill-rtl { to { background-position: 100% 0; } }

  /* generic rise-in for blocks as they enter */
  .m-on .f-head > p, .m-on .f-case-head, .m-on .f-case-links, .m-on .r-app, .m-on .f-skills-copy > p, .m-on .f-skills-copy > .r-button,
  .m-on .f-skills-list li, .m-on .f-about > div > p, .m-on .f-about .r-tools, .m-on .f-hire, .m-on .f-more li, .m-on .f-cs-block, .m-on .f-gallery figure {
    animation: m-rise linear both; animation-timeline: view(); animation-range: entry 0% entry 75%;
  }
  .m-on .r-app:nth-child(3n + 2) { animation-range: entry 8% entry 85%; }
  .m-on .r-app:nth-child(3n) { animation-range: entry 16% entry 95%; }
  .m-on .f-skills-list li:nth-child(2) { animation-range: entry 10% entry 85%; }
  .m-on .f-skills-list li:nth-child(3) { animation-range: entry 20% entry 95%; }

  /* the case card lifts in, its screen rises from below */
  .m-on .f-case { animation: m-case linear both; animation-timeline: view(); animation-range: entry 0% entry 40%; }
  @keyframes m-case { from { opacity: 0; scale: .96; translate: 0 40px; } }
  .m-on .f-stage { animation: m-stage linear both; animation-timeline: view(); animation-range: entry 0% entry 70%; }
  @keyframes m-stage { from { translate: 0 80px; rotate: -3deg; } }

  /* the skills section turns the whole scene dark as it arrives */
  .m-on #skills { animation: m-dark linear both; animation-timeline: view(); animation-range: entry 15% cover 35%; }
  @keyframes m-dark { from { background-color: #fff0; } to { background-color: #0d0d10; } }
  .m-on #skills .f-skills { animation: m-grow linear both; animation-timeline: view(); animation-range: entry 0% cover 30%; }
  @keyframes m-grow { from { scale: .92; } to { scale: 1; } }

  /* app rail progress (phones) */
  @media (max-width: 640px) {
    .m-on .r-app { animation: none; }
    .f-rail-bar i { animation: m-rail linear both; animation-timeline: --rail; }
    @keyframes m-rail { from { transform: scaleX(.12); } to { transform: scaleX(1); } }
  }
}

/* ---------- fallback reveals (no scroll-driven animations): motion.js adds .m-r then .m-in ---------- */
html.m-on:not(.m-sdt) .m-r { opacity: 0; translate: 0 26px; transition: opacity .8s cubic-bezier(.2, .7, .2, 1), translate .8s cubic-bezier(.2, .7, .2, 1); }
html.m-on:not(.m-sdt) .m-r.m-in { opacity: 1; translate: 0 0; }
