/* =========================================================================
   ReviewFlow — Design System
   Direction: editorial receipt. Cream paper, charcoal ink, terracotta stamp.
   This file holds tokens + primitives only. Page-specific layout lives
   in landing.css / app.css.
   ========================================================================= */

/* ----- 1. Tokens ------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Brand constants */
  --ink:            #151312;
  --cream:          #F2EBDF;
  --terracotta:     #C8624A;

  /* Derived ink scale */
  --ink-900:        #151312;
  --ink-800:        #221F1C;
  --ink-700:        #35302C;
  --ink-500:        #5E564F;
  --ink-400:        #665D55;
  --ink-300:        #A79D92;

  /* Derived paper scale */
  --paper-0:        #FBF7F0;   /* raised surface */
  --paper-1:        #F2EBDF;   /* page */
  --paper-2:        #E9E0D1;   /* sunken / inset */
  --paper-3:        #DFD4C1;   /* edge */

  /* Terracotta scale */
  --clay-100:       #F6E2DA;
  --clay-300:       #D9927B;
  --clay-500:       #C8624A;
  --clay-700:       #A34C37;
  --clay-900:       #7A3624;

  /* Semantic roles */
  --surface:            var(--paper-1);
  --surface-raised:     var(--paper-0);
  --surface-sunken:     var(--paper-2);
  --surface-inverse:    var(--ink-900);
  --text-primary:       var(--ink-900);
  --text-secondary:     var(--ink-500);
  --text-muted:         var(--ink-400);
  --text-on-inverse:    var(--paper-1);
  --text-on-accent:     #FFF6EF;
  /* Three accent roles, because one terracotta cannot do all three jobs at
     WCAG AA on cream:
       --accent        brand terracotta: rules, icons, fills, large display text
       --accent-text   the step that clears 4.5:1 for small terracotta text
       --accent-solid  the fill a filled button uses under cream text        */
  --accent:             var(--clay-500);
  --accent-text:        var(--clay-700);
  --accent-solid:       #AE5239;
  --accent-hover:       var(--clay-700);
  --accent-quiet:       var(--clay-100);

  /* Inverted panels (dark CTA blocks) keep their own scale. These do NOT
     flip in dark mode — in dark they lift one step so the panel is still
     readable as a distinct surface. */
  --panel-bg:     #151312;
  --panel-fg:     #F2EBDF;
  --panel-fg-dim: color-mix(in srgb, #F2EBDF 70%, transparent);
  --panel-bd:     transparent;

  /* Hairlines — the primary structural device in this system */
  --rule:        color-mix(in srgb, var(--ink) 14%, transparent);
  --rule-strong: color-mix(in srgb, var(--ink) 28%, transparent);
  --rule-accent: color-mix(in srgb, var(--accent) 45%, transparent);

  /* Status (reserved — never reused as a series colour) */
  --status-good:     #2F7A5F;
  --status-warn:     #9A6B12;
  --status-critical: #A34C37;
  --status-neutral:  #8C8279;

  /* Data-viz roles (validated: see README "Chart palette") */
  --series-1:        #C8624A;
  --series-2:        #0F6E9C;
  --funnel-1:        #D9927B;
  --funnel-2:        #C8624A;
  --funnel-3:        #91422B;
  --sent-pos:        #2F7A5F;
  --sent-neu:        #8C8279;
  --sent-neg:        #A34C37;
  --viz-grid:        color-mix(in srgb, var(--ink) 10%, transparent);
  --viz-axis:        color-mix(in srgb, var(--ink) 22%, transparent);

  /* Type families */
  --font-display: "Fraunces", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Type scale — 1.25 modular, fluid at the top end */
  --fs-micro:   0.6875rem;  /* 11px — mono labels only */
  --fs-xs:      0.75rem;
  --fs-sm:      0.8125rem;
  --fs-base:    0.9375rem;
  --fs-md:      1.0625rem;
  --fs-lg:      clamp(1.125rem, 1.05rem + 0.35vw, 1.3125rem);
  --fs-xl:      clamp(1.375rem, 1.24rem + 0.6vw, 1.625rem);
  --fs-2xl:     clamp(1.75rem, 1.5rem + 1.1vw, 2.25rem);
  --fs-3xl:     clamp(2rem, 1.65rem + 1.6vw, 2.875rem);
  --fs-display: clamp(2.625rem, 1.65rem + 4vw, 4.5rem);

  --lh-tight:   1.04;
  --lh-snug:    1.18;
  --lh-normal:  1.5;
  --lh-relaxed: 1.65;

  --ls-display: -0.028em;
  --ls-tight:   -0.015em;
  --ls-normal:  0em;
  --ls-label:   0.14em;   /* mono eyebrow tracking */

  /* Spacing — 4px base */
  --s-1:  0.25rem;  --s-2:  0.5rem;   --s-3:  0.75rem;  --s-4:  1rem;
  --s-5:  1.5rem;   --s-6:  2rem;     --s-7:  3rem;     --s-8:  4rem;
  --s-9:  6rem;     --s-10: 8rem;     --s-11: 10rem;

  --section-y: clamp(3.5rem, 2.6rem + 4.2vw, 6.5rem);

  /* Layout */
  --container:   75rem;      /* 1200 */
  --container-w: 78.5rem;    /* 1256 wide variant */
  --gutter:      clamp(1.25rem, 0.6rem + 3vw, 4rem);

  /* Shape — crisp, near-square. Roundness is used sparingly. */
  --r-xs:   2px;
  --r-sm:   4px;
  --r-md:   8px;
  --r-lg:   14px;
  --r-pill: 999px;

  /* Elevation — paper, not glass. Warm shadows, never blue-grey. */
  --shadow-sm: 0 1px 2px color-mix(in srgb, var(--ink) 8%, transparent);
  --shadow-md: 0 2px 4px color-mix(in srgb, var(--ink) 6%, transparent),
               0 8px 24px -12px color-mix(in srgb, var(--ink) 22%, transparent);
  --shadow-lg: 0 4px 8px color-mix(in srgb, var(--ink) 6%, transparent),
               0 24px 56px -24px color-mix(in srgb, var(--ink) 30%, transparent);

  /* Motion — see README "Motion personality" */
  --dur-instant: 90ms;
  --dur-quick:   160ms;
  --dur-base:    220ms;
  --dur-slow:    380ms;
  --dur-scene:   620ms;

  --ease-standard: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-entrance: cubic-bezier(0.16, 1, 0.30, 1);
  --ease-exit:     cubic-bezier(0.40, 0.00, 1, 1);
  --ease-settle:   cubic-bezier(0.34, 1.32, 0.64, 1);

  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

/* Dark mode is *selected*, not inverted: charcoal page, warmer ink-on-dark
   ramp, and its own validated chart steps. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
  :root:not([data-theme="light"]) {
    --paper-0: #211E1B; --paper-1: #151312; --paper-2: #100E0D; --paper-3: #2C2825;
    --text-primary: #F4EEE4;
    --text-secondary: #B7ADA1;
    --text-muted: #9C9289;
    --text-on-inverse: var(--ink-900);
    --surface-inverse: #F2EBDF;
    --panel-bg: #221F1C;
    --panel-bd: color-mix(in srgb, #F2EBDF 12%, transparent);
    --accent: #D6705A;
    --accent-text: #D6705A;
    --accent-solid: #D6705A;
    --text-on-accent: #1A0E0A;
    --accent-hover: #E4866F;
    --accent-quiet: #34211B;
    --rule:        color-mix(in srgb, #F2EBDF 14%, transparent);
    --rule-strong: color-mix(in srgb, #F2EBDF 30%, transparent);
    --rule-accent: color-mix(in srgb, var(--accent) 50%, transparent);
    --series-1: #D6705A; --series-2: #3E9BC4;
    --funnel-1: #E8A38C; --funnel-2: #C8624A; --funnel-3: #7A3624;
    --sent-pos: #5FB08C; --sent-neu: #A89C90; --sent-neg: #E0806A;
    --viz-grid: color-mix(in srgb, #F2EBDF 10%, transparent);
    --viz-axis: color-mix(in srgb, #F2EBDF 24%, transparent);
    --status-good: #5FB08C; --status-warn: #C9A227; --status-critical: #E0806A; --status-neutral: #A89C90;
    --shadow-md: 0 2px 4px #0000004d, 0 8px 24px -12px #00000080;
    --shadow-lg: 0 4px 8px #0000004d, 0 24px 56px -24px #000000a6;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper-0: #211E1B; --paper-1: #151312; --paper-2: #100E0D; --paper-3: #2C2825;
  --text-primary: #F4EEE4;
  --text-secondary: #B7ADA1;
  --text-muted: #9C9289;
  --text-on-inverse: var(--ink-900);
  --surface-inverse: #F2EBDF;
  --panel-bg: #221F1C;
  --panel-bd: color-mix(in srgb, #F2EBDF 12%, transparent);
  --accent: #D6705A;
  --accent-text: #D6705A;
  --accent-solid: #D6705A;
  --text-on-accent: #1A0E0A;
  --accent-hover: #E4866F;
  --accent-quiet: #34211B;
  --rule:        color-mix(in srgb, #F2EBDF 14%, transparent);
  --rule-strong: color-mix(in srgb, #F2EBDF 30%, transparent);
  --rule-accent: color-mix(in srgb, var(--accent) 50%, transparent);
  --series-1: #D6705A; --series-2: #3E9BC4;
  --funnel-1: #E8A38C; --funnel-2: #C8624A; --funnel-3: #7A3624;
  --sent-pos: #5FB08C; --sent-neu: #A89C90; --sent-neg: #E0806A;
  --viz-grid: color-mix(in srgb, #F2EBDF 10%, transparent);
  --viz-axis: color-mix(in srgb, #F2EBDF 24%, transparent);
  --status-good: #5FB08C; --status-warn: #C9A227; --status-critical: #E0806A; --status-neutral: #A89C90;
  --shadow-md: 0 2px 4px #0000004d, 0 8px 24px -12px #00000080;
  --shadow-lg: 0 4px 8px #0000004d, 0 24px 56px -24px #000000a6;
}

/* ----- 2. Reset -------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Anchor targets clear the sticky headers */
  scroll-padding-top: 6rem;
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  font-feature-settings: "cv05" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100%;
}

