/* ============================================================================
   STORLY CORE — LAYER 1: PRIMITIVES + COMPONENTS
   ----------------------------------------------------------------------------
   The design system is four layers, each owned in exactly one place:

     1. PRIMITIVES   this file — raw scales (radius, shadow, type, motion,
                     spacing, container constants) + the base reset +
                     shared components (.btn / forms / page shell / utilities /
                     cart drawer). No brand colour, no semantic role.
     2. MERCHANT     <style id="storly-global-design-tokens"> from DesignTokens.php,
                     rendered AFTER every stylesheet: --core-primary, --core-text,
                     --core-background, --core-card-*, --core-button-*, --core-font-*
     3. SEMANTIC     core-dna.css (loaded last) — maps layer 2 to the roles every
                     section consumes (--brand / --bg / --text / --btn-* / …) plus
                     the per-section --<prefix>-* contract and the heading scale.
     4. SECTION      each <section>/style.css — consumes layer 3, declares only its
                     own --<prefix>-* locals. No inline hex fallbacks.

   `var()` resolves lazily against the final cascade, so a component here can use
   a role token that core-dna.css defines later. Nothing in this file hard-codes
   a niche or uses !important to win a colour.
   ============================================================================ */

/* ── Self-hosted typeface ──────────────────────────────────────────────────── */
@font-face {
  font-family: "InterVariable";
  src: url("fonts/inter-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ── LAYER 1 — primitive scales ────────────────────────────────────────────── */
:root {
  /* Radius */
  --r-xs: 4px;
  --r-sm: 4px;
  --r: 6px;
  --r-md: 12px;
  --r-lg: 8px;
  --r-xl: 10px;
  --r-pill: 999px;

  /* Elevation — one soft, layered scale */
  --shadow-xs: 0 1px 2px rgba(17, 19, 23, .05);
  --shadow-sm: 0 2px 6px rgba(17, 19, 23, .06);
  --shadow: 0 4px 14px -4px rgba(17, 19, 23, .10), 0 2px 5px rgba(17, 19, 23, .05);
  --shadow-md: 0 14px 38px -14px rgba(17, 19, 23, .13), 0 3px 8px rgba(17, 19, 23, .05);
  --shadow-lg: 0 30px 70px -22px rgba(17, 19, 23, .18), 0 8px 20px rgba(17, 19, 23, .06);
  --shadow-xl: 0 48px 100px -30px rgba(17, 19, 23, .26);

  /* Motion */
  --ease: cubic-bezier(.22, 1, .36, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --dur-fast: 160ms;
  --dur: 260ms;
  --dur-slow: 420ms;

  /* Type — fluid scale for bare h1-h4 on content pages. Section headings resolve
     through core-dna.css's --core-heading-section instead. */
  --fs-xs: 12px;
  --fs-sm: 13.5px;
  --fs-body: 16px;
  --fs-md: 18px;
  --fs-h3: clamp(1.35rem, 1.9vw, 1.8rem);
  --fs-h2: clamp(1.9rem, 3.4vw, 2.9rem);
  --fs-h1: clamp(2.35rem, 5vw, 3.9rem);
  --fs-display: clamp(2.8rem, 6vw, 5rem);
  --lh-tight: 1.05;
  --lh-heading: 1.12;
  --lh-body: 1.62;
  --tracking-tight: -.012em;
  --tracking-label: .12em;

  /* Spacing — ONE ladder. Inner-section gaps resolve against these; section
     vertical rhythm resolves against --core-rhythm (core-dna.css). */
  --space-2xs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 20px;
  --space-lg: 32px;
  --space-xl: clamp(32px, 4vw, 48px);
  --space-2xl: clamp(48px, 6vw, 80px);

  /* Layout constants (the merchant container width lives in layer 2) */
  --container-wide: 1440px;
  --container-reading: 720px;

  /* Semantic constants that are never brand-tinted */
  --accent-contrast: #fff;
  --star: #e8a33d;
  --warning: #b45309;

  /* Focus ring (uses the brand role, resolved lazily) */
  --ring: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);

  /* Component sizing primitives (colours come from layer 3) */
  --btn-padding-y: 14px;
  --btn-padding-x: 26px;
  --btn-font-size: 14px;
}

/* ── Base reset ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
  overflow-x: clip;
}
body {
  margin: 0;
  max-width: 100%;
  overflow-x: clip;
  color: var(--text);
  background: var(--bg);
  font: 400 var(--fs-body)/var(--lh-body) var(--font);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
[dir="rtl"] *, :lang(ar) * { letter-spacing: 0 !important; }
body, button, input, select, textarea { font-family: var(--font); }

h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text);
  line-height: var(--lh-heading);
  letter-spacing: var(--tracking-tight);
  font-weight: 400;
  text-wrap: balance;
}
h1 { font-size: var(--fs-h1); line-height: var(--lh-tight); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
p { text-wrap: pretty; }
a { color: inherit; text-decoration: none; }
img, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
button, [role="button"], a { -webkit-tap-highlight-color: transparent; }
::selection { background: color-mix(in srgb, var(--brand) 18%, transparent); }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
  border-radius: var(--r-xs);
}

/* ── Section shell ────────────────────────────────────────────────────────── */
.storly-section { max-width: 100%; }
.section { padding-block: var(--core-rhythm, 64px); }
.section-sm { padding-block: calc(var(--core-rhythm, 64px) * .72); }
.storly-section.sf-container-narrow .container { max-width: var(--core-track-narrow, 1040px); }
.storly-section.sf-container-wide .container { max-width: var(--container-wide); }
.storly-section.sf-container-full .container { max-width: none; }
.storly-section.sf-align-left { text-align: start; }
.storly-section.sf-align-center { text-align: center; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: var(--btn-padding-y) var(--btn-padding-x);
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  background: var(--btn-bg);
  color: var(--btn-color);
  font-family: var(--font);
  font-size: var(--btn-font-size);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: .01em;
  cursor: pointer;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast),
              box-shadow var(--dur) var(--ease), transform var(--dur-fast) var(--ease), opacity var(--dur-fast);
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-xs); }
.btn-primary { background: var(--btn-bg); color: var(--btn-color); }
.btn-primary:hover { background: var(--btn-hover-bg); color: var(--btn-hover-color); }
.btn-accent { background: var(--accent); color: var(--accent-contrast); }
.btn-accent:hover { background: var(--accent-d); }
.btn-outline { border-color: var(--border-strong); background: transparent; color: var(--text); box-shadow: none; }
.btn-outline:hover { border-color: var(--text); background: var(--text); color: var(--surface); box-shadow: var(--shadow-md); }
.btn-pill { border-radius: var(--r-pill); }
.btn-sm { min-height: 40px; padding: 9px 16px; font-size: 13px; }
.btn-lg { min-height: 54px; padding: 16px 32px; font-size: 15px; }
.btn-full { width: 100%; }
.btn-icon { width: 48px; height: 48px; padding: 0; }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: .48; transform: none; box-shadow: none; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; color: var(--text); font-size: 13px; font-weight: 600; }
.form-group .required { color: var(--danger); }
.form-input {
  width: 100%;
  min-height: 50px;
  padding: 13px 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--input-radius);
  outline: 0;
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background-color var(--dur-fast);
}
.form-input:hover { border-color: var(--text-m); }
.form-input:focus { border-color: var(--brand); box-shadow: var(--ring); }
.form-input::placeholder { color: var(--text-m); }
select.form-input {
  appearance: none;
  padding-inline-end: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238c8c84' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 15px center;
}
[dir="rtl"] select.form-input { background-position: left 15px center; }

