/* Quiet Matter — the one stylesheet.
 * Tokens harvested from the V3.8 design-system prototype and verified value by
 * value against QM_Typography_System.md. Typography is the only visual system:
 * no icons, no decoration, no color accents on customer surfaces. Word-links,
 * hairlines, warm paper. Sizes are rem so user zoom works; nothing renders
 * above 18px on customer surfaces except the site arrival scale (CLAUDE.md D2).
 *
 * Structure follows the V3.8 token architecture: primitives (what values ARE)
 * → semantic roles (what they DO; the rules below consume ONLY roles) → the
 * dusk theme remaps roles, never primitives (CLAUDE.md D1).
 *
 * FOOTER COLOR — the flagged supersession (Brief, consistency matrix): the
 * Typography System's #888888 (3.39:1) is superseded by Legal §4.1: "#767676
 * or darker … meeting ≥4.5:1" against #fafaf8. #767676 itself measures 4.35:1
 * on #fafaf8, so the built value is the darker #6e6c6a (5.0:1), which satisfies
 * both clauses. Recorded in QA_CHECKLIST.md.
 */
:root {
  /* ── Primitives ── */
  /* Ink ramp */
  --qm-ink-900: #1a1a1a;      /* body — near-black, not pure black */
  --qm-ink-600: #4a4a4a;      /* operational layer — recedes behind serif */
  --qm-ink-450: #6e6c6a;      /* footer / license / labels — ≥4.5:1 on paper */
  --qm-ink-300: #b8b5b0;      /* disabled/placeholder only — never load-bearing */
  /* Paper ramp */
  --qm-paper-0: #ffffff;
  --qm-paper-50: #fafaf8;     /* the page — warm off-white, reads as paper */
  --qm-paper-100: #f2f0ec;    /* sunk surface */
  /* Dusk ramp — paper at night (CLAUDE.md D1) */
  --qm-night-900: #161513;    /* page at night — warm off-black, not pure */
  --qm-night-800: #1f1e1b;    /* card at night */
  --qm-night-700: #2a2825;    /* sunk surface at night */
  --qm-paperlight-100: #ece9e3;  /* primary text on night */
  --qm-paperlight-300: #c4c0b8;  /* secondary text on night */
  --qm-paperlight-500: #928d84;  /* subtle text on night (AA on night-900) */
  /* Hairlines */
  --qm-line-ink: rgba(26, 26, 26, 0.10);
  --qm-line-paper: rgba(236, 233, 227, 0.14);

  /* Admin status hues — architect tools only, muted, always paired with a
     text label (never color alone). Never used on a customer surface. */
  --qm-status-ok: #2f6b4f;
  --qm-status-warn: #755c17;   /* darkened from the prototype's #8a6d1f for ≥4.5:1 on its bg */
  --qm-status-fail: #8c3b34;
  --qm-status-ok-bg: #e9f0ea;
  --qm-status-warn-bg: #f3eddc;
  --qm-status-fail-bg: #f3e4e2;

  /* Faces — Spectral/Libre Franklin pre-license (Legal §3.4); Lyon/Suisse when
     FONTS_LICENSED (server swaps the @font-face block, same variables). */
  --qm-serif: 'QM Serif', Georgia, serif;
  --qm-sans: 'QM Sans', system-ui, sans-serif;

  /* Sizes — the sanctioned steps: 11 / 13 / 15 / 16 / 18. 1rem = 16px. */
  --s11: 0.6875rem; --s13: 0.8125rem; --s15: 0.9375rem; --s16: 1rem; --s18: 1.125rem;
  /* Leading — unitless, 1.44–1.5×: 18/26, 16/24, 15/23, 15/22, 13/18, 11/16 */
  --lh-shape: 1.4445; --lh-body: 1.5; --lh-transition: 1.5334; --lh-reflection: 1.4667;
  --lh-ops: 1.3847; --lh-foot: 1.4546;
  --track-label: 0.12em; --track-foot: 0.04em;
  --w-regular: 400; --w-medium: 500; --w-semibold: 600;

  --measure: 37ch;            /* mobile body 34–40 characters per line */
  --measure-editorial: 56ch;
  --container-day: 30rem;
  --qm-touch-min: 44px;       /* WCAG 2.5.5 — standalone taps reach this */

  /* ── Semantic roles — the rules below consume ONLY these ── */
  --text-primary: var(--qm-ink-900);
  --text-secondary: var(--qm-ink-600);
  --text-subtle: var(--qm-ink-450);
  --text-disabled: var(--qm-ink-300);
  --text-on-fill: var(--qm-paper-50);
  --surface-page: var(--qm-paper-50);
  --surface-card: var(--qm-paper-0);
  --surface-sunk: var(--qm-paper-100);
  --border-hairline: var(--qm-line-ink);
  --border-strong: var(--qm-ink-900);
  --border-control: var(--qm-ink-450);
  --link: var(--qm-ink-600);
  --link-hover: var(--qm-ink-900);
  --focus-ring: var(--qm-ink-900);
  --fill-strong: var(--qm-ink-900);
  --fill-strong-hover: #333333;
  --penline-opacity: 0.22;
}

