/* =============================================================================
   ShiftHawk — App Clip "share a swap" section + animated flow
   Companion to assets/js/app-clip.js (mount: #appclip-flow-mount).
   Reuses the design-system tokens (styles.css) and the .stage-* conventions
   established by buddy-match.css / team-invite.css so it matches the site.
   Motion is disabled under prefers-reduced-motion (media query at the bottom);
   the JS then composes the final told state with no animation.
   ========================================================================== */

/* ---- Section accent: a soft glow behind the band, like #team / #buddy ------ */
.appclip-section { position: relative; overflow: hidden; }
.appclip-glow {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(640px 360px at 82% 6%, rgba(34,211,238,.16), transparent 62%),
    radial-gradient(520px 320px at 8% 92%, rgba(196,181,253,.14), transparent 62%);
}
.appclip-section > .container { position: relative; z-index: 1; }

/* the left column carries the story + steps; the right is the phone stage */
.appclip-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-7);
  align-items: center;
}
@media (max-width: 920px) { .appclip-grid { grid-template-columns: 1fr; gap: var(--s-7); } }

.appclip-lede { font-size: 1.05rem; color: var(--text-2); margin: 0 0 var(--s-5); }
.appclip-lede strong { color: var(--text-1); }

/* a tidy "no install needed" callout pill */
.ac-headline-pill {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-family: var(--font-mono); font-size: .72rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--primary-deep); background: var(--primary-soft);
  border: 1px solid var(--primary-tint);
  padding: 6px 12px; border-radius: var(--r-pill);
  margin-bottom: var(--s-4);
}
.ac-headline-pill i { font-size: 1.05rem; }

/* ---- The concrete example card (Dr. Maya's story) ------------------------- */
.ac-story {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-3); box-shadow: var(--shadow-sm);
  padding: var(--s-5); margin-bottom: var(--s-6);
}
.ac-story-head {
  display: flex; align-items: center; gap: var(--s-2);
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  color: var(--text-1); margin-bottom: var(--s-3);
}
.ac-story-head i { color: var(--pink); font-size: 1.4rem; }
.ac-story p { margin: 0 0 var(--s-3); font-size: .96rem; color: var(--text-2); }
.ac-story p:last-child { margin-bottom: 0; }
.ac-story strong { color: var(--text-1); }

/* ---- The three things that make it special ------------------------------- */
.ac-specials { display: grid; gap: var(--s-3); margin: 0; padding: 0; list-style: none; }
.ac-specials li {
  display: grid; grid-template-columns: 38px 1fr; gap: var(--s-3);
  align-items: start;
}
.ac-specials li i {
  width: 38px; height: 38px; border-radius: var(--r-2);
  display: grid; place-items: center; font-size: 1.25rem;
  background: var(--primary-soft); color: var(--primary-deep);
  border: 1px solid var(--primary-tint);
}
.ac-specials li.is-name   i { background: rgba(34,211,238,.10); color: var(--primary-deep); border-color: var(--primary-tint); }
.ac-specials li.is-ledger i { background: rgba(110,231,183,.14); color: var(--success); border-color: rgba(110,231,183,.5); }
.ac-specials li.is-invite i { background: rgba(244,114,182,.12); color: var(--pink); border-color: rgba(244,114,182,.45); }
.ac-specials li p { margin: 0; font-size: .95rem; color: var(--text-2); }
.ac-specials li strong { color: var(--text-1); }

/* ---- "How it will work" — the 5 beat captions under the phone (left col) -- */
.ac-beats {
  counter-reset: acbeat; display: grid; gap: var(--s-3);
  margin: var(--s-6) 0 0; padding: 0; list-style: none;
}
.ac-beats li { display: grid; grid-template-columns: 34px 1fr; gap: var(--s-3); align-items: start; }
.ac-beats li .acb-num {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: .9rem;
  background: var(--primary-soft); color: var(--primary-deep);
  border: 1px solid var(--primary-tint);
}
.ac-beats li p { margin: 0; font-size: .95rem; color: var(--text-2); }
.ac-beats li strong { color: var(--text-1); }

