/* 现代诗 · 阅读器 */

:root {
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", Georgia, serif;
  --read-size: 18px;
  --sidebar-w: 302px;
  --topbar-h: 60px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f2eee5;
  --bg-glow: #fbf6ea;
  --paper: #fffdf8;
  --paper-2: #f8f3e8;
  --ink: #26221b;
  --ink-2: #4d473c;
  --muted: #877e6e;
  --faint: #a79d8b;
  --line: #ded5c5;
  --line-soft: #ebe4d6;
  --accent: #9c3f2e;
  --accent-2: #b45b42;
  --accent-soft: #f1e0d8;
  --shadow: 0 24px 60px -34px rgba(63, 48, 32, .5);
  --overlay: rgba(38, 32, 24, .42);
  --kbd-bg: #ece5d7;
  --topbar: rgba(242, 238, 229, .86);
}

html[data-theme="sepia"] {
  color-scheme: light;
  --bg: #e9dcc4;
  --bg-glow: #f7ecd7;
  --paper: #f8eeda;
  --paper-2: #f2e5cc;
  --ink: #3a2f22;
  --ink-2: #594a38;
  --muted: #88785f;
  --faint: #a19076;
  --line: #d5c3a4;
  --line-soft: #e2d3b8;
  --accent: #8d4a2b;
  --accent-2: #a8613d;
  --accent-soft: #ead6bd;
  --shadow: 0 24px 60px -34px rgba(74, 55, 30, .5);
  --overlay: rgba(54, 43, 27, .42);
  --kbd-bg: #e0d0b4;
  --topbar: rgba(233, 220, 196, .88);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141416;
  --bg-glow: #221d26;
  --paper: #1c1c20;
  --paper-2: #242428;
  --ink: #e9e3d7;
  --ink-2: #cbc3b4;
  --muted: #918a7d;
  --faint: #6f695f;
  --line: #303034;
  --line-soft: #27272b;
  --accent: #d18b6b;
  --accent-2: #e0a083;
  --accent-soft: #33241f;
  --shadow: 0 30px 80px -30px rgba(0, 0, 0, .85);
  --overlay: rgba(0, 0, 0, .58);
  --kbd-bg: #2a2a2f;
  --topbar: rgba(20, 20, 22, .86);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(1000px 520px at 12% -12%, var(--bg-glow) 0%, transparent 62%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent); color: var(--paper); }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.count { color: var(--faint); font-weight: 400; font-size: 11px; }
kbd {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--kbd-bg);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 9.5px;
  line-height: 1.4;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: relative;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 clamp(12px, 2.4vw, 24px);
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: none;
  white-space: nowrap;
  transition: color .16s;
}
.back:hover { color: var(--accent); }
.back-arrow { font-size: 16px; line-height: 1; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
}
.seal {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 2px;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  line-height: 1;
  transform: rotate(-1.5deg);
}
.brand-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brand-text b {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .08em;
}
.brand-text small {
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: .03em;
}

.actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: .16s;
}
.tool:hover { color: var(--ink); border-color: var(--line); background: var(--paper-2); }
.tool:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.badge {
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  display: inline-grid;
  place-items: center;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.heart { font-size: 14px; line-height: 1; }
.theme-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: inset 0 0 0 2px var(--paper);
  border: 1px solid var(--accent);
}
.only-mobile { display: none; }

