/* ============================================================
   An Index — stylesheet
   Palette : cool laid paper, ink, ballpoint blue, pencil grey
   Type    : EB Garamond (prose) · DM Mono (data + interface)
   ============================================================ */

:root {
  --paper:      #eeefeb;
  --paper-deep: #e4e6e0;
  --ink:        #16181a;
  --pen:        #1f3fbf;
  --pen-wash:   rgba(31, 63, 191, 0.09);
  --pencil:     #7e837a;
  --rule:       #c9cbc4;

  --serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono:  "DM Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: 34rem;
  --gutter: clamp(1.25rem, 5vw, 4.5rem);
  --rhythm: clamp(3.5rem, 8vw, 7rem);

  --step--1: 0.78rem;
  --step-0:  1.0625rem;
  --step-1:  1.25rem;
  --step-2:  clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem);
  --step-3:  clamp(2.25rem, 1.3rem + 4vw, 4rem);
  --step-4:  clamp(2.25rem, 0.4rem + 7.6vw, 7.5rem);
}

/* The dark palette is assigned twice on purpose. The media query serves
   "auto" — and still works with JavaScript off. The attribute serves an
   explicit choice from the toggle, and must win over the system setting.
   Keep the two blocks in step. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #131519;
    --paper-deep: #191c21;
    --ink:        #e6e7e2;
    --pen:        #8ba2ff;
    --pen-wash:   rgba(139, 162, 255, 0.12);
    --pencil:     #7c8079;
    --rule:       #2e3238;
  }
}

:root[data-theme="dark"] {
  --paper:      #131519;
  --paper-deep: #191c21;
  --ink:        #e6e7e2;
  --pen:        #8ba2ff;
  --pen-wash:   rgba(139, 162, 255, 0.12);
  --pencil:     #7c8079;
  --rule:       #2e3238;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--step-0);
  line-height: 1.55;
  font-feature-settings: "onum" 1, "kern" 1;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--pen); }

:focus-visible {
  outline: 2px solid var(--pen);
  outline-offset: 3px;
  border-radius: 1px;
}

::selection { background: var(--pen); color: var(--paper); }

/* ---------- shared utilities ---------- */

.wrap { max-width: 74rem; margin-inline: auto; padding-inline: var(--gutter); }

.mono {
  font-family: var(--mono);
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pencil);
  font-weight: 400;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--ink); color: var(--paper);
  padding: 0.6rem 1rem; font-family: var(--mono); font-size: var(--step--1);
}
.skip:focus { left: 0.75rem; top: 0.75rem; z-index: 99; }

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem 2rem;
  padding-block: 1.4rem 1.1rem;
  border-bottom: 1px solid var(--ink);
}

.masthead__mark {
  font-family: var(--mono);
  font-size: var(--step--1);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
}
.masthead__mark b { font-weight: 500; }
.masthead__mark span { color: var(--pencil); }

.nav { display: flex; gap: 1.5rem; font-family: var(--mono); font-size: var(--step--1); letter-spacing: 0.06em; }
.nav a { text-decoration: none; color: var(--pencil); text-transform: lowercase; }
.nav a:hover { color: var(--pen); }
.nav a[aria-current="page"] { color: var(--ink); }
.nav a[aria-current="page"]::before { content: "\2192\00a0"; color: var(--pen); }
.nav a[data-authoring] { color: var(--pen); }
.nav a[hidden] { display: none; }

.theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  color: var(--pencil);
  background: transparent;
  border: 0;
  cursor: pointer;
  border-radius: 0;
  line-height: 0;
}
.theme:hover { color: var(--pen); }
.theme svg { display: block; overflow: visible; }

/* light — an empty ring. dark — a solid disc. */
.theme__ring { fill: none; stroke: currentColor; stroke-width: 1.4; }
.theme[data-state="dark"] .theme__ring { fill: currentColor; }

/* ---------- hero ---------- */

.hero { padding-block: clamp(3rem, 9vw, 7rem) clamp(2rem, 4vw, 3.25rem); }

.hero__lede {
  font-size: var(--step-4);
  line-height: 0.94;
  letter-spacing: -0.022em;
  margin: 0;
  max-width: 16ch;
  font-weight: 400;
  overflow-wrap: break-word;
}
.hero__lede em { font-style: italic; color: var(--pen); }

.hero__foot {
  margin-top: clamp(2rem, 5vw, 3.5rem);
  display: flex;
  flex-wrap: wrap;
  gap: 2rem 4rem;
  align-items: flex-start;
  justify-content: space-between;
}

