:root {
  color-scheme: dark;
  --bg: #141210;
  --paper: #1c1916;
  --text: #e8e2d6;
  --muted: #a39888;
  --line: #3a342c;
  --accent: #e0b15a;
  --accent-dim: #8c6b32;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
}

body {
  min-height: 100vh;
}

a { color: var(--accent); }

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: rgba(20, 18, 16, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.crumb {
  margin: 0;
  flex: 1;
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.85rem;
}

.chat {
  margin-left: auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.82rem;
  text-decoration: none;
  white-space: nowrap;
}

.chat-card { margin-top: 1.6rem; }

main {
  width: min(40rem, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.4rem 0 6.5rem;
}

h1, h2, h3 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.25;
  font-weight: 650;
}

.section-label {
  margin: 1.6rem 0 0.6rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-hint {
  margin: -0.35rem 0 0.55rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
}

.card--muted {
  cursor: default;
  opacity: 0.88;
}

.expected-books {
  margin: 1.6rem 0 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  overflow: hidden;
}

.expected-books-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.expected-books-summary::-webkit-details-marker {
  display: none;
}

.expected-books-summary::before {
  content: "▸";
  color: var(--accent);
  font-size: 0.85rem;
  transition: transform 0.15s ease;
}

.expected-books[open] .expected-books-summary::before {
  transform: rotate(90deg);
}

.expected-books-count {
  margin-left: auto;
  font-weight: 650;
  letter-spacing: 0;
  color: var(--accent);
}

.expected-books .section-hint {
  margin: 0;
  padding: 0 1rem 0.65rem;
}

.expected-books .section-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78em;
}

.expected-books .card-list {
  padding: 0 0.65rem 0.75rem;
  max-height: min(22rem, 55vh);
  overflow-y: auto;
}

.card-list { display: grid; gap: 0.6rem; }

.card-list-head {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  margin: 0 0 0.35rem;
  padding: 0 0.15rem;
}

.card-list-head-spacer {
  flex: 1;
  min-width: 0;
}

.read-col-label {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.read-aside--head {
  justify-content: flex-end;
}

.card-row {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
}

.card-row.is-read .card {
  opacity: 0.55;
}

.card {
  display: block;
  flex: 1;
  min-width: 0;
  padding: 0.95rem 1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
}

.read-aside {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-shrink: 0;
}

.read-aside .count {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1;
  min-width: 2.35rem;
  text-align: right;
}

.count--empty {
  visibility: hidden;
  pointer-events: none;
}

.read-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.5rem;
  padding: 0;
  margin: 0;
  cursor: pointer;
  user-select: none;
}

.read-toggle input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.doc-read-bar,
.section-read-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.88rem;
}

.section-read-row {
  margin: 1.4rem 0 0.35rem;
  padding: 0.45rem 0.75rem;
}

.doc-read-bar.is-read,
.section-read-row.is-read {
  opacity: 0.75;
}

.count {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 650;
  letter-spacing: 0;
  color: var(--accent);
  white-space: nowrap;
}

.footnote {
  margin: 1.8rem 0 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
}

.footnote .star {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--accent);
}

.book-actions {
  margin: 1.5rem 0 0;
  text-align: center;
}

.btn-reset {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.82rem;
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
}

.btn-reset:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.card strong {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1.05rem;
}

.card span {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.prose {
  font-size: 1.125rem;
  line-height: 1.65;
}

.prose h1 { font-size: 1.7rem; margin: 0 0 0.8rem; }
.prose h2 { font-size: 1.25rem; margin: 1.6rem 0 0.5rem; }
.prose h3 { font-size: 1.05rem; margin: 1.2rem 0 0.4rem; }
.prose p { margin: 0.7rem 0; }
.prose ul, .prose ol { padding-left: 1.2rem; }
.prose li { margin: 0.35rem 0; }
.prose strong { font-weight: 700; }

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.92rem;
  margin: 1rem 0 1.4rem;
}

.prose th, .prose td {
  text-align: left;
  vertical-align: top;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--line);
}

.prose blockquote {
  margin: 1rem 0;
  padding-left: 0.9rem;
  border-left: 3px solid var(--accent-dim);
  color: var(--muted);
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
}

.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
  padding: 0.7rem 0.8rem calc(0.7rem + env(safe-area-inset-bottom));
  background: rgba(20, 18, 16, 0.94);
  border-top: 1px solid var(--line);
}

.bar a, .bar button {
  flex: 1;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.85rem;
  text-align: center;
  text-decoration: none;
  border-radius: 10px;
  padding: 0.7rem 0.4rem;
}

.bar a[aria-disabled="true"],
.bar button:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.error { color: #e08a7a; }
