/*
  ScribesLament — hub theme.

  Artificer, not netrunner: warm paper and deep ink, a single accent of aged brass,
  hairline rules instead of shadows, and motion only on state transitions.

  Applies to hub pages only. Documentation sites keep their own styling; the injected
  widget is deliberately neutral and lives in a shadow root.
*/

/*
  Spectral is self-hosted, latin subset only — no CDN, no third-party request on any
  page load. Body and monospace deliberately stay on system stacks: they resolve to
  SF, Segoe and Cantarell, cost nothing to ship, and render better than anything a
  webfont would buy here. Only the display face has a character worth the bytes.

  SIL Open Font License 1.1 — see wwwroot/fonts/OFL.txt.
*/
@font-face {
  font-family: "Spectral";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/spectral-400.woff2") format("woff2");
}

@font-face {
  font-family: "Spectral";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/spectral-500.woff2") format("woff2");
}

@font-face {
  font-family: "Spectral";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/spectral-400-italic.woff2") format("woff2");
}

:root {
  --font-display: "Spectral", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --step-0: 1rem;
  --step-1: 1.15rem;
  --step-2: 1.4rem;
  --step-3: 1.85rem;
  --step-4: 2.4rem;

  --measure: 68ch;
  --rule-width: 1px;
  --radius: 2px;
  --transition: 120ms ease;

  /* Paper — the daylight reading room. */
  --bg: #f4f0e8;
  --surface: #fbf9f4;
  --surface-sunk: #ece6da;
  --ink: #23201c;
  --ink-muted: #6b6355;
  --ink-faint: #938a79;
  --rule: #dcd3c3;
  --rule-strong: #c4b8a3;
  --brass: #8a6220;
  --brass-bright: #a87c33;
  --brass-wash: #f0e6d2;
  --oxblood: #7d2b2b;
  --verdigris: #40685c;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Lamplight — warm dark, never blue-black. */
    --bg: #1b1815;
    --surface: #232019;
    --surface-sunk: #15130f;
    --ink: #e9e1d1;
    --ink-muted: #a29883;
    --ink-faint: #79705f;
    --rule: #383129;
    --rule-strong: #4d443a;
    --brass: #c99a4e;
    --brass-bright: #ddae5f;
    --brass-wash: #2b2419;
    --oxblood: #b05a56;
    --verdigris: #6fa08f;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 0.5em;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }

p { margin: 0 0 1em; max-width: var(--measure); }

a {
  color: var(--brass);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color var(--transition);
}

a:hover { color: var(--brass-bright); }

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

code, kbd, samp { font-family: var(--font-mono); font-size: 0.9em; }

hr {
  border: 0;
  border-top: var(--rule-width) solid var(--rule);
  margin: 2.5rem 0;
}

/* ---------- Shell ---------- */

.shell {
  width: 100%;
  max-width: 78rem;
  margin-inline: auto;
  padding-inline: 1.75rem;
}

.masthead {
  border-bottom: var(--rule-width) solid var(--rule);
  background: var(--surface);
}

.masthead__inner {
  display: flex;
  align-items: baseline;
  gap: 2rem;
  padding-block: 1.1rem;
}

.wordmark {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.wordmark:hover { color: var(--ink); }

.wordmark__mark { color: var(--brass); margin-right: 0.4rem; }

.nav {
  display: flex;
  gap: 1.5rem;
  margin-left: auto;
  align-items: baseline;
}

.nav a {
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 0.94rem;
  letter-spacing: 0.02em;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}

.nav a:hover { color: var(--ink); border-bottom-color: var(--rule-strong); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brass); }

main { flex: 1 0 auto; padding-block: 3rem 4rem; }

.colophon {
  border-top: var(--rule-width) solid var(--rule);
  padding-block: 1.25rem;
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.colophon__inner { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ---------- Page furniture ---------- */

.page-head { margin-bottom: 2.5rem; }

.page-head__lede {
  color: var(--ink-muted);
  font-size: var(--step-1);
  max-width: var(--measure);
  margin: 0;
}

.section-rule {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin: 3rem 0 1.25rem;
}

.section-rule h2 { margin: 0; font-size: var(--step-2); }

.section-rule::after {
  content: "";
  flex: 1;
  border-top: var(--rule-width) solid var(--rule);
  transform: translateY(-0.3em);
}

.section-rule__count {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* ---------- Search ---------- */

.searchbar { max-width: 42rem; margin-bottom: 1rem; }

.searchbar__field {
  display: flex;
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--transition);
}

.searchbar__field:focus-within { border-color: var(--brass); }

.searchbar input {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 0.75rem 0.9rem;
  font: inherit;
  color: var(--ink);
}

.searchbar input:focus-visible { outline: none; }

.searchbar button {
  border: 0;
  border-left: var(--rule-width) solid var(--rule);
  background: transparent;
  color: var(--brass);
  font: inherit;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  padding-inline: 1.1rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.searchbar button:hover { background: var(--brass-wash); color: var(--brass-bright); }

.searchbar__hint { color: var(--ink-faint); font-size: 0.85rem; margin: 0.5rem 0 0; }

/* ---------- Card grid ---------- */

/*
  Cards carry their own borders rather than being separated by a 1px grid gap over a
  coloured background. That trick draws tidy hairlines between neighbours, but auto-fill
  leaves empty tracks — and their background shows as a large filled block beside a single
  card, which is exactly the case a library starts in.
*/
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 1rem;
  align-items: stretch;
}

.card {
  background: var(--surface);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-decoration: none;
  color: inherit;
  transition: background var(--transition);
}

a.card:hover { background: var(--brass-wash); border-color: var(--rule-strong); }

.card__title {
  font-family: var(--font-display);
  font-size: var(--step-1);
  color: var(--ink);
}

.card__meta {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-faint);
  letter-spacing: 0.03em;
}

.card__body { color: var(--ink-muted); font-size: 0.92rem; margin: 0; }

/* ---------- Status ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  color: var(--ink-muted);
}

.pill--online { color: var(--verdigris); border-color: currentColor; }
.pill--offline { color: var(--oxblood); border-color: currentColor; }

/* ---------- Empty state ---------- */

.empty {
  border: var(--rule-width) dashed var(--rule-strong);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  color: var(--ink-muted);
  background: var(--surface-sunk);
}

.empty p { margin-inline: auto; }
.empty p:last-child { margin-bottom: 0; }

/* ---------- Forms ---------- */

.panel {
  background: var(--surface);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
}

.panel--narrow { max-width: 30rem; }

.field { margin-bottom: 1.15rem; }

.field label {
  display: block;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.4rem;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="url"],
.field textarea,
.field select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  transition: border-color var(--transition);
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--brass);
  outline: none;
}

