/*
 * Intuitive Mothers — Motion patterns
 *
 * The eight approved motion behaviors from the brand bible.
 * Import after components.css. Pair with motion.js for the JS-driven patterns.
 *
 * Approved patterns:
 *   1. Magnetic lift on CTAs (auto-applied to .btn-primary / .btn-secondary)
 *   2. Scroll fade-in (.fade-in)
 *   3. Sticky nav with blur backdrop (.nav-sticky-blur)
 *   4. Scroll progress bar (#scroll-progress)
 *   5. Animated hero headline (.hero-words .word > span)
 *   6. Image hover (.img-hover)
 *   7. Smooth accordion (.accordion .acc-item)
 *
 * Plus reduced-motion overrides at the bottom.
 */

/* ============================================================
 * 1. MAGNETIC LIFT — primary + secondary CTAs
 * Applied automatically to .btn-primary and .btn-secondary, replacing
 * the static opacity-only hover from components.css.
 * ============================================================ */

.btn-primary, .btn-secondary {
  transition: transform 280ms var(--ease-out),
              box-shadow 280ms var(--ease-out),
              opacity 150ms var(--ease-soft);
  box-shadow: 0 1px 2px rgba(45, 26, 40, 0.06);
}
/* Magnetic lift — primary and secondary both lift on hover.
 * Primary deepens its Strawberry-tinted shadow (matching the pill nav CTA pattern).
 * Secondary picks up a soft Strawberry shadow for subtle affordance. */
.btn-primary:hover, .btn-secondary:hover {
  transform: translateY(-2px);
  opacity: 1; /* override the 0.92 from components.css */
}
.btn-primary:hover {
  box-shadow: 0 8px 20px rgba(188, 69, 101, 0.28);
}
.btn-secondary:hover {
  box-shadow: 0 6px 16px rgba(188, 69, 101, 0.18),
              0 1px 2px rgba(45, 26, 40, 0.06);
}
.btn-primary:active, .btn-secondary:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(45, 26, 40, 0.08);
  transition-duration: 100ms;
}

/* ============================================================
 * 2. SCROLL FADE-IN
 * Apply .fade-in to any element. Stagger by adding nth-child rules.
 * The motion.js IntersectionObserver toggles the .visible class.
 * ============================================================ */

.fade-in {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 600ms var(--ease-out),
              transform 600ms var(--ease-out);
}
.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Common stagger pattern — apply to a parent.
 * E.g. <div class="fade-stack"><div class="fade-in">...</div>...</div>
 */
.fade-stack .fade-in:nth-child(2) { transition-delay: 100ms; }
.fade-stack .fade-in:nth-child(3) { transition-delay: 200ms; }
.fade-stack .fade-in:nth-child(4) { transition-delay: 300ms; }
.fade-stack .fade-in:nth-child(5) { transition-delay: 400ms; }
.fade-stack .fade-in:nth-child(6) { transition-delay: 500ms; }

/* ============================================================
 * 3. STICKY NAV WITH BLUR BACKDROP
 * ============================================================ */

.nav-sticky-blur {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(248, 248, 246, 0.7);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  transition: background 280ms var(--ease-out);
}

/* Animated underline on nav links — right-to-left grow */
.nav-sticky-blur a, .nav-link-underline {
  position: relative;
  text-decoration: none;
  color: var(--ink);
  transition: opacity 200ms var(--ease-soft);
}
.nav-sticky-blur a::after, .nav-link-underline::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -4px;
  height: 2px;
  width: 100%;
  background: var(--strawberry);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 280ms var(--ease-out);
}
.nav-sticky-blur a:hover::after, .nav-link-underline:hover::after {
  transform: scaleX(1);
  transform-origin: left;
}

/* ============================================================
 * 4. SCROLL PROGRESS BAR
 * Place <div id="scroll-progress"></div> at the top of <body>.
 * motion.js drives the width.
 * ============================================================ */

#scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--strawberry);
  width: 0%;
  z-index: 100;
  transition: width 80ms linear;
}

/* ============================================================
 * 5. ANIMATED HERO HEADLINE — words slide up sequentially
 *
 * Markup:
 *   <h1 class="hero-words">
 *     <span class="word"><span>Mothering</span></span>
 *     <span class="word"><span>by</span></span>
 *     <span class="word"><span><em>instinct</em>,</span></span>
 *   </h1>
 *
 * Plays once on page load.
 * ============================================================ */

