/* ==========================================================================
   Inkwell base layer
   Reset, paper ground, grain, grid, and typography defaults.
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: light;
}
[data-theme='dark'] html, html[data-theme='dark'] { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-weight: var(--fw-normal);
  overflow-x: hidden;          /* never any horizontal scroll */
  -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
   Paper grain. A fixed, pre-rasterised SVG noise tile — it never repaints on
   scroll and is never applied as a filter to scrolling content.
   -------------------------------------------------------------------------- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
}
[data-theme='dark'] body::before { mix-blend-mode: screen; }

/* --------------------------------------------------------------------------
   Faint graph grid — main canvas only, never behind dense text blocks.
   -------------------------------------------------------------------------- */
.grid-paper {
  background-image:
    linear-gradient(to right, var(--line-faint) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-faint) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
}
.grid-dots {
  background-image: radial-gradient(var(--line-faint) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-hand);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  margin: 0 0 var(--sp-3);
  letter-spacing: 0.01em;
}
/* Handwriting faces need a step up in size to read at the same visual weight. */
h1 { font-size: var(--fs-4xl); }
h2 { font-size: var(--fs-3xl); }
h3 { font-size: var(--fs-2xl); }
h4 { font-size: var(--fs-xl); }

p { margin: 0 0 var(--sp-4); }

/* Anything read or edited at length uses the comfortable face, never handwriting. */
.longform, .longform p, .longform li,
textarea, input, select, .table, .log, .memory-text {
  font-family: var(--font-long);
  line-height: var(--lh-body);
}

small, .meta, .hint {
  font-size: var(--fs-sm);
  color: var(--pencil);
}

.label-hand {
  font-family: var(--font-hand);
  font-size: var(--fs-xl);
  line-height: var(--lh-snug);
}

/* No all-caps anywhere, as the brief requires. */
.eyebrow {
  font-family: var(--font-hand);
  font-size: var(--fs-lg);
  color: var(--pencil);
  text-transform: none;
}

a {
  color: var(--ink);
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  text-decoration-color: var(--line-faint);
}
a:hover { text-decoration-color: var(--marker-yellow); }

code, kbd, samp {
  font-family: 'Cascadia Mono', 'Consolas', ui-monospace, monospace;
  font-size: 0.92em;
  background: var(--paper-deep);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

::selection { background: var(--marker-yellow); color: var(--ink); }

hr {
  border: 0;
  height: var(--stroke-thin);
  background: var(--line-faint);
  margin: var(--sp-5) 0;
}

/* --------------------------------------------------------------------------
   Focus: a drawn ring, never the browser default outline removal.
   -------------------------------------------------------------------------- */
:focus { outline: none; }
:focus-visible {
  outline: var(--focus-w) solid var(--marker-sky);
  outline-offset: 2px;
  border-radius: 4px;
}
/* Drawn circle variant for sketch controls. */
.focus-drawn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 var(--focus-w) var(--marker-sky);
}

/* --------------------------------------------------------------------------
   Accessibility helpers
   -------------------------------------------------------------------------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--sp-4); top: calc(-1 * var(--sp-7));
  z-index: 100; background: var(--paper-lift);
  padding: var(--sp-2) var(--sp-4);
  transition: top var(--dur-base) var(--ease);
}
.skip-link:focus { top: var(--sp-4); }

/* --------------------------------------------------------------------------
   Motion: honour the system preference. Lines become static, nothing moves.
   -------------------------------------------------------------------------- */
@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;
  }
  .draw-in { stroke-dasharray: none !important; stroke-dashoffset: 0 !important; }
}

/* --------------------------------------------------------------------------
   Utility: aligned to the spacing scale only.
   -------------------------------------------------------------------------- */
.stack > * + * { margin-top: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--pencil); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }