/*
 * Lubb IT motion system – "Settle"
 *
 * The site promises software that feels simple however complex it is. Motion
 * tells that story literally: things arrive slightly displaced and settle into
 * a calm, still grid. One easing family, one direction (up), one beat.
 *
 * Rules (see docs/motion.md for the full spec):
 *  1. Every duration, delay and curve comes from the tokens below.
 *  2. Only transform and opacity animate continuously. clip-path and
 *     background-size are used only on single small elements (screenshot
 *     wipe, headline marker, link underline).
 *  3. Only interactive elements respond to the pointer.
 *  4. All movement lives inside `screen and (prefers-reduced-motion:
 *     no-preference)`. Without it the page is complete and still (color
 *     feedback remains), and print always gets the complete, still page.
 *  5. Motion never gates content: if this file or motion.js fails, everything
 *     is visible and works.
 */

:root {
  /* Time. One beat is the unit of choreography and stagger. */
  --beat: 80ms;
  --dur-instant: 100ms;   /* press feedback */
  --dur-quick: 180ms;     /* color, opacity feedback */
  --dur-base: 320ms;      /* hover lifts, indicator travel */
  --dur-slow: 640ms;      /* scroll reveals */
  --dur-slower: 960ms;    /* hero entrance, image reveals */

  /* Curves. */
  --ease-settle: cubic-bezier(0.16, 1, 0.3, 1);  /* arrives quickly, rests long: all entrances and lifts */
  --ease-swift: cubic-bezier(0.2, 0, 0, 1);      /* responsive UI feedback */
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);       /* leaving: accelerates away */

  /* Space. */
  --rise: 24px;
  --rise-sm: 12px;
  --lift: -2px;
  --lift-card: -4px;
  --nudge: 4px;
}

/* ── Feedback that stays even with reduced motion: color only ── */
a, .btn-primary, .btn-secondary, .contact-btn, .nav-cta {
  transition:
    color var(--dur-quick) var(--ease-swift),
    background-color var(--dur-quick) var(--ease-swift);
}

/* ── Navigation scaffolding (positions only; movement is below) ── */
.site-nav::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  box-shadow: 0 6px 24px var(--shadow); opacity: 0;
  transition: opacity var(--dur-base) var(--ease-swift);
}
.site-nav.is-scrolled::after { opacity: 1; }
.nav-sentinel { position: absolute; top: 0; left: 0; width: 1px; height: 8px; pointer-events: none; }
.nav-inner { position: relative; }
.nav-indicator {
  position: absolute; top: 0; left: 0; width: 1px; height: 2px; pointer-events: none;
  background: var(--accent); transform-origin: 0 0; opacity: 0;
  transition: opacity var(--dur-quick) var(--ease-swift);
}
.nav-indicator.is-active { opacity: 1; }

/* ── Pointer spotlight on clickable cards (fine pointers only) ── */
[data-spotlight] { isolation: isolate; }
[data-spotlight]::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(360px circle at var(--spot-x, 50%) var(--spot-y, 50%),
    color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-swift);
}
@media (hover: hover) and (pointer: fine) {
  [data-spotlight]:hover::before { opacity: 1; }
}

/*
 * Hero headline highlight: a soft marker behind the lower third of the words.
 * Thick and translucent on purpose: a thin green line would read as a link.
 */
.hero-title .w { display: inline-block; }
.hero-title em {
  --mark-height: 0.3em;
  padding: 0 0.06em;
  background: linear-gradient(rgba(121, 206, 103, 0.3), rgba(121, 206, 103, 0.3)) no-repeat 0 88% / 100% var(--mark-height);
  /* Default "slice" decoration: when the phrase wraps, the mark draws across lines in reading order. */
}

/*
 * Screen only: in print nothing is ever hidden or displaced, so pages the
 * reader hasn't scrolled through yet still print in full.
 */
