/* ============================================================================
   ADRIANO JEWELRY · base.css
   Reset · document defaults · chapter system (dark/paper) · layout primitives
   (container, 12-col grid, section rhythm) · base typography · a11y · motion law.
   Depends on tokens.css. (CLAUDE.md §1.2 Space & Composition, §1.5 A11y.)
   ============================================================================ */

/* ---- Reset (concise, modern) --------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

html, body { height: 100%; }

body {
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-synthesis: none;
  /* Guard against any stray horizontal overflow without breaking fixed header
     (clip, unlike hidden, creates no scroll container / does not affect fixed). */
  overflow-x: clip;
}

/* The velvet is dark → tell the UA so form controls / scrollbars follow. */
:root { color-scheme: dark; }

img, picture, video, canvas, svg { display: block; max-width: 100%; }
img, video { height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
p, h1, h2, h3, h4, li, figcaption { overflow-wrap: break-word; } /* no long-word overflow */
ul[class], ol[class] { list-style: none; padding: 0; }

/* ---- Smooth anchor scrolling (motion-law gated below) -------------------- */
html { scroll-behavior: smooth; }
:where(a[href^="#"]) { scroll-margin-top: calc(var(--header-h) + env(safe-area-inset-top) + 16px); }
:target { scroll-margin-top: calc(var(--header-h) + env(safe-area-inset-top) + 16px); }

::selection { background: var(--accent); color: var(--bg); }

/* ---- Base typography ------------------------------------------------------ */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: var(--lh-display);
  letter-spacing: var(--ls-display);
  text-wrap: balance;
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); line-height: var(--lh-tight); }

p { text-wrap: pretty; }
strong, b { font-weight: 500; }

a { color: var(--accent); text-decoration: none; text-underline-offset: 0.2em; }
a:where(:hover) { color: var(--accent-bright); }

/* Body prose: constrained measure, readable link underlines */
.prose { max-width: var(--measure); }
.prose p + p { margin-top: var(--space-sm); }
.prose a { text-decoration: underline; text-decoration-color: var(--accent-soft); }
.prose a:hover { text-decoration-color: var(--accent); }

.tnum { font-variant-numeric: tabular-nums; }

/* ---- Chapter system — the lookbook page-turn between darkness & light -----
   Role-based modifiers: --dark (velvet), --surface (elevated), --paper (cream). */
.chapter { padding-block: var(--section-y); position: relative; }
.chapter--dark { background: var(--bg); color: var(--text); }
.chapter--surface { background: var(--surface); color: var(--text); }
.chapter--paper {
  background: var(--paper);
  color: var(--ink);
  --local-dim: var(--ink-dim); /* secondary text token flips on paper */
}
/* On dark chapters, secondary text uses text-dim (AA-safe). */
.chapter--dark, .chapter--surface { --local-dim: var(--text-dim); }
/* Links inside paper chapters keep gold but use the AA-safe darker token.
   Hover darkens to ink — light champagne is ~1.8:1 on cream, never for text. */
.chapter--paper a { color: var(--accent-ink); }
.chapter--paper a:hover { color: var(--ink); }

/* ---- Layout primitives ---------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  /* Blend safe-area insets into the gutter so header/footer content clears the
     notch / rounded corners in landscape (viewport-fit=cover). */
  padding-inline:
    max(var(--gutter), env(safe-area-inset-left))
    max(var(--gutter), env(safe-area-inset-right));
}
/* 12-col grid; children use minmax(0,1fr) so content can't blow out the track. */
.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gutter);
}

/* Stack helper */
.stack > * + * { margin-top: var(--space-sm); }
.stack-lg > * + * { margin-top: var(--space-lg); }

/* ---- Accessibility -------------------------------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed;
  top: var(--space-2xs);
  left: var(--space-2xs);
  z-index: var(--z-skip);
  padding: 0.6em 1em;
  background: var(--accent);
  color: var(--bg);
  font-size: var(--fs-small);
  font-weight: 500;
  letter-spacing: 0.04em;
  border-radius: var(--radius);
  transform: translateY(-160%);
  transition: transform var(--dur-micro) var(--ease-out);
}
.skip-link:focus { transform: translateY(0); color: var(--bg); }

/* Gold focus-visible ring everywhere (2px offset). */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 1px;
}
:focus:not(:focus-visible) { outline: none; }
/* The champagne ring is ~1.8:1 on cream — paper chapters use the dark gold. */
.chapter--paper :focus-visible { outline-color: var(--accent-ink); }

/* ---- Scroll reveals — visible by default; only .js hides, reveal.js shows --- */
.js .reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity var(--dur-reveal) var(--ease-out),
              transform var(--dur-reveal) var(--ease-out);
  transition-delay: var(--reveal-delay, 0ms);
}
.reveal.is-visible { opacity: 1; transform: none; }
/* A focused control may never sit at opacity:0 (WCAG 2.4.7). */
.js .reveal:focus-within,
.js .reveal:focus-visible { opacity: 1; transform: none; }
/* Failsafe: if reveal.js never runs (module 404 / parse error), un-hide
   everything at ~1.5s — the observer adding .is-visible earlier cancels it. */
@media (prefers-reduced-motion: no-preference) {
  .js .reveal { animation: revealFailsafe 0.01s linear 1.5s forwards; }
  .js .reveal.is-visible { animation: none; }
}
@keyframes revealFailsafe { to { opacity: 1; transform: none; } }

/* ---- Cross-page view transitions — a quiet lookbook page-turn --------------
   Progressive enhancement: browsers without cross-document view transitions
   ignore the at-rule and navigate instantly, exactly as before. */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation-duration: 200ms; }
::view-transition-new(root) { animation-duration: 300ms; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  /* Second guard for engines that support view transitions but not the nested
     descriptor: kill the crossfade animation so navigation resolves instantly. */
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
}

/* ---- Motion law — honor prefers-reduced-motion globally ------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
  /* Reduced motion never depends on JS: reveals are simply visible. */
  .js .reveal { opacity: 1; transform: none; transition: none; }
}