.hero__gloss { max-width: 30rem; margin: 0; font-size: var(--step-1); line-height: 1.5; }

.tally { display: flex; gap: 2.25rem; font-family: var(--mono); }
.tally div { display: flex; flex-direction: column; gap: 0.15rem; }
.tally dt, .tally .t { font-size: var(--step--1); letter-spacing: 0.08em; text-transform: uppercase; color: var(--pencil); }
.tally dd, .tally .n { margin: 0; font-family: var(--serif); font-size: var(--step-2); line-height: 1; letter-spacing: -0.01em; }

/* ---------- section headers ---------- */

.band { padding-block: clamp(2.5rem, 5vw, 4rem) var(--rhythm); border-top: 1px solid var(--rule); }
.band:first-of-type { border-top: 0; }

.band__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 2.25rem;
}
.band__title { margin: 0; font-size: var(--step-2); font-weight: 400; letter-spacing: -0.01em; }
.band__note { margin: 0; max-width: 34ch; }

/* flex-basis:100% won't wrap the note onto its own line, because max-width
   clamps the hypothetical size back down. Drop out of flex instead. */
@media (max-width: 40rem) {
  .band__head { display: block; }
  .band__note { margin-top: 0.55rem; }
  .tally { gap: 1.25rem; }
}

/* ---------- controls (search + alphabet) ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  padding-block: 0.9rem;
  border-block: 1px solid var(--rule);
  margin-bottom: 2rem;
}

.search { flex: 1 1 16rem; display: flex; align-items: baseline; gap: 0.7ch; }
.search label { font-family: var(--mono); font-size: var(--step--1); letter-spacing: 0.06em; text-transform: uppercase; color: var(--pencil); white-space: nowrap; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  font-family: var(--serif);
  font-size: var(--step-0);
  color: inherit;
  padding: 0.1rem 0;
}
.search input::placeholder { color: var(--pencil); opacity: 0.7; }
.search input:focus { outline: 0; border-bottom-color: var(--pen); }

.alphabet { display: flex; flex-wrap: wrap; gap: 0.1rem; font-family: var(--mono); font-size: var(--step--1); }
.alphabet a { padding: 0.15rem 0.38rem; text-decoration: none; color: var(--pencil); text-transform: uppercase; }
.alphabet a:hover { color: var(--paper); background: var(--pen); }
.alphabet span { padding: 0.15rem 0.38rem; color: var(--rule); text-transform: uppercase; }

/* ---------- the index (signature) ---------- */

.index { columns: 2; column-gap: 4.5rem; }
@media (max-width: 46rem) { .index { columns: 1; } }

.topic {
  break-inside: avoid;
  page-break-inside: avoid;
  margin: 0 0 1.9rem;
}

.topic__name {
  margin: 0 0 0.15rem;
  font-size: var(--step-1);
  font-weight: 400;
  font-variant: small-caps;
  letter-spacing: 0.035em;
  scroll-margin-top: 5rem;
}
.topic__name a { text-decoration: none; }
.topic__name a:hover { color: var(--pen); }
.topic__name sup {
  font-family: var(--mono);
  font-size: 0.5em;
  letter-spacing: 0.05em;
  color: var(--pencil);
  vertical-align: super;
  margin-left: 0.5ch;
}

.entry {
  display: block;
  text-decoration: none;
  padding-left: 1.35rem;
  line-height: 1.42;
  padding-block: 0.09rem;
}
.entry__line { display: flex; align-items: baseline; }
.entry__title { flex: 0 1 auto; }
.entry__leader {
  flex: 1 1 1.5rem;
  min-width: 1.5rem;
  border-bottom: 1px dotted var(--rule);
  transform: translateY(-0.3em);
  margin-inline: 0.55ch;
}
.entry__ref {
  font-family: var(--mono);
  font-size: 0.74em;
  letter-spacing: 0.04em;
  color: var(--pencil);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.entry:hover .entry__title { color: var(--pen); }
.entry:hover .entry__leader { border-bottom-color: var(--pen); }
.entry:hover .entry__ref { color: var(--pen); }
.entry[data-kind="note"] .entry__title { font-style: italic; }

.entry__gloss {
  display: block;
  margin: 0.1rem 0 0.05rem;
  font-size: 0.85em;
  line-height: 1.42;
  color: var(--pencil);
  text-wrap: pretty;
}
.entry:hover .entry__gloss { color: var(--ink); }

/* Descriptions triple the height of the index, so they can be turned off.
   Pure CSS, keyed off the container — survives every search re-render. */
.index[data-glosses="off"] .entry__gloss { display: none; }
.index[data-glosses="on"] .entry { padding-block: 0.3rem; }
.index[data-glosses="on"] .topic { margin-bottom: 2.4rem; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5ch;
  font-family: var(--mono);
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pencil);
  cursor: pointer;
  white-space: nowrap;
}
.toggle input { accent-color: var(--pen); margin: 0; cursor: pointer; }
.toggle:hover { color: var(--ink); }

.seealso {
  padding-left: 1.35rem;
  margin-top: 0.2rem;
  font-size: 0.86em;
  font-style: italic;
  color: var(--pencil);
}
.seealso a { text-decoration: none; border-bottom: 1px solid var(--rule); }
.seealso a:hover { border-bottom-color: var(--pen); }

.index__empty { font-style: italic; color: var(--pencil); }

/* ---------- ledger (links + notes listings) ---------- */

.ledger { border-top: 1px solid var(--ink); }

.row {
  position: relative;
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr) 12rem 6rem;
  gap: 0 1.5rem;
  align-items: baseline;
  padding-block: 1.05rem;
  border-bottom: 1px solid var(--rule);
}
.row:hover { background: var(--pen-wash); }
.row__ref { font-family: var(--mono); font-size: var(--step--1); color: var(--pencil); font-variant-numeric: tabular-nums; }
.row:hover .row__ref { color: var(--pen); }
.row__title { font-size: var(--step-1); line-height: 1.3; }

/* The title link covers the whole row so anywhere is clickable... */
.row__link { text-decoration: none; }
.row__link::after { content: ""; position: absolute; inset: 0; }
.row:hover .row__link { color: var(--pen); }

.row__gloss { display: block; margin-top: 0.28rem; font-size: 0.92rem; color: var(--pencil); max-width: 46ch; line-height: 1.5; }
.row__topics { font-family: var(--mono); font-size: var(--step--1); color: var(--pencil); line-height: 1.6; }

/* ...and the topic links ride above that overlay so they stay clickable. */
.row__topics a {
  position: relative;
  z-index: 1;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.row__topics a:hover { color: var(--pen); border-bottom-color: var(--pen); }

.row__date { font-family: var(--mono); font-size: var(--step--1); color: var(--pencil); text-align: right; font-variant-numeric: tabular-nums; }

.row--head { padding-block: 0.55rem; border-bottom-color: var(--ink); }
.row--head span { font-family: var(--mono); font-size: var(--step--1); letter-spacing: 0.08em; text-transform: uppercase; color: var(--pencil); }
.row--head .row__date { text-align: right; }

@media (max-width: 58rem) {
  .row { grid-template-columns: 3.5rem minmax(0, 1fr); }
  .row__topics { grid-column: 2; margin-top: 0.35rem; }
  .row__date { grid-column: 2; text-align: left; margin-top: 0.15rem; }
  .row--head { display: none; }
}

/* ---------- topic permalink page ---------- */

.topicpage__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 2rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--rule);
}
.topicpage__bar p { margin: 0; }

.pager { display: flex; gap: 1.75rem; font-family: var(--mono); font-size: var(--step--1); }
.pager a { text-decoration: none; color: var(--pencil); }
.pager a:hover { color: var(--pen); }

.topicpage__title {
  margin: clamp(1.75rem, 4vw, 3rem) 0 0;
  font-size: var(--step-3);
  line-height: 1;
  letter-spacing: -0.02em;
  font-weight: 400;
  font-variant: small-caps;
}

.topicpage__tally { margin: 0.7rem 0 0; }
.topicpage__see { padding-left: 0; margin: 0.5rem 0 clamp(2rem, 4vw, 3rem); font-size: var(--step-0); }

/* ---------- filters ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.75rem; }
.filters button {
  font-family: var(--mono);
  font-size: var(--step--1);
  letter-spacing: 0.04em;
  color: var(--pencil);
  background: transparent;
  border: 1px solid var(--rule);
  padding: 0.28rem 0.7rem;
  cursor: pointer;
  border-radius: 0;
}
.filters button:hover { color: var(--ink); border-color: var(--pencil); }
.filters button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.filters button sup { font-size: 0.75em; margin-left: 0.45ch; opacity: 0.65; }

/* ---------- reading view ---------- */

.article { padding-block: clamp(3rem, 7vw, 5.5rem) var(--rhythm); }
.article__head { margin-bottom: 3rem; }
.article__title {
  margin: 0.6rem 0 0;
  font-size: var(--step-3);
  line-height: 1.02;
  letter-spacing: -0.02em;
  font-weight: 400;
  max-width: 20ch;
}
.article__dek { margin: 1rem 0 0; font-size: var(--step-1); color: var(--pencil); font-style: italic; max-width: var(--measure); }

