/* ==========================================================================
   SILVARIS — cross-browser + multi-device polish
   Loads last. Safe fallbacks for Safari, Firefox, older Chromium, iOS, Android.
   ========================================================================== */

/* ---- Viewport / root ---- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: rgba(194, 75, 66, 0.15);
  text-rendering: optimizeLegibility;
}

/* Prevent iOS rubber-band horizontal scroll */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Safe areas (notched iPhones, Android cutouts) */
.bar {
  padding-left: max(var(--gutter, 1.25rem), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter, 1.25rem), env(safe-area-inset-right, 0px));
  padding-top: max(0.55rem, env(safe-area-inset-top, 0px));
}

.header {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.mnav__panel,
.drawer {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* WP admin bar + sticky header */
.admin-bar .header {
  top: 32px;
}
@media screen and (max-width: 782px) {
  .admin-bar .header {
    top: 46px;
  }
}
.admin-bar .hist-rail {
  top: calc(50% + 16px);
}
@media screen and (max-width: 782px) {
  .admin-bar .hist-rail {
    top: auto;
    bottom: calc(0.75rem + 46px);
  }
}

/* ---- Layout helpers (older browser fallbacks) ---- */
.wrap {
  width: 92%;
  width: min(100% - var(--gutter) * 2, var(--max));
  margin-left: auto;
  margin-right: auto;
  /* margin-inline already in main.css */
}

/* overflow: clip is modern — hide as fallback where used */
.history-page--v2 .hist-cinema,
.history-page--v2 .history-timeline--epic {
  overflow: hidden;
}

/* text-wrap: balance — ignore if unsupported (progressive) */
@supports not (text-wrap: balance) {
  .hist-chapter__title,
  .hist-cinema__portal h2 {
    /* already fine without balance */
  }
}

/* ---- Media ---- */
img,
video,
svg,
canvas {
  max-width: 100%;
  height: auto;
}

img[width][height] {
  height: auto; /* keep aspect when only width constrained */
}

/* Avoid broken aspect-ratio containers in very old browsers */
@supports not (aspect-ratio: 1) {
  .history-era__visual-frame,
  .hist-chapter__media {
    min-height: 12rem;
  }
}

/* ---- Forms: stop iOS zoom on focus (needs ≥16px) ---- */
@media (max-width: 900px) {
  input,
  select,
  textarea,
  .woocommerce form .input-text,
  .woocommerce form select,
  .woocommerce-input-wrapper input,
  .woocommerce-input-wrapper select,
  .contact-form input,
  .contact-form textarea,
  .nl-popup input,
  [data-newsletter-popup] input {
    font-size: 16px !important;
  }
}

/* Touch targets */
@media (pointer: coarse) {
  .btn,
  .burger,
  .header__account,
  .header__cart,
  .hist-rail__btn,
  .history-chip,
  .faq-item button,
  [data-faq] button,
  .mnav a,
  .footer a {
    min-height: 2.75rem;
  }

  .hist-rail__btn {
    min-width: 2.5rem;
  }
}

/* ---- Header / nav ---- */
@media (max-width: 1023px) {
  .nav-desktop {
    display: none !important;
  }
  .burger {
    display: inline-flex !important;
  }
}

/* Fixed mobile nav: use dynamic viewport when available */
.mnav {
  height: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: -webkit-fill-available;
}

.mnav__panel {
  max-height: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  max-height: -webkit-fill-available;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Body lock when menu/cart open.
   Works with JS position:fixed pin (Chrome Android, DDG WebView, iOS Safari).
   Do NOT use touch-action:none on html/body — freezes everything if drawer fails. */
html.silvaris-lock {
  overflow: hidden !important;
  height: 100%;
  overscroll-behavior: none;
}
body.silvaris-lock {
  overflow: hidden !important;
  overscroll-behavior: none;
  overscroll-behavior-y: none;
  /* width handled in JS; avoid horizontal shift */
  max-width: 100vw;
}
/* Drawer / mobile menu must remain scrollable while page is locked */
body.silvaris-lock .drawer,
body.silvaris-lock .drawer__body,
body.silvaris-lock .drawer__foot,
body.silvaris-lock .mnav__panel,
body.silvaris-lock .mnav__list {
  touch-action: pan-y;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* Mobile menu stack above content but below bag when both race */
body.silvaris-lock .mnav {
  z-index: 10065;
}

/* ---- Hero: reliable full viewport ---- */
.hero {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

/* Soften heavy filters on low-power / coarse pointers */
@media (pointer: coarse) {
  .hero__wash,
  .hist-cinema__orb {
    filter: none;
    opacity: 0.45;
  }
  .hero--banner .hero__media > img {
    animation: none !important;
    transform: none !important;
    will-change: auto !important;
  }
  .hero__media {
    will-change: auto !important;
    transform: none !important;
  }
  /* Kill expensive compositing layers on mobile */
  .hero__fx,
  .hero__aurora,
  .hero__blob,
  .hero__orbit,
  .hero__particles,
  .hero__bubbles,
  .hero__spark,
  .hero__pulse,
  .hero__drop,
  .hero__spotlight,
  .hero__float-badge {
    display: none !important;
    animation: none !important;
  }
  .hero--playful .hero__wash,
  .hero__wash {
    display: none !important;
  }
  .hero__shade {
    opacity: 0.95;
  }
  .hero--banner .hero__body {
    animation: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(6, 18, 16, 0.82) !important;
  }
  .hero--banner .hero__body::after {
    display: none !important;
  }
  .hero__ticker {
    display: none !important;
  }
}

/* Lite / DuckDuckGo / WebView: fully static hero + simple menu (no GPU thrash) */
html.is-lite .hero,
html.is-ddg .hero,
html.is-webview .hero,
.hero.is-static {
  overflow: hidden;
}
html.is-lite .hero__fx,
html.is-ddg .hero__fx,
html.is-webview .hero__fx,
.hero.is-static .hero__fx,
html.is-lite .hero__ticker,
html.is-ddg .hero__ticker,
.hero.is-static .hero__ticker {
  display: none !important;
}
html.is-lite .hero--banner .hero__media > img,
html.is-ddg .hero--banner .hero__media > img,
html.is-webview .hero--banner .hero__media > img,
.hero.is-static .hero__media > img {
  animation: none !important;
  transform: none !important;
  will-change: auto !important;
  object-fit: cover;
}
html.is-lite .hero__media,
html.is-ddg .hero__media,
.hero.is-static .hero__media {
  transform: none !important;
  will-change: auto !important;
}
html.is-lite .hero--banner .hero__body,
html.is-ddg .hero--banner .hero__body,
.hero.is-static .hero--banner .hero__body,
.hero.is-static .hero__body {
  animation: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  background: rgba(6, 18, 16, 0.86) !important;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
html.is-lite .hero--banner .hero__body::after,
html.is-ddg .hero--banner .hero__body::after,
.hero.is-static .hero__body::after {
  display: none !important;
}
html.is-lite .hero h1 em,
html.is-ddg .hero h1 em,
.hero.is-static h1 em {
  animation: none !important;
  -webkit-text-fill-color: #f4c7c1 !important;
  background: none !important;
  color: #f4c7c1 !important;
}

/* ---- Mobile menu: solid, high z-index, no blur (DDG-safe) ---- */
.mnav {
  z-index: 10090 !important;
  /* Avoid opacity+visibility-only open which can flash under fixed header in WebViews */
}
.mnav__backdrop {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  background: rgba(4, 14, 13, 0.62) !important;
}
.mnav__panel {
  /* Prefer translate3d for stable compositing; no glow animation */
  -webkit-transform: translate3d(100%, 0, 0);
  transform: translate3d(100%, 0, 0);
  transition: transform 0.28s ease, -webkit-transform 0.28s ease !important;
  will-change: transform;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Solid fill — multi-gradient + animation causes DDG flicker */
  background: #0b2522 !important;
}
.mnav.is-open .mnav__panel {
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}
.mnav__glow {
  display: none !important;
  animation: none !important;
}
html.is-lite .mnav,
html.is-ddg .mnav,
html.is-webview .mnav {
  transition: none !important;
}
html.is-lite .mnav__panel,
html.is-ddg .mnav__panel,
html.is-webview .mnav__panel {
  transition: transform 0.2s ease, -webkit-transform 0.2s ease !important;
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.4);
}
/* When menu open, hide sticky buy so it doesn't paint over the sheet */
body.silvaris-lock .sticky-buy {
  visibility: hidden !important;
  pointer-events: none !important;
}
/* Header stays under menu sheet */
.header {
  z-index: 110;
}
html.is-lite .header,
html.is-ddg .header {
  /* Avoid backdrop blur on sticky header (common WebView glitch) */
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  background: rgba(247, 244, 238, 0.97) !important;
}
.header.is-scrolled {
  /* keep solid when scrolled on lite */
}
html.is-lite .header.is-scrolled,
html.is-ddg .header.is-scrolled {
  background: #f7f4ee !important;
  box-shadow: 0 1px 0 rgba(28, 27, 31, 0.08);
}

/* ---- Cart drawer ---- */
.drawer {
  max-width: 100vw;
  -webkit-overflow-scrolling: touch;
}
.drawer__body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---- History cinema: sticky story (desktop) + safe stack (mobile/tablet) ---- */
.history-page--v2 .hist-chapter__media {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
}

.history-page--v2 .hist-chapter__flow {
  margin-top: -100vh;
  margin-top: -100svh;
  margin-top: -100dvh;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
}

/* iOS Safari: stacked chapters (sticky + negative margin is unreliable) */
html.is-ios .history-page--v2 .hist-chapter__media {
  position: relative;
  top: auto;
  height: auto;
  min-height: 40vh;
  aspect-ratio: 16 / 11;
}
html.is-ios .history-page--v2 .hist-chapter__flow {
  margin-top: 0;
  min-height: 0;
}
html.is-ios .history-page--v2 .hist-chapter__hook {
  min-height: 0;
  margin-top: -4.5rem;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(5, 13, 12, 0.55) 28%,
    #050d0c 70%
  );
}
html.is-ios .history-page--v2 .hist-chapter__stage,
html.is-ios .history-page--v2 .hist-chapter__hook-inner {
  transform: none;
  opacity: 1;
}

/* Sticky + negative-margin can glitch on small viewports — use stacked chapters */
@media (max-width: 900px) {
  /* Never smooth-scroll the document on history — fights finger scroll on Chrome */
  html:has(.history-page--v2) {
    scroll-behavior: auto !important;
  }
  .history-page--v2 .hist-chapter {
    min-height: 0;
    /* Avoid 100svh chapters that reflow when Chrome URL bar shows/hides → scroll jumps */
    overflow: visible;
  }
  .history-page--v2 .hist-chapter__media {
    /* Override desktop sticky (main.css) — sticky+URL-bar = scroll-to-top on Chrome */
    position: relative !important;
    top: auto !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    height: auto !important;
    max-height: none !important;
    min-height: 38vh;
    min-height: 38svh;
    aspect-ratio: 16 / 11;
  }
  .history-page--v2 .hist-chapter__media img {
    animation: none !important;
    transform: none !important;
    will-change: auto !important;
    filter: saturate(0.95) brightness(0.58) !important;
  }
  .history-page--v2 .hist-chapter.is-active .hist-chapter__media img {
    animation: none !important;
    transform: none !important;
  }

  .history-page--v2 .hist-chapter__flow {
    margin-top: 0 !important;
    min-height: 0;
    padding-bottom: 5.5rem;
  }

  .history-page--v2 .hist-chapter__hook {
    min-height: 0;
    margin-top: -4.5rem;
    padding-top: 0.5rem;
    padding-bottom: 1rem;
    background: linear-gradient(
      to bottom,
      transparent 0%,
      rgba(5, 13, 12, 0.55) 28%,
      #050d0c 70%
    );
  }

  .history-page--v2 .hist-chapter__hook .hist-chapter__watermark {
    font-size: clamp(2.5rem, 14vw, 4rem);
    top: 0.5rem;
    opacity: 0.35;
  }

  .history-page--v2 .hist-chapter__hook .hist-chapter__giant-n {
    font-size: 3.5rem;
    opacity: 0.4;
  }

  .history-page--v2 .hist-chapter__stage {
    transform: none;
    opacity: 1;
  }

  .history-page--v2 .hist-chapter__hook-inner {
    transform: none;
    opacity: 1;
  }

  /* Bottom rail clear of home indicators */
  .history-page--v2 .hist-rail {
    bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
    left: max(0.65rem, env(safe-area-inset-left, 0px));
    right: max(0.65rem, env(safe-area-inset-right, 0px));
  }
}

/* Desktop: keep rail clear of edges */
@media (min-width: 901px) {
  .history-page--v2 .hist-rail {
    right: max(1rem, env(safe-area-inset-right, 0px));
  }
}

/* Firefox: slightly stronger panel bg (backdrop weaker) */
@-moz-document url-prefix() {
  .history-page--v2 .hist-chapter__stage,
  .history-page--v2 .hist-rail,
  .header {
    background-color: rgba(11, 37, 34, 0.92);
  }
  .header {
    background-color: rgba(247, 244, 238, 0.97);
  }
  .history-page--v2 .hist-chapter__stage {
    background: linear-gradient(160deg, rgba(11, 37, 34, 0.95), rgba(5, 13, 12, 0.92));
  }
}

/* Safari: force GPU for sticky media (reduces flicker) */
@media (min-width: 901px) {
  .history-page--v2 .hist-chapter__media {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
  }
}

/* ---- Site-wide responsive polish ---- */

/* Sections don't overflow gutters */
.section,
main,
.footer {
  max-width: 100%;
}

/* Product / grid cards: consistent on narrow screens */
@media (max-width: 600px) {
  h1 {
    font-size: clamp(2.1rem, 9vw, 2.85rem);
  }
  h2 {
    font-size: clamp(1.75rem, 7vw, 2.25rem);
  }

  .btns {
    flex-direction: column;
    align-items: stretch;
  }

  .btns .btn {
    width: 100%;
  }

  .hero .btns {
    width: 100%;
  }
}

/* Tables (legal/Woo) scroll instead of blowing layout */
table {
  max-width: 100%;
}
.woocommerce table.shop_table,
.entry-content table,
.wp-block-table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Footer stacking */
@media (max-width: 700px) {
  .footer__top,
  .footer__cols,
  .footer__grid {
    grid-template-columns: 1fr !important;
  }
  .footer__bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    text-align: left;
  }
}

/* Cookie / newsletter overlays */
[data-cookie-banner],
[data-newsletter-popup],
.cookie-banner,
.nl-popup {
  max-width: 100vw;
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
  padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

/* Focus: visible for keyboard, not thick ring on mouse */
:focus:not(:focus-visible) {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--coral, #c24b42);
  outline-offset: 3px;
}

/* Buttons/links: no 300ms delay on old mobile browsers */
a,
button,
.btn,
input,
select,
textarea,
label {
  touch-action: manipulation;
}

/* Sticky buy bar clear of home indicator */
.sticky-buy {
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
}

/* Journey / chip horizontal rails */
.history-journey__track,
.history-nav,
[data-history-nav] {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}

/* Reduce motion: kill heavy ken burns site-wide (extra safety) */
@media (prefers-reduced-motion: reduce) {
  .hero--banner .hero__media > img,
  .hist-chapter.is-active .hist-chapter__media img,
  .history-era.is-active .history-era__visual-frame img,
  .bar {
    animation: none !important;
  }
  html {
    scroll-behavior: auto !important;
  }
}

/* High contrast / forced colors (Windows) */
@media (forced-colors: active) {
  .btn,
  .hist-rail__btn,
  .header {
    border: 1px solid ButtonText;
  }
  .hist-chapter__stage {
    border: 1px solid CanvasText;
  }
}

/* Print: readable product + history */
@media print {
  .bar,
  .header,
  .mnav,
  .drawer,
  .hist-rail,
  .sticky-buy,
  [data-cookie-banner],
  [data-newsletter-popup],
  .footer__social {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
  }
  .hist-chapter__media img {
    max-height: 180px;
    object-fit: cover;
  }
  .hist-chapter__flow {
    margin-top: 0 !important;
  }
  a[href]::after {
    content: none !important;
  }
}

/* ---- Contact / content pages ---- */
@media (max-width: 640px) {
  .contact-layout,
  .page-hero,
  .section-head {
    text-align: left;
  }
}

/* ---- WooCommerce mobile polish ---- */
@media (max-width: 768px) {
  .woocommerce .col2-set,
  .woocommerce-page .col2-set {
    display: block !important;
  }
  .woocommerce .col2-set .col-1,
  .woocommerce .col2-set .col-2,
  .woocommerce-page .col2-set .col-1,
  .woocommerce-page .col2-set .col-2 {
    width: 100% !important;
    float: none !important;
    max-width: 100% !important;
  }

  .woocommerce table.cart td.actions .coupon {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }

  .woocommerce table.cart td.actions .coupon .input-text,
  .woocommerce table.cart td.actions .coupon .button {
    width: 100% !important;
    margin: 0 !important;
  }
}

/* Checkout focus shell: full height on mobile browsers */
.silvaris-checkout-focus,
body.silvaris-checkout-focus {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---- Utility: prevent flex/grid children from overflowing ---- */
.hist-chapter__stage,
.hist-chapter__body-grid,
.hist-chapter__copy,
.hist-chapter__side,
.product-layout,
.footer__intro {
  min-width: 0;
}

/* Long unbroken strings */
.hist-chapter__title,
.hist-chapter__copy p,
.entry-content p {
  overflow-wrap: anywhere;
  word-wrap: break-word;
}

/* Safari button appearance reset (keep design) */
button,
[type="button"],
[type="submit"] {
  -webkit-appearance: none;
  appearance: none;
}

/* Select / number inputs */
select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23123F3A' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.25rem;
}

input[type="number"] {
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
