:root {
  --paper: #f4f0e6;
  --paper-deep: #ece5d6;
  --surface: #faf7ef;
  --surface-raised: #fffdf7;
  --ink: #1f241f;
  --ink-soft: #414940;
  --ink-muted: #70786f;
  --ink-faint: #8b9188;
  --line: #d9d2c2;
  --line-strong: #bcb29d;
  --jade: #496c5f;
  --jade-deep: #355247;
  --jade-soft: #e0e9e3;
  --cinnabar: #963f32;
  --cinnabar-soft: #f0e0dc;
  --gold: #84683d;
  --gold-soft: #eee5d2;
  --selection: #d8e4dc;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, serif;
  --sans: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "Fira Code", "Cascadia Mono", Consolas, monospace;
  --sidebar-width: 248px;
  --topbar-height: 62px;
  --radius: 3px;
  color-scheme: light;
}

[data-theme="ink"] {
  --paper: #141815;
  --paper-deep: #101310;
  --surface: #1a201b;
  --surface-raised: #202720;
  --ink: #e7e1d2;
  --ink-soft: #c1c3b5;
  --ink-muted: #929b8f;
  --ink-faint: #747d71;
  --line: #343b33;
  --line-strong: #4d564b;
  --jade: #8db3a4;
  --jade-deep: #b0cbbc;
  --jade-soft: #24332c;
  --cinnabar: #c07a6d;
  --cinnabar-soft: #3a2925;
  --gold: #bea272;
  --gold-soft: #332d23;
  --selection: #2e4a3d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--jade-deep); text-decoration: none; }
a:hover { color: var(--cinnabar); }
::selection { background: var(--selection); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { margin: 0; font-family: var(--serif); font-weight: 600; letter-spacing: .02em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
li { list-style: none; }
code, kbd, pre { font-family: var(--mono); }
[hidden] { display: none !important; }
kbd {
  font-size: 10px;
  border: 1px solid var(--line);
  border-bottom-color: var(--line-strong);
  padding: 1px 5px;
  border-radius: 2px;
  color: var(--ink-muted);
  background: var(--surface);
}
mark { background: var(--gold-soft); color: inherit; padding: 0 1px; }
:focus-visible { outline: 2px solid var(--jade); outline-offset: 2px; }

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 200;
  padding: 8px 14px;
  background: var(--ink);
  color: var(--paper);
}
.skip-link:focus { top: 12px; }

.icon { flex: 0 0 auto; vertical-align: middle; }

/* Shell */
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 26px 18px 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  z-index: 30;
}
.brand { padding: 0 10px 26px; border-bottom: 1px solid var(--line); }
.brand-link { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.brand-link:hover { color: var(--ink); }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1;
  background: var(--paper);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-family: var(--serif); font-size: 19px; letter-spacing: .12em; }
.brand-text small { color: var(--ink-faint); font-size: 9.5px; letter-spacing: .08em; margin-top: 4px; }
.main-nav { padding: 18px 0; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 11px;
  color: var(--ink-soft);
  font-size: 13px;
  border-left: 2px solid transparent;
  border-radius: 0;
}
.nav-item:hover { color: var(--ink); background: var(--paper-deep); }
.nav-item.active { color: var(--jade-deep); background: var(--jade-soft); border-left-color: var(--jade); }
.nav-item .icon { color: var(--ink-muted); }
.nav-item.active .icon { color: var(--jade-deep); }
.nav-item kbd { margin-left: auto; }
.sidebar-meta { flex: 1; overflow-y: auto; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
button.nav-item, .theme-toggle { width: 100%; border: 0; background: transparent; text-align: left; border-left: 2px solid transparent; }
.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-height);
  padding: 0 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(8px);
}
.topbar-context { color: var(--ink-muted); font-size: 12px; display: flex; gap: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 12px;
}
.search-trigger:hover { border-color: var(--line-strong); color: var(--ink); }
.search-trigger kbd { margin-left: 12px; }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
}
.icon-button:hover { border-color: var(--line); color: var(--ink); }
.menu-button { display: none; }
.main {
  padding: 38px 48px 96px;
  max-width: 1760px;
  margin: 0 auto;
}
.main-wide { max-width: none; }

