/* ==========================================================================
   Er Pang — motion layer
   Everything here is progressive enhancement: content is fully visible
   without JS, and all motion is gated behind prefers-reduced-motion.
   ========================================================================== */

:root {
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-in-quart: cubic-bezier(0.5, 0, 0.75, 0);
}

/* Header + chat launcher persist across page navigations (see @view-transition) */
.header { view-transition-name: site-header; }
.chat-launcher { view-transition-name: chat-launcher; }

@media (prefers-reduced-motion: no-preference) {

  /* ============================ Page transitions ========================= */
  /* Cross-document View Transitions (Chromium 126+, Safari 18.2+). Others: normal nav. */
  @view-transition { navigation: auto; }

  ::view-transition-old(root) {
    animation: vt-out 220ms var(--ease-in-quart) both;
  }
  ::view-transition-new(root) {
    animation: vt-in 520ms var(--ease-out-expo) 60ms both;
  }
  @keyframes vt-out { to { opacity: 0; transform: translateY(-10px); } }
  @keyframes vt-in { from { opacity: 0; transform: translateY(14px); } }

  /* Theme switch uses a same-document view transition driven from JS */
  html.theme-vt::view-transition-old(root),
  html.theme-vt::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
  }

  /* ============================ Header ================================== */
  /* Steam in the logo drifts gently when you hover the brand */
  .brand:hover svg path[opacity] {
    animation: logo-steam 1.4s ease-in-out infinite;
  }
  .brand:hover svg path[opacity] + path[opacity] { animation-delay: 0.25s; }
  @keyframes logo-steam {
    0%, 100% { transform: translateY(0); opacity: 0.85; }
    50% { transform: translateY(-5px); opacity: 0.35; }
  }

  /* Mobile nav: panel fades down, links cascade in */
  @media (max-width: 860px) {
    .nav.open { animation: nav-in 360ms var(--ease-out-expo) both; }
    .nav.open .nav-links li {
      animation: rise-in 520ms var(--ease-out-expo) both;
      animation-delay: calc(80ms + var(--i, 0) * 55ms);
    }
    .nav.open .nav-links li:nth-child(1) { --i: 0; }
    .nav.open .nav-links li:nth-child(2) { --i: 1; }
    .nav.open .nav-links li:nth-child(3) { --i: 2; }
    .nav.open .nav-links li:nth-child(4) { --i: 3; }
    .nav.open .nav-links li:nth-child(5) { --i: 4; }
  }
  @keyframes nav-in { from { opacity: 0; transform: translateY(-12px); } }

  /* ============================ Home hero =============================== */
  .hero-media img {
    animation: hero-settle 2.6s var(--ease-out-quart) both;
    transform-origin: 50% 55%;
  }
  @keyframes hero-settle {
    from { transform: scale(1.12); filter: brightness(0.55) saturate(0.8); }
    to { transform: scale(1); filter: none; }
  }

  .hero-content > * {
    animation: rise-in 900ms var(--ease-out-expo) both;
  }
  .hero-content > :nth-child(1) { animation-delay: 350ms; }
  .hero-content > :nth-child(2) { animation-delay: 450ms; }
  .hero-content > :nth-child(3) { animation-delay: 620ms; }
  .hero-content > :nth-child(4) { animation-delay: 740ms; }
  .hero-content > :nth-child(5) { animation-delay: 860ms; }

  /* Headline wipes up from behind a mask, like lifting a lid */
  .hero-content > .hero-title {
    animation: title-unmask 1.2s var(--ease-out-expo) 450ms both;
  }
  @keyframes title-unmask {
    from { clip-path: inset(0 0 100% 0); transform: translateY(0.35em); opacity: 0; }
    40% { opacity: 1; }
    to { clip-path: inset(-10% -5% -20% -5%); transform: none; opacity: 1; }
  }

  /* Eyebrow rule draws itself */
  .hero-eyebrow::before {
    transform-origin: left center;
    animation: draw-x 700ms var(--ease-out-expo) 500ms both;
  }
  @keyframes draw-x { from { transform: scaleX(0); } }

  /* Parallax: image drifts slower than the page, copy lifts away */
  @supports (animation-timeline: scroll()) {
    .hero-media {
      animation: hero-parallax linear both;
      animation-timeline: scroll(root);
      animation-range: 0 100vh;
    }
    .hero-content {
      animation: hero-copy-out linear both;
      animation-timeline: scroll(root);
      animation-range: 0 75vh;
    }
    @keyframes hero-parallax { to { transform: translateY(22%); } }
    @keyframes hero-copy-out { to { opacity: 0; transform: translateY(-48px); } }
  }

  /* Steam curling off the hot pot (elements injected by motion.js) */
  .hero-steam {
    position: absolute;
    left: 50%;
    top: 56%;
    width: min(34vw, 420px);
    height: 60%;
    translate: -50% -100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    animation: fade-in 2s ease 1.2s forwards;
  }
  .hero-steam span {
    position: absolute;
    bottom: 0;
    left: var(--x);
    width: var(--s);
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(closest-side, oklch(1 0 0 / 0.55), oklch(1 0 0 / 0));
    filter: blur(14px);
    mix-blend-mode: screen;
    opacity: 0;
    animation: steam-rise var(--d) ease-out var(--delay) infinite;
    will-change: transform, opacity;
  }
  .hero-steam.is-paused span { animation-play-state: paused; }
  @keyframes steam-rise {
    0% { transform: translate(0, 0) scale(0.5); opacity: 0; }
    20% { opacity: 0.55; }
    60% { transform: translate(var(--sway), -55%) scale(1.3); opacity: 0.3; }
    100% { transform: translate(calc(var(--sway) * -0.6), -110%) scale(1.9); opacity: 0; }
  }

  /* ============================ Interior page heroes ==================== */
  .page-hero { position: relative; overflow: hidden; isolation: isolate; }
  .page-hero::before {
    content: '';
    position: absolute;
    inset: -40% -10%;
    z-index: -1;
    background:
      radial-gradient(40% 50% at 20% 30%, oklch(from var(--color-gold) l c h / 0.16), transparent 70%),
      radial-gradient(35% 45% at 80% 70%, oklch(from var(--color-primary) l c h / 0.12), transparent 70%);
    animation: lantern-drift 18s ease-in-out infinite alternate;
  }
  @keyframes lantern-drift {
    to { transform: translate3d(4%, -6%, 0) rotate(4deg) scale(1.06); }
  }
  .page-hero .wrap > * {
    animation: rise-in 900ms var(--ease-out-expo) both;
  }
  .page-hero .wrap > :nth-child(2) { animation-delay: 110ms; }
  .page-hero .wrap > :nth-child(3) { animation-delay: 220ms; }
  .page-hero .eyebrow::before {
    transform-origin: left center;
    animation: draw-x 700ms var(--ease-out-expo) 200ms both;
  }
  .page-hero .tag-row .pill {
    animation: pop-in 520ms var(--ease-out-expo) both;
    animation-delay: calc(360ms + var(--i, 0) * 70ms);
  }
  .page-hero .tag-row .pill:nth-child(2) { --i: 1; }
  .page-hero .tag-row .pill:nth-child(3) { --i: 2; }

  /* ============================ Scroll reveals ========================== */
  /* data-reveal is only ever added by motion.js, which animates entrances with
     the Web Animations API. CSS just holds the pre-reveal state, so no-JS
     visitors see everything and nothing lingers to fight hover transitions.
     Screen-only so unrevealed sections still print. */
  @media screen { [data-reveal]:not(.is-revealed) { opacity: 0; } }

  /* ============================ Micro-interactions ====================== */
  .btn {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    transition:
      color var(--transition-interactive),
      background var(--transition-interactive),
      border-color var(--transition-interactive),
      box-shadow var(--transition-interactive),
      transform 260ms var(--ease-out-expo);
  }
  .btn:hover { transform: translateY(-2px); }
  .btn:active { transform: translateY(0) scale(0.97); transition-duration: 80ms; }
  .btn-primary:hover, .btn-gold:hover { box-shadow: var(--shadow-md); }

  /* Light sweep across solid buttons */
  .btn-primary::after,
  .btn-gold::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(105deg, transparent 35%, oklch(1 0 0 / 0.28) 50%, transparent 65%);
    transform: translateX(-110%);
    pointer-events: none;
  }
  .btn-primary:hover::after,
  .btn-gold:hover::after {
    transform: translateX(110%);
    transition: transform 700ms var(--ease-out-quart);
  }

  .icon-btn { transition: color var(--transition-interactive), border-color var(--transition-interactive), transform 260ms var(--ease-out-expo); }
  .icon-btn:hover { transform: translateY(-2px); }
  .icon-btn:active { transform: scale(0.92); }
  [data-theme-toggle] svg { animation: icon-spin 520ms var(--ease-out-expo); }
  @keyframes icon-spin { from { transform: rotate(-90deg) scale(0.6); opacity: 0; } }

  .insta-card { transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive), transform 320ms var(--ease-out-expo); }
  .insta-card:hover { transform: translateY(-3px); }
  .insta-icon { transition: transform 420ms var(--ease-out-expo); }
  .insta-card:hover .insta-icon { transform: rotate(-8deg) scale(1.08); }

  /* Open-status dot breathes when the kitchen is open */
  [data-open-status].is-open::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6fcf6a;
    box-shadow: 0 0 0 0 oklch(0.78 0.17 145 / 0.6);
    animation: live-dot 2.4s ease-out infinite;
    display: inline-block;
    margin-inline-start: var(--space-1);
  }
  @keyframes live-dot {
    0% { box-shadow: 0 0 0 0 oklch(0.78 0.17 145 / 0.55); }
    70%, 100% { box-shadow: 0 0 0 8px oklch(0.78 0.17 145 / 0); }
  }

  /* ============================ Chat concierge ========================== */
  .chat-launcher.is-entering { animation: launcher-in 700ms var(--ease-out-expo) 1.2s both; }
  .chat-launcher {
    transition: background var(--transition-interactive), transform 260ms var(--ease-out-expo);
  }
  .chat-launcher:hover { transform: translateY(-3px); }
  .chat-launcher:active { transform: scale(0.96); }
  .chat-launcher::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid var(--color-primary);
    opacity: 0;
    pointer-events: none;
  }
  .chat-launcher.is-nudging::before { animation: nudge-ring 1.6s var(--ease-out-quart) 2; }
  @keyframes launcher-in { from { opacity: 0; transform: translateY(24px) scale(0.9); } }
  @keyframes nudge-ring {
    0% { opacity: 0.7; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.35, 1.7); }
  }

  .chat-panel {
    transform-origin: 100% 100%;
    transform: translateY(16px) scale(0.94);
    transition:
      opacity 0.22s var(--ease-out-expo),
      transform 0.42s var(--ease-out-expo);
  }
  .chat-panel.open .chat-quick button {
    animation: pop-in 460ms var(--ease-out-expo) both;
    animation-delay: calc(200ms + var(--i, 0) * 70ms);
  }
  .chat-quick button:nth-child(2) { --i: 1; }
  .chat-quick button:nth-child(3) { --i: 2; }

  .msg { animation: msg-in 380ms var(--ease-out-expo) both; }
  .msg.bot { transform-origin: 0 100%; }
  .msg.user { transform-origin: 100% 100%; }
  @keyframes msg-in { from { opacity: 0; transform: translateY(8px) scale(0.92); } }

  .msg.typing span { animation: typing-bounce 1.1s infinite var(--ease-out-quart); }
  @keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
  }

  /* ============================ Shared keyframes ======================== */
  @keyframes rise-in { from { opacity: 0; transform: translateY(18px); } }
  @keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.9); } }
  @keyframes fade-in { to { opacity: 1; } }
}
