/* =========================================================
   Nule-Legends base: reset, type, browser surfaces, layout
   primitives and the view frame. Loaded on every page after
   tokens.css. No component styles here (see css/components/).
   ========================================================= */

/* -------------------- Reset -------------------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--head-h) + var(--s-4));
  interpolate-size: allow-keywords; /* lets <details> and menus animate to height: auto where supported */
}
body, h1, h2, h3, h4, p, ul, ol, figure, dl, dd, blockquote { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg, video { max-width: 100%; display: block; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }
table { border-collapse: collapse; }

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--ink-0);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-feature-settings: 'cv11', 'ss01'; /* Inter: single-storey a off, open digits */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}
main { flex: 1 0 auto; }
html.menu-open { overflow: hidden; }

/* -------------------- Browser surfaces -------------------- */
::selection { background: color-mix(in srgb, var(--accent) 38%, transparent); color: var(--text); }
html { scrollbar-color: var(--gold-lo) var(--ink-00); scrollbar-width: thin; }
input, textarea { caret-color: var(--accent-hi); }
a { text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
[tabindex="-1"]:focus { outline: none; }
::placeholder { color: var(--text-3); opacity: 1; }
strong, b { font-weight: 600; }
code, kbd {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--tint);
  border: 1px solid var(--line);
  padding: 0.05em 0.35em;
  border-radius: var(--r-1);
  overflow-wrap: anywhere;
}
hr { border: 0; height: 1px; background: var(--line); margin: var(--s-6) 0; }

/* -------------------- Type -------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--heading);
  font-weight: 600;
  line-height: var(--lh-snug);
  letter-spacing: var(--tr-display);
  text-wrap: balance;
}
h1 { font-size: var(--fs-3xl); line-height: 1.06; }
h2 { font-size: var(--fs-2xl); line-height: 1.1; }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
p, li, dd { text-wrap: pretty; }

/* Small capitals in Cinzel: data labels, table heads, field groups. Never above a heading. */
.label {
  display: block;
  font-family: var(--font-label);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--accent);
  line-height: 1.4;
}
.lede { font-size: var(--fs-md); color: var(--text-2); max-width: 62ch; margin-top: var(--s-3); }
.fine { font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--s-3); }
.soft { color: var(--text-2); }
.num, .tabular { font-variant-numeric: tabular-nums; }

/* Running text: links inside prose are gold and underlined. */
.prose { max-width: var(--prose); }
.prose > * + * { margin-top: var(--s-4); }
.prose ul { list-style: disc; padding-inline-start: 1.25rem; }
.prose ol { list-style: decimal; padding-inline-start: 1.25rem; }
.prose li + li { margin-top: var(--s-1); }
.prose a, .lede a, .fine a, .callout a, .alert a, .card-note a, .step a, .faq-item a, .form-submit-status a, .checkbox-field a, .empty a {
  color: var(--link);
  text-decoration-color: color-mix(in srgb, var(--link) 45%, transparent);
  transition: text-decoration-color var(--dur-1) var(--ease-out);
}
.prose a:hover, .lede a:hover, .fine a:hover, .callout a:hover, .alert a:hover, .card-note a:hover, .step a:hover, .faq-item a:hover, .empty a:hover { text-decoration-color: currentColor; }

/* The crest's red gem: the one ornament. */
.gem {
  display: inline-block;
  flex: none;
  width: 9px;
  height: 9px;
  background: var(--action);
  border: 1px solid var(--accent);
  transform: rotate(45deg);
}

/* -------------------- Icons -------------------- */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  display: inline-block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
}

/* -------------------- Accessibility helpers -------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  left: var(--s-3);
  top: var(--s-3);
  z-index: var(--z-skip);
  padding: var(--s-2) var(--s-4);
  background: var(--gold-hi);
  color: var(--ink-0);
  font-weight: 600;
  border-radius: var(--r-2);
  box-shadow: var(--e-2);
  transform: translateY(-200%);
  transition: transform var(--dur-2) var(--ease-out);
}
/* Only for keyboard focus: a mouse or touch focus never flashes it. */
.skip-link:focus-visible { transform: none; }

/* -------------------- Layout primitives -------------------- */
.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container.narrow { max-width: calc(var(--narrow) + 2 * var(--gutter)); }

/* Vertical rhythm: children spaced by --stack (default 1rem). */
.stack { display: flex; flex-direction: column; gap: var(--stack, var(--s-4)); }
/* A wrapping row of things: buttons, chips, meta. */
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster, var(--s-3)); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
/* Sidebar + content that stacks when the content side would get narrower than 60%. */
.split { display: flex; flex-wrap: wrap; gap: var(--split-gap, var(--s-6)); }
.split > :first-child { flex: 1 1 var(--split-side, 18rem); }
.split > :last-child { flex: 999 1 0; min-width: min(100%, 60%); }
/* A size container: components inside switch layout by the space they get, not the viewport. */
.cq { container-type: inline-size; }
/* Sticky only while it fits: stickyWhenFits() in js/lib/ui.js sets .is-sticky while the element is shorter
   than the screen, so a side column pins under the masthead but never needs a scroller of its own. */