/* a small "forthcoming" note so we never overstate availability */
.ac-soon-note {
  margin-top: var(--s-5); font-size: .85rem; color: var(--text-3);
  display: flex; align-items: center; gap: var(--s-2);
}
.ac-soon-note i { color: var(--primary); font-size: 1rem; }

/* =============================================================================
   The animation stage — a phone mock that walks the 5 beats
   ========================================================================== */
.ac-stage {
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-4); box-shadow: var(--shadow-md);
  padding: var(--s-6) var(--s-5) var(--s-5);
  min-height: 480px;
  display: grid; grid-template-rows: auto 1fr auto;
  gap: var(--s-4);
  overflow: hidden;
}
.ac-stage .stage-body { display: grid; place-items: center; }

/* .stage-caption / .stage-foot / .stage-replay are already defined (unscoped)
   by team-invite.css, which every page loads before this file — only the two
   deltas this stage needs are restated here. */
.ac-stage .stage-caption { min-height: 22px; }   /* clears the 20px .ac-beat-num */
.ac-beat-num {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-family: var(--font-mono); font-weight: 700; font-size: .68rem;
  flex: 0 0 auto;
}
/* two-line beat captions live here — reserve the height so the stage never
   reflows as the story advances */
.ac-stage .stage-foot { min-height: 2.6em; }

