:root {
  color-scheme: light;
  --paper: #f9f7f2;
  --ink: #292524;
  --muted: #78716c;
  --muted-soft: #a8a29e;
  --line: #e7e5e4;
  --soft: #f5f5f4;
  --red: #b91c1c;
  --red-dark: #7f1d1d;
  --green: #15803d;
  --yellow: #a16207;
  --blue: #2563eb;
  --shadow: 0 18px 40px rgba(41, 37, 36, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(rgba(120, 113, 108, 0.12) 0.7px, transparent 0.7px),
    radial-gradient(rgba(120, 113, 108, 0.08) 0.7px, transparent 0.7px);
  background-position: 0 0, 5px 5px;
  background-size: 10px 10px;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
textarea,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid rgba(231, 229, 228, 0.9);
  box-shadow: 0 1px 8px rgba(41, 37, 36, 0.05);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 6px;
  color: #fff;
  background: var(--red);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
}

.brand-title {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.nav-links {
  display: none;
  align-items: center;
  gap: 24px;
  font-size: 0.92rem;
  font-weight: 600;
}

.nav-links a {
  text-decoration: none;
}

.nav-links a:hover {
  color: var(--red);
}

.mobile-actions {
  display: flex;
  gap: 8px;
}

.mobile-actions button {
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

.mobile-red {
  color: #fff;
  background: var(--red);
}

.mobile-light {
  color: #57534e;
  background: #f5f5f4;
}

.main-shell {
  max-width: 896px;
  margin: 0 auto;
  padding: 32px 16px 0;
}

.hero {
  margin-bottom: 48px;
  text-align: center;
}

.hero h1 {
  margin: 0 0 16px;
  color: var(--red-dark);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(2.25rem, 7vw, 3.25rem);
  font-weight: 800;
  line-height: 1.16;
  letter-spacing: 0;
}

.hero p {
  max-width: 36rem;
  margin: 0 auto;
  color: #57534e;
  line-height: 1.75;
}

.search-card,
.result-card,
.stats-card,
.reader-shell {
  border: 1px solid #e7e5e4;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

.search-card {
  position: relative;
  margin-bottom: 48px;
  padding: 24px;
}

#quote-input {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  border: 2px solid #f5f5f4;
  border-radius: 12px;
  padding: 12px;
  color: var(--ink);
  background: #fafaf9;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1rem;
  line-height: 1.7;
  outline: none;
}

#quote-input:focus {
  border-color: var(--red);
}

.search-actions {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 24px;
}

button {
  cursor: pointer;
}

.primary-action,
.secondary-action,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  border: 0;
  border-radius: 12px;
  padding: 0 22px;
  font-weight: 800;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease;
}

.primary-action {
  flex: 1;
  color: #fff;
  background: var(--red);
  box-shadow: 0 12px 20px rgba(185, 28, 28, 0.23);
}

.primary-action:hover {
  background: #991b1b;
}

.primary-action:active,
.secondary-action:active,
.download-button:active {
  transform: scale(0.98);
}

.primary-action span,
.secondary-action span {
  margin-right: 8px;
  font-size: 1.1rem;
}

.secondary-action {
  color: #57534e;
  background: #f5f5f4;
}

.secondary-action:hover {
  background: #e7e5e4;
}

.tool-note {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.result-card {
  position: relative;
  overflow: hidden;
  margin-bottom: 48px;
  padding: 32px;
  border-style: dashed;
  box-shadow: none;
}

.result-card[hidden],
.stats-card[hidden],
.reader-section[hidden] {
  display: none;
}

.result-stamp {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 1;
  display: inline-block;
  border: 3px solid currentColor;
  border-radius: 4px;
  padding: 4px 12px;
  color: var(--red);
  font-weight: 900;
  text-transform: uppercase;
  transform: rotate(-15deg);
  opacity: 0.88;
}

.result-stamp[data-status="TRUE"] {
  color: var(--green);
}

.result-stamp[data-status="PARTIAL"] {
  color: var(--yellow);
}

.result-stamp[data-status="SIMILAR"] {
  color: var(--blue);
}

.result-stamp[data-status="NOT_FOUND"] {
  color: #78716c;
}

.result-kicker {
  margin: 0 0 16px;
  color: var(--muted-soft);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result-quote {
  margin: 0 88px 24px 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.25rem;
  font-style: italic;
  line-height: 1.8;
  word-break: break-word;
}

.source-block {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding-top: 24px;
  border-top: 1px solid #f5f5f4;
}

.source-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 6px;
  color: #57534e;
  background: #f5f5f4;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-weight: 800;
}

.source-block h2 {
  margin: 0 0 4px;
  font-size: 1rem;
}

#result-meta {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.context-box {
  margin-top: 16px;
  padding: 16px;
  border-left: 4px solid #e7e5e4;
  border-radius: 8px;
  color: #57534e;
  background: #fafaf9;
  font-size: 0.92rem;
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
}

mark {
  padding: 1px 3px;
  border-radius: 3px;
  color: #dc2626;
  background: #fecaca;
  font-weight: 800;
}

.result-actions {
  margin-top: 18px;
}

.stats-card {
  margin-bottom: 48px;
  padding: 32px;
}

.stats-card h2 {
  margin: 0 0 24px;
  color: var(--red-dark);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.55rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.stats-grid div {
  text-align: center;
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid strong {
  margin-bottom: 6px;
  color: var(--red);
  font-size: 2.4rem;
}

.stats-grid span {
  color: var(--muted);
  font-size: 0.9rem;
}

.reader-section {
  width: min(1400px, calc(100vw - 32px));
  margin: 0 50% 48px;
  transform: translateX(-50%);
}

.reader-shell {
  overflow: hidden;
}

.reader-layout {
  position: relative;
  display: flex;
  height: 100vh;
  min-height: 680px;
}

.toc-panel {
  width: 320px;
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fafaf9;
}

.toc-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: #fef2f2;
}

.toc-head h2 {
  margin: 0;
  color: var(--red-dark);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.25rem;
}

.toc-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.toc-search {
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--line);
  background: #fef2f2;
}

#article-filter {
  width: 100%;
  border: 1px solid #e7e5e4;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
}