/* ── Content-page shell + rich text ──────────────────────────────────────── */
.page-shell { padding-block: calc(var(--core-rhythm, 64px) * .72) var(--core-rhythm, 64px); background: var(--bg); }
.page-shell-inner { max-width: var(--container-reading); }
.page-hero { margin-bottom: 40px; }
.page-kicker { margin-bottom: 12px; color: var(--accent); font-size: var(--fs-xs); font-weight: 700; letter-spacing: var(--tracking-label); text-transform: uppercase; }
.page-title { margin-bottom: 16px; font-family: var(--font-display); font-size: clamp(2.1rem, 4.4vw, 3.4rem); font-weight: 500; letter-spacing: var(--tracking-tight); }
.page-subtitle { max-width: 680px; color: var(--text-s); font-size: var(--fs-md); line-height: 1.6; }
.page-article { border-top: 1px solid var(--border); padding-top: 40px; }
.page-rich-content { color: var(--text); font-size: 16.5px; line-height: 1.85; }
.page-rich-content :where(h1, h2, h3, h4) { margin: 1.5em 0 .55em; }
.page-rich-content :where(p, ul, ol, blockquote, table) { margin: 1em 0; }
.page-rich-content :where(ul, ol) { padding-inline-start: 1.4em; }
.page-rich-content blockquote { border-inline-start: 3px solid var(--accent); padding-block: .5em; padding-inline-start: 1.25em; color: var(--text-s); font-size: 1.15em; }
.page-rich-content a { color: var(--accent-d); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.page-rich-content img { margin-block: 1.5em; border-radius: var(--r); }
.page-rich-content table { display: block; width: 100%; overflow: auto; border-collapse: collapse; }
.page-rich-content :where(td, th) { border: 1px solid var(--border); padding: 10px 12px; text-align: start; }

/* ── Feedback + utilities ────────────────────────────────────────────────── */
.toast {
  position: fixed; z-index: 9999; inset-inline-end: 20px; bottom: 20px;
  display: flex; max-width: min(380px, calc(100vw - 32px)); align-items: center; gap: 10px;
  padding: 14px 18px; border-radius: var(--r-sm); box-shadow: var(--shadow-lg);
  color: #fff; font-size: 14px; font-weight: 600;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast-success { background: #166534; }
.toast-error { background: var(--danger); }
.toast__action {
  margin-inline-start: auto;
  flex: 0 0 auto;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}
.cart-count {
  position: absolute; top: -4px; inset-inline-end: -4px;
  display: flex; min-width: 18px; height: 18px; align-items: center; justify-content: center;
  padding: 0 4px; border: 2px solid var(--surface); border-radius: 999px;
  background: var(--accent); color: var(--accent-contrast); font-size: 12px; font-weight: 700;
}
.skeleton { border-radius: var(--r-xs); background: linear-gradient(100deg, var(--bg-t) 30%, var(--bg-s) 50%, var(--bg-t) 70%); background-size: 200% 100%; animation: sk-shimmer 1.4s ease-in-out infinite; }
@keyframes sk-shimmer { to { background-position: -200% 0; } }
.text-center { text-align: center; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ── Motion: reveal-on-scroll ──
   Guarded by .js-reveal on <html> (theme.js). Without JS everything is visible.
   The reduced-motion reset lives once, in core-dna.css. */
.js-reveal [data-reveal] { opacity: 0; transform: translateY(18px); transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out); will-change: opacity, transform; }
.js-reveal [data-reveal].is-in { opacity: 1; transform: none; }
.js-reveal [data-reveal="fade"] { transform: none; }
.js-reveal [data-reveal-stagger] > * { opacity: 0; transform: translateY(18px); transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out); }
.js-reveal [data-reveal-stagger].is-in > * { opacity: 1; transform: none; }
.js-reveal [data-reveal-stagger].is-in > *:nth-child(2) { transition-delay: 60ms; }
.js-reveal [data-reveal-stagger].is-in > *:nth-child(3) { transition-delay: 120ms; }
.js-reveal [data-reveal-stagger].is-in > *:nth-child(4) { transition-delay: 180ms; }
.js-reveal [data-reveal-stagger].is-in > *:nth-child(5) { transition-delay: 240ms; }
.js-reveal [data-reveal-stagger].is-in > *:nth-child(6) { transition-delay: 300ms; }

@media (prefers-reduced-motion: no-preference) {
  [data-reveal], [data-reveal-stagger] > * { animation: storlyRise 640ms var(--ease-out) both; }
  [data-reveal-stagger] > *:nth-child(2) { animation-delay: 70ms; }
  [data-reveal-stagger] > *:nth-child(3) { animation-delay: 140ms; }
  [data-reveal-stagger] > *:nth-child(4) { animation-delay: 210ms; }
  [data-reveal-stagger] > *:nth-child(5) { animation-delay: 280ms; }
}
@keyframes storlyRise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }

