/* ============================================================================
   RE-SKIN HERE. Every colour, font and radius is a token on :root.
   Skin: "Oxblood & Ink" — noir editorial, committed single dark. Warm ink-black
   ground, paper-white text, one garnet accent for the things that cut. The four
   Courts carry their own hue; in-world canon is warm, development material cools
   to steel so a draft never reads as canon.
   ============================================================================ */
:root {
  color-scheme: dark;
  --bg: #141210;              /* warm ink-black */
  --surface: #1d1a17;
  --surface-2: #252019;
  --text: #ece5da;            /* warm paper — never pure white */
  --muted: #a1968a;
  --border: #352e27;
  --accent: #c05a55;          /* oxblood / garnet — link, brand, emphasis */
  --accent-weak: #4a2f2c;
  --private-bg: #211512;      /* author-only (oxblood-tinted) */
  --private-border: #5e3a37;
  --private-label: #d98a86;

  /* development / behind-the-page: cool steel, held apart from the warm world */
  --dev-bg: #15171a;
  --dev-border: #2b323a;
  --dev-accent: #8893a0;
  --dev-text: #c6ccd4;

  /* the four Courts */
  --court-summer: #cba043;
  --court-winter: #86a0ba;
  --court-spring: #8aa55e;
  --court-autumn: #bb6a3e;

  /* status (keyed to the real status strings for var(--st-<status>)) */
  --st-canon: #c05a55;
  --st-review: #c08a3e;
  --st-draft: #c08a3e;
  --st-proposed: #9a8d7e;
  --st-parked: #9a8d7e;
  --st-merged: #6b6358;

  --radius: 10px;
  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --font: "Source Serif 4", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --maxw: 820px;
  --maxw-wide: 1180px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.65;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* editorial type — Playfair for display titles, Source Serif for body + labels */
.site-header .brand,
.entry-head h1,
.signin h1,
.prose h1, .prose h2 { font-family: var(--font-display); font-weight: 700; letter-spacing: .005em; }
h1, h2, h3, h4, h5 { text-wrap: balance; }

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.site-header .inner {
  max-width: var(--maxw); margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: baseline; gap: 16px;
}
body.wide .site-header .inner { max-width: var(--maxw-wide); }
.site-header .brand { font-weight: 700; letter-spacing: .01em; color: var(--text); font-size: 19px; }
.site-header .nav { display: flex; gap: 14px; }
.site-header .nav a { color: var(--muted); font-size: 14px; }
.site-header .nav a:hover { color: var(--text); text-decoration: none; }
.site-header .tag { color: var(--muted); font-size: 13px; font-style: italic; }

/* search (header) */
.search { position: relative; margin-left: auto; }
.search input {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 14px; width: 220px;
}
.search input:focus { outline: none; border-color: var(--accent); }
.search ul {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; margin: 0; padding: 4px;
  list-style: none; width: 320px; max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,.35);
}
.search li a { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 7px; color: var(--text); }
.search li a:hover, .search li.active a { background: var(--surface-2); text-decoration: none; }
.search .r-type { color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* account chip (header, when auth is on) */
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.account .who { color: var(--muted); }

/* admin tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl .muted { color: var(--muted); }
.tbl select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font: inherit; font-size: 13px; }
#invite-form button { align-self: end; background: var(--accent); color: #15161a; border: none; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; }

/* character index table */
.index-tbl td a { font-weight: 600; }
.index-tbl th:nth-child(2), .index-tbl th:nth-child(3), .index-tbl th:nth-child(4),
.index-tbl td:nth-child(2), .index-tbl td:nth-child(3), .index-tbl td:nth-child(4) { white-space: nowrap; }
.counts { margin-bottom: 24px; }
.linkish { background: none; border: none; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; padding: 0; }

main { max-width: var(--maxw); margin: 0 auto; padding: 28px 20px 80px; }
body.wide main { max-width: var(--maxw-wide); }

.badge {
  display: inline-block; font-size: 12.5px; font-family: var(--font); letter-spacing: .02em;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--muted); background: var(--surface-2);
}
.badge.accent { color: var(--accent); border-color: var(--accent-weak); }
/* court + status badges take their hue from an inline --chip var set per entry */
.badge.court, .badge.status { color: var(--chip, var(--muted)); border-color: color-mix(in srgb, var(--chip, var(--border)) 42%, var(--border)); background: color-mix(in srgb, var(--chip, var(--surface-2)) 8%, var(--surface-2)); }
a.badge:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.badge.id { font-family: var(--mono); letter-spacing: 0; }
/* drafts shortcut in the counts bar */
.badge.draft-chip { color: var(--accent); border-style: dashed; border-color: var(--accent-weak); }
.badge.draft-chip::before { content: "✎ "; opacity: .8; }