/* ── Dusk — "paper at night" (CLAUDE.md D1). Set from the OS preference by the
   one-line script in the page head; an explicit data-theme always wins. Only
   the roles remap; primitives never change. ─────────────────────────────── */
[data-theme=dusk] {
  --text-primary: var(--qm-paperlight-100);
  --text-secondary: var(--qm-paperlight-300);
  --text-subtle: var(--qm-paperlight-500);
  --text-disabled: #5a564f;
  --text-on-fill: var(--qm-night-900);
  --surface-page: var(--qm-night-900);
  --surface-card: var(--qm-night-800);
  --surface-sunk: var(--qm-night-700);
  --border-hairline: var(--qm-line-paper);
  --border-strong: var(--qm-paperlight-100);
  --border-control: var(--qm-paperlight-500);
  --link: var(--qm-paperlight-300);
  --link-hover: var(--qm-paperlight-100);
  --focus-ring: var(--qm-paperlight-100);
  --fill-strong: var(--qm-paperlight-100);
  --fill-strong-hover: #d8d3ca;
  --penline-opacity: 0.30;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body {
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--qm-serif);
  font-size: var(--s16);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

/* ── Interpretive layer (serif) ─────────────────────────────────────────── */
p, li, blockquote {
  font-family: var(--qm-serif);
  font-weight: var(--w-regular);
  font-size: var(--s16);
  line-height: var(--lh-body);
  max-width: var(--measure);
}
em { font-style: italic; }                       /* structural, not emotional */
strong { font-weight: var(--w-semibold); }       /* locating, not shouting */

/* Headings never exceed 18px and never use display weights. */
h1, h2, h3 {
  font-family: var(--qm-serif);
  font-weight: var(--w-semibold);
  font-size: var(--s16);
  line-height: var(--lh-body);
  max-width: var(--measure);
}
h1.qm-shape, .qm-shape {
  font-weight: var(--w-regular);
  font-size: var(--s18);                          /* the ceiling */
  line-height: var(--lh-shape);
}

/* ── Operational layer (sans) ───────────────────────────────────────────── */
.ops, address, time {
  font-family: var(--qm-sans);
  font-weight: var(--w-regular);
  font-size: var(--s13);
  line-height: var(--lh-ops);
  color: var(--text-secondary);
  font-style: normal;
}
.qm-label {
  font-family: var(--qm-sans);
  font-weight: var(--w-medium);
  font-size: var(--s11);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-subtle);
}
.qm-transition { font-size: var(--s15); line-height: var(--lh-transition); }
.qm-reflection {
  font-family: var(--qm-sans);
  font-size: var(--s15);
  line-height: var(--lh-reflection);
  color: var(--text-secondary);
  max-width: var(--measure);
}
footer, .qm-foot {
  font-family: var(--qm-sans);
  font-weight: var(--w-regular);
  font-size: var(--s11);
  line-height: var(--lh-foot);
  letter-spacing: var(--track-foot);
  color: var(--text-subtle);
}

/* ── Links: the word, underlined, is the interface ──────────────────────── */
a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
a:hover { color: var(--link-hover); }
.qm-link-serif { font-family: var(--qm-serif); font-size: inherit; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus-ring);           /* the one sanctioned decoration */
  outline-offset: 2px;
}

