/* ==========================================================================
   JapanVisit — enhancement layer
   Additive CSS loaded on every page. Does not modify Framer's own styles;
   only adds a mobile menu, back-to-top control, motion polish, and mobile
   fixes. Everything degrades gracefully if enhance.js fails to run.

   Motion follows Emil Kowalski's craft bar (animations.dev):
   custom ease-out curves, sub-300ms UI, press feedback, gated hover,
   staggered entrances, honest reduced-motion.
   ========================================================================== */

:root {
  --jv-accent: #c41610;
  --jv-accent-2: #d5211b;
  --jv-ink: #1c1c1c;
  /* Canonical curves (Emil Kowalski) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);      /* strong ease-out for UI */
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);   /* iOS-like drawer curve */
}

/* --- Mobile: kill accidental horizontal scroll, keep media contained ------ */
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: clip; }
img, video { max-width: 100%; }

/* Smooth in-page scrolling (anchor jumps, back-to-top) */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ==========================================================================
   Back-to-top button
   ========================================================================== */
#jv-top {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: var(--jv-accent);
  color: #fff; cursor: pointer;
  box-shadow: 0 8px 24px rgba(196, 22, 16, 0.35);
  opacity: 0; visibility: hidden; transform: translateY(12px) scale(0.9);
  /* Appear snaps in under the 300ms UI bar */
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out),
              visibility 0.2s, background 0.2s ease;
  z-index: 2147483000;
}
#jv-top.jv-show { opacity: 1; visibility: visible; transform: none; }
#jv-top:active { transform: scale(0.94); }   /* press feedback (all pointers) */
#jv-top svg { width: 22px; height: 22px; display: block; }

/* ==========================================================================
   Mobile navigation menu (built + toggled by enhance.js)
   ========================================================================== */
#jv-menu, #jv-scrim { display: none; }

@media (max-width: 809px) {
  #jv-scrim {
    display: block;
    position: fixed; inset: 0;
    background: rgba(15, 15, 20, 0.5);
    opacity: 0; visibility: hidden;
    transition: opacity 0.3s var(--ease-out), visibility 0.3s;
    z-index: 2147483400;
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  }
  #jv-menu {
    display: flex; flex-direction: column;
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(86vw, 340px);
    padding: 22px 22px calc(28px + env(safe-area-inset-bottom));
    background: #fff; color: var(--jv-ink);
    box-shadow: -18px 0 50px rgba(0, 0, 0, 0.28);
    transform: translateX(105%);
    /* Drawer: deliberate slide with the iOS-like curve, within 200-500ms */
    transition: transform 0.4s var(--ease-drawer);
    z-index: 2147483401;
    overflow-y: auto; overscroll-behavior: contain;
    font-family: "Poppins", system-ui, sans-serif;
  }
  html.jv-menu-open #jv-scrim { opacity: 1; visibility: visible; }
  html.jv-menu-open #jv-menu { transform: none; }
  html.jv-menu-open { overflow: hidden; }
}

/* Force the panel to show even if a desktop viewport is used for testing,
   once explicitly opened (keeps parity with the media query above). */
html.jv-menu-open #jv-menu { display: flex; }
html.jv-menu-open #jv-scrim { display: block; }

.jv-menu-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.jv-menu-head strong { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.jv-menu-head strong span { color: var(--jv-accent); }
#jv-close {
  width: 40px; height: 40px; flex: none;
  border: none; border-radius: 50%; cursor: pointer;
  background: #f2f2f4; color: var(--jv-ink);
  display: grid; place-items: center;
  transition: background 0.2s ease, transform 0.14s var(--ease-out);
}
#jv-close:active { transform: scale(0.92); }  /* press feedback */
#jv-close svg { width: 18px; height: 18px; }