.field__hint { color: var(--ink-faint); font-size: 0.82rem; margin: 0.35rem 0 0; }

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.check input { accent-color: var(--brass); }

.actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.6rem;
}

.btn {
  font: inherit;
  font-size: 0.92rem;
  letter-spacing: 0.03em;
  padding: 0.6rem 1.3rem;
  border-radius: var(--radius);
  border: var(--rule-width) solid var(--rule-strong);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.btn:hover { border-color: var(--brass); color: var(--brass); }

.btn--primary {
  background: var(--brass);
  border-color: var(--brass);
  color: var(--surface);
}

.btn--primary:hover {
  background: var(--brass-bright);
  border-color: var(--brass-bright);
  color: var(--surface);
}

.btn--quiet { border-color: transparent; color: var(--ink-muted); padding-inline: 0; }
.btn--quiet:hover { border-color: transparent; color: var(--brass); }

.btn--danger { color: var(--oxblood); }
.btn--danger:hover { border-color: var(--oxblood); color: var(--oxblood); }

/* ---------- Notices ---------- */

.notice {
  border: var(--rule-width) solid var(--rule-strong);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.5rem;
  font-size: 0.92rem;
  background: var(--surface);
}

.notice--error { border-left-color: var(--oxblood); color: var(--oxblood); }
.notice--ok { border-left-color: var(--verdigris); color: var(--verdigris); }
.notice--note { border-left-color: var(--brass); color: var(--ink-muted); }

.notice p { margin: 0; max-width: none; }

/* ---------- Identity strip ---------- */

.whoami {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.whoami__name { color: var(--ink); }

.whoami form { display: inline; }

/* ---------- Ledger tables ---------- */

.ledger {
  width: 100%;
  border-collapse: collapse;
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.92rem;
}

.ledger th {
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0.75rem 1rem;
  border-bottom: var(--rule-width) solid var(--rule-strong);
  white-space: nowrap;
}

.ledger td {
  padding: 0.7rem 1rem;
  border-top: var(--rule-width) solid var(--rule);
  vertical-align: middle;
}

.ledger tbody tr:first-child td { border-top: 0; }
.ledger tbody tr:hover { background: var(--brass-wash); }

.ledger__muted { color: var(--ink-muted); }
.ledger__stamp { font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-muted); white-space: nowrap; }
.ledger__actions { text-align: right; white-space: nowrap; }
.ledger__actions form { display: inline; }

.table-scroll { overflow-x: auto; }

.rolebar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.rolebar .check { font-size: 0.84rem; }
.rolebar .btn { font-size: 0.82rem; }

.pill + .pill { margin-left: 0.35rem; }

/* ---------- Copy box ---------- */

.copybox {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: var(--rule-width) solid var(--brass);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 2rem;
  max-width: 52rem;
}

.copybox__value {
  flex: 1;
  padding: 0.8rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  overflow-x: auto;
  white-space: nowrap;
}

.copybox .btn {
  border: 0;
  border-left: var(--rule-width) solid var(--brass);
  border-radius: 0;
  color: var(--brass);
}

.copybox .btn:hover { background: var(--brass-wash); }

/* ---------- Motion ---------- */

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

/* ---------- Rendered configuration ---------- */

.config, pre.plain {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface-sunk);
  border: var(--rule-width) solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  overflow-x: auto;
  white-space: pre;
  margin: 0;
}