.prose { max-width: var(--measure); font-size: 1.19rem; line-height: 1.62; }
/* Order matters here: the reset must come first, and every rule below it must
   stay at the same specificity (0,1,0) or the sibling spacing gets cancelled. */
.prose > * { margin-block: 0; }
.prose > * + * { margin-top: 1.35em; }
.prose h2 {
  font-size: var(--step-1);
  font-weight: 400;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  margin-top: 2.4em;
}
.prose blockquote {
  margin: 2em 0;
  padding-left: 1.4rem;
  border-left: 1px solid var(--pen);
  font-style: italic;
  color: var(--pencil);
}
.prose a { text-decoration-color: var(--pen); }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.6em 0; }
.prose code { font-family: var(--mono); font-size: 0.85em; background: var(--paper-deep); padding: 0.1em 0.35em; }

.colophon-list { max-width: var(--measure); }
.colophon-list dt { font-family: var(--mono); font-size: var(--step--1); letter-spacing: 0.06em; text-transform: uppercase; color: var(--pencil); margin-top: 1.6rem; }
.colophon-list dd { margin: 0.3rem 0 0; }

/* ---------- authoring form (admin.html only) ---------- */

.field { margin-bottom: 1.6rem; max-width: var(--measure); }
.field label {
  display: block;
  font-family: var(--mono);
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pencil);
  margin-bottom: 0.4rem;
}
.field input, .field textarea {
  width: 100%;
  background: transparent;
  color: inherit;
  border: 1px solid var(--rule);
  padding: 0.55rem 0.7rem;
  font-family: var(--serif);
  font-size: var(--step-0);
  line-height: 1.5;
  border-radius: 0;
}
.field textarea { min-height: 16rem; resize: vertical; }
.field input:focus, .field textarea:focus { outline: 0; border-color: var(--pen); }
.field .hint { margin: 0.4rem 0 0; font-size: 0.9rem; color: var(--pencil); font-style: italic; }
.field--split { display: grid; grid-template-columns: 1fr 12rem; gap: 1.2rem; max-width: var(--measure); }
.field--split > * { margin-bottom: 0; }

.btn {
  font-family: var(--mono);
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  padding: 0.55rem 1.3rem;
  cursor: pointer;
  border-radius: 0;
}
.btn:hover { background: var(--pen); border-color: var(--pen); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.btn--quiet {
  background: transparent;
  color: var(--pencil);
  border-color: var(--rule);
  padding: 0.25rem 0.7rem;
  text-transform: none;
  letter-spacing: 0.04em;
}
.btn--quiet:hover { background: transparent; color: var(--pen); border-color: var(--pen); }

.notice {
  max-width: var(--measure);
  margin: 0 0 1.75rem;
  padding: 0.75rem 1rem;
  border-left: 2px solid var(--pen);
  background: var(--pen-wash);
  font-size: 0.96rem;
}
.notice--bad { border-left-color: #c0392b; background: rgba(192, 57, 43, 0.09); }
.notice[hidden] { display: none; }

.manage { border-top: 1px solid var(--ink); }
.manage__row {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr) auto;
  gap: 0 1.5rem;
  align-items: baseline;
  padding-block: 0.95rem;
  border-bottom: 1px solid var(--rule);
}
.manage__row .row__ref { font-family: var(--mono); font-size: var(--step--1); color: var(--pencil); }
.manage__meta { display: block; margin-top: 0.25rem; font-family: var(--mono); font-size: var(--step--1); color: var(--pencil); }
@media (max-width: 40rem) {
  .manage__row { grid-template-columns: 3.5rem minmax(0, 1fr); }
  .manage__row .btn--quiet { grid-column: 2; justify-self: start; margin-top: 0.5rem; }
  .field--split { grid-template-columns: 1fr; }
}

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

.foot {
  border-top: 1px solid var(--ink);
  padding-block: 2rem 3.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2.5rem;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--mono);
  font-size: var(--step--1);
  letter-spacing: 0.05em;
  color: var(--pencil);
}
.foot a { text-decoration: none; }
.foot nav { display: flex; gap: 1.5rem; }

/* ---------- entrance ---------- */

@media (prefers-reduced-motion: no-preference) {
  .rise { opacity: 0; transform: translateY(0.6rem); animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
  @keyframes rise { to { opacity: 1; transform: none; } }
}