/* ---------- 布局 ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: calc(100dvh - var(--topbar-h));
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  overflow: hidden;
}
.side-top {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 16px 10px;
}
.side-title {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .12em;
}
.link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 11.5px;
}
.link:hover { color: var(--accent); }

.pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.searchbox {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 4px 16px 10px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  transition: border-color .16s, box-shadow .16s;
}
.searchbox:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-glyph { color: var(--faint); font-size: 15px; line-height: 1; }
.searchbox input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 12.5px;
}
.searchbox input::placeholder { color: var(--faint); }
.searchbox.big { margin: 14px 22px; padding: 10px 13px; }
.searchbox.big input { font-size: 15px; }

.letters {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  padding: 0 14px 8px;
}
.letter {
  min-width: 21px;
  height: 21px;
  padding: 0 3px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 21px;
  text-align: center;
  transition: .12s;
}
.letter:hover { color: var(--ink); background: var(--paper-2); }
.letter.active { background: var(--accent); color: var(--paper); }

.scroll-area {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 10px 26px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.scroll-area::-webkit-scrollbar { width: 8px; }
.scroll-area::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.poet-list { display: flex; flex-direction: column; }
.letter-divider {
  padding: 13px 9px 5px;
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .18em;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 3px;
}
.poet {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--ink-2);
  text-align: left;
  font-size: 13px;
  transition: .12s;
}
.poet:hover { background: var(--paper-2); color: var(--ink); }
.poet.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.poet .n { color: var(--faint); font-size: 10px; font-variant-numeric: tabular-nums; }
.poet.active .n { color: var(--accent); opacity: .75; }

.load-more {
  width: 100%;
  margin: 8px 0 4px;
  padding: 9px;
  border: 1px dashed var(--line);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
}
.load-more:hover { border-color: var(--accent); color: var(--accent); }
.empty {
  padding: 28px 12px;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.8;
  text-align: center;
}

.works-head {
  flex: none;
  padding: 0 18px 12px;
}
.works-name {
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: .06em;
}
.works-meta { margin-top: 3px; color: var(--faint); font-size: 11px; }
.work-list { display: flex; flex-direction: column; }
.work {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0 3px 3px 0;
  background: transparent;
  text-align: left;
  transition: .12s;
}
.work:hover { background: var(--paper-2); }
.work.active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}
.work-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
  font-size: 12.5px;
}
.work.active .work-title { color: var(--accent); font-weight: 600; }
.work-date {
  flex: none;
  color: var(--faint);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 阅读区 ---------- */
.reader {
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.reader::-webkit-scrollbar { width: 10px; }
.reader::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
.reader-inner {
  max-width: 850px;
  margin: 0 auto;
  padding: 26px clamp(18px, 4vw, 52px) 60px;
}
.reader-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.crumb {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: .12em;
}
.reader-tools { display: flex; gap: 4px; flex: none; }
.mini {
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  transition: .14s;
}
.mini:hover { border-color: var(--line); color: var(--ink); background: var(--paper-2); }

.poem-card {
  position: relative;
  padding: clamp(30px, 5.2vw, 62px) clamp(24px, 5vw, 58px) clamp(26px, 4vw, 48px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: var(--shadow);
  transition: opacity .18s ease;
}
.poem-card::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  width: 38%;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
.poem-card.busy { opacity: .55; }

.poem-head { padding-bottom: 18px; border-bottom: 1px dashed var(--line); }
.poem-head h1 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: clamp(29px, 4.2vw, 44px);
  font-weight: 600;
  letter-spacing: .04em;
  line-height: 1.32;
  word-break: break-word;
}
.poem-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 16px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .02em;
}
.author-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 12.5px;
  letter-spacing: .06em;
}
.author-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.poem-body {
  margin-top: clamp(26px, 4vw, 40px);
  font-family: var(--serif);
  font-size: var(--read-size);
  font-weight: 400;
  line-height: 2.06;
  letter-spacing: .025em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  color: var(--ink);
}
.poem-body:empty::after {
  content: "正在取诗…";
  color: var(--faint);
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: .06em;
}

.poem-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: clamp(30px, 4vw, 44px);
  padding-top: 20px;
  border-top: 1px dashed var(--line);
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  transition: .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--paper-2); }
.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper);
}
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--paper); }
.btn.primary kbd {
  border-color: color-mix(in srgb, var(--paper) 42%, transparent);
  background: transparent;
  color: color-mix(in srgb, var(--paper) 80%, transparent);
}
.btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.btn.on .heart { color: var(--accent); }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 2px 0;
}
.pager-btn {
  padding: 6px 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11.5px;
  transition: .14s;
}
.pager-btn:hover { color: var(--accent); }
.position {
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: .08em;
  font-variant-numeric: tabular-nums;
}
.corpus-note a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.corpus-note a:hover { color: var(--accent); border-color: var(--accent); }
.corpus-note {
  margin: 34px 0 0;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1.7;
  text-align: center;
  letter-spacing: .02em;
}

