/* ============================================================
   TextKit — Design tokens
   Concept: "Manuscript" — warm paper surfaces, graphite ink,
   editor's-red accent borrowed from proofreading marks.
   ============================================================ */

:root {
  /* Type scale — fluid */
  --text-xs:   clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm:   clamp(0.875rem, 0.85rem + 0.15vw, 0.9375rem);
  --text-base: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
  --text-lg:   clamp(1.125rem, 1.05rem + 0.4vw, 1.375rem);
  --text-xl:   clamp(1.5rem, 1.3rem + 0.9vw, 2.125rem);
  --text-stat: clamp(1.75rem, 1.2rem + 2vw, 2.75rem);

  /* Spacing — 4px base */
  --space-1: 0.25rem;  --space-2: 0.5rem;   --space-3: 0.75rem;
  --space-4: 1rem;     --space-5: 1.25rem;  --space-6: 1.5rem;
  --space-8: 2rem;     --space-10: 2.5rem;  --space-12: 3rem;
  --space-16: 4rem;    --space-20: 5rem;    --space-24: 6rem;

  /* Radius */
  --radius-sm: 0.375rem; --radius-md: 0.5rem;
  --radius-lg: 0.75rem;  --radius-xl: 1rem; --radius-full: 9999px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --t-fast: 120ms var(--ease-out);
  --t-base: 180ms var(--ease-out);
  --t-slow: 320ms var(--ease-out);

  /* Layout */
  --rail-w: 264px;
  --content-narrow: 680px;
  --content-default: 1000px;
  --content-wide: 1340px;

  /* Fonts */
  --font-display: 'Gambetta', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Switzer', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

/* ---------- Light (paper) ---------- */
:root,
[data-theme='light'] {
  --bg:            #faf7f0;
  --surface:       #fffdf8;
  --surface-2:     #f4f0e6;
  --surface-3:     #ece7d9;
  --border:        #e2dbcb;
  --border-strong: #cfc6b2;
  --divider:       #ece7da;

  --text:          #1c1a16;
  --text-muted:    #6b6457;   /* 5.47:1 on --bg */
  --text-faint:    #746c5c;   /* 4.86:1 on --bg — still passes AA, used for labels */
  --text-ghost:    #a39b8b;   /* decorative only: placeholders, disabled, dividers */
  --text-inverse:  #fffdf8;

  --accent:        #a63a22;
  --accent-hover:  #862c18;
  --accent-soft:   #f6e7e0;
  --accent-line:   #e0c4b8;
  --on-accent:     #fffdf8;   /* 6.46:1 on --accent */

  --success:       #3f6b2c;
  --success-soft:  #e7eede;
  --warning:       #8a5a10;
  --warning-soft:  #f6eddb;
  --danger:        #98243c;
  --danger-soft:   #f6e3e6;

  --shadow-sm: 0 1px 2px rgb(40 32 20 / 0.05);
  --shadow-md: 0 2px 4px rgb(40 32 20 / 0.04), 0 8px 20px rgb(40 32 20 / 0.06);
  --shadow-lg: 0 4px 8px rgb(40 32 20 / 0.05), 0 20px 48px rgb(40 32 20 / 0.12);
  --sheet-edge: 0 0 0 1px var(--border), var(--shadow-md);
}

/* ---------- Dark (slate) ---------- */
[data-theme='dark'] {
  --bg:            #14130f;
  --surface:       #1b1a15;
  --surface-2:     #21201a;
  --surface-3:     #2a2822;
  --border:        #35322a;
  --border-strong: #4a463c;
  --divider:       #262419;

  --text:          #e9e4d7;
  --text-muted:    #948d7d;   /* 5.63:1 on --bg */
  --text-faint:    #8a8474;   /* 4.99:1 on --bg */
  --text-ghost:    #6b6558;   /* decorative only */
  --text-inverse:  #14130f;

  --accent:        #e4674a;
  --accent-hover:  #f0836a;
  --accent-soft:   #33211c;
  --accent-line:   #4d2f26;
  --on-accent:     #1b0f0b;   /* 5.66:1 — light accent needs dark ink, not white */

  --success:       #7fb055;
  --success-soft:  #23291b;
  --warning:       #d09a45;
  --warning-soft:  #2b2418;
  --danger:        #e2718a;
  --danger-soft:   #2e1c21;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-md: 0 2px 4px rgb(0 0 0 / 0.25), 0 8px 20px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 4px 8px rgb(0 0 0 / 0.3), 0 20px 48px rgb(0 0 0 / 0.5);
  --sheet-edge: 0 0 0 1px var(--border), var(--shadow-md);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #14130f; --surface: #1b1a15; --surface-2: #21201a; --surface-3: #2a2822;
    --border: #35322a; --border-strong: #4a463c; --divider: #262419;
    --text: #e9e4d7; --text-muted: #948d7d; --text-faint: #8a8474; --text-ghost: #6b6558; --text-inverse: #14130f;
    --accent: #e4674a; --accent-hover: #f0836a; --accent-soft: #33211c; --accent-line: #4d2f26; --on-accent: #1b0f0b;
    --success: #7fb055; --success-soft: #23291b; --warning: #d09a45; --warning-soft: #2b2418;
    --danger: #e2718a; --danger-soft: #2e1c21;
  }
}

/* ============================ Base ============================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  font-feature-settings: 'ss01' 1;
  overflow-x: hidden;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
ul[role='list'], ol[role='list'] { list-style: none; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
table { border-collapse: collapse; width: 100%; }

h1, h2, h3, h4 { text-wrap: balance; line-height: 1.2; font-weight: 600; }
p, li { text-wrap: pretty; }

a { color: var(--accent); text-decoration-color: var(--accent-line); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

a, button, [role='button'], input, textarea, select {
  transition: color var(--t-base), background-color var(--t-base),
              border-color var(--t-base), box-shadow var(--t-base),
              transform var(--t-fast);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

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