/* ── Responsive foundations — the three canonical breakpoints ─────────────── */
@media (max-width: 767px) {
  .page-article { padding-top: 30px; }
  h1, h2 { overflow-wrap: normal; text-wrap: balance; }
}
@media (min-width: 1025px) { .sf-hide-desktop { display: none !important; } }
@media (min-width: 768px) and (max-width: 1024px) { .sf-hide-tablet { display: none !important; } }
@media (max-width: 767px) { .sf-hide-mobile { display: none !important; } }

/* ============================================================================
   CORE CART DRAWER (component — colours are Global Design roles)
   ============================================================================ */
.storly-cartd { position: fixed; inset: 0; z-index: 9999; }
.storly-cartd[hidden] { display: none; }
.storly-cartd__scrim {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--text) 46%, transparent);
  opacity: 0; transition: opacity 220ms var(--ease);
}
.storly-cartd.is-open .storly-cartd__scrim { opacity: 1; }
.storly-cartd__panel {
  position: absolute; inset-block: 0; inset-inline-end: 0;
  display: flex; flex-direction: column;
  width: min(420px, 100%); max-width: 100%;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 240ms var(--ease);
}
[dir="rtl"] .storly-cartd__panel { transform: translateX(-100%); }
.storly-cartd.is-open .storly-cartd__panel { transform: none; }
.storly-cartd.is-busy .storly-cartd__body { opacity: .55; pointer-events: none; }
.storly-cartd__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.storly-cartd__title { margin: 0; font-family: var(--font-display); font-size: 18px; font-weight: 500; }
.storly-cartd__close {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: var(--btn-radius);
  background: transparent; color: var(--text-s); cursor: pointer;
}
.storly-cartd__close svg { width: 18px; height: 18px; }
.storly-cartd__close:hover { background: var(--bg-s); color: var(--text); }
.storly-cartd__body { flex: 1; overflow-y: auto; padding: 8px 20px; }
.storly-cartd__list { margin: 0; padding: 0; list-style: none; }
.storly-cartd__item {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px;
  align-items: start; padding: 16px 0;
  border-bottom: 1px solid var(--border-l);
}
.storly-cartd__img {
  width: 64px; aspect-ratio: 4/5; object-fit: cover;
  border-radius: var(--card-radius); background: var(--bg-s);
}
.storly-cartd__img--empty { display: block; }
.storly-cartd__meta { min-width: 0; }
.storly-cartd__name { margin: 0; font-size: 14px; font-weight: 550; line-height: 1.35; }
.storly-cartd__variant { margin: 3px 0 0; font-size: 12px; color: var(--text-s); }
.storly-cartd__price { margin: 6px 0 0; font-size: 13.5px; font-weight: 600; }
.storly-cartd__qty { display: inline-flex; align-items: center; gap: 2px; margin-top: 10px;
  border: 1px solid var(--border); border-radius: var(--btn-radius); }