/* ---- The phone frame ------------------------------------------------------ */
.ac-phone {
  position: relative; width: 248px; max-width: 78vw; aspect-ratio: 9 / 18.5;
  margin: 0 auto; align-self: center;
  background: var(--ink); border-radius: 30px;
  padding: 10px;
  box-shadow: var(--shadow-lg), 0 0 0 2px var(--ink-border) inset;
}
html[data-theme="dark"] .ac-phone { box-shadow: var(--shadow-lg), 0 0 0 2px #25324a inset; }
.ac-phone-notch {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 86px; height: 18px; border-radius: var(--r-pill);
  background: #000; z-index: 6;
}
.ac-screen {
  position: relative; width: 100%; height: 100%;
  border-radius: 22px; overflow: hidden;
  background: var(--surface-2);
  isolation: isolate;
}
html[data-theme="dark"] .ac-screen { background: #0c1525; }

/* ---- Generic in-phone chrome --------------------------------------------- */
.ac-app-bar {
  display: flex; align-items: center; gap: 7px;
  padding: 22px 12px 10px;
  font-family: var(--font-display); font-weight: 700; font-size: .82rem;
  color: var(--text-1); background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.ac-app-bar i { color: var(--primary); font-size: 1.15rem; }
.ac-chat-bar i { color: var(--lilac); }

/* the chips reused across scenes */
.ac-shift-chip {
  font-family: var(--font-mono); font-size: .68rem; font-weight: 700;
  color: var(--primary-deep); background: var(--primary-soft);
  border: 1px solid var(--primary-tint); border-radius: var(--r-1);
  padding: 4px 8px; white-space: nowrap;
}
.ac-open-chip {
  font-family: var(--font-mono); font-size: .66rem; font-weight: 700;
  color: var(--text-3); background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: var(--r-1);
  padding: 4px 8px;
}

/* ---- Scene base: scenes stack absolutely inside the screen ----------------
   Each scene is opaque (screen-coloured) so a later scene fully occludes the
   one beneath it — no bleed-through from the previous beat. */
.ac-scene {
  position: absolute; inset: 0;
  padding-bottom: 12px;
  background: var(--surface-2);
  opacity: 0; transition: opacity .45s ease;
}
html[data-theme="dark"] .ac-scene { background: #0c1525; }
.ac-scene-offer { z-index: 1; opacity: 1; }
.ac-scene-chat  { z-index: 2; }

/* Scene 1 — the swap-offer card */
.ac-swap-card {
  margin: 14px 12px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-3); box-shadow: var(--shadow-sm);
}
html[data-theme="dark"] .ac-swap-card { background: var(--ink-surface); border-color: var(--ink-border); }
.ac-swap-row { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.ac-swap-arrow { color: var(--primary); font-size: 1rem; }
.ac-swap-note { margin: 0 0 11px; font-size: .76rem; color: var(--text-2); line-height: 1.45; }
.ac-share-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-display); font-weight: 700; font-size: .76rem;
  color: #fff; background: var(--primary);
  border-radius: var(--r-pill); padding: 8px 14px;
  box-shadow: var(--shadow-cyan);
}
.ac-share-btn i { font-size: .85rem; }

/* Scene 2 — the group-chat bubbles */
.ac-bubble {
  margin: 12px 12px 0; max-width: 84%;
  font-size: .76rem; line-height: 1.4;
  padding: 9px 11px; border-radius: 14px;
}
.ac-bubble-out {
  margin-left: auto; color: #fff; background: var(--primary);
  border-bottom-right-radius: 4px;
}
.ac-bubble-link {
  display: flex; align-items: center; gap: 9px;
  color: var(--text-1); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  border-bottom-left-radius: 4px;
}
html[data-theme="dark"] .ac-bubble-link { background: var(--ink-surface); border-color: var(--ink-border); }
.ac-bubble-link i { color: var(--primary); font-size: 1.3rem; flex: 0 0 auto; }
.ac-bubble-link strong { color: var(--primary-deep); font-family: var(--font-mono); font-size: .72rem; }
.ac-bubble-link small { color: var(--text-3); font-size: .66rem; }

/* the tap ripple that lands on the link bubble */
.ac-tap-ring {
  position: absolute; left: 38%; bottom: 28%;
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--primary); opacity: 0;
  z-index: 4;
}

/* ---- Scene 3/4/5 — the App Clip card (rises over the screen) -------------- */
.ac-clip-card {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 5;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 -10px 30px rgba(8,145,178,.16), var(--shadow-md);
  padding: 9px 12px 13px;
  transform: translateY(120%); opacity: 0;
}
html[data-theme="dark"] .ac-clip-card { background: var(--ink-surface); border-color: var(--ink-border); }
.ac-clip-handle {
  width: 34px; height: 4px; border-radius: var(--r-pill);
  background: var(--border-strong); margin: 0 auto 9px;
}
.ac-clip-head { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; }
.ac-clip-app {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff; font-size: 1.1rem; box-shadow: var(--shadow-sm);
}
.ac-clip-titles { display: flex; flex-direction: column; line-height: 1.2; }
.ac-clip-titles strong { font-family: var(--font-display); font-size: .86rem; color: var(--text-1); }
.ac-clip-sub { font-family: var(--font-mono); font-size: .58rem; color: var(--text-3); letter-spacing: .02em; }
.ac-clip-body { display: grid; gap: 9px; }
.ac-clip-detail { display: flex; align-items: center; gap: 8px; }
.ac-clip-from { font-size: .72rem; color: var(--text-2); }
.ac-clip-from strong { color: var(--text-1); }
.ac-clip-accept {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-display); font-weight: 700; font-size: .8rem;
  color: #fff; background: var(--primary);
  border-radius: var(--r-pill); padding: 9px 14px;
  box-shadow: var(--shadow-cyan); transition: background .3s ease;
}
.ac-clip-accept i { font-size: .9rem; }

/* the "name attached + ledger" line — hidden until beat 4 */
.ac-ledger {
  display: flex; align-items: center;
  opacity: 0; max-height: 0; overflow: hidden;
  transition: opacity .4s ease, max-height .4s ease;
}
.ac-ledger-line {
  display: flex; align-items: center; gap: 7px;
  font-size: .72rem; color: var(--text-2);
  background: rgba(110,231,183,.14); border: 1px solid rgba(110,231,183,.5);
  border-radius: var(--r-2); padding: 7px 9px; width: 100%;
}
.ac-ledger-line i { color: var(--success); font-size: 1.05rem; flex: 0 0 auto; }
.ac-ledger-line strong { color: var(--text-1); }

/* the gentle install invitation — hidden until beat 5 */
.ac-invite {
  display: flex; align-items: center; gap: 7px;
  font-size: .72rem; color: var(--text-2);
  background: rgba(244,114,182,.10); border: 1px dashed rgba(244,114,182,.55);
  border-radius: var(--r-2); padding: 7px 9px;
  opacity: 0; max-height: 0; overflow: hidden;
  transition: opacity .4s ease, max-height .4s ease;
}
.ac-invite i { color: var(--pink); font-size: 1.1rem; flex: 0 0 auto; }
.ac-invite strong { color: var(--pink); }