img, svg, canvas { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
ul, ol { padding: 0; list-style: none; }
h1, h2, h3, h4 { font-weight: 400; line-height: var(--lh-snug); text-wrap: balance; }
p { text-wrap: pretty; }
table { border-collapse: collapse; width: 100%; }

/* ----- 3. Accessibility primitives ------------------------------------- */

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.skip-link {
  position: absolute; left: var(--s-4); top: var(--s-4);
  transform: translateY(-160%);
  z-index: 200;
  background: var(--text-primary); color: var(--surface);
  padding: var(--s-3) var(--s-5);
  font: 500 var(--fs-sm)/1 var(--font-sans);
  border-radius: var(--r-sm);
  transition: transform var(--dur-base) var(--ease-entrance);
}
.skip-link:focus { transform: translateY(0); }

/* ----- 4. Layout primitives -------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container--wide { max-width: var(--container-w); }

.section { padding-block: var(--section-y); }

.stack > * + * { margin-top: var(--flow, var(--s-4)); }

/* ----- 5. Typographic primitives --------------------------------------- */

.display {
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 0, "WONK" 1, "opsz" 120;
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-display);
}
.h2 {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-variation-settings: "SOFT" 0, "WONK" 1, "opsz" 72;
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-display);
}
.h3 {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-snug);
}
.h4 {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: 560;
  letter-spacing: var(--ls-tight);
}