.hero-words .word {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
}
.hero-words .word > span {
  display: inline-block;
  transform: translateY(110%);
  animation: word-up 800ms var(--ease-out) forwards;
}
.hero-words .word:nth-child(1) > span { animation-delay: 100ms; }
.hero-words .word:nth-child(2) > span { animation-delay: 220ms; }
.hero-words .word:nth-child(3) > span { animation-delay: 340ms; }
.hero-words .word:nth-child(4) > span { animation-delay: 460ms; }
.hero-words .word:nth-child(5) > span { animation-delay: 580ms; }
.hero-words .word:nth-child(6) > span { animation-delay: 700ms; }
.hero-words .word:nth-child(7) > span { animation-delay: 820ms; }
.hero-words .word:nth-child(8) > span { animation-delay: 940ms; }

@keyframes word-up {
  to { transform: translateY(0); }
}

/* ============================================================
 * 6. IMAGE HOVER — slow zoom + saturation lift + caption fade
 *
 * Markup:
 *   <div class="img-hover">
 *     <div class="img-hover-bg" style="background-image: url(...)"></div>
 *     <div class="img-hover-cap">Caption text</div>
 *   </div>
 * ============================================================ */

.img-hover {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  cursor: pointer;
}
.img-hover-bg {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  transition: transform 600ms var(--ease-out),
              filter 400ms var(--ease-out);
  filter: saturate(0.85);
}
.img-hover:hover .img-hover-bg {
  transform: scale(1.04);
  filter: saturate(1.05);
}
.img-hover-cap {
  position: absolute;
  bottom: 16px;
  left: 18px;
  right: 18px;
  color: var(--cream);
  font-family: var(--body);
  font-size: 13px;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 400ms var(--ease-out),
              transform 400ms var(--ease-out);
}
.img-hover:hover .img-hover-cap {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================
 * 7. SMOOTH ACCORDION — FAQ pattern
 *
 * Markup:
 *   <div class="accordion">
 *     <div class="acc-item">
 *       <button class="acc-question" onclick="toggleAcc(this)">
 *         Question?
 *         <span class="acc-icon">+</span>
 *       </button>
 *       <div class="acc-answer">
 *         <div class="acc-answer-inner">Answer.</div>
 *       </div>
 *     </div>
 *   </div>
 *
 * toggleAcc() lives in motion.js.
 * ============================================================ */

.accordion {
  background: var(--cream);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.acc-item { border-bottom: 1px solid var(--border); }
.acc-item:last-child { border-bottom: none; }
.acc-question {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 24px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  font-family: var(--display);
  font-weight: 800;
  font-size: 19px;
  color: var(--ink);
  letter-spacing: -0.01em;
  transition: background 200ms var(--ease-soft);
}
.acc-question:hover { background: rgba(188, 69, 101, 0.04); }
.acc-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--strawberry);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 280ms var(--ease-out);
  font-family: var(--body);
  font-weight: 500;
  font-size: 16px;
  line-height: 1;
}
.acc-item.open .acc-icon { transform: rotate(45deg); }
.acc-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 400ms var(--ease-out);
}
.acc-item.open .acc-answer { max-height: 400px; }
.acc-answer-inner {
  padding: 0 28px 24px;
  font-family: var(--body);
  font-size: 15px;
  color: var(--ink);
  opacity: 0.85;
  line-height: 1.65;
}

/* ============================================================
 * 9. HIGHLIGHT SWIPE — animated marker swipe behind a word
 *
 * Markup:
 *   <span class="highlight-swipe">instinct</span>
 *
 * Triggers when scrolled into view (50% threshold). Plays once.
 * Use sparingly — once per page, on the single key idea.
 *
 * Sibling pattern: .highlight (in colors_and_type.css) is the static
 * always-on version. Use .highlight for emphasis that should be
 * visible from first paint; use .highlight-swipe for emphasis you
 * want the user to "discover" as they scroll.
 * ============================================================ */