:not(table).is-sticky { position: sticky; top: calc(var(--head-h) + var(--s-4)); }

/* -------------------- The view frame -------------------- */
/* The router renders one <section class="view v-NAME" data-view="ROUTE"> into #view. */
#view { display: block; view-transition-name: view; }
.view { container: view / inline-size; padding-block: var(--s-6) var(--section); }
.view.v-home { padding-block: 0; }
@media (max-width: 767px) { .view { padding-block: var(--s-5) var(--s-8); } }

::view-transition-old(view) { animation: vt-out var(--dur-2) var(--ease-in-out) both; }
::view-transition-new(view) { animation: vt-in var(--dur-3) var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(10px); } }

/* Fine grain, so large dark fields read as material, not as a flat fill. */
.grain { position: relative; isolation: isolate; }
.grain::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  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='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* -------------------- Page painting -------------------- */
/* The page's own band art (or the season's on pages without one), under a heavy veil and a 4 % lattice.
   --page-art is set by the router to the image the band already loaded, so it costs no bytes. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--veil), var(--page-art) center top / cover no-repeat;
}
.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23D6AA52' stroke-width='1'%3E%3Cpath d='M28 4l24 24-24 24L4 28z'/%3E%3Cpath d='M28 16l12 12-12 12-12-12z'/%3E%3C/g%3E%3C/svg%3E");
}

/* -------------------- Page grid: band on top, content and rail under it -------------------- */
/* Below 1180 px: one column, the rail is a sheet (css/rail.css). From 1180 px: five tracks,
   outer gutters that grow, the content column and the rail. <main> is a subgrid that holds the band
   (full width, row 1) and the view (row 2), so the h1 stays inside <main> and the rail starts under the band.
   html.rail-left / html.rail-right (js/rail.config.js) swap the two inner tracks; the source order never changes. */
.app-body { flex: 1 0 auto; width: 100%; }
@media (min-width: 1180px) {
  .app-body {
    --main-w: calc(var(--shell-max) - 2 * var(--gutter) - var(--rail-gap) - var(--rail-w));
    display: grid;
    grid-template-columns: minmax(var(--gutter), 1fr) minmax(0, var(--main-w)) var(--rail-gap) var(--rail-w) minmax(var(--gutter), 1fr);
    grid-template-rows: auto 1fr;
    align-items: start;
  }
  html.rail-left .app-body { grid-template-columns: minmax(var(--gutter), 1fr) var(--rail-w) var(--rail-gap) minmax(0, var(--main-w)) minmax(var(--gutter), 1fr); }
  .app-body > main {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    display: grid;
    grid-template-columns: subgrid;
    grid-template-rows: subgrid;
    align-items: start;
    min-width: 0;
  }
  #band { grid-column: 1 / -1; grid-row: 1; min-width: 0; }
  #view { grid-column: 2; grid-row: 2; min-width: 0; }
  html.rail-left #view { grid-column: 4; }
  .app-body > .rail { grid-column: 4; grid-row: 2; }
  html.rail-left .app-body > .rail { grid-column: 2; }
  /* Inside the content column the column is the container: no second gutter. */
  .app-body #view .container { max-width: none; padding-inline: 0; }
  .app-body #view .container.narrow { max-width: var(--narrow); margin-inline: 0; } /* on the band title's left edge, not floating mid-column */
  /* A view's lead block (home hero, js/routes.js `lead`) bleeds over the whole width above the rail. */
  .app-body #view .is-view-lead { margin-left: calc(-1 * var(--lead-l, 0px)); margin-right: calc(-1 * var(--lead-r, 0px)); }
  .app-body #view .is-view-lead .container { max-width: calc(var(--shell-max) - 2 * var(--gutter)); margin-inline: auto; padding-inline: var(--gutter); box-sizing: content-box; }
  /* Home's first block opens with a block head (a 44 px row: the text link sets it), so the rail starts level
     with the panel under that head, not with the heading: the two top borders share a line. */
  html.has-lead .app-body > .rail { margin-top: calc(var(--lead-h, 0px) + var(--s-6) + max(44px, var(--fs-2xl) * 1.1) + var(--s-4)); }
}

/* -------------------- Band bridge (until a view drops its .page-head) -------------------- */
/* The router shows the h1 and lede in the band. A view that still carries a .page-head keeps it in the
   markup (scripts and aria-labelledby still find it), folded out of sight and out of the reading order. */
.band-mirrored, .page-head-folded {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}
html.has-band .view .page-head { margin-bottom: var(--s-5); }

/* A heading for a block: h2 with the crimson gem, an optional note or link on the right. */
.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  margin-bottom: var(--s-4);
}
.block-head h2 { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-2xl); }
.block-head h2::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  rotate: 45deg;
  background: var(--action);
  box-shadow: 0 0 0 1px var(--gold), 0 0 0 3px var(--ink-0);
}
.block-head p { color: var(--text-2); font-size: var(--fs-sm); }
@media (max-width: 900px) { .block-head h2 { font-size: var(--fs-xl); } }
