:root {
  --bg: #14120f;
  --surface: #1b1815;
  --text: #e8e1d5;
  --muted: #96897a;
  --accent: #b5442f;
  --link: #d06a52;
  --line: #3c342c;
  --chip: #faf6ee;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #faf6ee;
    --surface: #fffaf3;
    --text: #201d19;
    --muted: #5c5348;
    --accent: #b5442f;
    --link: #8d3a28;
    --line: #ddd2c3;
    --chip: #faf6ee;
    color-scheme: light;
  }
}

:root[data-theme="dark"] {
  --bg: #14120f;
  --surface: #1b1815;
  --text: #e8e1d5;
  --muted: #96897a;
  --accent: #b5442f;
  --link: #d06a52;
  --line: #3c342c;
  --chip: #faf6ee;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #faf6ee;
  --surface: #fffaf3;
  --text: #201d19;
  --muted: #5c5348;
  --accent: #b5442f;
  --link: #8d3a28;
  --line: #ddd2c3;
  --chip: #faf6ee;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 17px;
  line-height: 1.65;
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  transform: translateY(-150%);
  background: var(--chip);
  color: #201d19;
  padding: 0.4rem 0.7rem;
  z-index: 5;
}

.skip:focus { transform: none; }

.mast,
.colophon,
.shell {
  width: min(760px, calc(100% - 2rem));
  margin-inline: auto;
}

.mast { padding: 2.4rem 0 0.4rem; }

.mast-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.updated {
  margin: 0;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.14em;
  font-size: 0.82rem;
  color: var(--muted);
}

.intro { margin: 1.15rem 0 0; max-width: 68ch; }

a { color: var(--link); text-underline-offset: 0.16em; }

a:hover { text-decoration-thickness: 2px; }

.shell { padding-top: 1.4rem; }

.nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0.15rem 0 0.7rem;
  margin: 0 0 0.8rem;
  max-width: 100%;
}

.tools { margin: 0 0 0.4rem; }

.search {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.search input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 0;
  font: inherit;
  font-size: 1rem;
  padding: 0.55rem 0.7rem;
}

.search input::placeholder { color: var(--muted); opacity: 1; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 0;
}

.chip,
#clear,
.theme {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 0.45rem 0.65rem;
  white-space: nowrap;
}

.chip { color: var(--muted); }

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--chip);
}

#clear[hidden] { display: none; }

.count {
  margin: 0.55rem 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.books,
.nested {
  list-style: none;
  margin: 0;
  padding: 0;
}

section { scroll-margin-top: 1rem; }

h2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin: 2.5rem 0 0.35rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.entry {
  border-left: 2px solid var(--line);
  margin: 1.2rem 0;
  padding: 0.05rem 0 0.05rem 0.85rem;
  scroll-margin-top: 1rem;
}

.nested { margin-top: 0.35rem; }

.nested .entry { margin: 0.7rem 0; }

.title-line,
.by,
.desc,
h3 { margin: 0; }

h3 {
  font-size: 1.08rem;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: 0;
  text-transform: none;
}

.title-line strong { font-weight: 650; }

.year {
  margin-left: 0.35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-style: normal;
  font-weight: 400;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.clause { font-style: italic; font-weight: 400; }

h3 .clause { font-size: 0.98rem; }

.clause.period::after {
  content: ".";
  font-style: normal;
}

.clause cite { font-style: italic; }

.by {
  margin-top: 0.12rem;
  color: var(--muted);
}

.desc { margin-top: 0.4rem; }

.empty { color: var(--muted); }

.entry.is-hot { border-left-color: var(--accent); animation: hot 1.8s ease; }

@keyframes hot {
  from { background: rgba(181, 68, 47, 0.34); }
  to { background: transparent; }
}

.colophon {
  margin-top: 3rem;
  padding: 1.4rem 0 2.8rem;
  border-top: 1px solid var(--line);
}

.colophon p { margin: 0.35rem 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
}

@media (min-width: 1024px) {
  .mast,
  .colophon,
  .shell { width: min(1040px, calc(100% - 3rem)); }

  .shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 760px);
    column-gap: 2.75rem;
    align-items: start;
    padding-top: 1.8rem;
  }

  .nav {
    position: sticky;
    top: 1.25rem;
    flex-direction: column;
    align-items: stretch;
    overflow: visible;
    margin: 0;
    padding: 0.2rem 0 0;
  }

  .chip { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .entry.is-hot { animation: none; background: rgba(181, 68, 47, 0.22); }
}

@media print {
  :root,
  :root[data-theme="dark"],
  :root[data-theme="light"] {
    --bg: #fff;
    --surface: #fff;
    --text: #000;
    --muted: #222;
    --accent: #000;
    --link: #000;
    --line: #000;
  }

  body { background: #fff; color: #000; }

  .skip,
  .theme,
  .tools,
  .nav,
  .back { display: none !important; }

  .shell,
  .mast,
  .colophon {
    display: block;
    width: auto;
    max-width: none;
  }

  a { color: #000; text-decoration: none; }

  .entry,
  .nested .entry { break-inside: avoid; }

  h2 { break-after: avoid; }
}
