/* 綺閣藏書 — paper & ink. No web fonts (fast in every region); relies on system CJK serif faces. */
:root {
  --bg: #f6f1e7; --paper: #fbf8f1; --ink: #2b2620; --muted: #8a7f70; --line: #e3d9c6;
  --accent: #9b2d20; --accent-ink: #fff; --mark: #f3dc9b; --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 4px 16px rgba(60, 40, 20, .06);
  --fs: 19px; --lh: 2.0; --maxw: 1080px; --readw: 720px;
  --serif: "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
html[lang="zh-Hant"] {
  --serif: "Noto Serif TC", "Noto Serif CJK TC", "Source Han Serif TC", "Songti TC", "PMingLiU", "MingLiU", serif;
  --sans: -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans CJK TC", sans-serif;
}
html.night { --bg: #15140f; --paper: #1d1b16; --ink: #c9c0ad; --muted: #7d7565; --line: #34302a; --accent: #c8553f; --mark: #5a4a1e; --shadow: none; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.7 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.inline { display: inline; margin: 0; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.danger { color: #b3261e !important; }

/* header */
.site-header { background: var(--paper); border-bottom: 1px solid var(--line); position: relative; z-index: 5; }
.header-inner { display: flex; align-items: center; gap: 16px; min-height: 58px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-family: var(--serif); font-size: 21px; letter-spacing: .12em; }
.brand:hover { text-decoration: none; }
.seal { display: inline-grid; place-items: center; width: 32px; height: 32px; background: var(--accent); color: #f6f1e7; border-radius: 6px; font-size: 19px; letter-spacing: 0; }
.search-form { flex: 1; min-width: 160px; max-width: 360px; }
.search-form input, .hero-search input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--ink); font: inherit; }
.nav { display: flex; gap: 14px; align-items: center; margin-left: auto; flex-wrap: wrap; font-size: 15px; }
.nav a { color: var(--ink); }
.nav a.active { color: var(--accent); }
#user-nav { display: contents; }
.lang-toggle { border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; }

.main { padding-top: 24px; padding-bottom: 48px; min-height: 60vh; }
.site-footer { border-top: 1px solid var(--line); background: var(--paper); font-size: 14px; padding: 20px 0; color: var(--muted); }
.site-footer p { margin: 4px 0; }

/* generic */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; margin: 0 0 22px; box-shadow: var(--shadow); }
.panel h2, .page-title { font-family: var(--serif); font-weight: 600; letter-spacing: .06em; margin: 0 0 14px; }
.panel h2 { font-size: 19px; }
.page-title { font-size: 24px; margin-bottom: 18px; }
.btn { display: inline-block; padding: 8px 18px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 8px; font: inherit; cursor: pointer; line-height: 1.4; }
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 4px 12px; font-size: 14px; }
.btn.disabled { opacity: .45; cursor: default; }
.alert { background: #fbe9e7; color: #8c1d18; border: 1px solid #f1c0b9; padding: 10px 14px; border-radius: 8px; }
.notice { background: #eef5e9; color: #2f5b1f; border: 1px solid #cfe3c2; padding: 10px 14px; border-radius: 8px; }
html.night .alert { background: #3a1f1c; color: #f0b8b0; border-color: #5a2a24; }
html.night .notice { background: #1f2c1a; color: #b9d7a8; border-color: #34502a; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { padding: 3px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); font-size: 14px; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip small { opacity: .7; }
.pager { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 18px; }
mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 2px; }
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* hero */
.hero { text-align: center; padding: 28px 0 30px; }
.hero h1 { font-family: var(--serif); font-size: 40px; letter-spacing: .3em; margin: 0 0 4px; font-weight: 600; }
.tagline { color: var(--muted); letter-spacing: .2em; margin: 0 0 18px; }
.hero-search { display: flex; gap: 8px; max-width: 520px; margin: 0 auto 22px; }
.hero-search input { padding: 11px 18px; font-size: 16px; background: var(--paper); }
.hero-search button { padding: 0 22px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font: inherit; cursor: pointer; }

/* covers */
.cover { flex: none; border-radius: 4px 8px 8px 4px; box-shadow: 2px 3px 10px rgba(0, 0, 0, .18); object-fit: cover; }
.cover-sm { width: 64px; height: 88px; } .cover-md { width: 120px; height: 166px; }
.cover-lg { width: 112px; height: 156px; } .cover-xl { width: 168px; height: 232px; }
.cover-gen { position: relative; background: linear-gradient(135deg, var(--c1), color-mix(in srgb, var(--c1) 70%, #000)); overflow: hidden; }
.cover-gen::before { content: ""; position: absolute; inset: 6px 6px 6px 10px; border: 1px solid color-mix(in srgb, var(--c2) 55%, transparent); border-radius: 2px; }
.cover-gen::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: rgba(0, 0, 0, .25); }
.cover-title { position: absolute; top: 12%; right: 16%; writing-mode: vertical-rl; background: var(--c2); color: var(--c1); padding: 8px 4px; font-family: var(--serif); font-weight: 700; letter-spacing: .15em; font-size: 15px; border: 1px solid rgba(0, 0, 0, .2); max-height: 72%; overflow: hidden; }
.cover-xl .cover-title { font-size: 22px; padding: 12px 6px; }
.cover-sm .cover-title { font-size: 10px; padding: 4px 2px; }
.cover-author { position: absolute; bottom: 8%; left: 18%; writing-mode: vertical-rl; color: var(--c2); font-size: 11px; opacity: .85; letter-spacing: .2em; }
.cover-sm .cover-author { display: none; }

/* grids */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 22px 16px; }
.book-card { display: flex; flex-direction: column; align-items: center; text-align: center; color: var(--ink); }
.book-card:hover { text-decoration: none; }
.book-card:hover .cover { transform: translateY(-2px); }
.bc-title { margin-top: 10px; font-family: var(--serif); font-weight: 600; }
.bc-meta { font-size: 13px; color: var(--muted); }
.featured-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.featured-item { display: flex; gap: 16px; color: var(--ink); padding: 10px; border-radius: 10px; }
.featured-item:hover { background: var(--bg); text-decoration: none; }
.featured-item h3 { margin: 4px 0; font-family: var(--serif); font-size: 19px; }
.featured-item .meta { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.featured-item .intro { margin: 0; font-size: 14px; }
.latest-list { list-style: none; margin: 0; padding: 0; }
.latest-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.latest-list li:last-child { border-bottom: 0; }
.continue-list { display: flex; gap: 12px; flex-wrap: wrap; }
.continue-item { display: flex; flex-direction: column; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); min-width: 200px; }
.continue-item span { font-size: 13px; color: var(--muted); }

/* book page */
.book-head { display: flex; gap: 28px; margin-bottom: 24px; align-items: flex-start; }
.book-info h1 { font-family: var(--serif); font-size: 32px; letter-spacing: .12em; margin: 4px 0 12px; }
.book-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0 0 18px; }
.book-meta dt { color: var(--muted); } .book-meta dd { margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.intro-text p { text-indent: 2em; margin: .4em 0; font-family: var(--serif); }
.toc { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2px 24px; }
.toc li a { display: block; padding: 8px 4px; border-bottom: 1px dashed var(--line); color: var(--ink); font-family: var(--serif); }
.toc li a:hover { color: var(--accent); text-decoration: none; }

/* reader */
body.reader .main { max-width: calc(var(--readw) + 32px); }
#progress-bar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 20; }
#progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.chapter-title { font-family: var(--serif); font-size: 26px; text-align: center; letter-spacing: .08em; line-height: 1.6; margin: 18px 0 30px; font-weight: 600; }
.chapter-body { font-family: var(--serif); font-size: var(--fs); line-height: var(--lh); text-align: justify; word-break: break-all; }
.chapter-body p { margin: 0 0 .9em; text-indent: 2em; }
.chapter-nav { display: flex; justify-content: space-between; gap: 10px; margin: 36px 0 30px; }
.chapter-nav .btn { flex: 1; text-align: center; }
.reader-toolbar { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 15; }
.reader-toolbar a, .reader-toolbar button, .reader-toolbar span { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font: 15px var(--sans); cursor: pointer; box-shadow: var(--shadow); }
.reader-toolbar a:hover, .reader-toolbar button:hover { border-color: var(--accent); text-decoration: none; }
.reader-toolbar .disabled { opacity: .35; cursor: default; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: rgba(30, 25, 20, .9); color: #fff; padding: 8px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; font-size: 14px; }
.toast.show { opacity: 1; }
.comments h2 small { color: var(--muted); font-size: 14px; }
.comment-form textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; resize: vertical; }
.comment-form .row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.comment-list { list-style: none; padding: 0; margin: 14px 0 0; }
.comment-list li { padding: 10px 0; border-top: 1px dashed var(--line); }
.c-body { margin-top: 4px; white-space: normal; word-break: break-word; }

/* search */
.search-hits { list-style: none; padding: 0; margin: 0; }
.search-hits li { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.snippet { margin: 4px 0 0; color: var(--ink); font-family: var(--serif); font-size: 15px; }
.page-title .q { color: var(--accent); }

/* forms */
form label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
form label input:not([type=checkbox]), form label textarea, form label select { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: 15px var(--sans); }
form label.check { display: inline-flex; gap: 6px; align-items: center; margin-right: 16px; color: var(--ink); }
.auth { max-width: 420px; margin: 20px auto; }
.auth h1 { font-family: var(--serif); letter-spacing: .2em; text-align: center; }
.auth .btn { width: 100%; padding: 10px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 22px; }
.bookmark-list { list-style: none; padding: 0; margin: 0; }
.bookmark-list li { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.bookmark-list .note { margin: 4px 0; font-size: 14px; }
.err-code { font-size: 56px; font-family: var(--serif); color: var(--accent); margin: 0; }

/* shelf */
.shelf-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.shelf-item { display: flex; gap: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.si-body { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.si-title { font-family: var(--serif); font-size: 18px; color: var(--ink); font-weight: 600; }
.si-body .actions { margin-top: 6px; }

/* admin */
body.admin .main { max-width: 1280px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 24px; font-family: var(--serif); }
.stat span { color: var(--muted); font-size: 13px; }
.table { width: 100%; border-collapse: collapse; background: var(--paper); font-size: 14px; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.table th { background: var(--bg); font-weight: 600; white-space: nowrap; }
.table tr.dim td { opacity: .55; }
.wrapcell { max-width: 420px; word-break: break-word; white-space: pre-wrap; }
.ops { white-space: nowrap; }
.ops > * { margin-right: 8px; }
.toolbar-row { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar-row form { display: flex; gap: 6px; }
.toolbar-row input { padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; }
.admin-form { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.admin-form textarea { font-family: var(--serif) !important; line-height: 1.7; }

@media (max-width: 720px) {
  .header-inner { gap: 8px; }
  .search-form { order: 3; max-width: none; flex-basis: 100%; }
  .nav { gap: 10px; font-size: 14px; }
  .hero h1 { font-size: 30px; }
  .book-head { flex-direction: column; align-items: center; text-align: center; }
  .book-meta { justify-content: center; text-align: left; }
  .actions { justify-content: center; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .cover-md { width: 96px; height: 134px; }
  .featured-grid, .toc, .grid2 { grid-template-columns: 1fr; }
  .reader-toolbar { flex-direction: row; left: 0; right: 0; bottom: 0; justify-content: space-around; background: var(--paper); border-top: 1px solid var(--line); padding: 6px; }
  .reader-toolbar a, .reader-toolbar button, .reader-toolbar span { box-shadow: none; width: 38px; height: 38px; }
  body.reader .main { padding-bottom: 80px; }
  .chapter-title { font-size: 22px; }
}
@media print { .site-header, .site-footer, .reader-toolbar, .comments, .chapter-nav, #progress-bar { display: none; } }