/* ---------- 弹窗 ---------- */
dialog.sheet {
  width: min(700px, calc(100vw - 28px));
  max-height: min(84dvh, 860px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 34px 100px rgba(0, 0, 0, .38);
  overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(3px);
}
.sheet-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 0;
}
.sheet-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .08em;
}
.sheet-sub {
  margin-top: 3px;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: .04em;
}
.close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.close:hover { border-color: var(--line); color: var(--ink); background: var(--paper-2); }

.search-tabs {
  flex: none;
  display: flex;
  gap: 2px;
  margin: 14px 22px 0;
  border-bottom: 1px solid var(--line);
}
.tab {
  padding: 7px 12px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  transition: .14s;
}
.tab:hover { color: var(--ink); }
.tab.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

.search-status {
  flex: none;
  min-height: 18px;
  padding: 0 22px 8px;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: .03em;
}
.fulltext-btn {
  flex: none;
  align-self: flex-start;
  margin: 0 22px 10px;
}
.fulltext-btn .hint { font-size: 9.5px; opacity: .7; }

.search-results {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 12px 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.result {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  text-align: left;
  transition: background .12s;
}
.result:hover { background: var(--paper-2); }
.result-title { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.result-meta {
  display: block;
  margin-top: 2px;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: .03em;
}
.result-snippet {
  display: block;
  margin-top: 4px;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1.72;
}
.result.poet-result {
  background: var(--accent-soft);
  border-bottom-color: transparent;
  margin-bottom: 4px;
  border-radius: 3px;
}
.result.poet-result .result-title { color: var(--accent); }
.result.poet-result .result-meta { color: var(--accent); opacity: .7; }

.fav-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 12px 20px;
}
.fav-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-bottom: 1px solid var(--line-soft);
  padding: 11px 4px 11px 12px;
}
.fav-open {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
}
.fav-open .result-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-remove {
  flex: none;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--faint);
  font-size: 15px;
  line-height: 1;
}
.fav-remove:hover { color: var(--accent); background: var(--accent-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 100;
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  letter-spacing: .03em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: .95; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */
.backdrop {
  display: none;
  border: 0;
  padding: 0;
}

@media (max-width: 900px) {
  :root { --topbar-h: 56px; }
  .only-mobile { display: inline-flex; }
  .brand-text small { display: none; }
  .back-text { display: none; }
  .topbar { gap: 10px; padding: 0 10px; }
  .brand { gap: 8px; }
  .tool { padding: 6px 7px; }
  .tool kbd { display: none; }

  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    z-index: 40;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: min(87vw, 342px);
    background: var(--bg);
    transform: translateX(-103%);
    transition: transform .22s cubic-bezier(.2, .7, .3, 1);
    box-shadow: 20px 0 60px rgba(0, 0, 0, .18);
  }
  .shell.open .sidebar { transform: none; }
  .backdrop {
    display: block;
    position: fixed;
    z-index: 35;
    inset: var(--topbar-h) 0 0;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s;
  }
  .shell.open .backdrop { opacity: 1; pointer-events: auto; }

  .reader-inner { padding: 18px 14px 52px; }
  .reader-bar { margin-bottom: 11px; }
  .poem-card {
    padding: 28px 21px 24px;
    border-radius: 1px;
  }
  .poem-head h1 { font-size: clamp(27px, 8vw, 36px); }
  .poem-body { line-height: 1.98; }
  .poem-foot .btn { flex: 1 1 auto; justify-content: center; }
  .corpus-note { margin-top: 26px; }

  dialog.sheet {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .sheet-head { padding-top: 18px; }
  .search-results { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
  .brand-text { display: none; }
  .theme-btn #theme-label { display: none; }
  .actions { gap: 1px; }
  .tool { padding: 6px 6px; }
  .poem-card { padding: 25px 18px 22px; }
  .poem-meta { gap: 4px 12px; }
  .reader-tools .mini { padding: 3px 6px; }
}

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

.poem-card.swap { animation: poem-in .24s cubic-bezier(.2, .7, .3, 1); }
@keyframes poem-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.sheet-foot {
  flex: none;
  display: block;
  padding: 12px 22px 18px;
  border-top: 1px solid var(--line-soft);
  color: var(--accent);
  font-size: 11.5px;
  text-decoration: none;
  letter-spacing: .03em;
}
.sheet-foot:hover { text-decoration: underline; text-underline-offset: 3px; }
