/* ============================================================================
   base.css — reset, element defaults, utilities.

   There is one surface now, so the six surface variables below are declared
   once on :root and never flipped. Utilities still read them rather than
   naming colours directly: components that want a different register (a well,
   a brass control) rebind the variables locally and everything inside follows.
   ========================================================================= */

:root {
  --fg:         var(--c-fg);
  --fg-dim:     var(--c-fg-dim);
  --fg-mute:    var(--c-fg-mute);
  --rule:       var(--c-rule);
  --link:       var(--c-amber);
  --link-hover: var(--c-amber-hi);
  --accent:     var(--c-brass);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 6.5rem;      /* keep anchors clear of the masthead */
}

/* A column, so the footer lands on the floor of the viewport instead of halfway
   up it on a page short enough to fit — 404 is the one that does. The skip link
   and the icon defs are both position: absolute, so neither becomes a flex item.
   The unit is svh: on a phone, vh counts the strip the address bar occupies. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  font-family: var(--ff-body);
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: var(--lh-body);
  color: var(--fg);
  background-color: var(--c-ground);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

body > main { flex: 1 0 auto; }

/* The drafting surface: a warm graphite ground ruled with a grid — minor
   divisions every --grid-minor, a heavier line every fifth. Fixed, so the
   grid belongs to the surface rather than to the page sliding over it. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-color: var(--c-ground);
  background-image:
    linear-gradient(90deg, var(--c-grid-hi) 0 1px, transparent 1px),
    linear-gradient(180deg, var(--c-grid-hi) 0 1px, transparent 1px),
    linear-gradient(90deg, var(--c-grid) 0 1px, transparent 1px),
    linear-gradient(180deg, var(--c-grid) 0 1px, transparent 1px);
  background-size:
    var(--grid-major) var(--grid-major),
    var(--grid-major) var(--grid-major),
    var(--grid-minor) var(--grid-minor),
    var(--grid-minor) var(--grid-minor);
}

/* Lamplight. One warm source high on the right — the corner the hero lamp
   hangs in — and the faintest fall-off at the edges. Kept low: the ground
   should read as evenly lit paper, not as a spotlight on a stage. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(46% 34% at 86% -4%, var(--glow-warm), transparent 72%),
    radial-gradient(140% 110% at 50% 34%, transparent 46%, rgba(12, 10, 8, 0.5) 100%);
}

img, svg, video, canvas { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
ul, ol { list-style: none; padding: 0; }
table { border-collapse: collapse; width: 100%; }

/* ── Typography ───────────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--ff-display);
  font-weight: 600;
  line-height: var(--lh-head);
  letter-spacing: var(--ls-display);
  color: var(--fg);
  text-wrap: balance;
}

h1 { font-size: var(--fs-hero); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }

p { text-wrap: pretty; }

em { font-style: italic; }
strong, b { font-weight: 600; color: var(--fg); }

a {
  color: var(--link);
  text-decoration-color: color-mix(in srgb, currentColor 34%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color var(--t-fast) var(--ease-mech);
}
a:hover { color: var(--link-hover); text-decoration-color: currentColor; }

code, kbd, samp, pre {
  font-family: var(--ff-mono);
  font-size: 0.9em;
  letter-spacing: 0;
}

code {
  padding: 0.08em 0.36em;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--c-well);
  color: var(--fg-dim);
}

/* A ruled line, drawn with a straight-edge and fading at both ends. */
hr {
  height: 1px;
  border: 0;
  background: linear-gradient(90deg,
      transparent, var(--rule) 12%, var(--rule) 88%, transparent);
}

::selection { background: rgba(185, 144, 47, 0.3); color: var(--c-fg); }

