:root {
  color-scheme: dark;
  --ink: #151515;
  --panel: #1c1c1c;
  --panel-raised: #222222;
  --band: #323232;
  --line: #3a3a3a;
  --line-soft: #2a2a2a;
  --paper: #c8c5c0;
  --muted: #8f8c88;
  --accent: #bda786;
  --accent-strong: #e0c99f;
  --sans: "Microsoft YaHei", "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--paper);
  background:
    linear-gradient(rgba(255,255,255,.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.01) 1px, transparent 1px),
    var(--ink);
  background-size: 36px 36px;
  font-family: var(--sans);
  font-size: 15px;
}

a { color: inherit; }
button, input, select { font: inherit; }
button, select { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.library-header { padding: 26px 18px 0; }
.header-frame, .page-frame {
  width: min(960px, 100%);
  margin: 0 auto;
}
.header-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid #565656;
  background: rgba(24,24,24,.96);
}
.theme-toggle {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 2;
  width: 38px;
  height: 38px;
  padding: 0;
  color: #aaa7a2;
  background: transparent;
  border: 1px solid #414141;
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--accent-strong); border-color: #70614d; }
.library-brand {
  display: block;
  padding: 15px 24px 10px;
  color: #d1ceca;
  font-family: var(--sans);
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: .22em;
  text-align: center;
  text-decoration: none;
}
.library-subtitle {
  margin: 0;
  padding: 7px 16px;
  color: #b9b6b1;
  background: #414141;
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}
.library-subtitle strong { color: #f0d8aa; font-variant-numeric: tabular-nums; }

.directory-board { border-top: 1px solid #1d1d1d; }
.directory-row { border-top: 1px solid #1c1c1c; }
.directory-row h2 {
  margin: 0;
  padding: 6px 14px;
  color: #bdbab6;
  background: var(--band);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: .16em;
  text-align: center;
}
.directory-links {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0 18px;
  padding: 12px 42px 14px;
}
.directory-links a {
  min-width: 0;
  padding: 5px 8px;
  color: #aaa7a2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}
.directory-links a:hover, .directory-links a.is-active { color: var(--accent-strong); }
.directory-links a.is-active { text-decoration: underline; text-underline-offset: 4px; }
.directory-row-compact .directory-links { padding-block: 8px 10px; }
.directory-pair { display: grid; grid-template-columns: 1fr 1px 1fr; align-items: center; }
.directory-pair .directory-links { grid-template-columns: repeat(3, minmax(0, 1fr)); padding-inline: 28px; }
.directory-divider { width: 1px; height: 26px; background: var(--line); }
.fixed-links { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 420px; margin: 0 auto; }

.page-frame { padding: 24px 18px 80px; }
.search-panel {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 18px 0 26px;
  padding: 12px;
  background: rgba(21,21,21,.94);
  border-block: 1px solid var(--line-soft);
  backdrop-filter: blur(12px);
}
.search-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  max-width: 700px;
  margin: 0 auto;
  border: 1px solid #484848;
  background: #1d1d1d;
}
.search-label {
  padding: 0 17px;
  color: var(--accent);
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: .12em;
}
.search-field input {
  width: 100%;
  min-height: 46px;
  padding: 10px 46px 10px 14px;
  color: #dedbd6;
  background: transparent;
  border: 0;
  border-left: 1px solid #3d3d3d;
  outline: 0;
}
.search-field input::placeholder { color: #73716e; }
.clear-search {
  position: absolute;
  right: max(calc((100% - 700px) / 2 + 14px), 22px);
  width: 36px;
  height: 36px;
  color: #aaa7a2;
  background: transparent;
  border: 0;
  font-size: 24px;
  cursor: pointer;
}

.catalog-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 46px;
  align-items: start;
}
.catalog-main { min-width: 0; }
.catalog-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  margin: 0 0 4px;
  color: #77746f;
  font-size: 10px;
  letter-spacing: .22em;
}
.catalog-heading h1 {
  margin: 0;
  color: #cecbc6;
  font-family: var(--sans);
  font-size: 25px;
  line-height: 1.2;
  letter-spacing: .08em;
}
.sort-label { color: #898681; font-size: 12px; }
.sort-label select {
  min-height: 34px;
  margin-left: 6px;
  padding: 5px 28px 5px 9px;
  color: #bbb8b3;
  background: #1c1c1c;
  border: 1px solid #414141;
  border-radius: 0;
}
.result-count { margin: 0 0 10px; color: #7d7a76; font-size: 12px; }

.book-list { display: grid; gap: 10px; }
.book-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 54px;
  padding: 12px 15px;
  color: #b5b2ad;
  background: var(--panel);
  border: 1px solid #272727;
  text-decoration: none;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}
.book-row:hover {
  color: #e0ddd7;
  background: #232323;
  border-color: #46413a;
}
.book-title {
  min-width: 0;
  overflow: hidden;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: #74716d;
  font-size: 11px;
  white-space: nowrap;
}
.book-date { color: #96866e; font-variant-numeric: tabular-nums; }
.book-topic::before, .book-length::before { content: "·"; margin-right: 8px; color: #53514e; }
.empty { padding: 72px 18px; color: #77746f; text-align: center; border: 1px dashed #3c3c3c; }

.catalog-sidebar { position: sticky; top: 84px; display: grid; gap: 26px; }
.sidebar-section h2 {
  margin: 0 0 8px;
  padding-bottom: 8px;
  color: #aaa7a2;
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 17px;
  letter-spacing: .12em;
}
.sidebar-links { display: grid; }
.sidebar-links a {
  padding: 5px 2px;
  color: #84817d;
  border-bottom: 1px dashed #343434;
  font-size: 13px;
  text-decoration: none;
}
.sidebar-links a:hover, .sidebar-links a.is-active { color: var(--accent-strong); }
.sidebar-links-secondary { margin-top: 8px; }

.pager {
  display: grid;
  grid-template-columns: 100px minmax(90px, auto) 100px;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
}
.pager button {
  min-height: 38px;
  color: #aaa7a2;
  background: #1d1d1d;
  border: 1px solid #3b3b3b;
  cursor: pointer;
}
.pager button:hover:not(:disabled) { color: var(--accent-strong); border-color: #675c4b; }
.pager button:disabled { opacity: .35; cursor: default; }
.page-status { color: #77746f; text-align: center; font-size: 13px; }
.noscript { padding: 30px; color: #aaa7a2; text-align: center; }

html[data-theme="light"] {
  color-scheme: light;
  --ink: #eee9e0;
  --panel: #faf7f1;
  --panel-raised: #ffffff;
  --band: #d8d0c4;
  --line: #c9beae;
  --line-soft: #d8cfc3;
  --paper: #302a23;
  --muted: #746b61;
  --accent: #8a6534;
  --accent-strong: #6d4a20;
}
html[data-theme="light"] body {
  background:
    linear-gradient(rgba(89,72,52,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(89,72,52,.025) 1px, transparent 1px),
    var(--ink);
  background-size: 36px 36px;
}
html[data-theme="light"] .header-frame { background: rgba(248,244,237,.97); border-color: #afa18e; }
html[data-theme="light"] .library-brand { color: #332d26; }
html[data-theme="light"] .library-subtitle { color: #4e463c; background: #d6cec2; }
html[data-theme="light"] .library-subtitle strong { color: #6d4a20; }
html[data-theme="light"] .theme-toggle { color: #665d52; border-color: #b5aa9b; }
html[data-theme="light"] .directory-board,
html[data-theme="light"] .directory-row { border-color: #c6baaa; }
html[data-theme="light"] .directory-row h2 { color: #534a40; background: #d9d1c6; }
html[data-theme="light"] .directory-links a { color: #5d554c; }
html[data-theme="light"] .directory-links a:hover,
html[data-theme="light"] .directory-links a.is-active { color: #704c21; }
html[data-theme="light"] .directory-divider { background: #c7bbab; }
html[data-theme="light"] .search-panel { background: rgba(238,233,224,.94); }
html[data-theme="light"] .search-field { background: #faf7f1; border-color: #b9ad9d; }
html[data-theme="light"] .search-label { color: #765326; }
html[data-theme="light"] .search-field input { color: #332d26; border-left-color: #c8bcad; }
html[data-theme="light"] .search-field input::placeholder { color: #91877b; }
html[data-theme="light"] .clear-search { color: #746a5f; }
html[data-theme="light"] .eyebrow { color: #8a7f72; }
html[data-theme="light"] .catalog-heading h1 { color: #302a23; }
html[data-theme="light"] .sort-label { color: #746b61; }
html[data-theme="light"] .sort-label select { color: #463e35; background: #faf7f1; border-color: #b9ad9d; }
html[data-theme="light"] .result-count { color: #7d7267; }
html[data-theme="light"] .book-row { color: #40382f; background: #faf7f1; border-color: #d5cbbd; }
html[data-theme="light"] .book-row:hover { color: #241f1a; background: #fffdf8; border-color: #a89170; }
html[data-theme="light"] .book-meta { color: #7a7064; }
html[data-theme="light"] .book-date { color: #80613b; }
html[data-theme="light"] .book-topic::before,
html[data-theme="light"] .book-length::before { color: #b4a99b; }
html[data-theme="light"] .sidebar-section h2 { color: #494138; }
html[data-theme="light"] .sidebar-links a { color: #746a5f; border-color: #d4cabc; }
html[data-theme="light"] .sidebar-links a:hover,
html[data-theme="light"] .sidebar-links a.is-active { color: #704c21; }
html[data-theme="light"] .pager button { color: #5d554c; background: #faf7f1; border-color: #b9ad9d; }
html[data-theme="light"] .page-status { color: #7d7267; }

@media (max-width: 820px) {
  .directory-links { padding-inline: 22px; }
  .catalog-layout { grid-template-columns: minmax(0, 1fr) 180px; gap: 28px; }
}

@media (max-width: 680px) {
  .library-header { padding: 0; }
  .header-frame { border-inline: 0; }
  .library-brand { padding: 16px 12px 9px; font-size: 29px; letter-spacing: .15em; }
  .library-subtitle { font-size: 14px; }
  .directory-links { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px 10px 12px; }
  .directory-pair { grid-template-columns: 1fr; }
  .directory-pair .directory-links { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 8px 8px; }
  .directory-divider { display: none; }
  .fixed-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-frame { padding: 14px 12px 60px; }
  .search-panel { margin: 10px -12px 20px; padding-inline: 12px; }
  .search-label { padding-inline: 12px; }
  .clear-search { right: 18px; }
  .catalog-layout { display: flex; flex-direction: column; gap: 30px; }
  .catalog-main { width: 100%; }
  .catalog-sidebar { position: static; width: 100%; grid-template-columns: 1fr 1fr; order: 2; }
  .sidebar-section:last-child { display: none; }
  .book-row { grid-template-columns: minmax(0, 1fr); gap: 5px; min-height: 62px; padding: 11px 12px; }
  .book-title { font-size: 16px; white-space: normal; }
  .book-meta { flex-wrap: wrap; }
  .catalog-heading { align-items: center; }
  .catalog-heading h1 { font-size: 22px; }
  .sort-label { font-size: 0; }
  .sort-label select { margin: 0; font-size: 12px; }
  .pager { grid-template-columns: 88px minmax(76px, auto) 88px; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