.lede {
  font-size: var(--fs-lg);
  line-height: var(--lh-relaxed);
  color: var(--text-secondary);
  max-width: 46ch;
}
.body-copy { color: var(--text-secondary); line-height: var(--lh-relaxed); max-width: 62ch; }
.small { font-size: var(--fs-sm); color: var(--text-secondary); }

/* The eyebrow "stamp" — the system's most recognisable small element. */
.eyebrow {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: 500;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
}
.eyebrow::before {
  content: ""; inline-size: 1.25rem; block-size: 1px;
  background: var(--accent); flex: none;
}
.eyebrow--bare::before { display: none; }

/* Numbered section marker: 01 / 02 / 03 */
.marker {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--ls-label);
  color: var(--accent-text);
  font-variant-numeric: tabular-nums;
}

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

.mono {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

/* Accent underline for a single emphasised phrase. Drawn, not straight. */
.mark-underline {
  position: relative;
  isolation: isolate;   /* keeps the z-index:-1 stroke inside this span */
  white-space: nowrap;
}
.mark-underline::after {
  content: "";
  position: absolute; left: -0.04em; right: -0.04em; bottom: 0.02em;
  block-size: 0.34em;
  background: var(--accent);
  opacity: 0.22;
  border-radius: var(--r-xs);
  z-index: -1;
  transform-origin: left center;
  transform: scaleX(1);
}
/* With JS the stroke draws in when the line arrives; without it, it's just there. */
.js .mark-underline::after {
  transform: scaleX(0);
  transition: transform var(--dur-slow) var(--ease-standard);
}
.js .mark-underline.is-marked::after { transform: scaleX(1); }
.js.motion-failed .mark-underline::after { transform: scaleX(1); }
@media (prefers-reduced-motion: reduce) {
  .js .mark-underline::after { transform: scaleX(1); }
}

/* ----- 6. Rules & paper texture ---------------------------------------- */

.rule { border: 0; border-top: 1px solid var(--rule); }
.rule--strong { border-top-color: var(--rule-strong); }

/* Perforated edge — the "receipt" signature. */
.perf {
  --perf-size: 10px;
  position: relative;
}
.perf::after {
  content: "";
  position: absolute; inset-inline: 0; bottom: calc(var(--perf-size) / -2);
  block-size: var(--perf-size);
  background:
    radial-gradient(circle at center,
      var(--surface) 0 calc(var(--perf-size) / 2 - 0.5px),
      transparent calc(var(--perf-size) / 2));
  background-size: calc(var(--perf-size) * 1.8) var(--perf-size);
  background-position: center;
  background-repeat: repeat-x;
  pointer-events: none;
}

/* Paper grain. One tiny inline SVG, fixed, never repainted. */
.grain {
  position: fixed; inset: 0; z-index: 1;
  pointer-events: none;
  opacity: 0.4;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.28'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .grain { mix-blend-mode: screen; opacity: 0.16; }
}
:root[data-theme="dark"] .grain { mix-blend-mode: screen; opacity: 0.16; }

/* ----- 7. Buttons ------------------------------------------------------ */

.btn {
  --btn-bg: transparent;
  --btn-fg: var(--text-primary);
  --btn-bd: var(--rule-strong);
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  min-block-size: 2.875rem;
  padding: 0.75rem 1.375rem;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 540;
  letter-spacing: -0.006em;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color var(--dur-quick) var(--ease-standard),
    border-color var(--dur-quick) var(--ease-standard),
    color var(--dur-quick) var(--ease-standard),
    transform var(--dur-instant) var(--ease-standard);
}
.btn:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.btn:active { transform: translateY(1px); }

.btn--primary {
  --btn-bg: var(--accent-solid);
  --btn-fg: var(--text-on-accent);
  --btn-bd: var(--accent-solid);
}
.btn--primary:hover { --btn-bg: var(--accent-hover); --btn-bd: var(--accent-hover); }

.btn--ink {
  --btn-bg: var(--panel-bg); --btn-fg: var(--panel-fg); --btn-bd: var(--panel-bg);
}
.btn--ink:hover { --btn-bg: var(--ink-700); --btn-bd: var(--ink-700); }

.btn--ghost { --btn-bd: transparent; }
.btn--quiet { --btn-bd: var(--rule); --btn-fg: var(--text-secondary); }

.btn--lg { min-block-size: 3.375rem; padding: 0.9375rem 1.75rem; font-size: var(--fs-md); }
.btn--block { inline-size: 100%; }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.45; pointer-events: none;
}