/* facet filter bar */
.filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 24px; }
.filterbar .fb-label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.fchip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--text); }
.fchip:hover { border-color: var(--accent); text-decoration: none; }
.fchip .x { color: var(--muted); font-size: 14px; }
.filterbar .clear { color: var(--muted); font-size: 13px; margin-left: 4px; }

/* browse index */
.group { margin: 0 0 28px; }
.group h2 { font-family: var(--font-display); font-size: 22px; font-weight: 700; letter-spacing: 0; text-transform: none; color: var(--text); margin: 0 0 12px; }
.group h2 .count { color: var(--muted); font-weight: 400; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.card .name { font-weight: 600; display: block; }
.card .sub { color: var(--muted); font-size: 13px; }

/* entry page: two columns — prose left (wide), relationships right */
.entry-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; align-items: start; }
.entry-main { min-width: 0; }
.entry-side { position: sticky; top: 72px; }
.side-block { margin-bottom: 24px; }
.side-block h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.side-block ul { list-style: none; margin: 0; padding: 0; }
.side-block li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.side-block li:last-child { border-bottom: none; }
.side-block .rel-label { color: var(--muted); font-size: 12px; }
/* development zone — cool steel, visibly apart from the warm in-world prose */
.technical { margin-top: 40px; border: 1px solid var(--dev-border); background: var(--dev-bg); border-radius: var(--radius); padding: 2px 20px 16px; }
.technical > summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--dev-accent); padding: 13px 0; list-style: none; }
.technical > summary::before { content: "▸ "; }
.technical[open] > summary::before { content: "▾ "; }
.tech-section { margin: 14px 0; border-left: 2px dashed var(--dev-border); padding-left: 14px; }
.tech-section h3 { font-family: var(--font); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; color: var(--dev-text); margin: 0 0 6px; }
.tech-section .prose { color: var(--dev-text); font-size: 14px; }
.tech-section .prose a { color: var(--dev-accent); }
@media (max-width: 860px) {
  .entry-grid { grid-template-columns: 1fr; gap: 24px; }
  .entry-side { position: static; border-top: 1px solid var(--border); padding-top: 18px; }
}

/* entry page */
.entry-head { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 24px; }
.entry-head h1 { margin: 0 0 12px; font-size: clamp(32px, 4.6vw, 48px); line-height: 1.03; }
.entry-head .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
/* drop-cap opens the in-world prose */
.entry-main > .prose > p:first-child::first-letter {
  font-family: var(--font-display); font-weight: 700; float: left;
  font-size: 3.2em; line-height: .78; padding: 8px 10px 0 0; color: var(--accent);
}
.prose h1, .prose h2, .prose h3 { line-height: 1.25; }
.prose img { max-width: 100%; border-radius: var(--radius); }
.prose blockquote { border-left: 3px solid var(--border); margin: 1em 0; padding: 0 1em; color: var(--muted); }

.private {
  margin: 28px 0; border: 1px solid var(--private-border); border-radius: var(--radius);
  background: var(--private-bg); padding: 4px 18px 14px;
}
.private > .label {
  font-family: var(--font); font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--private-label); margin: 12px 0 0; font-weight: 600;
}