/* =============================================================================
   ANIMATION — the JS adds .ac-step-1 … .ac-step-5 additively to .ac-phone.
   Each beat builds on the last so the story stacks.
   ========================================================================== */

/* Beat 1 — the swap card settles in (a soft lift) */
.ac-phone.ac-step-1 .ac-swap-card { animation: ac-cardin .55s ease both; }
.ac-phone.ac-step-1 .ac-share-btn { animation: ac-pulse 1s ease .4s both; }

/* Beat 2 — chat scene fades over; bubbles slide up; tap ring lands on the link */
.ac-phone.ac-step-2 .ac-scene-chat { opacity: 1; }
.ac-phone.ac-step-2 .ac-bubble-out  { animation: ac-bubblein .4s ease .05s both; }
.ac-phone.ac-step-2 .ac-bubble-link { animation: ac-bubblein .4s ease .35s both; }
.ac-phone.ac-step-2 .ac-tap-ring    { animation: ac-tap 1.1s ease .9s both; }

/* Beat 3 — the App Clip card rises from the bottom (no install) */
.ac-phone.ac-step-3 .ac-clip-card { animation: ac-clipin .6s cubic-bezier(.2,.8,.2,1) both; }

/* Beat 4 — Accept → accepted: button turns green, ledger line reveals */
.ac-phone.ac-step-4 .ac-clip-accept { background: var(--success); }
.ac-phone.ac-step-4 .ac-ledger { opacity: 1; max-height: 60px; }

/* Beat 5 — the gentle invitation reveals */
.ac-phone.ac-step-5 .ac-invite { opacity: 1; max-height: 60px; }

@keyframes ac-cardin {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes ac-bubblein {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes ac-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}
@keyframes ac-tap {
  0%   { opacity: 0; transform: scale(.4); }
  35%  { opacity: .9; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.7); }
}
@keyframes ac-clipin {
  from { transform: translateY(120%); opacity: 0; }
  60%  { transform: translateY(-4%);  opacity: 1; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* the static (told-at-once) state used for reduced motion / no IO */
.ac-phone.is-static .ac-scene-chat,
.ac-phone.is-static .ac-clip-card { opacity: 1; }
.ac-phone.is-static .ac-clip-card { transform: none; }
.ac-phone.is-static .ac-clip-accept { background: var(--success); }
.ac-phone.is-static .ac-ledger,
.ac-phone.is-static .ac-invite { opacity: 1; max-height: 60px; }
.ac-phone.is-static .ac-tap-ring { display: none; }

/* small-screen niceties */
@media (max-width: 480px) {
  .ac-phone { width: 220px; }
  .ac-stage { padding: var(--s-5) var(--s-4) var(--s-4); min-height: 460px; }
}

/* ---- prefers-reduced-motion: kill every keyframe + the looping --------------
   JS already renders the static told-at-once state; this is belt-and-braces so
   even a forced .ac-step-* class never animates. */
@media (prefers-reduced-motion: reduce) {
  .ac-phone[class*="ac-step-"] .ac-swap-card,
  .ac-phone[class*="ac-step-"] .ac-share-btn,
  .ac-phone[class*="ac-step-"] .ac-bubble-out,
  .ac-phone[class*="ac-step-"] .ac-bubble-link,
  .ac-phone[class*="ac-step-"] .ac-tap-ring,
  .ac-phone[class*="ac-step-"] .ac-clip-card {
    animation: none !important;
  }
  .ac-scene, .ac-clip-card, .ac-ledger, .ac-invite, .ac-clip-accept { transition: none !important; }
  .ac-tap-ring { display: none !important; }
  /* compose the full state regardless of which step classes are present */
  .ac-scene-chat, .ac-clip-card { opacity: 1 !important; }
  .ac-clip-card { transform: none !important; }
  .ac-clip-accept { background: var(--success) !important; }
  .ac-ledger, .ac-invite { opacity: 1 !important; max-height: 60px !important; }
}