/* ── Accessibility ────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--c-brass-lt);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip-link {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: var(--z-top);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--c-rule-brass);
  border-radius: var(--r-ctl);
  background: var(--c-panel);
  color: var(--c-fg);
  font-family: var(--ff-mono);
  font-size: var(--fs-sm);
  text-decoration: none;
  transform: translateY(calc(-100% - var(--sp-5)));
  transition: transform var(--t-mid) var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(0); }

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

/* ── Scrollbar: a brass rail set into the ground ──────────────────────────── */
* { scrollbar-color: var(--c-brass-dk) var(--c-void); scrollbar-width: thin; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--c-void); }
::-webkit-scrollbar-thumb {
  border: 2px solid var(--c-void);
  border-radius: 6px;
  background: var(--c-brass-dk);
}
::-webkit-scrollbar-thumb:hover { background: var(--c-brass); }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.mono {
  font-family: var(--ff-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--ls-mono);
}

/* Draughtsman's caption: "SHEET 01", "REV 2026.08" and friends. */
.label {
  font-family: var(--ff-mono);
  font-size: var(--fs-label);
  font-weight: 600;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--fg-mute);
}

.label--accent { color: var(--accent); }
.label--red    { color: var(--c-st-hold); }
.label--verd   { color: var(--c-st-live); }

.lead {
  font-size: var(--fs-lead);
  line-height: 1.6;
  color: var(--fg-dim);
  max-width: 62ch;
}

.dim  { color: var(--fg-dim); }
.mute { color: var(--fg-mute); }
.nowrap { white-space: nowrap; }

/* ── Respect reduced-motion preferences ───────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Print: hand over the document, not the drawing office ────────────────── */
@media print {
  /* The whole site names roles, and every role resolves back to the twenty-odd
     literals in theme.css layer 1. So paper is a second set of literals and
     nothing more: repaint the materials here and the roles derived from them —
     hairlines, the grid, the mark — follow without a single component knowing.
     Without this, body copy stays at --fg-dim, which is cream, and most of the
     page prints as blank paper. */
  :root {
    --c-ground:    #fff;
    --c-ground-hi: #fff;
    --c-ground-lo: #fff;
    --c-void:      #fff;
    --c-panel:     #fff;
    --c-panel-hi:  #fff;
    --c-well:      #f4f1ea;

    --c-fg:        #1a1a1a;
    --c-fg-dim:    #423d37;
    --c-fg-mute:   #67615a;

    /* Brass is a line material, so on paper it goes to ink. "Lit" becomes the
       stronger of the two, which is the darker one here. */
    --c-brass:     #7c5f28;
    --c-brass-lt:  #5b4417;
    --c-brass-dk:  #3f2f10;

    --c-wine:      #8b3345;   /* still a fill, still carries light text */
    --c-wine-lt:   #7a2434;
    --c-amber:     #8a4e14;
    --c-amber-hi:  #6d3c0e;

    --c-st-live:   #2f6a52;
    --c-st-wip:    #6d5210;
    --c-st-hold:   #8f3b2c;
    --c-st-arch:   #67615a;
  }

  /* Back to a block: the flex column exists to put a floor under a short page,
     and paper has no viewport to put a floor in. Flex items also break across
     printed pages less predictably than blocks do. */
  body { display: block; background: #fff; color: var(--c-fg); }
  body::before, body::after { display: none; }
  .masthead, .hero__decor, .hero__draft, .hero__lamp, .hero__glow, .hero__hint,
  .gear, .compass, .section__flourish, .pagehead__decor, .footer__decor,
  .measure, .footer__hint,
  .plate::before, .plate::after { display: none !important; }
  /* Reveals are opacity 0 until the observer reaches them. Whatever the visitor
     had scrolled past when they hit Ctrl+P is not a reason for a section to come
     out of the printer blank. */
  .reveal { opacity: 1 !important; transform: none !important; }
  a::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #555; }
  /* Except on the filled control, where the appended URL runs off the fill in a
     colour chosen for paper, not for wine. Its label already names where it
     goes, and the quiet routes beside it still print their targets. */
  .btn--fill::after { content: none; }
}