#article-filter:focus {
  border-color: var(--red);
}

.toc-tree {
  flex: 1;
  overflow: auto;
  padding: 12px;
}

.volume-block + .volume-block {
  margin-top: 12px;
}

.volume-toggle,
.article-link {
  width: 100%;
  border: 0;
  text-align: left;
}

.volume-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--red-dark);
  background: #fee2e2;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-weight: 800;
}

.article-list {
  border-left: 2px solid #e7e5e4;
  margin-left: 8px;
  padding: 8px 0 0 8px;
}

.article-link {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-height: 34px;
  border-radius: 8px;
  padding: 8px 10px;
  color: #57534e;
  background: transparent;
  font-size: 0.88rem;
  font-weight: 600;
}

.article-link:hover,
.article-link.active {
  color: #fff;
  background: var(--red);
}

.article-link small {
  color: inherit;
  opacity: 0.7;
  white-space: nowrap;
}

.article-panel {
  min-width: 0;
  flex: 1;
  overflow: auto;
  background: #fff;
  outline: none;
}

.article-content-area {
  min-height: calc(100% - 48px);
}

.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #fafaf9;
  box-shadow: 0 1px 4px rgba(41, 37, 36, 0.06);
}

#current-article-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  color: #57534e;
  background: #f5f5f4;
}

.icon-button:hover {
  color: var(--red);
  background: #fee2e2;
}

.empty-reader {
  display: grid;
  min-height: calc(100% - 48px);
  place-items: center;
  align-content: center;
  color: var(--muted-soft);
  text-align: center;
}

.empty-book {
  margin-bottom: 16px;
  color: #d6d3d1;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 4rem;
  font-weight: 800;
}