@media screen and (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }

  /* Cross-document page transitions (index ↔ 404). */
  @view-transition { navigation: auto; }

  /* Keyframes: every entrance is a variation of "settle upward". */
  @keyframes enter-rise { from { opacity: 0; transform: translateY(var(--rise)); } }
  @keyframes enter-rise-sm { from { opacity: 0; transform: translateY(var(--rise-sm)); } }
  @keyframes enter-drop { from { opacity: 0; transform: translateY(calc(var(--rise-sm) * -0.66)); } }
  @keyframes enter-word { from { opacity: 0; transform: translateY(0.45em); } }
  /* Transform-only: content that can be the LCP element is never faded (see below). */
  @keyframes enter-portrait { from { transform: scale(0.94); } }
  @keyframes settle-up { from { transform: translateY(var(--rise-sm)); } }
  @keyframes draw-mark { from { background-size: 0 var(--mark-height); } }
  @keyframes wipe-in { from { clip-path: inset(0 0 100% 0); transform: scale(1.06); } }
  @keyframes drift-down { to { transform: translateY(14%); } }
  @keyframes drift-away { to { opacity: 0.35; transform: translateY(-6%); } }
  @keyframes fade-out { to { opacity: 0; } }
  @keyframes fade-rise-in { from { opacity: 0; transform: translateY(var(--rise-sm)); } }

  /*
   * Page-load choreography (beats of 80ms):
   *   0    nav drops in, portrait and intro settle: who
   *   1    eyebrow tag
   *   2–6  headline, word by word (half-beat stagger): what
   *   7    primary action, 7.75 secondary
   *   11   "känns enkel" highlighted: the promise lands last
   * Everything is readable before beat 8 (~0.65s); motion ends by ~1.9s.
   *
   * LCP rule: the portrait and intro paragraph are the largest paints. Chrome
   * only counts a fading element once its fade ends, so these two are visible
   * from the first frame and merely settle (transform only, no delay).
   */
  .site-nav { animation: enter-drop var(--dur-slow) var(--ease-settle) backwards; }
  .hero-photo { animation: enter-portrait var(--dur-slower) var(--ease-settle) backwards; }
  .hero-tag { animation: enter-rise-sm var(--dur-slow) var(--ease-settle) var(--beat) backwards; }
  .hero-title .w {
    animation: enter-word var(--dur-slower) var(--ease-settle)
      calc(var(--beat) * 2 + var(--beat) * 0.5 * var(--i, 0)) backwards;
  }
  .hero-title em { animation: draw-mark var(--dur-slower) var(--ease-settle) calc(var(--beat) * 11) backwards; }
  .hero-content > p { animation: settle-up var(--dur-slower) var(--ease-settle) backwards; }
  .hero-buttons > :nth-child(1) { animation: enter-rise-sm var(--dur-slow) var(--ease-settle) calc(var(--beat) * 7) backwards; }
  .hero-buttons > :nth-child(2) { animation: enter-rise-sm var(--dur-slow) var(--ease-settle) calc(var(--beat) * 7.75) backwards; }

  /*
   * Scroll reveals. motion.js adds .reveal only to elements below the fold
   * (never to anything the reader can already see), then .is-revealed once
   * they enter. --reveal-delay staggers elements that enter together.
   */
  .reveal:not(.is-revealed) { opacity: 0; }
  .reveal.is-revealed {
    animation: enter-rise var(--dur-slow) var(--ease-settle) var(--reveal-delay, 0ms) backwards;
  }
  /* Screenshots load like the page they show: wiped in top-down, settling from a slight zoom. */
  .project-card.reveal:not(.is-revealed) .project-shot { clip-path: inset(0 0 100% 0); }
  .project-card.is-revealed .project-shot {
    animation: wipe-in var(--dur-slower) var(--ease-settle) calc(var(--reveal-delay, 0ms) + var(--beat) * 1.5) backwards;
  }

  /* Hover and press: lift on hover, settle back on press. */
  .btn-primary, .btn-secondary, .contact-btn, .nav-cta {
    transition:
      color var(--dur-quick) var(--ease-swift),
      background-color var(--dur-quick) var(--ease-swift),
      transform var(--dur-base) var(--ease-settle);
  }
  .btn-primary:hover, .btn-secondary:hover, .contact-btn:hover, .nav-cta:hover { transform: translateY(var(--lift)); }
  .btn-primary:active, .btn-secondary:active, .contact-btn:active, .nav-cta:active {
    transform: translateY(0) scale(0.97);
    transition-duration: var(--dur-quick), var(--dur-quick), var(--dur-instant);
  }

  .project-card { transition: transform var(--dur-base) var(--ease-settle), box-shadow var(--dur-base) var(--ease-settle); }
  .project-card:hover { transform: translateY(var(--lift-card)); }
  .project-card:active { transform: translateY(calc(var(--lift-card) / 2)); transition-duration: var(--dur-instant); }
  .project-shot { transition: transform var(--dur-slower) var(--ease-settle); }
  .project-card:hover .project-shot { transform: scale(1.03); }
  .project-link { transition: color var(--dur-quick) var(--ease-swift), background-size var(--dur-base) var(--ease-settle); }

  .arrow { display: inline-block; transition: transform var(--dur-base) var(--ease-settle); }
  a:hover > .arrow, .project-card:hover .arrow { transform: translateX(var(--nudge)); }

  /* Active-section indicator glides between menu items. */
  .nav-indicator {
    transition:
      opacity var(--dur-quick) var(--ease-swift),
      transform var(--dur-base) var(--ease-settle);
  }

  /* Focus is deliberately not animated: keyboard feedback must be immediate. */
  .skip-link { transition: top var(--dur-base) var(--ease-settle); }

  /*
   * Parallax: a single, scroll-linked hand-off from the hero to the content.
   * The portrait drifts slower than the page; the intro steps back. Pure CSS
   * on the compositor; browsers without scroll timelines just scroll normally.
   */
  @supports (animation-timeline: scroll()) {
    .hero-photo-wrap {
      animation: drift-down auto linear both;
      animation-timeline: scroll(root block);
      animation-range: 0 90vh;
    }
    .hero-content {
      animation: drift-away auto linear both;
      animation-timeline: scroll(root block);
      animation-range: 0 90vh;
    }
  }

  ::view-transition-old(root) { animation: fade-out var(--dur-quick) var(--ease-exit) both; }
  ::view-transition-new(root) { animation: fade-rise-in var(--dur-slow) var(--ease-settle) both; }
}
