:root {
  color-scheme: light;
  --bg: #f5f8fc;
  --panel: #ffffff;
  --line: #d8e2ee;
  --text: #172235;
  --muted: #5d6f84;
  --brand: #1d65b7;
  --brand-dark: #174d8a;
  --brand-soft: #f0f6fe;
  --soft: #e9f2fc;
  --warm: #faf4e8;
  --green: #edf7ef;
  --accent: #b23b55;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  color: var(--brand-dark);
}

.wrap {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
}

.site-header {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 6px 18px rgba(23, 77, 138, 0.06);
}

.header-inner {
  min-height: 64px;
  display: grid;
  grid-template-columns: auto minmax(220px, 440px) auto;
  gap: 18px;
  align-items: center;
}

.brand {
  font-weight: 800;
  font-size: 20px;
  color: var(--brand-dark);
  line-height: 1.1;
}

.top-search {
  display: flex;
  min-width: 0;
}

.top-search input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px 0 0 6px;
  padding: 10px 12px;
  font-size: 15px;
}

.top-search button,
.button,
.reader-settings button {
  border: 1px solid var(--brand);
  background: #ffffff;
  color: var(--brand);
  border-radius: 6px;
  padding: 9px 13px;
  font-size: 14px;
  cursor: pointer;
}

.top-search button {
  border-radius: 0 6px 6px 0;
  background: var(--brand);
  color: #fff;
  white-space: nowrap;
}

.top-nav {
  display: flex;
  gap: 14px;
  justify-content: flex-end;
}

.search-panel {
  padding: 14px;
  margin-bottom: 18px;
}

.search-refine {
  display: flex;
  gap: 0;
  min-width: 0;
}

.search-refine input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px 0 0 6px;
  padding: 10px 12px;
  font-size: 15px;
}

.search-refine button {
  border-radius: 0 6px 6px 0;
  background: var(--brand);
  color: #fff;
  white-space: nowrap;
}

.search-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.search-tabs .button {
  background: var(--soft);
  border-color: #c4d8ed;
  color: #255d99;
}

.search-tabs .button.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.main {
  padding: 22px 0 42px;
}

.page-head,
.home-hero {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: flex-end;
  margin-bottom: 18px;
}