.highlight-swipe {
  /* Background-image approach so the highlight wraps cleanly across lines.
   * box-decoration-break: clone makes each line of a wrapped inline span
   * carry its own copy of the background, instead of one giant rect that
   * spans from start-of-line-1 to end-of-last-line (which looks broken). */
  display: inline;
  color: inherit;
  padding: 0 2px;
  background-image: linear-gradient(120deg, var(--peach), var(--butter));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 100%;
  border-radius: 2px;
  transition: background-size 1200ms cubic-bezier(0.65, 0, 0.35, 1);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.highlight-swipe.active {
  background-size: 100% 100%;
}

/* ============================================================
 * 10. HAND-CIRCLE TITLE — SVG path "marker pen circle" around a title
 *
 * Markup:
 *   <div class="hand-circle">
 *     <svg class="hand-circle-bg" viewBox="0 0 1200 600" preserveAspectRatio="none">
 *       <path class="hand-circle-path-under" d="M 950 90 C 1250 280, 1080 480, 600 510 C 220 510, 130 460, 150 290 C 170 110, 380 70, 600 80 C 830 90, 950 200, 950 200" />
 *       <path class="hand-circle-path"       d="M 950 90 C 1250 280, 1080 480, 600 510 C 220 510, 130 460, 150 290 C 170 110, 380 70, 600 80 C 830 90, 950 200, 950 200" />
 *     </svg>
 *     <h2 class="hand-circle-title">Trust the <em>body.</em></h2>
 *     <p class="hand-circle-sub">Read the research.</p>
 *   </div>
 *
 * The .drawn class is added by motion.js when the wrap scrolls into view
 * (50% threshold). Plays once. Use 1-2 per page max — for major section titles
 * (manifesto headers, About Melissa, course module openers, chapter dividers).
 * Never apply to every h2 — overuse breaks the "marker pen" feel.
 * ============================================================ */

.hand-circle {
  position: relative;
  width: 100%;
  max-width: 800px;
  padding: 80px 40px;
  margin: 0 auto;
  text-align: center;
}
.hand-circle-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}
.hand-circle-path,
.hand-circle-path-under {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1800;
  stroke-dashoffset: 1800;
  opacity: 0;
}
.hand-circle-path {
  stroke: var(--strawberry);
  stroke-width: 4;
}
.hand-circle-path-under {
  stroke: var(--peach);
  stroke-width: 12;
}
.hand-circle.drawn .hand-circle-path {
  animation: hand-draw 2400ms cubic-bezier(0.43, 0.13, 0.23, 0.96) forwards;
}
.hand-circle.drawn .hand-circle-path-under {
  animation: hand-draw-under 2400ms cubic-bezier(0.43, 0.13, 0.23, 0.96) forwards;
  animation-delay: 50ms;
}
@keyframes hand-draw {
  0%   { stroke-dashoffset: 1800; opacity: 0; }
  5%   { opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 1; }
}
@keyframes hand-draw-under {
  0%   { stroke-dashoffset: 1800; opacity: 0; }
  5%   { opacity: 0.4; }
  100% { stroke-dashoffset: 0; opacity: 0.4; }
}

.hand-circle-title {
  position: relative;
  font-family: var(--display);
  font-weight: var(--w-extrabold);
  font-size: 64px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.025em;
  z-index: 2;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 600ms var(--ease-out), transform 600ms var(--ease-out);
  transition-delay: 600ms;
}
.hand-circle-title em {
  font-family: var(--quote);
  font-style: italic;
  font-weight: var(--w-regular);
  letter-spacing: 0;
}
.hand-circle.drawn .hand-circle-title { opacity: 1; transform: translateY(0); }

.hand-circle-sub {
  position: relative;
  font-family: var(--quote);
  font-style: italic;
  font-size: 19px;
  color: var(--ink);
  opacity: 0;
  margin-top: 16px;
  transition: opacity 600ms var(--ease-out);
  transition-delay: 1200ms;
}
.hand-circle.drawn .hand-circle-sub { opacity: 0.85; }

@media (max-width: 1024px) {
  .hand-circle-title { font-size: clamp(32px, 6vw, 56px); }
}
@media (max-width: 640px) {
  .hand-circle { padding: 40px 20px; }
  .hand-circle-title { font-size: clamp(28px, 7vw, 40px); line-height: 1.1; }
  .hand-circle-sub { font-size: 14px; margin-top: 12px; }
}

/* ============================================================
 * 11. TYPEWRITER — text types out character by character, with cursor
 *
 * Markup:
 *   <span class="typewriter" data-typewriter='["instinct.", "evidence.", "the body."]'>
 *     <span class="typewriter-text"></span><span class="typewriter-cursor"></span>
 *   </span>
 *
 * Optional data attributes:
 *   data-typewriter   — JSON array of strings to rotate (or single string)
 *   data-tw-speed     — ms per character (default 80)
 *   data-tw-delete    — ms per delete (default 40)
 *   data-tw-wait      — ms to pause at full text before deleting (default 2200)
 *   data-tw-loop      — "false" to play through once and stop (default loops)
 *
 * Tier 2: use only when the content is genuinely a multi-stage rotation
 * (e.g., audience: pregnancy / postpartum / toddler). Don't use as a default
 * headline treatment — the existing static Karla + Marcellus italic is the
 * default. Slower than the typical typewriter (80ms vs the common 50ms) so it
 * doesn't feel frantic.
 * ============================================================ */