.article-title {
  margin: 42px auto 8px;
  padding: 0 28px;
  max-width: 820px;
  color: var(--red-dark);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  line-height: 1.28;
  text-align: center;
}

.article-meta {
  max-width: 820px;
  margin: 0 auto 28px;
  padding: 0 28px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.article-paragraph {
  max-width: 820px;
  margin: 0 auto 1.25em;
  padding: 0 28px;
  color: #44403c;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.05rem;
  line-height: 1.95;
  text-align: justify;
  text-indent: 2em;
}

.article-annotation {
  color: #888;
  font-size: 0.65em;
  vertical-align: super;
}

.site-footer {
  padding: 48px 16px 42px;
  border-top: 1px solid var(--line);
  color: var(--muted-soft);
  text-align: center;
}

.footer-inner {
  max-width: 896px;
  margin: 0 auto;
}

.site-footer h2 {
  margin: 0 0 18px;
  color: #57534e;
  font-size: 1.15rem;
}

.resource-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-bottom: 34px;
}

.resource-card {
  display: block;
  border-radius: 12px;
  padding: 24px;
  color: inherit;
  background: #fff;
  box-shadow: 0 1px 10px rgba(41, 37, 36, 0.06);
  text-decoration: none;
}

.resource-card h3 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 1rem;
}

.resource-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.8rem;
}

.download-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 16px;
  color: #fff;
  background: var(--red);
  font-size: 0.9rem;
}

.qr-card span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.qr-card img {
  width: 96px;
  height: 96px;
  border-radius: 6px;
  image-rendering: pixelated;
}

.qr-card em {
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
  line-height: 2;
  text-align: left;
}

.copyright {
  margin: 0;
  font-size: 0.82rem;
}

.mobile-only {
  display: none;
}

body.reader-fullscreen {
  overflow: hidden;
}

body.reader-fullscreen .topbar,
body.reader-fullscreen .main-shell > :not(.reader-section),
body.reader-fullscreen .site-footer {
  display: none;
}

body.reader-fullscreen .main-shell {
  max-width: none;
  padding: 0;
}

body.reader-fullscreen .reader-section {
  width: 100vw;
  height: 100vh;
  margin: 0;
  transform: none;
}

body.reader-fullscreen .reader-shell,
body.reader-fullscreen .reader-layout {
  height: 100vh;
  min-height: 0;
  border-radius: 0;
}

@media (min-width: 768px) {
  .nav-links {
    display: flex;
  }

  .mobile-actions {
    display: none;
  }

  .main-shell {
    padding-top: 64px;
  }

  .search-actions {
    flex-direction: row;
  }

  .secondary-action {
    width: 128px;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .resource-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .topbar {
    min-height: 64px;
    padding: 12px 16px;
  }

  .brand-title {
    max-width: calc(100vw - 190px);
    overflow: hidden;
    font-size: 1.12rem;
    text-overflow: ellipsis;
  }

  .hero h1 {
    font-size: clamp(2rem, 10vw, 2.8rem);
  }

  .hero {
    margin-bottom: 38px;
  }

  .search-card {
    padding: 24px;
  }

  .result-card {
    padding: 28px 20px;
  }

  .result-stamp {
    position: static;
    width: max-content;
    margin: 0 0 18px auto;
  }

  .result-quote {
    margin-right: 0;
  }

  .reader-section {
    width: calc(100vw - 24px);
    margin-bottom: 40px;
  }

  .reader-layout {
    height: 76vh;
    min-height: 620px;
  }

  .mobile-only {
    display: inline-grid;
  }

  .toc-panel {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    width: min(86vw, 340px);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }

  .toc-panel.open {
    transform: translateX(0);
  }

  .toc-overlay {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(41, 37, 36, 0.34);
  }

  .article-panel {
    width: 100%;
  }

  .article-title {
    margin-top: 30px;
  }

  .article-paragraph {
    padding: 0 20px;
    font-size: 1rem;
  }
}