.rels { margin-top: 36px; border-top: 1px solid var(--border); padding-top: 18px; }
.rels h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.rels ul { list-style: none; margin: 0 0 16px; padding: 0; }
.rels li { padding: 4px 0; }
.rels .rel-label { color: var(--muted); font-size: 13px; }
.rels .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.rels .chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 14px; }
.missing { color: var(--private-label); }

.admin { margin-top: 40px; padding: 12px 16px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); font-size: 13px; font-family: var(--mono); }
.admin .warn { color: var(--private-label); }
p.admin.warn { color: var(--private-label); }

/* edit form */
.field-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px; min-width: 240px;
}
#content {
  width: 100%; min-height: 60vh; resize: vertical;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; font-family: var(--mono); font-size: 13px; line-height: 1.5;
}
#content:focus, .field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
#save {
  background: var(--accent); color: #15161a; border: none; border-radius: 8px;
  padding: 9px 18px; font: inherit; font-weight: 600; cursor: pointer;
}
#save:hover { filter: brightness(1.08); }
.status { color: var(--muted); font-family: var(--mono); font-size: 13px; }

/* fields editor (structured metadata) */
.fields-editor { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 28px; }
.fields-editor h2, .prose-h { font-family: var(--font-display); font-size: 22px; margin: 0 0 4px; }
.prose-h { margin: 8px 0 12px; }
.fields-editor .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.field .tbd { color: var(--muted); font-weight: 400; font-size: 11px; }
.field.wide { min-width: 0; }
.field.wide input { width: 100%; min-width: 0; }
#save-fields { background: var(--accent); color: #15110f; border: none; border-radius: 8px; padding: 9px 18px; font: inherit; font-weight: 600; cursor: pointer; }

/* court tick in the relationships rail */
.side-block .tick { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }

/* sortable table headers */
.index-tbl th { cursor: pointer; user-select: none; }
.index-tbl th:hover { color: var(--text); }
.index-tbl th .arrow { color: var(--accent); font-size: 10px; margin-left: 5px; opacity: 0; }
.index-tbl th[aria-sort] .arrow { opacity: 1; }
.index-tbl td.role-main a, .index-tbl td.role-main { color: var(--text); font-weight: 600; }
.role-dot { display: inline-block; width: 7px; height: 7px; border-radius: 999px; margin-right: 7px; vertical-align: middle; background: var(--muted); }
.role-dot.main { background: var(--accent); }
.role-dot.supporting { background: var(--court-summer); }
.role-dot.historical { background: var(--dev-accent); }

/* home-page guided-reads strip */
.home-reads { margin: 0 0 32px; }
.home-reads-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--text); }
.home-reads-title:hover { color: var(--accent); text-decoration: none; }
.home-reads-sub { color: var(--muted); margin: 4px 0 0; font-size: 15px; }
.read-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.read-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--text); }
.read-chip:hover { border-color: var(--accent); text-decoration: none; }

/* ---- reading view ---- */
/* wide two-column: sticky table of contents + the reading column */
.reading-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 48px; align-items: start; }
.reading-toc { position: sticky; top: 80px; }
.reading-toc .back { font-size: 13px; color: var(--muted); }
.reading-toc .toc-label { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 16px 0 10px; }
.reading-toc ol { list-style: none; margin: 0; padding: 0; counter-reset: toc; }
.reading-toc li { counter-increment: toc; margin: 0; }
.reading-toc li a { display: block; padding: 5px 0 5px 24px; position: relative; color: var(--muted); font-size: 14px; line-height: 1.3; border-left: 2px solid var(--border); }
.reading-toc li a::before { content: counter(toc); position: absolute; left: 8px; font-size: 11px; color: var(--muted); opacity: .6; }
.reading-toc li a:hover { color: var(--text); text-decoration: none; }
.reading-toc li a.current { color: var(--accent); border-left-color: var(--accent); }
.read-section { scroll-margin-top: 84px; }
@media (max-width: 820px) {
  .reading-layout { grid-template-columns: 1fr; gap: 20px; }
  .reading-toc { position: static; border-bottom: 1px solid var(--border); padding-bottom: 14px; }
  .reading-toc ol { columns: 2; }
}

