/* AdaptoFlow motion system: intro wave, ambient effects, funnel UI.
   Everything here is driven by window.AF.motion (src/data/motion.json). */

/* ---------- Intro: rolling waves ---------- */
html.af-intro-pending { background: #000; }
html.af-intro-pending body > :not(#af-intro) { visibility: hidden; }
html.af-intro-active { overflow: hidden; }
#af-intro { position: fixed; inset: 0; z-index: 1000; overflow: hidden; visibility: visible; cursor: pointer; background: transparent; contain: strict; }
#af-intro .af-intro-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#af-intro .af-welcome { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20; text-align: center; color: #fff; opacity: 0; will-change: opacity, transform; text-shadow: 0 2px 0 rgba(5,20,60,.4), 0 10px 24px rgba(3,8,30,.6); pointer-events: none; }
#af-intro .af-welcome-kicker { display: block; font: italic 400 clamp(1.4rem, 3.2vw, 2.6rem)/1 "Instrument Serif", Georgia, serif; opacity: .95; margin-bottom: .4em; }
#af-intro .af-welcome-logo { display: block; width: min(72vw, 640px); height: auto; margin: 0 auto; filter: drop-shadow(0 14px 30px rgba(3,8,30,.6)); }
#af-intro .af-intro-skip { position: absolute; right: 18px; bottom: 18px; z-index: 30; color: rgba(255,255,255,.7); font: 600 .8rem/1 "Inter Tight", system-ui, sans-serif; background: rgba(11,16,38,.4); border: 1px solid rgba(255,255,255,.35); border-radius: 999px; padding: 9px 14px; cursor: pointer; opacity: 0; transition: opacity .4s; }
#af-intro .af-intro-skip.show { opacity: 1; }
#af-intro .af-intro-skip:hover { color: #fff; border-color: rgba(255,255,255,.7); }

/* ---------- Ambient: hero ---------- */
/* overflow-x: clip keeps the caustics' side bleed from widening the page (a sideways wobble on phones) */
[data-hero] { position: relative; isolation: isolate; overflow-x: clip; }
[data-hero] .af-sparkles { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
[data-hero] > .wrap { position: relative; z-index: 2; }
.af-caustics [data-hero]::before {
  content: ""; position: absolute; inset: -20% -10% 0; z-index: 0; pointer-events: none; opacity: .55;
  background:
    radial-gradient(60% 50% at 20% 30%, rgba(31,182,255,.22), transparent 70%),
    radial-gradient(45% 40% at 80% 20%, rgba(166,77,255,.22), transparent 70%),
    radial-gradient(50% 45% at 60% 80%, rgba(61,220,92,.14), transparent 70%),
    radial-gradient(40% 35% at 35% 75%, rgba(255,77,109,.14), transparent 70%);
  background-size: 160% 160%, 150% 150%, 170% 170%, 140% 140%;
  animation: af-caustics 22s ease-in-out infinite alternate;
  filter: blur(18px);
}
@keyframes af-caustics {
  0%   { background-position: 0% 0%, 100% 0%, 50% 100%, 20% 80%; }
  50%  { background-position: 40% 30%, 60% 20%, 20% 60%, 70% 40%; }
  100% { background-position: 100% 60%, 0% 100%, 80% 20%, 40% 0%; }
}

/* Floating bottles with mouse parallax (JS sets --px/--py) */
.af-float .hero-art .bottle { animation: af-float 6.5s ease-in-out infinite alternate; }
.af-float .hero-art .bottle:last-child { animation-duration: 7.4s; animation-delay: -2.1s; }
@keyframes af-float { from { translate: 0 0; } to { translate: 0 -12px; } }
.hero-art { transform: translate(calc(var(--px, 0) * 1px), calc(var(--py, 0) * 1px)); transition: transform .35s ease-out; }

/* Rainbow shimmer on the announcement bar and rules */
.af-shimmer .announce, .af-shimmer .rainbow-rule { animation: af-shimmer 14s linear infinite; background-size: 300% 100%; }
@keyframes af-shimmer { to { background-position: 300% 0; } }

/* Scroll reveal */
.af-reveal { opacity: 0; transform: translateY(22px); transition: opacity .7s cubic-bezier(.2,.7,.2,1), transform .7s cubic-bezier(.2,.7,.2,1); transition-delay: var(--d, 0ms); }
.af-reveal.af-in { opacity: 1; transform: none; }

/* Buttons: glow on the flow CTA */
.btn-flow { position: relative; overflow: hidden; background: linear-gradient(135deg, #ff7a1f, #ff4d6d); border-color: transparent; box-shadow: 0 10px 30px -10px rgba(255,120,60,.8); }
.btn-flow::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%); transform: translateX(-120%); }
.af-motion .btn-flow::after { animation: af-sheen 4.5s ease-in-out infinite; }
@keyframes af-sheen { 0%, 60% { transform: translateX(-120%); } 85%, 100% { transform: translateX(120%); } }
.btn-flow:hover { background: linear-gradient(135deg, #ff8a3a, #ff5f7d); }

/* ---------- Funnel ---------- */
.af-modal { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 16px; background: rgba(8, 12, 28, .62); backdrop-filter: blur(6px); opacity: 0; transition: opacity .3s; }
.af-modal[hidden] { display: none; }
.af-modal.show { opacity: 1; }
.af-card { position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--paper); color: var(--text); border-radius: 26px; box-shadow: 0 40px 80px -30px rgba(0,0,0,.6); transform: translateY(16px) scale(.98); transition: transform .35s cubic-bezier(.2,.8,.2,1); }
.af-modal.show .af-card { transform: none; }
.af-card::before { content: ""; display: block; height: 6px; background: var(--rainbow); background-size: 300% 100%; animation: af-shimmer 10s linear infinite; }
.af-card-inner { padding: 26px 28px 28px; }
.af-close { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: #f1e9db; color: var(--ink); font-size: 1.2rem; cursor: pointer; display: grid; place-items: center; }
.af-close:hover { background: #e8ddc9; }
.af-steps { display: flex; gap: 6px; margin-bottom: 18px; }
.af-steps i { height: 4px; flex: 1; border-radius: 2px; background: #e9e0cf; }
.af-steps i.on { background: var(--orange); }
.af-step { animation: af-step-in .35s cubic-bezier(.2,.8,.2,1); }
@keyframes af-step-in { from { opacity: 0; transform: translateX(14px); } }
.af-step h2 { font-size: 1.6rem; margin-bottom: .2em; }
.af-step .sub { color: var(--muted); margin-bottom: 18px; }
.af-options { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.af-opt { display: flex; align-items: center; gap: 12px; text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 14px; cursor: pointer; font: inherit; color: var(--ink); transition: border-color .15s, transform .15s, box-shadow .15s; }
.af-opt:hover { border-color: var(--orange); transform: translateY(-2px); box-shadow: 0 10px 20px -14px rgba(0,0,0,.4); }
.af-opt .ic { font-size: 1.5rem; width: 40px; height: 40px; display: grid; place-items: center; background: #fff1e4; border-radius: 12px; flex: none; }
.af-opt b { display: block; font-weight: 800; }
.af-opt small { color: var(--muted); font-size: .82rem; }
.af-opt.wide { grid-column: 1 / -1; }
.af-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; gap: 12px; }
.af-back { background: none; border: 0; color: var(--muted); font: inherit; font-weight: 700; cursor: pointer; padding: 6px 0; }
.af-back:hover { color: var(--ink); }

/* Result */
.af-result { display: grid; grid-template-columns: 120px 1fr; gap: 20px; align-items: center; background: radial-gradient(circle at 30% 20%, #2a3766, var(--ink) 75%); border-radius: 18px; padding: 18px; color: #fff; }
.af-result .bottle { width: 100px; padding-top: 42px; margin: 0 auto; filter: drop-shadow(0 14px 18px rgba(0,0,0,.45)); }
.af-result .bottle::before { width: 28px; height: 44px; }
.af-result .bottle-body { height: 150px; border-radius: 22px 22px 14px 14px; }
.af-result .bottle-label { top: 32px; height: 90px; }
.af-result .tag { padding: 3px 10px; border-radius: var(--pill); margin-bottom: 6px; font-size: .78rem; }
.af-result h3 { color: #fff; font-size: 1.2rem; margin: 0 0 4px; }
.af-result .why { color: #c9d0e4; font-size: .92rem; margin: 0 0 8px; }
.af-result .price { color: #fff; margin: 0; font-size: 1.4rem; }
.af-qty { display: inline-flex; align-items: center; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; }
.af-qty button { width: 38px; height: 38px; border: 0; background: #fff; font-size: 1.2rem; cursor: pointer; color: var(--ink); }
.af-qty button:hover { background: #fff1e4; }
.af-qty output { min-width: 36px; text-align: center; font-weight: 800; }
.af-summary { margin: 16px 0 0; font-size: .95rem; }
.af-summary div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.af-summary div.total { font-weight: 800; font-size: 1.05rem; border: 0; }
.af-summary .free { color: var(--green); font-weight: 800; }
.af-nudge { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }

/* Checkout form */
.af-form { display: grid; gap: 12px; }
.af-form label { display: grid; gap: 4px; font-size: .85rem; font-weight: 800; color: var(--muted); }
.af-form input, .af-form textarea { font: inherit; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--text); }
.af-form input:focus, .af-form textarea:focus { outline: 0; border-color: var(--orange); }
.af-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.af-form .check { display: flex; align-items: flex-start; gap: 10px; font-size: .9rem; font-weight: 600; color: var(--text); }
.af-form .check input { width: 18px; height: 18px; margin-top: 2px; }
.af-secure { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.af-done { text-align: center; padding: 10px 0; }
.af-done .big { font-size: 3rem; line-height: 1; margin-bottom: 10px; }

/* Sticky flow bar */
.af-bar { position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 140%); z-index: 800; display: flex; align-items: center; gap: 14px; background: rgba(12,18,34,.92); color: #fff; backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.12); border-radius: 999px; padding: 8px 8px 8px 18px; box-shadow: 0 20px 50px -20px rgba(0,0,0,.8); transition: transform .45s cubic-bezier(.2,.8,.2,1); max-width: calc(100% - 24px); }
.af-bar.show { transform: translate(-50%, 0); }
.af-bar span { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.af-bar .btn-small { padding: .6em 1.1em; }
.af-bar .x { background: none; border: 0; color: rgba(255,255,255,.6); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
.af-bar .x:hover { color: #fff; }

@media (max-width: 560px) {
  .af-options { grid-template-columns: 1fr; }
  .af-card-inner { padding: 22px 18px 22px; }
  .af-result { grid-template-columns: 1fr; text-align: center; }
  .af-form .row { grid-template-columns: 1fr; }
  .af-bar span { display: none; }
  .af-bar { padding-left: 8px; }
}

/* ---------- Control panel ---------- */
#af-control { display: grid; grid-template-columns: 340px 1fr; gap: 0; min-height: calc(100vh - 80px); background: #0f1528; color: #dfe4f2; }
#af-control .panel { padding: 22px 20px 40px; overflow: auto; max-height: calc(100vh - 80px); border-right: 1px solid rgba(255,255,255,.08); }
#af-control h1 { color: #fff; font-size: 1.4rem; margin: 0 0 4px; }
#af-control h2 { color: #ffb066; font-family: var(--font-body); font-size: .75rem; letter-spacing: .14em; text-transform: uppercase; margin: 26px 0 10px; }
#af-control .ctl { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.06); font-size: .92rem; }
#af-control .ctl label { flex: 1; }
#af-control .ctl small { display: block; color: #8790a8; font-size: .78rem; }
#af-control input[type=range] { width: 120px; accent-color: var(--orange); }
#af-control input[type=text], #af-control input[type=number], #af-control select { width: 140px; background: #1a2240; color: #fff; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: .88rem; }
#af-control .sw { position: relative; width: 44px; height: 24px; appearance: none; background: #2a3352; border-radius: 999px; cursor: pointer; transition: background .2s; }
#af-control .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
#af-control .sw:checked { background: var(--green); }
#af-control .sw:checked::after { transform: translateX(20px); }
#af-control .actions { display: grid; gap: 8px; margin-top: 20px; }
#af-control .actions .btn { width: 100%; }
#af-control textarea { width: 100%; height: 160px; background: #0b1020; color: #9fe3b0; border: 1px solid rgba(255,255,255,.12); border-radius: 10px; font: .78rem/1.4 ui-monospace, Consolas, monospace; padding: 10px; margin-top: 10px; }
#af-control .preview { position: relative; background: #000; }
#af-control .preview iframe { width: 100%; height: 100%; min-height: calc(100vh - 80px); border: 0; background: #0c1222; }
#af-control .viewport { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
#af-control .viewport button { background: rgba(12,18,34,.85); color: #fff; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: .8rem; cursor: pointer; }
#af-control .viewport button.on { background: var(--orange); border-color: var(--orange); }
#af-control .preview.mobile iframe { width: 390px; margin: 0 auto; display: block; }
@media (max-width: 900px) { #af-control { grid-template-columns: 1fr; } #af-control .panel { max-height: none; border-right: 0; } }

@media (prefers-reduced-motion: reduce) {
  .af-float .hero-art .bottle, .af-caustics [data-hero]::before, .af-shimmer .announce, .af-shimmer .rainbow-rule, .af-card::before, .btn-flow::after { animation: none !important; }
  .af-reveal { opacity: 1; transform: none; transition: none; }
}
