:root {
  --ink: #17211f;
  --muted: #5e6b68;
  --line: #d7e0dc;
  --wash: #f3f6f3;
  --paper: #fffefb;
  --deep: #153f3b;
  --accent: #c8772f;
  --accent-soft: #fff0dc;
  --max: 1240px;
  --ui-font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", ui-sans-serif, system-ui, sans-serif;
  --reading-font: "Noto Serif TC", "Source Han Serif TC", "PMingLiU", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html.auth-pending body { visibility: hidden; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--reading-font);
  line-height: 1.7;
}
button, input, select { font-family: var(--ui-font); }
button { cursor: pointer; }
.brand, nav, .search-form, .search-tips, .search-scope, .metrics, .subject-card-footer, .pagination, .book-card button, .toc, .results-heading, .result-meta, footer { font-family: var(--ui-font); }
:where(a, button, input, select):focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.search-form:focus-within { outline: 3px solid rgba(200, 119, 47, .42); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.site-header {
  min-height: 76px;
  padding: 14px max(24px, calc((100vw - var(--max)) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 251, .96);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { min-height: 44px; color: var(--ink); display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-logo { display: block; width: 52px; height: 52px; object-fit: contain; }
.brand strong, .brand small { display: block; line-height: 1.25; }
.brand strong { font-size: 17px; letter-spacing: .08em; }
.brand small { color: var(--muted); font-family: ui-sans-serif, system-ui, sans-serif; font-size: 10px; letter-spacing: .04em; margin-top: 3px; }
nav { display: flex; gap: 20px; }
nav a { min-height: 44px; color: var(--muted); text-decoration: none; font-size: 14px; display: inline-flex; align-items: center; }
nav a:hover { color: var(--deep); }
.nav-button { border: 0; padding: 0; color: var(--muted); background: transparent; font-size: 14px; }
.nav-button:hover { color: var(--deep); }

main { max-width: var(--max); margin: 0 auto; padding: 0 24px 64px; }
.hero { padding: 76px 0 54px; max-width: 880px; }
.eyebrow { color: var(--accent); font: 700 14px/1.4 ui-sans-serif, system-ui, sans-serif; letter-spacing: .1em; margin: 0 0 12px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(32px, 5vw, 58px); line-height: 1.25; letter-spacing: .04em; margin-bottom: 18px; font-weight: 700; }
h2 { font-size: 24px; line-height: 1.4; letter-spacing: .04em; margin-bottom: 0; }
h3 { font-size: 16px; margin-bottom: 8px; }
.hero-copy { max-width: 750px; color: var(--muted); font-size: 17px; margin-bottom: 28px; }
.search-form { display: flex; max-width: 760px; border: 1px solid var(--deep); background: white; scroll-margin-top: 104px; }
.search-form input { min-width: 0; flex: 1; border: 0; padding: 15px 17px; color: var(--ink); outline: none; }
.search-form button { border: 0; padding: 0 22px; color: white; background: var(--deep); font-weight: 700; }
.search-form button:hover { background: #0f302d; }
.search-tips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); font-size: 13px; }
.search-tips button { min-width: 44px; min-height: 44px; border: 0; color: var(--deep); background: transparent; border-bottom: 1px solid #9fb5ae; padding: 8px 3px; }
.login-page { min-height: calc(100vh - 76px); display: grid; place-items: center; padding-top: 48px; }
.login-panel { width: min(100%, 520px); padding: clamp(26px, 5vw, 42px); border: 1px solid var(--line); border-top: 4px solid var(--deep); background: #fff; box-shadow: 0 18px 50px rgba(21, 63, 59, .08); }
.login-panel h1, .login-panel h2 { font-size: clamp(27px, 4vw, 36px); margin-bottom: 9px; }
.login-panel > p:not(.eyebrow):not(.login-message) { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.reader-login-form { display: grid; gap: 8px; font-family: var(--ui-font); }
.reader-login-form label { margin-top: 8px; color: var(--deep); font-weight: 700; font-size: 13px; }
.reader-login-form > input, .password-field { min-height: 50px; border: 1px solid #a9b8b4; background: #fff; }
.reader-login-form input { width: 100%; min-width: 0; border: 0; padding: 12px 14px; outline: none; font-size: 16px; }
.reader-login-form > input { border: 1px solid #a9b8b4; }
.reader-login-form > input:focus, .password-field:focus-within { outline: 3px solid rgba(200, 119, 47, .42); outline-offset: 2px; }
.password-field { display: flex; }
.password-toggle { min-width: 64px; border: 0; border-left: 1px solid var(--line); color: var(--deep); background: var(--wash); }
.login-submit, .primary-link, .secondary-action { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; margin-top: 14px; border: 1px solid var(--deep); padding: 10px 20px; font-family: var(--ui-font); font-weight: 700; text-decoration: none; }
.login-submit, .primary-link { color: #fff; background: var(--deep); }
.login-submit:hover, .primary-link:hover { background: #0f302d; }
.secondary-action { color: var(--deep); background: #fff; }
.reader-login-form button:disabled, .account-actions button:disabled { cursor: wait; opacity: .65; }
.login-message { min-height: 1.6em; margin: 10px 0 0; color: #9a3d27; font-size: 13px; }
.account-panel strong { color: var(--deep); }
.account-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.account-actions > * { margin-top: 0; }
.account-actions .primary-link { grid-column: 1 / -1; }
.password-change-panel { margin-top: 24px; }
.password-change-panel hr { margin: 0 0 24px; border: 0; border-top: 1px solid var(--line); }
.password-change-panel h2 { font-size: 24px; margin-bottom: 6px; }
.password-change-panel > p { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.form-guidance { margin: 5px 0 0; color: var(--muted); font: 12px/1.6 var(--ui-font); }
.show-passwords { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 13px; font-weight: 400 !important; }
.show-passwords input { width: 18px; height: 18px; margin: 0; }
.success-message { color: var(--deep); }
.reader-account-link { color: var(--deep); font-weight: 700; }
.home-hero { max-width: none; padding: 32px 0 24px; }
.home-banner { display: block; width: 100%; height: auto; margin: 0 0 30px; }
.topic-hero { padding-bottom: 42px; }
body[data-collection="biographies"] .topic-hero { padding-bottom: 14px; }
.banner-hero { max-width: none; padding-top: 32px; }
.banner-hero .home-banner { width: 100%; max-width: none; }
.breadcrumb { color: var(--muted); font-size: 13px; margin: -2px 0 18px; }
.breadcrumb a { color: var(--deep); text-decoration-color: var(--accent); text-underline-offset: 3px; }
.breadcrumb span { color: var(--accent); margin: 0 7px; }
.search-scope { color: var(--muted); font-size: 13px; margin: 13px 0 0; }
.global-results { max-width: 940px; padding: 10px 0 36px; }
.global-results:empty { display: none; }
.pagination { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.pagination-status { color: var(--muted); font-size: 13px; }
.pagination-controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.pagination button { min-width: 38px; min-height: 38px; padding: 6px 11px; border: 1px solid var(--line); color: var(--deep); background: #fff; }
.pagination button:hover:not(:disabled), .pagination button.current { border-color: var(--deep); color: #fff; background: var(--deep); }
.pagination button:disabled { cursor: default; opacity: .42; }
.subject-section { padding: 30px 0 58px; border-top: 1px solid var(--line); }
.subject-heading { max-width: none; margin-bottom: 24px; }
.subject-heading h2 { color: var(--deep); font-size: clamp(30px, 4vw, 44px); line-height: 1.25; letter-spacing: .08em; }
.subject-heading > p:last-child { color: var(--muted); font-size: 15px; margin: 12px 0 0; }
.subject-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.subject-card { overflow: hidden; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; display: block; transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease; }
.subject-card.available:hover, .subject-card.organizing:hover { border-color: var(--deep); box-shadow: 0 12px 30px rgba(21, 63, 59, .11); transform: translateY(-2px); }
.subject-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.subject-visual { display: block; width: 100%; background: #fff; }
.subject-visual img { display: block; width: 100%; height: auto; aspect-ratio: 3750 / 2652; object-fit: contain; }
.subject-card-footer { min-height: 58px; padding: 12px 18px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.subject-card-footer > strong { color: var(--deep); font-size: 17px; letter-spacing: .04em; }
.subject-card.planned { border-top: 3px solid #bdc8c3; background: #fbfcfb; }
.subject-status { color: var(--accent); font: 700 11px/1.4 ui-sans-serif, system-ui, sans-serif; letter-spacing: .1em; margin-bottom: 16px; }
.subject-card.planned .subject-status { color: var(--muted); }
.subject-card h3 { color: var(--deep); font-size: 22px; margin-bottom: 5px; }
.subject-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.subject-card > p:last-of-type { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.subject-action { color: var(--deep); font-size: 16px; font-weight: 700; letter-spacing: .08em; text-align: center; }
.biography-workspace { max-width: 940px; padding: 26px 0 58px; }
.biography-heading { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 14px; }
.biography-heading > p:last-child { color: var(--muted); font-size: 14px; margin: 9px 0 0; }
.biography-result { min-height: 128px; display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 16px; align-items: start; }
.biography-result-content { min-width: 0; }
.portrait-frame { display: grid; place-items: center; width: 88px; aspect-ratio: 3 / 4; overflow: hidden; border: 1px solid var(--line); background: var(--wash); color: var(--muted); font: 700 11px/1.4 ui-sans-serif, system-ui, sans-serif; letter-spacing: .06em; text-align: center; }
.portrait-frame img { width: 100%; height: 100%; object-fit: cover; }
.portrait-missing { border-style: dashed; padding: 8px; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metrics article { padding: 22px 24px; border-right: 1px solid var(--line); }
.metrics article:last-child { border-right: 0; }
.metrics strong { display: block; color: var(--deep); font: 700 30px/1.1 ui-sans-serif, system-ui, sans-serif; }
.metrics span { display: block; color: var(--muted); font-size: 13px; margin-top: 7px; }

.workspace { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(0, 2fr); gap: 36px; padding: 58px 0; }
.catalog-panel { border-right: 1px solid var(--line); padding-right: 30px; }
.section-heading { margin-bottom: 16px; }
.book-card { border: 0; background: transparent; padding: 0; text-align: center; }
.book-switcher { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 0 0 20px; }
.book-switcher[hidden] { display: none; }
.book-switcher button { min-height: 40px; border: 1px solid var(--line); background: #fff; color: var(--deep); font-family: var(--ui-font); font-weight: 700; padding: 7px 10px; }
.book-switcher button:hover, .book-switcher button[aria-pressed="true"] { border-color: var(--deep); background: var(--deep); color: #fff; }
.book-cover { width: min(100%, 220px); margin: 0 auto 18px; border: 1px solid var(--line); background: #fff; box-shadow: 0 10px 26px rgba(21, 63, 59, .12); }
.book-cover img { display: block; width: 100%; height: auto; }
.book-card .book-title { color: var(--deep); font-size: 18px; line-height: 1.55; margin: 0 0 10px; }
.book-card .book-editors { color: var(--ink); font-size: 14px; line-height: 1.65; margin: 0 0 7px; }
.book-card .book-editors span { color: var(--accent); font: 700 12px/1.4 ui-sans-serif, system-ui, sans-serif; letter-spacing: .08em; margin-right: 8px; }
.book-card .book-meta { color: var(--muted); font-size: 12px; margin: 0 0 16px; }
.book-card button { width: 100%; min-height: 44px; border: 1px solid var(--deep); background: transparent; color: var(--deep); padding: 9px 12px; }
.book-card button:hover { background: var(--deep); color: white; }
.toc { margin-top: 18px; }
.toc h3 { margin-bottom: 8px; }
.toc-group { border-top: 1px solid var(--line); padding: 10px 0; }
.toc-group:last-child { border-bottom: 1px solid var(--line); }
.toc-group > span { color: var(--accent); display: block; font: 700 13px/1.5 ui-sans-serif, system-ui, sans-serif; letter-spacing: .05em; margin-bottom: 5px; }
.toc button { display: block; width: 100%; min-height: 44px; border: 0; background: transparent; color: var(--ink); padding: 9px 0; text-align: left; font-size: 14px; }
.toc button:hover { color: var(--deep); text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
.toc button.active { color: var(--deep); font-weight: 700; }
.ingest-note { margin-top: 22px; padding: 16px 0 0 14px; border-left: 3px solid var(--accent); }
.ingest-note strong { font-size: 14px; }
.ingest-note p { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

.main-panel { min-width: 0; }
.search-results { margin-bottom: 34px; }
.loading-skeleton { align-content: center; color: var(--muted); min-height: 180px; border: 1px solid var(--line); background: linear-gradient(90deg, var(--wash), #fff, var(--wash)); background-size: 200% 100%; animation: skeleton-pulse 1.2s linear infinite; padding: 24px; }
.workspace[aria-busy="true"] .result-list { opacity: .42; }
@keyframes skeleton-pulse { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .loading-skeleton { animation: none; } }
.results-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.results-heading h2 { font-size: 20px; }
.results-heading span { color: var(--muted); font-size: 13px; }
.result-list { display: grid; gap: 10px; }
.result { width: 100%; text-align: left; color: inherit; background: white; border: 1px solid var(--line); padding: 16px; }
.result:hover { border-color: var(--deep); }
.result-meta { color: var(--accent); display: block; font: 700 13px/1.55 ui-sans-serif, system-ui, sans-serif; letter-spacing: .04em; margin-bottom: 7px; }
.result-citation { display: block; color: var(--deep); font-size: 15px; line-height: 1.65; margin-bottom: 6px; }
.result-citation, .result-snippet { font-family: var(--reading-font); }
.result-snippet { color: var(--muted); display: block; font-size: 14px; line-height: 1.75; }
mark { background: var(--accent-soft); color: var(--ink); padding: 0 1px; }
.empty-search { color: var(--muted); background: var(--wash); padding: 18px; font-size: 14px; }
.literature-organizing { display: block; padding-top: 32px; }
.organizing-notice { max-width: 760px; margin: 0 auto; padding: 42px 32px; border: 1px solid var(--line); background: var(--wash); text-align: center; }
.organizing-notice h2 { color: var(--deep); margin: 0 0 12px; }
.organizing-notice p { color: var(--muted); margin: 0 auto 24px; }
.organizing-notice a { display: inline-block; color: white; background: var(--deep); padding: 10px 20px; text-decoration: none; font-family: var(--ui-font); font-weight: 700; }

.reader-controls { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.reader-controls button, .reader-controls input { border: 1px solid var(--line); background: white; padding: 7px 10px; color: var(--ink); }
.reader-controls button:hover { border-color: var(--deep); color: var(--deep); }
.reader-controls label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.reader-controls input { width: 70px; }

.principles { padding-top: 28px; border-top: 1px solid var(--line); }
.principles > h2 { max-width: 700px; font-size: 30px; margin-bottom: 26px; }
.principle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.principle-grid article { padding-top: 14px; border-top: 2px solid var(--accent); }
.principle-grid p { color: var(--muted); font-size: 14px; margin-bottom: 0; }
footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 28px; padding: 24px max(24px, calc((100vw - var(--max)) / 2)); background: var(--deep); color: #dce7e3; font-size: 12px; }
.footer-notice { max-width: 760px; }
.footer-notice span { display: block; margin-bottom: 4px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 10px; }
.footer-contact { display: flex; align-items: center; gap: 9px; min-width: 156px; min-height: 44px; padding: 9px 12px; color: #fff4e8; border: 1px solid rgba(220, 231, 227, .35); background: rgba(255, 255, 255, .04); text-decoration: none; }
.footer-contact:hover { border-color: #c8772f; background: rgba(255, 255, 255, .09); }
.contact-icon { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: #e9b27b; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.footer-contact span, .footer-contact small, .footer-contact strong { display: block; }
.footer-contact small { color: #b9cbc5; font: 700 10px/1.25 ui-sans-serif, system-ui, sans-serif; letter-spacing: .08em; }
.footer-contact strong { margin-top: 2px; font: 600 12px/1.35 ui-sans-serif, system-ui, sans-serif; }

@media (max-width: 1024px) {
  .site-header { padding-inline: 24px; }
  main { padding-inline: 20px; }
  .hero { padding-top: 44px; }
  .banner-hero, .home-hero { padding-top: 24px; }
  .subject-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { grid-template-columns: 1fr; gap: 34px; padding-top: 42px; }
  .catalog-panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 32px; }
  .toc { columns: 2; column-gap: 28px; }
  .toc > h3 { column-span: all; }
  .toc-group { break-inside: avoid; }
  footer { padding-inline: 24px; }
}

@media (max-width: 800px) {
  .site-header { position: sticky; min-height: 68px; }
  .brand-logo { width: 44px; height: 44px; }
  .brand strong { font-size: 16px; }
  nav { gap: 14px; }
  nav a { font-size: 13px; }
  .principle-grid { grid-template-columns: 1fr; }
  .biography-result { grid-template-columns: 68px minmax(0, 1fr); gap: 12px; }
  .portrait-frame { width: 68px; }
  footer { display: block; }
  .footer-links { margin-top: 16px; }
}

@media (max-width: 640px) {
  .site-header { position: static; flex-wrap: wrap; gap: 10px; padding: 10px 16px 0; }
  .brand { gap: 9px; }
  .brand-logo { width: 40px; height: 40px; }
  .brand small { display: none; }
  nav { width: calc(100% + 32px); margin-inline: -16px; padding: 0 16px; border-top: 1px solid var(--line); }
  nav a { flex: 1; min-height: 44px; display: grid; place-items: center; white-space: nowrap; }
  .nav-button { flex: 0 0 58px; min-height: 44px; }
  main { padding: 0 16px 44px; }
  .hero, .banner-hero, .home-hero { padding: 20px 0 30px; }
  body[data-collection="biographies"] .topic-hero { padding-bottom: 8px; }
  .biography-workspace { padding-top: 18px; }
  .home-banner {
    width: calc(100% + 32px);
    max-width: none;
    height: auto;
    margin: 0 -16px 20px;
    object-fit: contain;
  }
  .search-form { flex-direction: column; max-width: none; }
  .search-form input { width: 100%; min-height: 52px; padding: 13px 14px; font-size: 16px; }
  .search-form button { min-height: 48px; padding: 10px 16px; }
  .login-panel { padding: 20px 16px; }
  .login-page { min-height: calc(100vh - 95px); padding-top: 28px; }
  .search-tips { margin-top: 12px; line-height: 1.8; }
  .subject-cards { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr; }
  .metrics article { border-right: 0; border-bottom: 1px solid var(--line); }
  .metrics article:last-child { border-bottom: 0; }
  .subject-card { min-height: 0; }
  .subject-card-footer { min-height: 54px; padding: 11px 14px; }
  .subject-card-footer > strong { font-size: 16px; }
  .subject-action { font-size: 15px; }
  .toc { columns: 1; }
  .workspace { padding: 36px 0; }
  .results-heading { display: block; }
  .results-heading span { display: block; margin-top: 5px; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .pagination-controls { justify-content: flex-start; }
  .pagination button { min-width: 42px; min-height: 42px; }
  .result { padding: 14px; }
  .result-snippet { font-size: 13px; }
  .principles > h2 { font-size: 25px; }
  footer { padding: 22px 16px; }
  .footer-contact { flex: 1 1 100%; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