.storly-cartd__qty button {
  width: 30px; height: 30px; border: 0; background: transparent;
  color: var(--text); font-size: 15px; cursor: pointer;
}
.storly-cartd__qty span { min-width: 26px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.storly-cartd__remove {
  border: 0; background: transparent; color: var(--text-s);
  cursor: pointer; padding: 4px; border-radius: 6px;
}
.storly-cartd__remove svg { width: 15px; height: 15px; }
.storly-cartd__remove:hover { color: var(--danger); }
.storly-cartd__empty { padding: 56px 8px; text-align: center; color: var(--text-s); }
.storly-cartd__empty-title { margin: 0 0 12px; font-size: 15px; }
.storly-cartd__foot { padding: 16px 20px 20px; border-top: 1px solid var(--border); }
.storly-cartd__subtotal {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 14px; font-size: 14px;
}
.storly-cartd__subtotal strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.storly-cartd__cta {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px; border-radius: var(--btn-radius);
  background: var(--btn-bg); color: var(--btn-color);
  font-size: 14.5px; font-weight: 600; text-decoration: none;
}
.storly-cartd__cta:hover { background: var(--btn-hover-bg); }
.storly-cartd__link {
  display: block; margin-top: 10px; text-align: center;
  font-size: 13px; color: var(--text-s); text-decoration: underline;
  text-underline-offset: 3px;
}
body.storly-cartd-open { overflow: hidden; }
@media (max-width: 520px) {
  .storly-cartd__panel { width: 100%; }
  .storly-cartd__item { grid-template-columns: 56px 1fr auto; }
  .storly-cartd__img { width: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  .storly-cartd__panel, .storly-cartd__scrim { transition: none; }
}