/* Typography and shared */
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; color: var(--ink-muted); font-size: 11.5px; margin-bottom: 20px; letter-spacing: .02em; }
.breadcrumbs a { color: var(--ink-muted); }
.breadcrumbs a:hover { color: var(--jade-deep); }
.breadcrumbs .sep { color: var(--line-strong); }
.page-header { margin-bottom: 30px; border-bottom: 1px solid var(--line); padding-bottom: 22px; }
.eyebrow { color: var(--ink-muted); font-size: 11px; letter-spacing: .12em; margin-bottom: 8px; }
.page-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.page-header h1 { font-size: clamp(30px, 3.4vw, 42px); line-height: 1.18; font-weight: 600; }
.aliases { margin-top: 7px; color: var(--ink-muted); font-family: var(--serif); font-size: 13.5px; letter-spacing: .04em; }
.page-description { margin-top: 13px; color: var(--ink-soft); font-family: var(--serif); font-size: 15px; max-width: 820px; }
.page-meta { display: flex; flex-wrap: wrap; gap: 6px 0; margin-top: 16px; color: var(--ink-muted); font-size: 11.5px; }
.page-meta > * + *::before { content: "/"; color: var(--line-strong); margin: 0 10px; }
.page-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.title-count { font-family: var(--sans); font-size: 12px; color: var(--ink-muted); margin-left: 12px; vertical-align: middle; }
.section { margin: 34px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-head h2 { font-size: 20px; letter-spacing: .04em; }
.section-head h2::before { content: ""; display: inline-block; width: 14px; height: 1px; background: var(--cinnabar); vertical-align: middle; margin-right: 10px; }
.section-link, .rail-link { color: var(--jade-deep); font-size: 11.5px; display: inline-flex; align-items: center; gap: 5px; }
.section-note { color: var(--ink-faint); font-size: 11.5px; }
.muted { color: var(--ink-muted); }
.small-copy { color: var(--ink-muted); font-size: 12px; line-height: 1.8; }
.empty-status { color: var(--ink-faint); font-size: 12px; padding: 18px 0; }
.muted-section { color: var(--ink-muted); }
.type-badge {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: 10px;
  letter-spacing: .05em;
  white-space: nowrap;
}
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--line); color: var(--ink-muted); font-size: 10px; }

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  line-height: 1.3;
  border-radius: var(--radius);
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.button:hover { background: var(--jade-deep); border-color: var(--jade-deep); color: var(--paper); }
.button.ghost { background: transparent; color: var(--ink-soft); border-color: var(--line-strong); }
.button.ghost:hover { border-color: var(--jade); color: var(--jade-deep); background: transparent; }
.button.primary { background: var(--jade-deep); border-color: var(--jade-deep); }
.button.small { min-height: 28px; padding: 3px 9px; font-size: 11px; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.text-link { color: var(--jade-deep); font-size: 12px; }

/* Grids and stats */
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 292px; gap: 48px; align-items: start; }
.content-main { min-width: 0; }
.content-rail { border-left: 1px solid var(--line); padding-left: 30px; min-width: 0; }
.reading-layout { grid-template-columns: minmax(0, 790px) 280px; justify-content: start; gap: 54px; }
.rail-section { padding: 0 0 24px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.rail-section:last-child { border-bottom: 0; }
.rail-section h3 { font-family: var(--sans); font-size: 11px; font-weight: 600; letter-spacing: .12em; color: var(--ink-muted); margin-bottom: 12px; text-transform: uppercase; }
.rail-progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 26px 0 8px;
}
.stat { padding: 18px 18px 16px; border-left: 1px solid var(--line); min-width: 0; }
.stat:first-child { border-left: 0; padding-left: 0; }
.stat-label { display: block; color: var(--ink-muted); font-size: 11px; letter-spacing: .06em; }
.stat strong { display: block; font-family: var(--serif); font-size: 30px; font-weight: 500; line-height: 1.25; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.stat .stat-time { font-size: 20px; padding-top: 8px; }
.stat .unit { font-size: 12px; margin-left: 4px; color: var(--ink-muted); }
.stat small { display: block; color: var(--ink-faint); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat small .status { margin-right: 4px; }
.split-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.split-stats span { display: block; color: var(--ink-muted); font-size: 11px; }
.split-stats strong { font-family: var(--serif); font-size: 18px; font-weight: 500; }

/* Status */
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--ink-muted); white-space: nowrap; }
.status i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); display: inline-block; }
.status-complete i { background: var(--jade); }
.status-draft i { background: var(--gold); }
.status-unfilled i { background: var(--line-strong); }
.status-published { color: var(--jade-deep); }
.status-in_progress, .status-partial { color: var(--gold); }
.status-planned, .status-unknown { color: var(--cinnabar); }
.status-pills { display: flex; flex-wrap: wrap; gap: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--line); padding: 7px 10px; min-width: 110px; }
.status-pill strong { font-family: var(--serif); font-size: 17px; font-weight: 500; }
.study-state { color: var(--ink-muted); font-size: 11px; }