.home-hero {
  align-items: stretch;
  background: linear-gradient(180deg, #ffffff 0%, #eef6ff 100%);
  border: 1px solid #cfe0f1;
  border-top: 4px solid var(--brand);
  border-radius: 8px;
  padding: 22px;
}

.home-hero-main {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.18;
}

h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.lead,
.meta,
.desc,
.object-note,
.empty {
  color: var(--muted);
}

.lead {
  max-width: 760px;
  line-height: 1.75;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  gap: 8px;
  margin: 0;
}

.stats.inline {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.home-stats {
  align-content: stretch;
  min-width: min(360px, 100%);
}

.home-stats div {
  background: rgba(255, 255, 255, 0.82);
}

.stats dt {
  color: var(--muted);
  font-size: 13px;
}

.stats dd {
  margin: 3px 0 0;
  font-weight: 800;
  font-size: 22px;
}

.tag-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 20px;
}

.home-tag-strip {
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.home-tag-strip strong {
  flex: 0 0 auto;
  color: var(--brand-dark);
  padding: 6px 4px 0 0;
  white-space: nowrap;
}

.home-tag-strip div {
  display: flex;
  flex: 1 1 720px;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.tag-strip a,
.chips a {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  border: 1px solid #c4d8ed;
  background: var(--soft);
  border-radius: 999px;
  padding: 6px 10px;
  color: #255d99;
  font-size: 13px;
}

.tag-strip span {
  color: var(--muted);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.home-featured {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.home-featured .book-card {
  display: block;
  padding: 12px;
}

.home-featured .cover-link {
  display: block;
}

.home-featured .cover {
  width: 100%;
  max-height: 238px;
}

.home-featured .book-card h2 {
  margin-top: 10px;
}

.home-featured .desc {
  display: -webkit-box;
  min-height: 4.6em;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.home-portal {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(0, 1fr) minmax(170px, 220px);
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.book-card,
.panel,
.detail,
.reader {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.book-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 13px;
  padding: 12px;
  min-width: 0;
  box-shadow: 0 8px 22px rgba(23, 34, 53, 0.04);
}

.cover {
  width: 92px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: var(--soft);
  border: 1px solid var(--line);
}

.cover-large {
  width: min(220px, 100%);
}

.book-card h2 {
  font-size: 18px;
  line-height: 1.25;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
  padding-bottom: 9px;
}

.section-head h2 {
  margin: 0;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.compact-panel,
.latest-panel {
  padding: 14px;
  margin-bottom: 0;
}

.rank-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rank-list li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.rank-list li span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
}

.rank-list li:nth-child(-n+3) span {
  background: #fff1f3;
  color: var(--accent);
}

.rank-list a,
.latest-item a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.latest-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}

.latest-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(4em, 7em) minmax(4em, 6em);
  gap: 10px;
  align-items: center;
  min-width: 0;
  border-bottom: 1px dashed #dbe5ef;
  padding: 7px 0;
  font-size: 14px;
}

.latest-item span,
.latest-item em {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-health {
  display: grid;
  gap: 8px;
  margin: 0;
}

.home-health div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px dashed #dbe5ef;
  padding-bottom: 7px;
}

.home-health dt {
  color: var(--muted);
}

.home-health dd {
  margin: 0;
  color: var(--brand-dark);
  font-weight: 700;
  text-align: right;
}

.library-head {
  margin: 20px 0 14px;
}

.library-head .eyebrow {
  margin-bottom: 3px;
}

.library-grid .book-card .desc {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.book-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 7px 0;
  font-size: 14px;
}

.desc {
  margin: 0 0 8px;
  line-height: 1.55;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
}

.detail {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 24px;
  padding: 22px;
  margin-bottom: 16px;
}

.meta-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 18px;
  margin: 18px 0;
}

.meta-list div {
  min-width: 0;
}

.meta-list dt {
  color: var(--muted);
  font-size: 13px;
}

.meta-list dd {
  margin: 3px 0 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button.primary,
.top-search button:hover {
  background: var(--brand);
  color: #ffffff;
}

.button.disabled {
  border-color: var(--line);
  color: #92a0af;
  cursor: default;
}

.panel {
  padding: 20px;
  margin-bottom: 16px;
  line-height: 1.8;
}

.reader {
  padding: 20px;
}

.reader-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.reader-head .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.reader-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 10px 0 14px;
  max-width: 100%;
  overflow: hidden;
}

.settings-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.reader-settings button {
  padding: 7px 10px;
}

.reader-pager,
.list-pager {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  background: #f9fbfe;
  border-radius: 8px;
  padding: 10px;
  margin: 14px 0;
}

.list-pager {
  margin-top: 18px;
}

.pager-status {
  color: var(--muted);
  text-align: center;
  flex: 1 1 260px;
}

.pager-pages {
  display: inline-flex;
  flex: 1 1 220px;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.pager-pages a,
.pager-pages strong,
.pager-pages span {
  display: inline-grid;
  min-width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  font-size: 14px;
}

.pager-pages strong {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.pager-pages span {
  border-color: transparent;
  color: var(--muted);
}

.result-count {
  color: var(--muted);
  margin: -4px 0 14px;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0 0 14px;
  padding: 10px 12px;
}

.notice-ok {
  background: var(--green);
  border-color: #b9dfc0;
}

.notice-error {
  background: #fff1f1;
  border-color: #f0b8b8;
  color: #9c1c1c;
}

.admin-panel {
  margin-bottom: 18px;
}

.admin-book-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.admin-book-list a {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.admin-book-list a.is-active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.admin-book-list span {
  color: var(--muted);
  font-size: 13px;
}

.admin-form {
  display: grid;
  gap: 12px;
}

.admin-form.narrow {
  max-width: 420px;
}

.admin-grid {
  display: grid;
  gap: 12px;
}

.admin-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-form label {
  display: grid;
  gap: 5px;
}

.admin-form label > span {
  color: var(--muted);
  font-size: 13px;
}

.admin-form input[type="text"],
.admin-form input[type="password"],
.admin-form input[type="number"],
.admin-form textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
}

.admin-form textarea {
  line-height: 1.7;
  resize: vertical;
}

.check-line {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.reader-content {
  font-size: var(--reader-font-size, 19px);
  line-height: var(--reader-line-height, 1.9);
  font-family: var(--reader-font-family, "Microsoft YaHei", system-ui, sans-serif);
  background: var(--reader-bg, #ffffff);
  color: var(--reader-color, var(--text));
  border-radius: 8px;
  padding: 20px;
}

.reader-content p {
  margin: 0 0 1em;
}

body.reader-theme-warm .reader-content {
  --reader-bg: var(--warm);
}

body.reader-theme-green .reader-content {
  --reader-bg: var(--green);
}

body.reader-theme-dark {
  background: #111827;
  --bg: #111827;
  --panel: #182235;
  --line: #2c3a52;
  --text: #e5edf8;
  --muted: #aebbd0;
  --soft: #22324a;
}

body.reader-theme-dark .reader-content {
  --reader-bg: #0f1724;
  --reader-color: #dce7f5;
}

body.reader-font-serif .reader-content {
  --reader-font-family: SimSun, "Songti SC", serif;
}

body.reader-font-hei .reader-content {
  --reader-font-family: SimHei, "Microsoft YaHei", sans-serif;
}

body.reader-line-compact .reader-content {
  --reader-line-height: 1.55;
}

body.reader-line-loose .reader-content {
  --reader-line-height: 2.25;
}

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 22px 0;
  background: #fff;
}

@media (max-width: 760px) {
  .header-inner {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 0;
  }

  .top-nav {
    justify-content: flex-start;
  }

  .page-head,
  .home-hero,
  .detail {
    display: block;
  }

  .home-hero {
    padding: 16px;
  }

  .home-stats {
    margin-top: 14px;
  }

  .home-featured,
  .home-portal,
  .latest-list {
    grid-template-columns: 1fr;
  }

  .home-featured .book-card {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .home-featured .cover {
    max-height: none;
  }

  .latest-item {
    grid-template-columns: minmax(0, 1fr) minmax(4em, 7em);
  }

  .latest-item em {
    display: none;
  }

  .detail-cover {
    margin-bottom: 16px;
  }

  .book-grid {
    grid-template-columns: 1fr;
  }

  .reader {
    padding: 12px;
  }

  .reader-content {
    padding: 14px;
    font-size: var(--reader-font-size, 18px);
  }

  .admin-grid.two {
    grid-template-columns: 1fr;
  }
}