/* ----- 8. Surfaces ----------------------------------------------------- */

.card {
  background: var(--surface-raised);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: var(--s-5);
}
.card--flush { padding: 0; }
.card--sunken { background: var(--surface-sunken); }

.tag {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 0.25rem 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-xs);
  color: var(--text-secondary);
}
.tag--accent { border-color: var(--rule-accent); color: var(--accent-text); background: var(--accent-quiet); }

/* Status pill: colour is never the only signal — a dot plus the word. */
.status {
  display: inline-flex; align-items: center; gap: 0.4375rem;
  font-size: var(--fs-xs); font-weight: 520;
  color: var(--text-secondary); white-space: nowrap;
}
.status::before {
  content: ""; inline-size: 7px; block-size: 7px; border-radius: 50%;
  background: var(--status-neutral); flex: none;
}
.status--good::before     { background: var(--status-good); }
.status--warn::before     { background: var(--status-warn); }
.status--critical::before { background: var(--status-critical); }

/* ----- 9. Form controls ------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field__label {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
}
.input, .textarea, .select {
  inline-size: 100%;
  padding: 0.8125rem 0.9375rem;
  background: var(--surface-raised);
  color: var(--text-primary);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  transition: border-color var(--dur-quick) var(--ease-standard),
              background-color var(--dur-quick) var(--ease-standard);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--ink-400); }
.textarea { resize: vertical; min-block-size: 8rem; line-height: var(--lh-relaxed); }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }

/* ----- 10. Motion policy ----------------------------------------------- */

/* Scene-level reveal. GSAP takes over when present; this is the no-JS
   and reduced-motion-safe baseline: without JS, content is simply visible. */
.js [data-reveal],
.js [data-reveal-lines],
.js [data-reveal-stagger] > * { opacity: 0; }

/* If the motion layer fails to load, nothing stays invisible. */
.js.motion-failed [data-reveal],
.js.motion-failed [data-reveal-lines],
.js.motion-failed [data-reveal-stagger] > * { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .js [data-reveal],
  .js [data-reveal-lines],
  .js [data-reveal-stagger] > * { opacity: 1 !important; transform: none !important; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .grain, .site-header, .site-footer { display: none !important; }
  body { background: #fff; color: #000; }
}