pre.plain {
  background: transparent;
  border: 0;
  padding: 0;
  white-space: pre-wrap;
  font-size: 0.82rem;
}

/* ---------- Search results ---------- */

.results { list-style: none; margin: 0; padding: 0; }

.result {
  padding: 1.1rem 0;
  border-top: var(--rule-width) solid var(--rule);
}

.result:first-child { border-top: 0; }

.result__title {
  font-family: var(--font-display);
  font-size: var(--step-1);
  text-decoration: none;
}

.result__title:hover { text-decoration: underline; }

.result__meta {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  color: var(--ink-faint);
  font-size: 0.82rem;
  margin: 0.15rem 0 0.4rem;
}

.result__path { font-family: var(--font-mono); font-size: 0.76rem; }

.result__snippet { color: var(--ink-muted); font-size: 0.92rem; margin: 0; }

.result__snippet mark {
  background: var(--brass-wash);
  color: var(--ink);
  padding: 0 0.1em;
  border-radius: 1px;
}

/* ---------- Card footer ---------- */

.card__footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.6rem;
}

.card__stat {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--ink-faint);
}

/* ---------- Reading paths ---------- */

.path { list-style: none; margin: 0; padding: 0; counter-reset: step; }

.path__heading {
  font-family: var(--font-display);
  font-size: var(--step-1);
  color: var(--ink);
  margin: 2rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: var(--rule-width) solid var(--rule);
}

.path__heading:first-child { margin-top: 0; }

.path__step {
  counter-increment: step;
  position: relative;
  padding: 0.9rem 0 0.9rem 2.6rem;
  border-top: var(--rule-width) solid var(--rule);
}

.path__step::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.95rem;
  width: 1.7rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.path__heading + .path__step { border-top: 0; }

.path__title { font-family: var(--font-display); font-size: var(--step-1); text-decoration: none; }
.path__title:hover { text-decoration: underline; }

.path__step--broken .path__title { color: var(--ink-faint); text-decoration: line-through; }

.path__meta {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  color: var(--ink-faint);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.path__path { font-family: var(--font-mono); font-size: 0.76rem; }
.path__note { color: var(--ink-muted); font-size: 0.92rem; margin: 0.4rem 0 0; }

/* ---------- Page picker ---------- */

.picker { position: relative; }

.picker__list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  max-height: 16rem;
  overflow-y: auto;
  margin-top: 2px;
  background: var(--surface);
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
}

.picker__option {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-top: var(--rule-width) solid var(--rule);
  background: transparent;
  padding: 0.5rem 0.75rem;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

.picker__option:first-child { border-top: 0; }
.picker__option:hover, .picker__option:focus { background: var(--brass-wash); outline: none; }

.picker__title { display: block; font-size: 0.92rem; }
.picker__path { display: block; font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-faint); }

.path__actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.path__actions form { display: inline; }
.path__actions .btn { font-size: 0.78rem; }

/* ---------- Pinned pages on a card ---------- */

.card__title { text-decoration: none; }
a.card__title:hover { text-decoration: underline; }

.card__pins {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0 0 0 0.9rem;
  border-left: 2px solid var(--rule);
}

.card__pins li { margin-bottom: 0.2rem; }
.card__pins a { font-size: 0.9rem; text-decoration: none; }
.card__pins a:hover { text-decoration: underline; }

.card__more { margin-left: auto; font-size: 0.8rem; text-decoration: none; }
.card__more:hover { text-decoration: underline; }

.result__sets { color: var(--ink-faint); }
.result__sets a { font-size: 0.82rem; }

/* ---------- Scrolling rail ---------- */

/*
  A bounded, scrollable region rather than a paginated one. The ordering is the
  information — a page break in the middle of a ranking hides the tail, and the tail is
  where the sites nobody reads are.

  tabindex on the container is deliberate: a scrollable region that cannot be reached or
  scrolled from the keyboard is unusable without a mouse.
*/
.rail {
  max-height: 32rem;
  overflow-y: auto;
  padding: 0.25rem;
  margin: -0.25rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}

.rail:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: var(--radius);
}

.rail::-webkit-scrollbar { width: 8px; }
.rail::-webkit-scrollbar-track { background: transparent; }

.rail::-webkit-scrollbar-thumb {
  background: var(--rule-strong);
  border-radius: 4px;
}

.rail::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
