/* tufte-dense — Edward Tufte tradition: ET Book serif, sidenotes,
   sparklines, dense small multiples, near-black ink on cream paper.
   Inspired by Tufte CSS (edwardtufte.github.io/tufte-css). */

:root {
  --paper:   #fffff8;
  --ink:     #111111;
  --dim:     #7a7263;
  --rule:    #bdb6a3;
  --accent:  #a02000;
  --ok:      #3a6b3a;
  --err:     #a02000;
  --pending: #8a6a14;
  --code-bg: #f4f0dd;
}

html[data-theme="dark"] {
  --paper:   #151513;
  --ink:     #e8e2cc;
  --dim:     #8a8270;
  --rule:    #3a3530;
  --accent:  #c95a3a;
  --ok:      #7caf6f;
  --err:     #c95a3a;
  --pending: #c2a04e;
  --code-bg: #1f1d18;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --paper:   #151513;
    --ink:     #e8e2cc;
    --dim:     #8a8270;
    --rule:    #3a3530;
    --accent:  #c95a3a;
    --ok:      #7caf6f;
    --err:     #c95a3a;
    --pending: #c2a04e;
    --code-bg: #1f1d18;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  /* ET Book or close serif fallback. ET Book itself isn't on Google Fonts;
     we list it first in case a viewer has it installed, then fall back to
     a comparable text-flavour serif. */
  font-family: "et-book", "ETBembo", "EB Garamond", "Iowan Old Style",
               "Apple Garamond", "Baskerville", Palatino, Georgia, serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* HEADER — narrow band, like a journal masthead */
header {
  border-bottom: 1px solid var(--rule);
  padding: 1rem 4%;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .5rem 1.5rem;
  align-items: baseline;
}
.brand { font-style: italic; font-size: 1.4rem; }
header nav { font-size: .9rem; color: var(--dim); }
header nav a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); }
header nav a:hover { border-bottom-color: var(--accent); }
.dateline { grid-column: 1 / -1; margin: 0; font-style: italic; color: var(--dim); font-size: .85rem; }
.link-btn {
  background: none; border: none; font: inherit; color: var(--ink);
  cursor: pointer; border-bottom: 1px solid var(--rule); padding: 0;
}

/* MAIN — Tufte-style 60% main column with margin reserved for sidenotes.
   On narrow screens the margin collapses. */
main { padding: 2rem 4% 1rem; max-width: 1400px; margin: 0 auto; }
article { width: 60%; }
@media (max-width: 920px) { article { width: 100%; } }

section { margin-bottom: 2.5rem; }

/* HEADINGS */
h1 {
  font-size: 2.2rem;
  font-weight: 400;
  font-style: italic;
  line-height: 1.1;
  margin: .5rem 0;
  letter-spacing: -.005em;
}
h1 .subtitle { font-size: 1.4rem; font-style: italic; color: var(--dim); display: block; margin-top: .25rem; }
h2 { font-size: 1.4rem; font-weight: 400; font-style: italic; margin: 1.5rem 0 .5rem; }
h3 { font-size: 1.05rem; font-weight: 400; font-style: italic; margin: 1rem 0 .25rem; }
.kicker { font-size: .85rem; color: var(--dim); font-style: italic; margin: 0 0 .25rem; }
.kicker a { color: var(--accent); }

p { margin: .5rem 0; }
.dim { color: var(--dim); }
.small { font-size: .85rem; }

/* SIDENOTES — Tufte signature */
.sidenote {
  float: right;
  clear: right;
  margin-right: -60%;
  width: 50%;
  margin-top: .25rem;
  margin-bottom: .25rem;
  font-size: .8rem;
  line-height: 1.4;
  color: var(--dim);
  position: relative;
}
.sidenote-number { counter-increment: sidenote-counter; }
.sidenote-number:after, .sidenote:before {
  font-feature-settings: 'sups';
  vertical-align: baseline;
  position: relative;
  top: -.5rem;
  font-size: .75rem;
  color: var(--accent);
  margin-right: .15rem;
}
.sidenote-number:after { content: counter(sidenote-counter); }
.sidenote:before { content: counter(sidenote-counter) " "; }
.margin-toggle { display: none; }
@media (max-width: 920px) {
  .sidenote { display: none; }
  label.margin-toggle:not(.sidenote-number) { display: inline; }
  .margin-toggle:checked + .sidenote { display: block; float: left; clear: both; width: 95%; margin: 1rem 2.5%; padding: .5rem .75rem; background: var(--code-bg); }
}

