/* NPWD — "Cartographer's Ledger"
   A weathered registry: faded sepia ink on aged vellum, ruled entries,
   a folio gutter in the margin. Plain CSS, custom properties, native nesting. */

/* ---- Self-hosted faces (priv/static/fonts) ---------------------------- */
@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/eb-garamond-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/eb-garamond-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/eb-garamond-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/eb-garamond-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IM Fell English";
  src: url("/fonts/im-fell-english-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IM Fell English";
  src: url("/fonts/im-fell-english-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* ---- Tokens ----------------------------------------------------------- */
:root {
  --vellum: #e7d9b9;
  --vellum-2: #ddcda6;
  --vellum-edge: #d8c6a0;
  --ink: #2b2117;
  --sepia: #6f5b3e;
  --rule: #b8a279;
  --madder: #7a2e22;
  --verdigris: #3f6b5e;

  --display: "IM Fell English", "Hoefler Text", Georgia, serif;
  --body: "EB Garamond", "Hoefler Text", Georgia, serif;

  --measure: 58rem;
  --gutter: 3.5rem;
  --radius: 2px;
}

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

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

body {
  margin: 0;
  font-family: var(--body);
  font-size: 1.15rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--vellum);
  /* foxing: faint age-stains scattered across the leaf */
  background-image:
    radial-gradient(
      ellipse at 17% 22%,
      rgba(120, 90, 50, 0.1),
      transparent 42%
    ),
    radial-gradient(ellipse at 83% 13%, rgba(120, 90, 50, 0.08), transparent 38%),
    radial-gradient(ellipse at 72% 82%, rgba(110, 80, 45, 0.1), transparent 46%),
    radial-gradient(ellipse at 28% 74%, rgba(120, 90, 50, 0.06), transparent 40%);
  background-attachment: fixed;
}

h1,
h2,
h3 {
  font-family: var(--display);
  font-weight: 400;
  color: var(--madder);
  line-height: 1.1;
  margin: 0 0 0.4em;
}

p {
  margin: 0 0 0.75em;
}

a {
  color: var(--verdigris);
  text-underline-offset: 2px;
}

/* ---- Form controls: ink written on a ruled line ----------------------- */
input,
select,
button {
  font-family: var(--body);
  font-size: 1rem;
  color: var(--ink);
}

input,
select {
  appearance: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  padding: 0.3rem 0.2rem;
  line-height: 1.4;
}

input::placeholder {
  color: var(--sepia);
  opacity: 0.7;
  font-style: italic;
}

input:focus,
select:focus {
  outline: 0;
  border-bottom-color: var(--madder);
  border-bottom-width: 2px;
}

select {
  cursor: pointer;
  padding-right: 1.4rem;
  /* a small sepia caret, since appearance:none drops the native one */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%236f5b3e'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.25rem center;
}

button {
  cursor: pointer;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--vellum-2);
  color: var(--ink);
  padding: 0.3rem 0.7rem;
  font-variant: small-caps;
  letter-spacing: 0.03em;
  transition: border-color 0.15s ease, background 0.15s ease;
}

button:hover {
  border-color: var(--ink);
}

/* ---- Accessibility floor --------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--madder);
  outline-offset: 2px;
}

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

/* ====================================================================== */
/* Components — the bound leaf                                             */
/* ====================================================================== */

/* ---- The codex: a leaf of the register -------------------------------- */
.codex {
  max-width: var(--measure);
  margin: 2rem auto;
  padding: 2.5rem clamp(1.25rem, 4vw, 3rem) 4rem;
  background: var(--vellum);
  border: 1px solid var(--vellum-edge);
  border-radius: var(--radius);
  box-shadow:
    0 1px 2px rgba(43, 33, 23, 0.18),
    0 22px 48px -30px rgba(43, 33, 23, 0.5);
  animation: leaf-in 0.5s ease both;
}

@keyframes leaf-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---- Masthead / running head ------------------------------------------ */
.masthead {
  margin-bottom: 1.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--madder);
}

.masthead__lead:not(:empty) {
  margin-bottom: 0.4rem;
}

.masthead__title {
  margin: 0;
  font-size: clamp(2.3rem, 6vw, 3.4rem);
  letter-spacing: 0.01em;
}

.masthead__sub {
  font-variant: small-caps;
  letter-spacing: 0.2em;
  color: var(--sepia);
  font-size: 0.9rem;
}

.masthead__back {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--verdigris);
  font-variant: small-caps;
  letter-spacing: 0.08em;
}

.masthead__back:hover {
  border: 0;
  text-decoration: underline;
}

/* ---- Chapters --------------------------------------------------------- */
.chapter {
  margin: 2.25rem 0;
}

.chapter__title {
  font-size: 1.65rem;
  margin: 0 0 0.85rem;
}

.chapter__title::before {
  content: "❧";
  margin-right: 0.5rem;
  color: var(--rule);
  font-size: 0.85em;
}