/* Progress */
.progress { display: inline-block; width: 90px; height: 3px; background: var(--paper-deep); vertical-align: middle; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--jade); }
.progress-number { font-size: 10px; color: var(--ink-muted); margin-left: 7px; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th { text-align: left; font-weight: 500; color: var(--ink-muted); font-size: 10px; letter-spacing: .1em; padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.data-table td { padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--paper-deep) 55%, transparent); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .title-cell { font-family: var(--serif); font-size: 14.5px; line-height: 1.5; }
.data-table .title-cell a { color: var(--ink); }
.data-table .title-cell a:hover { color: var(--cinnabar); }
.row-sub { display: block; color: var(--ink-faint); font-family: var(--sans); font-size: 10.5px; margin-top: 2px; }
.date-cell { color: var(--ink-faint); font-size: 10.5px; white-space: nowrap; }
.row-action { display: inline-grid; place-items: center; width: 24px; height: 24px; color: var(--ink-faint); border: 1px solid transparent; }
.row-action:hover { color: var(--jade-deep); border-color: var(--line); }
.ordinal { color: var(--ink-faint); font-family: var(--serif); }
.mini-table td { font-size: 11.5px; padding: 7px 6px; }
.mini-table .title-cell { font-size: 12.5px; }

/* Bars */
.bar-list { display: flex; flex-direction: column; gap: 9px; }
.bar-list.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 34px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 190px) minmax(60px, 1fr) 34px; align-items: center; gap: 12px; font-size: 11.5px; }
.bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.bar-track { height: 3px; background: var(--paper-deep); overflow: hidden; }
.bar-track span { display: block; height: 100%; background: var(--jade); }
.bar-value { text-align: right; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* Lists */
.compact-list { display: flex; flex-direction: column; gap: 0; }
.compact-list li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12px; line-height: 1.5; }
.compact-list li:last-child { border-bottom: 0; }
.compact-list a { color: var(--ink-soft); font-family: var(--serif); font-size: 13.5px; }
.compact-list a:hover { color: var(--cinnabar); }
.compact-list li > span { display: block; color: var(--ink-faint); font-size: 10px; margin-top: 1px; }

/* Meta */
.meta-list { display: flex; flex-direction: column; gap: 0; margin: 0; }
.meta-list > div { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; padding: 7px 0; border-bottom: 1px dotted var(--line); }
.meta-list > div:last-child { border-bottom: 0; }
.meta-list dt { color: var(--ink-muted); font-size: 11px; }
.meta-list dd { margin: 0; font-family: var(--serif); font-size: 12.5px; word-break: break-word; }
.metadata-grid { display: grid; gap: 24px; }
.metadata-grid .meta-list { max-width: 680px; }
.note-panel { border-left: 2px solid var(--line-strong); padding: 4px 0 4px 16px; }
.note-panel h3 { font-family: var(--sans); font-size: 11px; color: var(--ink-muted); letter-spacing: .08em; margin-bottom: 4px; }
.note-panel p { color: var(--ink-soft); font-family: var(--serif); font-size: 13px; }
.context-note { border: 1px solid var(--line); background: var(--surface); padding: 10px 14px; margin: -8px 0 26px; }
.context-note summary { cursor: pointer; color: var(--ink-muted); font-size: 11px; }
.context-note p { margin-top: 8px; color: var(--ink-soft); font-family: var(--serif); font-size: 12.5px; }