/* ── Forms — hairline underline inputs, word-buttons ────────────────────── */
label { font-family: var(--qm-sans); font-size: var(--s13); color: var(--text-secondary); display: block; margin-bottom: 0.25rem; }
input[type=text], input[type=email], input[type=date], input[type=number], select, textarea {
  font-family: var(--qm-sans);
  font-size: var(--s16);                          /* ≥16px prevents mobile zoom-jump */
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-control);
  border-radius: 0;
  padding: 0.25rem 0;
  width: 100%;
  max-width: 28rem;
}
textarea { border: 1px solid var(--border-control); padding: 0.5rem; min-height: 6rem; }
input:focus, select:focus, textarea:focus { border-color: var(--border-strong); }
::placeholder { color: var(--text-subtle); font-style: italic; }
input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--fill-strong); }
button {
  font-family: var(--qm-sans);
  font-size: var(--s13);
  color: var(--link);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0.5rem 0;
}
button:hover { color: var(--link-hover); }
button.qm-primary {
  color: var(--text-on-fill);
  background: var(--fill-strong);
  text-decoration: none;
  font-weight: var(--w-medium);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: var(--qm-touch-min);
  padding: 0.75rem 1.5rem;
}
button.qm-primary:hover { background: var(--fill-strong-hover); color: var(--text-on-fill); }

/* ── Page scaffolding ───────────────────────────────────────────────────── */
.qm-page { max-width: var(--container-day); margin: 0 auto; padding: 2.5rem 1.5rem 4rem; }
.qm-page--wide { max-width: 64rem; }
.qm-rule { border: none; border-top: 1px solid var(--border-hairline); margin: 2rem 0; }
.qm-stack > * + * { margin-top: 1rem; }
.qm-stack--loose > * + * { margin-top: 2rem; }
.qm-masthead { margin-bottom: 2.5rem; }
.qm-masthead .qm-wordmark { font-family: var(--qm-serif); font-weight: var(--w-semibold); font-size: var(--s16); color: var(--text-primary); text-decoration: none; }
nav.qm-nav { margin-top: 0.5rem; display: flex; gap: 1rem; flex-wrap: wrap; }
nav.qm-nav a { font-family: var(--qm-sans); font-size: var(--s13); }
/* Standalone word-links: the visual underline stays small; the HIT AREA grows
   to the touch minimum via padding + compensating negative margin, so the text
   rhythm is undisturbed (WCAG 2.5.5; the word, underlined, is the interface). */
nav.qm-nav a, .qm-tap { display: inline-block; padding-block: 0.75rem; margin-block: -0.5rem; }

/* ── The penline — a present hairline. Static: no width or opacity animation,
   so print, no-JS, and reduced motion always show the finished rule. ─────── */
.qm-penline {
  display: block;
  height: 1px;
  border: none;
  background: var(--border-strong);
  opacity: var(--penline-opacity);
}

/* ── Arrival settle (CLAUDE.md D2/D3) — transform ONLY, never opacity: the
   text is always present; a paused clock, print, or reduced motion shows the
   rest state in full. `both` holds the gentle lift during the stagger. ───── */
@media (prefers-reduced-motion: no-preference) {
  .qm-beat { animation: qm-settle 300ms ease both; }
  .qm-beat[data-beat="2"] { animation-delay: 120ms; }
  .qm-beat[data-beat="3"] { animation-delay: 240ms; }
}
@keyframes qm-settle {
  from { transform: translateY(-0.5rem); }
  to   { transform: none; }
}

/* ── The site scale (CLAUDE.md D2) — the front door is not the Day app. The
   single opening sentence and section leads may breathe above the Day's 18px
   ceiling. Scoped to [data-surface=site] so they cannot reach the Daybook. ── */
[data-surface=site] {
  --qm-site-21: 1.3125rem;                                       /* 21px — section leads */
  --qm-site-arrival: clamp(1.5rem, 1.04rem + 2.05vw, 1.875rem);  /* 24→30px — the one sentence */
  --qm-leading-arrival: 1.32;
}
[data-surface=site] .qm-site-arrival {
  font-weight: var(--w-regular);
  font-size: var(--qm-site-arrival);
  line-height: var(--qm-leading-arrival);
  max-width: 24ch;                                /* the sentence on its breath */
}
[data-surface=site] .qm-site-lead {
  font-family: var(--qm-serif);
  font-size: var(--qm-site-21);
  line-height: var(--lh-body);
  max-width: var(--measure-editorial);
}
[data-surface=site] .qm-site-penline { margin-top: 1.25rem; }
@media (prefers-reduced-motion: no-preference) {
  [data-surface=site] .qm-site-arrival { animation: qm-settle 300ms ease both; }
}