/* ---- Forms: a fair-hand panel ----------------------------------------- */
.panel {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  margin-bottom: 1.1rem;
  padding: 1rem 1.1rem;
  background: var(--vellum-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.panel input,
.panel select {
  flex: 1 1 9rem;
  min-width: 8rem;
}

.panel .subfields,
.panel .date-inputs,
.panel .generic-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  flex: 1 1 100%;
}

.panel .date-inputs input {
  flex: 1 1 4rem;
  min-width: 0;
}

/* graph filter: a path line (from — rel → to), then a key/value line */
.panel .filter-line {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  flex: 1 1 100%;
}

.panel .filter-actions {
  display: flex;
  gap: 0.5rem;
  flex: 1 1 100%;
}

/* primary action: pressed in rubric red */
.btn-primary {
  background: var(--madder);
  border-color: var(--madder);
  color: var(--vellum);
}

.btn-primary:hover {
  background: #682318;
  border-color: #682318;
}

/* ---- Registry: ruled, foliated entries -------------------------------- */
.registry {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: folio;
  border-top: 1px solid var(--rule);
}

.entry {
  counter-increment: folio;
  display: grid;
  grid-template-columns: var(--gutter) 1fr auto;
  align-items: baseline;
  gap: 0.4rem 1rem;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.entry::before {
  content: counter(folio, decimal-leading-zero);
  text-align: right;
  font-variant: small-caps;
  font-size: 0.8em;
  letter-spacing: 0.05em;
  color: var(--sepia);
}

.entry:nth-child(even) {
  background: rgba(43, 33, 23, 0.03);
}

.entry__body {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 0.7rem;
}

.entry__name {
  font-size: 1.15rem;
}

.entry__actions {
  display: flex;
  gap: 0.35rem;
}

.entry__actions button {
  font-size: 0.78rem;
  padding: 0.12rem 0.5rem;
}

/* a relationship written between two names: from —rel→ to */
.relation {
  color: var(--sepia);
  font-style: italic;
}

.relation::before {
  content: "—";
  margin: 0 0.3rem;
  color: var(--rule);
  font-style: normal;
}

.relation::after {
  content: "→";
  margin: 0 0.3rem;
  color: var(--rule);
  font-style: normal;
}

/* kind, a sepia small-cap tag */
.kind {
  font-variant: small-caps;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  color: var(--sepia);
}

/* ---- Annotations: a node's ordered entries, set apart in the panel ---- */
.descriptions {
  flex: 1 1 100%;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--rule);
}

.descriptions__head {
  margin: 0 0 0.5rem;
  font-variant: small-caps;
  letter-spacing: 0.16em;
  font-size: 0.8rem;
  color: var(--sepia);
}

.descriptions__list {
  list-style: none;
  margin: 0 0 0.9rem;
  padding: 0;
  counter-reset: note;
  border-top: 1px solid var(--rule);
}

.description {
  counter-increment: note;
  display: grid;
  grid-template-columns: 1.8rem 1fr auto;
  align-items: baseline;
  gap: 0.2rem 0.85rem;
  padding: 0.55rem 0.25rem;
  border-bottom: 1px solid var(--rule);
}

.description::before {
  content: counter(note);
  text-align: right;
  font-variant: small-caps;
  font-size: 0.8em;
  letter-spacing: 0.04em;
  color: var(--rule);
}

.description-body {
  margin: 0;
  line-height: 1.45;
}

.description-delete {
  align-self: start;
  font-size: 0.72rem;
  padding: 0.1rem 0.5rem;
  background: transparent;
  border-color: transparent;
  color: var(--sepia);
}

.description-delete:hover {
  border-color: var(--rule);
  color: var(--madder);
}

/* the composer: a ruled note slip + its action */
.descriptions__compose {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
}

textarea {
  font-family: var(--body);
  font-size: 1rem;
  color: var(--ink);
  width: 100%;
  min-height: 4rem;
  resize: vertical;
  appearance: none;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: rgba(231, 217, 185, 0.55);
  padding: 0.5rem 0.65rem;
  line-height: 1.5;
}

textarea::placeholder {
  color: var(--sepia);
  opacity: 0.7;
  font-style: italic;
}

textarea:focus {
  outline: 0;
  border-color: var(--madder);
}

/* ---- Status / empty states ------------------------------------------- */
.status {
  color: var(--sepia);
  font-style: italic;
  padding: 0.55rem 0.5rem;
}

/* ---- The web (graph) -------------------------------------------------- */
.graph__summary {
  font-variant: small-caps;
  letter-spacing: 0.06em;
  color: var(--sepia);
}

.graph__canvas {
  margin-top: 0.6rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--vellum-2);
  overflow: auto;
  max-width: 100%;
}

/* the web, drawn in ink on vellum (geometry comes from graph_ffi.mjs) */
.graph-svg {
  display: block;
  font-family: var(--body);
}

.graph-edge {
  stroke: var(--rule);
  stroke-width: 1;
}

.graph-edge-label {
  fill: var(--sepia);
  font-size: 11px;
  font-style: italic;
}

.graph-node {
  fill: var(--madder);
  stroke: var(--vellum);
  stroke-width: 1.5;
}

.graph-node-label {
  fill: var(--ink);
  font-size: 12px;
}

/* ---- The chronicle (timeline) ---------------------------------------- */
.chronicle {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.event {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  column-gap: 1rem;
  row-gap: 0.15rem;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.event__when {
  grid-column: 1;
  grid-row: 1;
  text-align: right;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  font-size: 0.85rem;
  color: var(--madder);
}

.event__name {
  grid-column: 2;
  grid-row: 1;
  font-size: 1.2rem;
}

.event__links {
  grid-column: 2;
  grid-row: 2;
  list-style: none;
  margin: 0.15rem 0 0;
  padding: 0;
}

.marginalia {
  color: var(--sepia);
  font-style: italic;
  font-size: 0.95rem;
}

.marginalia::before {
  content: "↳ ";
  color: var(--rule);
  font-style: normal;
}

/* ---- Narrow leaves ---------------------------------------------------- */
@media (max-width: 34rem) {
  body {
    font-size: 1.05rem;
  }

  .codex {
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  /* fold the actions onto their own line so rows never overflow */
  .entry {
    grid-template-columns: 1.9rem 1fr;
  }

  .entry__actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .event {
    grid-template-columns: 4.5rem 1fr;
  }
}