/* Prose */
.prose { font-family: var(--serif); font-size: 16.5px; line-height: 1.95; color: var(--ink-soft); overflow-wrap: anywhere; }
.prose > * + * { margin-top: 1.05em; }
.prose h1, .prose h2, .prose h3, .prose h4 { color: var(--ink); scroll-margin-top: 86px; }
.prose h2 { font-size: 22px; margin-top: 2em; padding-bottom: .35em; border-bottom: 1px solid var(--line); }
.prose h3 { font-size: 17px; margin-top: 1.7em; }
.prose a { color: var(--jade-deep); border-bottom: 1px solid color-mix(in srgb, var(--jade) 45%, transparent); }
.prose a:hover { color: var(--cinnabar); border-bottom-color: var(--cinnabar); }
.prose blockquote { margin-left: 0; padding: 4px 0 4px 18px; border-left: 2px solid var(--cinnabar); color: var(--ink-muted); font-size: 15px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { list-style: disc; margin: .3em 0; }
.prose ol li { list-style: decimal; }
.prose code { font-size: .82em; background: var(--paper-deep); padding: 1px 4px; }
.prose pre { background: var(--surface); border: 1px solid var(--line); padding: 14px; overflow-x: auto; font-size: 12px; line-height: 1.7; }
.prose table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 12.5px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose img { border: 1px solid var(--line); }
.prose .footnotes { font-size: 12px; color: var(--ink-muted); border-top: 1px solid var(--line); margin-top: 2.5em; padding-top: 1em; }
.archive-prose { max-width: 760px; }
.unfilled-block { padding: 36px 0 40px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.content-section { margin: 32px 0; }
.content-section h2, .citation-section h2, .relation-section h2 { font-size: 18px; margin-bottom: 12px; }
.content-section h2::before, .citation-section h2::before, .relation-section h2::before { content: ""; display: inline-block; width: 10px; height: 1px; background: var(--cinnabar); vertical-align: middle; margin-right: 8px; }
.toc ol { font-size: 12px; }
.toc li { padding: 4px 0; border-bottom: 1px dotted var(--line); }
.toc li a { color: var(--ink-soft); }
.toc-level-3 { padding-left: 12px !important; }
.citation-section, .relation-section { border-top: 1px solid var(--line); padding-top: 22px; margin: 34px 0; }
.citation-list { counter-reset: citation; }
.citation-list li { counter-increment: citation; position: relative; padding: 7px 0 7px 28px; font-size: 12px; line-height: 1.7; border-bottom: 1px dotted var(--line); }
.citation-list li::before { content: "[" counter(citation) "]"; position: absolute; left: 0; top: 7px; color: var(--ink-faint); font-family: var(--mono); font-size: 10px; }
.citation-locator { color: var(--ink-muted); margin-left: 8px; }
.citation-note { display: block; color: var(--ink-faint); font-size: 11px; }
.relation-group { margin: 16px 0; }
.relation-group h3 { font-family: var(--sans); font-size: 11px; color: var(--ink-muted); letter-spacing: .08em; margin-bottom: 7px; }
.relation-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.relation-item { display: flex; align-items: baseline; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); color: var(--ink-soft); }
.relation-item:hover { background: var(--paper-deep); color: var(--ink); }
.relation-type { color: var(--ink-faint); font-size: 10px; min-width: 46px; }
.relation-title { font-family: var(--serif); font-size: 14px; }
.relation-note { color: var(--ink-faint); font-size: 10px; margin-left: auto; }

/* Study controls */
.study-controls { border-top: 1px solid var(--line); margin-top: 34px; padding-top: 18px; display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
.control-line { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.control-label { color: var(--ink-muted); min-width: 62px; font-size: 11px; }
.study-controls select, .study-controls input[type="range"] { max-width: 220px; }
.study-controls select { border: 1px solid var(--line); background: var(--surface); padding: 4px 6px; font-size: 12px; }
.control-hint { color: var(--cinnabar); font-size: 11px; min-height: 16px; }
.timer { color: var(--ink-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.admin-inline-actions { display: flex; gap: 8px; margin: 24px 0; }

/* Poetry */
.period-strip { display: flex; flex-wrap: wrap; gap: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.period-chip { display: flex; align-items: baseline; gap: 8px; padding: 9px 13px; border-right: 1px solid var(--line); color: var(--ink-soft); font-family: var(--serif); font-size: 13.5px; }
.period-chip:last-child { border-right: 0; }
.period-chip strong { font-family: var(--sans); font-size: 10px; font-weight: 400; color: var(--ink-faint); }
.period-chip:hover, .period-chip.active { background: var(--jade-soft); color: var(--jade-deep); }
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; padding: 14px 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.filter-bar label, .search-page-form .filter-bar label { display: flex; flex-direction: column; gap: 4px; font-size: 10px; color: var(--ink-muted); letter-spacing: .05em; }
.filter-grow { flex: 1; min-width: 180px; }
.filter-bar input, .filter-bar select, .inline-search input {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 6px 8px;
  font-size: 12px;
  min-height: 32px;
  border-radius: 0;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--jade); outline: none; }
.inline-search { display: flex; gap: 6px; align-items: center; }
.inline-search input { min-width: 200px; }
.collection-list li { padding: 7px 0; }
.poem-sheet { border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); padding: 50px 28px 56px; margin-top: 4px; background: var(--surface); }
.poem-title-row { text-align: center; margin-bottom: 25px; }
.poem-title { font-size: 30px; letter-spacing: .1em; }
.poem-byline { margin-top: 6px; color: var(--ink-muted); font-family: var(--serif); font-size: 12px; letter-spacing: .08em; }
.poem-text { white-space: pre-wrap; font-family: var(--serif); font-size: 20px; line-height: 2.15; text-align: center; letter-spacing: .06em; color: var(--ink); }
.poem-text + .poem-text { margin-top: 1.5em; }
.works-table, .book-table { table-layout: auto; }

/* Books */
.toc-tree { margin: 0; padding: 0; }
.toc-tree li { list-style: none; border-bottom: 1px dotted var(--line); padding: 6px 0 6px 16px; position: relative; }
.toc-tree li::before { content: "—"; position: absolute; left: 0; color: var(--line-strong); font-size: 9px; top: 9px; }
.toc-tree .level-2, .toc-tree .level-3, .toc-tree .level-4 { margin-left: 16px; }
.toc-label { font-family: var(--serif); font-size: 13.5px; color: var(--ink-soft); }
.toc-label small { font-family: var(--sans); color: var(--ink-faint); font-size: 10px; margin-left: 8px; }
.toc-note { display: block; color: var(--ink-faint); font-size: 10.5px; }

/* Search */
.search-overlay { position: fixed; inset: 0; z-index: 100; background: color-mix(in srgb, var(--ink) 28%, transparent); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: flex-start; padding: 9vh 20px 20px; }
.search-overlay[hidden] { display: none; }
.search-panel { width: min(760px, 100%); background: var(--surface-raised); border: 1px solid var(--line-strong); box-shadow: 0 20px 60px rgba(20, 24, 20, .18); }
.search-box { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.search-box input { flex: 1; border: 0; background: transparent; font-size: 17px; font-family: var(--serif); outline: none; }
.search-filters { display: flex; justify-content: space-between; padding: 8px 18px; border-bottom: 1px solid var(--line); }
.search-filters select { border: 0; background: transparent; color: var(--ink-muted); font-size: 11px; }
.search-results { max-height: 55vh; overflow-y: auto; padding: 8px 18px 16px; }
.search-result-item { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
.search-result-item:hover { background: var(--paper-deep); }
.search-result-item .result-head { display: flex; gap: 8px; align-items: baseline; }
.search-result-item .result-title { font-family: var(--serif); font-size: 15px; color: var(--ink); }
.search-result-item .result-sub { color: var(--ink-muted); font-size: 10.5px; margin-top: 2px; }
.search-result-item .result-snippet { color: var(--ink-faint); font-size: 11px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-page-form { margin-bottom: 10px; }
.search-main-input { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--ink); padding: 4px 0 12px; }
.search-main-input input { flex: 1; border: 0; background: transparent; outline: none; font-family: var(--serif); font-size: 24px; }
.search-summary { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 0 8px; border-bottom: 1px solid var(--line); font-family: var(--serif); }
.search-summary strong { font-size: 12px; color: var(--ink-muted); font-family: var(--sans); font-weight: 400; }
.search-result-list .search-result { padding: 16px 0; border-bottom: 1px solid var(--line); }
.result-head { display: flex; align-items: baseline; gap: 10px; }
.result-title { font-family: var(--serif); font-size: 18px; color: var(--ink); }
.result-title:hover { color: var(--cinnabar); }
.result-sub { color: var(--ink-muted); font-size: 11px; margin-top: 3px; }
.result-snippet { color: var(--ink-soft); font-family: var(--serif); font-size: 13px; margin-top: 6px; line-height: 1.75; }

/* Pagination */
.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin: 22px 0 0; }
.page-link { min-width: 30px; height: 30px; display: inline-grid; place-items: center; padding: 0 9px; border: 1px solid var(--line); color: var(--ink-muted); font-size: 11px; }
.page-link:hover { border-color: var(--jade); color: var(--jade-deep); }
.page-link.current { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.page-gap { display: inline-grid; place-items: center; width: 20px; color: var(--ink-faint); }

/* Heatmap and charts */
.heatmap-wrap { overflow-x: auto; padding: 4px 0 2px; }
.heatmap { min-width: 760px; width: 100%; height: auto; }
.heatmap rect { fill: var(--paper-deep); }
.heatmap .heat-1 { fill: #dbe6df; }
.heatmap .heat-2 { fill: #b9cfc3; }
.heatmap .heat-3 { fill: #8caf9e; }
.heatmap .heat-4 { fill: #5f8877; }
.heatmap .heat-5 { fill: #355b4c; }
[data-theme="ink"] .heatmap rect { fill: #242b24; }
[data-theme="ink"] .heatmap .heat-1 { fill: #2b3b32; }
[data-theme="ink"] .heatmap .heat-2 { fill: #385345; }
[data-theme="ink"] .heatmap .heat-3 { fill: #4c7462; }
[data-theme="ink"] .heatmap .heat-4 { fill: #6c9c85; }
[data-theme="ink"] .heatmap .heat-5 { fill: #93bfa9; }
.heat-label, .heat-weekday { fill: var(--ink-faint); font-size: 8px; font-family: var(--sans); }
.trend-chart { width: 100%; height: auto; max-height: 150px; }
.trend-bar { fill: var(--jade); opacity: .8; }
.trend-label { fill: var(--ink-faint); font-size: 8px; font-family: var(--sans); }

/* Timeline */
.timeline-shell { border: 1px solid var(--line); background: var(--surface); }
.timeline-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 20px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--paper); }
.timeline-zoom { display: flex; gap: 5px; }
.timeline-presets { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-button { border: 1px solid var(--line); background: transparent; padding: 3px 8px; font-size: 10.5px; color: var(--ink-muted); }
.chip-button:hover, .chip-button.active { border-color: var(--jade); color: var(--jade-deep); background: var(--jade-soft); }
.timeline-layer-options { display: flex; flex-wrap: wrap; gap: 12px; margin-left: auto; font-size: 10.5px; color: var(--ink-muted); }
.timeline-layer-options label { display: inline-flex; align-items: center; gap: 4px; }
.timeline-app { position: relative; min-height: 540px; max-height: 760px; overflow: auto; }
.timeline-loading { padding: 40px; color: var(--ink-faint); font-size: 12px; }
.timeline-canvas { position: absolute; inset: 0; cursor: grab; }
.timeline-svg { display: block; }
.tl-axis-line { color: var(--line-strong); stroke-width: .8; }
.tl-group-label { font-family: var(--serif); font-size: 11px; fill: var(--ink-soft); }
.tl-group-range { font-family: var(--sans); font-size: 8px; fill: var(--ink-faint); }
.tl-bar-label { font-family: var(--sans); font-size: 7.5px; fill: #fff; pointer-events: none; }
.tl-period-bar { opacity: .8; }
.toc a.active { color: var(--cinnabar); }
.timeline-canvas.dragging { cursor: grabbing; }
.timeline-note { padding: 7px 14px; border-top: 1px solid var(--line); color: var(--ink-faint); font-size: 10.5px; font-family: var(--sans); }
.timeline-fallback { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
.timeline-fallback summary { cursor: pointer; color: var(--ink-muted); font-size: 11px; }
.timeline-fallback-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 20px; padding: 10px 0; font-size: 11px; }
.timeline-fallback-list div { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dotted var(--line); padding: 4px 0; }
.timeline-fallback-list span:last-child { color: var(--ink-faint); }
.tl-tooltip { position: absolute; z-index: 5; background: var(--ink); color: var(--paper); padding: 6px 9px; font-size: 10px; pointer-events: none; max-width: 260px; line-height: 1.5; }
.tl-axis-label { font-family: var(--sans); font-size: 9px; fill: var(--ink-faint); }
.tl-era-label { font-family: var(--serif); font-size: 11px; fill: var(--ink-soft); }
.tl-event-dot { cursor: pointer; stroke: var(--surface); stroke-width: 1; }
.tl-bar { cursor: pointer; opacity: .88; }
.tl-bar:hover { opacity: 1; }
.tl-grid { stroke: var(--line); stroke-width: .5; stroke-dasharray: 2 4; }
.tl-now { stroke: var(--cinnabar); stroke-width: 1; stroke-dasharray: 3 3; }

/* Graph */
.graph-shell { border-top: 1px solid var(--line); }
.graph-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.graph-search { position: relative; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 5px 9px; min-width: 220px; }
.graph-search input { border: 0; background: transparent; outline: none; width: 100%; font-size: 12px; }
.graph-suggest { position: absolute; left: 0; right: 0; top: calc(100% + 2px); background: var(--surface-raised); border: 1px solid var(--line-strong); z-index: 8; max-height: 280px; overflow-y: auto; }
.graph-suggest button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 7px 10px; font-size: 11px; }
.graph-suggest button:hover { background: var(--paper-deep); }
.graph-suggest small { display: block; color: var(--ink-faint); font-size: 9px; }
.graph-filters { display: flex; flex-wrap: wrap; gap: 10px; font-size: 10.5px; color: var(--ink-muted); }
.graph-filters label { display: inline-flex; align-items: center; gap: 4px; }
.graph-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.graph-hint { color: var(--ink-faint); font-size: 10px; }
.graph-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; min-height: 660px; }
.graph-canvas-wrap { position: relative; border-right: 1px solid var(--line); min-height: 660px; overflow: hidden; background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--jade-soft) 35%, transparent), transparent 70%); }
#graph-canvas { width: 100%; height: 660px; display: block; cursor: grab; }
#graph-canvas.dragging { cursor: grabbing; }
.graph-legend { position: absolute; left: 12px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 10px; font-size: 9.5px; color: var(--ink-muted); background: color-mix(in srgb, var(--surface) 85%, transparent); padding: 5px 8px; }
.legend-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 3px; }
.legend-dot.category { background: #52766a; } .legend-dot.knowledge { background: #8b6b3f; } .legend-dot.book { background: #596b7a; } .legend-dot.person { background: #8a5a4a; } .legend-dot.event { background: #8b4a42; } .legend-dot.poem { background: #6c5b7b; } .legend-dot.collection { background: #4f6f6a; } .legend-dot.period { background: #66735a; }
.graph-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-faint); font-size: 12px; }
.graph-panel { padding: 18px; overflow-y: auto; max-height: 660px; background: var(--surface); }
.graph-panel-empty { color: var(--ink-faint); font-size: 12px; padding-top: 20px; }
.graph-node-panel h2 { font-size: 22px; margin-bottom: 4px; }
.graph-node-panel .node-type { color: var(--ink-muted); font-size: 10px; letter-spacing: .08em; }
.graph-node-panel .node-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.graph-node-panel dt { color: var(--ink-muted); font-size: 10px; }
.graph-node-panel dd { margin: 0 0 8px; font-family: var(--serif); font-size: 12px; }
.graph-node-panel .neighbor-list { margin-top: 16px; }
.graph-node-panel .neighbor-list a { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dotted var(--line); font-size: 11px; }
.graph-node-panel .neighbor-list small { color: var(--ink-faint); font-size: 9px; }
.graph-node-panel .neighbor-list button { border: 0; background: transparent; color: var(--ink-soft); font: inherit; cursor: pointer; width: 100%; }
.graph-node-panel .neighbor-list button:hover { color: var(--cinnabar); }

/* Not found */
.not-found { padding: 18vh 0; text-align: center; }
.not-found h1 { font-size: 32px; margin-bottom: 18px; }
.not-found a { color: var(--jade-deep); font-size: 13px; }

/* Simple responsive */
@media (max-width: 1240px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat:nth-child(4) { border-left: 0; padding-left: 0; }
  .content-grid { grid-template-columns: minmax(0, 1fr) 260px; gap: 32px; }
  .reading-layout { grid-template-columns: minmax(0, 1fr) 240px; }
}
@media (max-width: 1040px) {
  .main { padding: 30px 30px 80px; }
  .content-grid, .reading-layout { grid-template-columns: minmax(0, 1fr); }
  .content-rail { border-left: 0; border-top: 1px solid var(--line); padding-left: 0; padding-top: 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 30px; }
  .rail-section { border-bottom: 1px solid var(--line); }
  .graph-layout { grid-template-columns: minmax(0, 1fr); }
  .graph-panel { border-top: 1px solid var(--line); max-height: none; }
  .graph-canvas-wrap { border-right: 0; }
}
@media (max-width: 860px) {
  :root { --sidebar-width: 0px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 14px 0 40px rgba(20, 24, 20, .12); }
  body.menu-open .sidebar { transform: translateX(0); }
  .menu-button { display: inline-grid; }
  .menu-backdrop { position: fixed; inset: 0; background: rgba(20, 24, 20, .28); z-index: 25; }
  .menu-backdrop[hidden] { display: none; }
  .topbar { padding: 0 18px; }
  .main { padding: 24px 18px 64px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(odd) { border-left: 0; padding-left: 0; }
  .content-rail { grid-template-columns: 1fr; }
  .bar-list.two-col { grid-template-columns: 1fr; }
  .poem-sheet { padding: 24px 16px 30px; }
  .poem-text { font-size: 18px; }
  .page-header-row { flex-direction: column; }
  .search-results { max-height: 60vh; }
  .timeline-layer-options { margin-left: 0; }
  .timeline-app { height: 440px; }
  .graph-canvas-wrap, #graph-canvas { min-height: 480px; height: 480px; }
  .filter-bar { align-items: stretch; }
  .filter-bar label { flex: 1 1 130px; }
}
@media print {
  .sidebar, .topbar, .study-controls, .admin-inline-actions, .search-overlay { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .content-grid, .reading-layout { display: block; }
  .content-rail { display: none; }
  body { background: white; color: black; }
  a { color: black; }
}