.jv-menu-links { list-style: none; margin: 14px 0 0; padding: 0; }
.jv-menu-links a {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 12px; min-height: 48px;
  border-radius: 12px;
  color: var(--jv-ink); text-decoration: none;
  font-size: 17px; font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease, transform 0.14s var(--ease-out);
}
/* Keyboard focus keeps the highlight (no movement needed) */
.jv-menu-links a:focus-visible { background: #faf3f2; color: var(--jv-accent); outline: none; }
.jv-menu-links a:active { transform: scale(0.97); }  /* press feedback */
.jv-menu-links .jv-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--jv-accent); flex: none; opacity: 0.85;
}

.jv-menu-label {
  margin: 18px 12px 4px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.09em; text-transform: uppercase; color: #9a9aa2;
}

.jv-menu-foot { margin-top: auto; padding-top: 20px; }
.jv-lang { display: flex; gap: 8px; margin-bottom: 16px; }
.jv-lang a {
  flex: 1; text-align: center; padding: 10px 8px; border-radius: 10px;
  border: 1.5px solid #ececef; text-decoration: none;
  font-size: 14px; font-weight: 600; color: var(--jv-ink);
  /* Explicit properties only — never `all` */
  transition: background 0.2s ease, border-color 0.2s ease,
              color 0.2s ease, transform 0.14s var(--ease-out);
}
.jv-lang a.jv-active { background: var(--jv-accent); border-color: var(--jv-accent); color: #fff; }
.jv-lang a:active { transform: scale(0.97); }  /* press feedback */
.jv-cta {
  display: block; text-align: center; padding: 15px;
  border-radius: 12px; background: var(--jv-accent); color: #fff;
  text-decoration: none; font-size: 16px; font-weight: 700;
  box-shadow: 0 8px 22px rgba(196, 22, 16, 0.3);
  transition: background 0.2s ease, transform 0.14s var(--ease-out);
}
.jv-cta:active { transform: scale(0.97); }  /* press feedback */

/* --- Hover motion: gated so touch taps don't fire false hovers ----------- */
@media (hover: hover) and (pointer: fine) {
  #jv-top:hover { background: var(--jv-accent-2); transform: translateY(-2px); }
  #jv-close:hover { background: #e7e7ea; transform: rotate(90deg); }
  .jv-menu-links a:hover { background: #faf3f2; color: var(--jv-accent); transform: translateX(4px); }
  .jv-lang a:not(.jv-active):hover { border-color: var(--jv-accent); color: var(--jv-accent); }
  .jv-cta:hover { background: var(--jv-accent-2); transform: translateY(-2px); }
}

/* --- Staggered entrance of menu rows -------------------------------------
   Animation lives on the <li> / foot container; interactive transforms live
   on the inner <a>, so a lingering fill never blocks press feedback. -------- */
@media (prefers-reduced-motion: no-preference) {
  html.jv-menu-open .jv-menu-links li,
  html.jv-menu-open .jv-menu-foot {
    animation: jv-row-in 0.3s var(--ease-out) both;
  }
  html.jv-menu-open .jv-menu-links li:nth-child(1) { animation-delay: 0ms; }
  html.jv-menu-open .jv-menu-links li:nth-child(2) { animation-delay: 40ms; }
  html.jv-menu-open .jv-menu-links li:nth-child(3) { animation-delay: 80ms; }
  html.jv-menu-open .jv-menu-links li:nth-child(4) { animation-delay: 120ms; }
  html.jv-menu-open .jv-menu-links li:nth-child(5) { animation-delay: 160ms; }
  html.jv-menu-open .jv-menu-links li:nth-child(6) { animation-delay: 200ms; }
  html.jv-menu-open .jv-menu-foot { animation-delay: 160ms; }
  @keyframes jv-row-in {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: none; }
  }
}

/* --- Reduced motion: drop movement everywhere, keep things legible -------- */
@media (prefers-reduced-motion: reduce) {
  #jv-menu, #jv-scrim, #jv-top { transition-property: opacity, background, visibility; }
  html.jv-menu-open .jv-menu-links li,
  html.jv-menu-open .jv-menu-foot { animation: none; }
}