.typewriter {
  display: inline-flex;
  align-items: baseline;
  white-space: pre;
}
.typewriter-text {
  font-family: inherit;
  font-weight: inherit;
  color: inherit;
}
.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 4px;
  background: var(--strawberry);
  animation: cursor-blink 1s steps(2, start) infinite;
  align-self: center;
}
@keyframes cursor-blink {
  to { visibility: hidden; }
}

/* ============================================================
 * REDUCED MOTION OVERRIDES
 * Honor user OS-level preference for reduced motion.
 * ============================================================ */

@media (prefers-reduced-motion: reduce) {
  /* Disable scroll fade-in — show everything immediately */
  .fade-in {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  /* Disable hero headline word reveal */
  .hero-words .word > span {
    transform: none !important;
    animation: none !important;
  }

  /* Magnetic lift becomes simple opacity */
  .btn-primary, .btn-secondary {
    transition: opacity 150ms !important;
  }
  .btn-primary:hover, .btn-secondary:hover {
    transform: none !important;
    box-shadow: 0 1px 2px rgba(45, 26, 40, 0.06) !important;
    opacity: 0.92 !important;
  }

  /* Image hover — disable zoom, keep saturation lift */
  .img-hover:hover .img-hover-bg {
    transform: none !important;
  }

  /* Accordion — instant expand */
  .acc-answer {
    transition: none !important;
  }
  .acc-icon {
    transition: none !important;
  }

  /* Highlight swipe — show solid highlight without animation */
  .highlight-swipe {
    background-size: 100% 100% !important;
    transition: none !important;
  }
  .highlight-swipe::before {
    transform: scaleX(1) !important;
    transition: none !important;
  }

  /* Hand-circle — show fully drawn instantly */
  .hand-circle-path,
  .hand-circle-path-under {
    stroke-dashoffset: 0 !important;
    opacity: 1 !important;
    animation: none !important;
  }
  .hand-circle-path-under { opacity: 0.4 !important; }
  .hand-circle-title, .hand-circle-sub {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  /* Typewriter — show full text instantly, hide cursor */
  .typewriter-cursor { display: none !important; }
  .typewriter-text[data-tw-final]::after { content: attr(data-tw-final); }

  /* Bubbles scene — stop all idle floating */
  .bubble, .bubble-pill { animation: none !important; }

  /* Avatar marquee — pause the scroll */
  .avatar-marquee-track { animation: none !important; }

  /* Aurora background — freeze the drift */
  .section-aurora-bg::before { animation: none !important; }
}

/* ============================================================
 * BUBBLES SCENE — idle floating keyframes
 * Four variants so adjacent bubbles don't sync.
 * Each keyframe step is wrapped in translate(-50%, -50%) (the centering
 * offset, since bubbles use left/top positioning) and adds the JS-driven
 * scroll parallax via var(--parallax-y, 0px) so the animation and the
 * scroll parallax compose without fighting each other.
 * ============================================================ */

@keyframes bubble-float-a {
  0%, 100% { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(0, 0) rotate(0deg); }
  50%      { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(10px, -18px) rotate(1.2deg); }
}
@keyframes bubble-float-b {
  0%, 100% { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(0, 0) rotate(0deg); }
  50%      { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(-14px, -12px) rotate(-1.4deg); }
}
@keyframes bubble-float-c {
  0%, 100% { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(0, 0) rotate(0deg); }
  50%      { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(16px, 14px) rotate(1.1deg); }
}
@keyframes bubble-float-d {
  0%, 100% { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(0, 0) rotate(0deg); }
  50%      { transform: translate(-50%, calc(-50% + var(--parallax-y, 0px))) translate(-12px, 16px) rotate(-0.9deg); }
}

/* ============================================================
 * AVATAR MARQUEE — infinite horizontal scroll
 * Track must contain 2× (or 3×) the avatars for a seamless loop.
 * Translate by exactly -50% (or -33.33%) of the track's width.
 * ============================================================ */

@keyframes avatar-marquee-scroll {
  0%   { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(-50%, 0, 0); }
}

/* ============================================================
 * SECTION-AURORA-BG — slow drifting gradient mesh
 * The blob layer translates and slightly scales over 28s.
 * ============================================================ */

@keyframes aurora-drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(4%, -3%) scale(1.04); }
  100% { transform: translate(-3%, 4%) scale(1.02); }
}