/* TABLES — dense, no zebra, hairline rules, top + bottom only */
.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  line-height: 1.35;
  margin: .5rem 0;
}
.data thead th {
  text-align: left;
  font-weight: 400; font-style: italic;
  color: var(--dim);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: .35rem .5rem;
}
.data tbody td {
  padding: .25rem .5rem;
  border-bottom: 1px dotted var(--rule);
  vertical-align: baseline;
}
.data tbody tr:last-child td { border-bottom: 1px solid var(--ink); }
.data tfoot td { padding: .35rem .5rem; font-style: italic; color: var(--dim); border-top: 1px solid var(--ink); }
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.data.dense { font-size: .85rem; }
.caption { font-style: italic; color: var(--dim); font-size: .8rem; margin: .25rem 0 0; }

.spark { width: 70px; height: 14px; color: var(--ink); display: inline-block; vertical-align: middle; }

.ok { color: var(--ok); }
.err { color: var(--err); font-weight: 700; }
.pending { color: var(--pending); }

/* ITEMS */
.items { list-style: decimal; padding-left: 1.5rem; }
.items li { margin-bottom: .85rem; }
.item-line { margin: 0; }
.item-line a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--accent); }
.item-meta { margin: 0; font-size: .82rem; color: var(--dim); font-style: italic; }
.item-meta a { color: var(--accent); border-bottom: 1px dotted var(--accent); text-decoration: none; }
.item-summary { margin: .15rem 0 0; font-size: .9rem; }

/* FORM */
.form { margin: .5rem 0; }
.field { display: flex; align-items: baseline; gap: .75rem; margin: .35rem 0; }
.field label { width: 7rem; font-style: italic; color: var(--dim); font-size: .9rem; text-align: right; }
.field input, .field select {
  font: inherit; font-size: .9rem;
  background: transparent; color: var(--ink);
  border: none; border-bottom: 1px solid var(--rule);
  padding: .15rem 0;
  flex: 1; max-width: 30rem;
}
.field input:focus, .field select:focus { outline: none; border-bottom-color: var(--accent); }

.button-row { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .75rem; }
.btn {
  font: inherit; font-size: .85rem;
  font-style: italic;
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  padding: .25rem .75rem;
  cursor: pointer;
  border-radius: 1px;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-secondary { background: transparent; }
.btn-danger { border-color: var(--err); color: var(--err); }

/* SMALL MULTIPLES */
.multiples {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  width: 100%;
  margin-top: .5rem;
}
@media (max-width: 720px) { .multiples { grid-template-columns: 1fr; } }
.multiples > div h3 { margin-top: 0; }

.status-list { list-style: none; padding: 0; margin: .25rem 0; font-size: .9rem; }
.status-list li { display: flex; gap: .5rem; padding: .25rem 0; border-bottom: 1px dotted var(--rule); }
.status-list li:last-child { border-bottom: none; }
.status-list .t { margin-left: auto; color: var(--dim); font-style: italic; font-size: .8rem; }

.settings { display: grid; grid-template-columns: max-content 1fr; gap: .15rem .75rem; margin: .25rem 0; font-size: .9rem; }
.settings dt { color: var(--dim); font-style: italic; }
.settings dd { margin: 0; }
.settings a { color: var(--accent); }

/* DIALOG — inline, no chrome */
.dialog {
  border-left: 3px solid var(--accent);
  padding: .25rem .75rem;
  margin: .5rem 0;
  background: var(--code-bg);
}
.dialog p { margin: .25rem 0; font-size: .9rem; }

/* CODE */
code, .code, .mono {
  font-family: "iA Writer Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;
  font-size: .85rem;
}
.code {
  background: var(--code-bg);
  padding: .5rem .75rem;
  border-left: 2px solid var(--rule);
  margin: .5rem 0;
  overflow-x: auto;
  font-size: .8rem;
}
code { background: var(--code-bg); padding: 1px 4px; }

/* EMPTY */
.empty { font-style: italic; color: var(--ink); padding: .5rem 0; border-top: 1px dotted var(--rule); border-bottom: 1px dotted var(--rule); }

/* PALETTE table swatches */
.palette td:nth-child(2) { width: 7rem; }
.palette td:nth-child(3) { width: 5rem; }
.sw { display: inline-block; width: 3rem; height: 1rem; vertical-align: middle; }

/* TYPE specimens */
.t-h1 { font-size: 2rem; font-style: italic; }
.t-h2 { font-size: 1.4rem; font-style: italic; }

/* FOOTER */
footer { margin: 3rem 4% 2rem; padding-top: 1rem; border-top: 1px solid var(--rule); width: 60%; max-width: 1400px; }
footer a { color: var(--accent); }

@media (max-width: 920px) {
  footer { width: 100%; }
}