/* ── The checkout (CLAUDE.md D7) — a QM surface; the Payment Element is themed
   from the tokens in static/checkout.js. Only layout lives here. ─────────── */
.qm-checkout { max-width: 28rem; }
.qm-checkout-summary { margin-top: 0.5rem; }
#qm-payment-element { margin: 1.5rem 0; }
#qm-pay-error:empty { display: none; }

/* ── Reading rows — dated word-links (CLAUDE.md D4): serif title, sans date,
   separated by space, no per-row rule. ──────────────────────────────────── */
.qm-reading-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 1.25rem; justify-content: space-between; max-width: var(--measure-editorial); }
.qm-reading-row a { font-family: var(--qm-serif); font-size: var(--s16); }
ul.qm-reading-list { list-style: none; }
ul.qm-reading-list > * + * { margin-top: 1.5rem; }

/* ── Admin (architect tool, not a publication): denser, tabular ─────────── */
[data-mode=admin] .qm-page { max-width: 72rem; }
[data-mode=admin] table { border-collapse: collapse; width: 100%; font-family: var(--qm-sans); font-size: var(--s13); }
[data-mode=admin] th {
  text-align: left; font-weight: var(--w-medium); font-size: var(--s11);
  letter-spacing: var(--track-label); text-transform: uppercase; color: var(--text-subtle);
  border-bottom: 1px solid var(--border-control); padding: 0.4rem 0.75rem 0.4rem 0;
}
[data-mode=admin] td { border-bottom: 1px solid var(--border-hairline); padding: 0.45rem 0.75rem 0.45rem 0; vertical-align: top; }
[data-mode=admin] p { max-width: var(--measure-editorial); }
.qm-status { font-family: var(--qm-sans); font-size: var(--s11); letter-spacing: var(--track-label); text-transform: uppercase; padding: 0.1rem 0.4rem; }
.qm-status--ok   { color: var(--qm-status-ok);   background: var(--qm-status-ok-bg); }
.qm-status--warn { color: var(--qm-status-warn); background: var(--qm-status-warn-bg); }
.qm-status--fail { color: var(--qm-status-fail); background: var(--qm-status-fail-bg); }
.qm-kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1.5rem; font-family: var(--qm-sans); font-size: var(--s13); }
.qm-kv dt { color: var(--text-subtle); }
.qm-kv dd { color: var(--text-primary); }

/* ── The Daybook: phone-first, one column, generous air ─────────────────── */
[data-surface=daybook] .qm-page { padding-top: 3.5rem; }
[data-surface=daybook] .qm-module { margin-top: 3.5rem; }
[data-surface=daybook] section > * + * { margin-top: 1rem; }  /* modules AND the how-to block breathe alike */
[data-surface=daybook] .qm-transition { margin-top: 2.5rem; }
[data-surface=daybook] .qm-penline { margin-top: 1.25rem; }
[data-surface=daybook] header .qm-shape { margin-top: 1.5rem; }
[data-surface=daybook] header .ops { margin-top: 1rem; }
[data-surface=daybook] footer { margin-top: 4rem; }

/* ── Training (CLAUDE.md D9): the rail and its texts — admin only, role
   tokens only, typography-only. A hairline box, never a color field. ─────── */
[data-mode=admin] .qm-training { border: 1px solid var(--border-hairline); padding: 0.75rem 1rem; margin-bottom: 1.5rem; }
[data-mode=admin] .qm-training > * + * { margin-top: 0.5rem; }
[data-mode=admin] .qm-training p { max-width: var(--measure-editorial); }
[data-mode=admin] .qm-training details > summary,
[data-mode=admin] .qm-training-text > summary { cursor: pointer; font-family: var(--qm-sans); font-size: var(--s13); color: var(--text-subtle); }
[data-mode=admin] pre { white-space: pre-wrap; font-family: var(--qm-serif); font-size: var(--s15); line-height: var(--lh-body); border-left: 1px solid var(--border-hairline); padding: 0.25rem 0 0.25rem 0.75rem; margin: 0.5rem 0; max-width: var(--measure-editorial); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

@media print {
  a { text-decoration: none; color: inherit; }
  .qm-page { max-width: none; }
}