.read-head { margin-bottom: 28px; }
.lede { color: var(--muted); font-size: 18px; max-width: 60ch; line-height: 1.55; }
.read-head h1, .reading-hero h1 { font-family: var(--font-display); font-weight: 700; }
.read-head h1 { font-size: clamp(30px, 4.5vw, 44px); margin: 0 0 12px; }
.thread-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.thread-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; }
.thread-card:hover { border-color: var(--accent); text-decoration: none; }
.thread-card h2 { font-family: var(--font-display); font-size: 24px; margin: 0 0 8px; color: var(--text); }
.thread-card p { color: var(--muted); margin: 0 0 14px; font-size: 15px; }
.thread-card .count { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }

.reading { max-width: 42rem; margin: 0 auto; }
.reading-hero { padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 40px; }
.reading-hero .back { font-size: 13px; color: var(--muted); }
.reading-hero h1 { font-size: clamp(34px, 5vw, 52px); margin: 12px 0 12px; line-height: 1.03; }
.read-section { margin: 0 0 56px; }
.read-section-head { margin-bottom: 16px; }
.read-section-head h2 { font-family: var(--font-display); font-size: 28px; margin: 0; }
.read-section-head h2 a { color: var(--text); }
.read-section-head h2 a:hover { color: var(--accent); text-decoration: none; }
.read-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.rtag { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; }
.rtag.court { color: var(--chip, var(--muted)); border-color: color-mix(in srgb, var(--chip, var(--border)) 42%, var(--border)); }
.read-section .prose { font-size: 18px; }
.read-section .prose > p:first-of-type::first-letter {
  font-family: var(--font-display); font-weight: 700; float: left;
  font-size: 3em; line-height: .8; padding: 7px 10px 0 0; color: var(--accent);
}
.read-more { display: inline-block; margin-top: 14px; color: var(--accent); font-size: 14px; }
.read-chapter { font-family: var(--font-display); font-size: 15px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 8px 0 28px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.reading-toc .toc-chapter { counter-increment: none; margin: 14px 0 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }

/* reading-collection curator */
.curate-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 36px; align-items: start; }
.curate-list { position: sticky; top: 80px; }
.curate-list ul { list-style: none; margin: 0 0 14px; padding: 0; }
.curate-list li a { display: block; padding: 5px 0; color: var(--muted); font-size: 14px; }
.curate-list li a.current { color: var(--accent); }
.curate-list li a:hover { color: var(--text); text-decoration: none; }
.newread { font-size: 14px; }
.curate-form h2 { font-family: var(--font-display); font-size: 22px; margin: 0 0 16px; }
.picker { display: flex; gap: 10px; align-items: flex-start; margin: 20px 0 10px; }
.picker-search { position: relative; flex: 1; min-width: 0; }
.picker-search input { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font: inherit; font-size: 14px; }
.picker-search ul { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; max-height: 50vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.4); }
.picker-search li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.picker-search li:hover { background: var(--surface-2); }
.picker-search .r-type { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.ghost { background: none; border: 1px dashed var(--border); color: var(--muted); border-radius: 8px; padding: 9px 14px; font: inherit; font-size: 14px; cursor: pointer; }
.ghost:hover { border-color: var(--accent); color: var(--text); }
.curate-items { list-style: none; margin: 0; padding: 0; counter-reset: ci; }
.ci { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--surface); }
.ci.chapter { background: var(--surface-2); border-style: dashed; }
.ci.chapter .ci-label { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; color: var(--muted); }
.ci.missing .ci-label { color: var(--private-label); }
.ci.empty { justify-content: flex-start; color: var(--muted); border-style: dashed; background: none; }
.ci-ctrls button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 4px; }
.ci-ctrls button:hover { color: var(--accent); }
#c-save { background: var(--accent); color: #15110f; border: none; border-radius: 8px; padding: 9px 18px; font: inherit; font-weight: 600; cursor: pointer; }
@media (max-width: 760px) { .curate-grid { grid-template-columns: 1fr; gap: 18px; } .curate-list { position: static; } }
