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

:root {
  --bg: #FBFAF8;
  --fg: #23211E;
  --sub: #8A857D;
  --line: #E8E4DC;
  --card: #FFFFFF;
  --accent: #7A5C3E;
  --fs: 20px;
  --lh: 1.9;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  transition: .2s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: .88; color: #fff; }
.btn-wide { width: 100%; text-align: center; padding: 13px; font-size: 15px; }

/* ---------- 书架 ---------- */
.shelf-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  max-width: 1080px;
  margin: 0 auto;
  padding: 56px 28px 26px;
}
.shelf-head h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 500;
  letter-spacing: .06em;
  font-family: var(--serif);
}
.shelf-head .sub { margin: 7px 0 0; font-size: 13px; color: var(--sub); }

.shelf-main { max-width: 1080px; margin: 0 auto; padding: 0 28px 90px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 30px 24px;
}

.card-wrap { position: relative; }

.del-form {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
  opacity: 0;
  transition: opacity .2s;
}
.card-wrap:hover .del-form { opacity: 1; }
.del-btn {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,.42);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.del-btn:hover { background: rgba(170,45,45,.92); }

.card { display: block; }
.cover {
  position: relative;
  aspect-ratio: 3 / 4.25;
  border-radius: 4px 8px 8px 4px;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: transform .28s cubic-bezier(.2,.7,.3,1), box-shadow .28s;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
}
.cover::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 7px;
  background: rgba(0,0,0,.16);
}
.card:hover .cover {
  transform: translateY(-5px);
  box-shadow: 0 12px 26px rgba(0,0,0,.14);
}
.cover-title {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  font-weight: 500;
  letter-spacing: .04em;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cover-author { font-size: 12px; opacity: .82; }

.fmt-badge {
  position: absolute;
  right: 10px;
  bottom: 9px;
  font-size: 9px;
  letter-spacing: .12em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,.24);
  color: inherit;
  font-family: var(--sans);
}

.card-body { padding: 12px 2px 0; }
.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta { margin: 4px 0 0; font-size: 12px; color: var(--sub); }
.card-date { margin: 2px 0 0; font-size: 11px; color: var(--sub); opacity: .7; }

.resume {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  vertical-align: 1px;
}

.empty { text-align: center; padding: 90px 20px; }
.empty-title { font-family: var(--serif); font-size: 21px; margin: 0 0 8px; }
.empty-desc { color: var(--sub); font-size: 14px; margin: 0 0 26px; }

/* ---------- 阅读页 ---------- */
.reader { min-height: 100vh; display: flex; flex-direction: column; }

.r-head {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.r-back { font-size: 20px; line-height: 1; padding: 2px 6px; opacity: .6; }
.r-back:hover { opacity: 1; }
.r-book {
  flex: 1;
  font-size: 13px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.r-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--sub);
  transition: .2s;
  flex: none;
}
.r-icon:hover { border-color: var(--accent); color: var(--accent); }

.r-progress { position: sticky; top: 51px; z-index: 29; height: 2px; background: transparent; }
.r-progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  opacity: .55;
  transition: width .1s linear;
}

.r-main { flex: 1; overflow-x: hidden; }
.r-article {
  max-width: 720px;
  margin: 0 auto;
  padding: 46px 26px 110px;
}
.r-chapter-no {
  margin: 0 0 14px;
  font-size: 11px;
  letter-spacing: .16em;
  color: var(--sub);
  text-transform: uppercase;
}
.r-title {
  margin: 0 0 42px;
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 500;
  line-height: 1.55;
  letter-spacing: .02em;
}
.r-text {
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: var(--lh);
  letter-spacing: .012em;
  text-align: justify;
  word-break: break-word;
}
.r-text p { margin: 0 0 1.05em; text-indent: 2em; }
.r-text p:last-child { margin-bottom: 0; }

.r-text h1, .r-text h2, .r-text h3,
.r-text h4, .r-text h5, .r-text h6 {
  font-family: var(--serif);
  font-weight: 500;
  line-height: 1.5;
  margin: 1.9em 0 .9em;
  text-indent: 0;
  letter-spacing: .02em;
}
.r-text h1 { font-size: 1.28em; }
.r-text h2 { font-size: 1.18em; }
.r-text h3 { font-size: 1.08em; }
.r-text h4, .r-text h5, .r-text h6 { font-size: 1em; color: var(--sub); }

.r-text blockquote {
  margin: 1.4em 0;
  padding: .2em 0 .2em 1.1em;
  border-left: 2px solid var(--line);
  color: var(--sub);
  text-indent: 0;
}
.r-text blockquote p { text-indent: 0; }

.r-text ul, .r-text ol {
  margin: 1.1em 0;
  padding-left: 1.9em;
  text-indent: 0;
}
.r-text li { margin: .35em 0; text-indent: 0; }
.r-text li > p { text-indent: 0; margin: 0; }

.r-text hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2.4em auto;
  width: 42%;
}

.r-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .86em;
  padding: .12em .38em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--fg) 7%, transparent);
}
.r-text pre {
  margin: 1.4em 0;
  padding: 14px 16px;
  overflow-x: auto;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--fg) 4%, transparent);
}
.r-text pre code { background: none; padding: 0; font-size: .84em; }

.r-text img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5em auto;
  border-radius: 6px;
}

.r-text table {
  width: 100%;
  margin: 1.4em 0;
  border-collapse: collapse;
  font-size: .9em;
}
.r-text th, .r-text td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
}
.r-text th { background: color-mix(in srgb, var(--fg) 4%, transparent); font-weight: 500; }

.r-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 64px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.r-pager a { color: var(--sub); transition: .2s; }
.r-pager a:hover { color: var(--accent); }
.pager-toc { font-size: 12px; }
.dim { color: var(--sub); opacity: .45; }

/* ---------- 目录抽屉 ---------- */
.toc-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 310px;
  max-width: 84vw;
  z-index: 60;
  background: var(--bg);
  border-right: 1px solid var(--line);
  transform: translateX(-102%);
  transition: transform .3s cubic-bezier(.3,.8,.3,1);
  display: flex;
  flex-direction: column;
}
.toc-drawer.open { transform: translateX(0); }
.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
}
.toc-head button { font-size: 22px; line-height: 1; color: var(--sub); }
.toc-list { flex: 1; overflow-y: auto; padding: 10px 0 30px; }
.toc-list a {
  display: block;
  padding: 10px 20px;
  font-size: 13.5px;
  color: var(--sub);
  line-height: 1.5;
  border-left: 2px solid transparent;
}
.toc-list a:hover { background: color-mix(in srgb, var(--fg) 5%, transparent); color: var(--fg); }
.toc-list a.cur { border-left-color: var(--accent); color: var(--accent); font-weight: 500; }
.toc-loading { padding: 20px; font-size: 13px; color: var(--sub); }

.mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s;
}
.mask.on { opacity: 1; pointer-events: auto; }

/* ---------- 排版面板 ---------- */
.set-panel {
  position: fixed;
  top: 58px; right: 16px;
  z-index: 55;
  width: 268px;
  padding: 6px 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 14px 38px rgba(0,0,0,.11);
  opacity: 0;
  transform: translateY(-8px) scale(.98);
  pointer-events: none;
  transition: .22s;
}
.set-panel.open { opacity: 1; transform: none; pointer-events: auto; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: none; }
.set-label { font-size: 13px; color: var(--sub); }
.set-ctrl { display: flex; align-items: center; gap: 6px; }
.set-ctrl button {
  width: 34px; height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 12px;
  transition: .18s;
}
.set-ctrl button:hover { border-color: var(--accent); color: var(--accent); }
.set-ctrl span { min-width: 34px; text-align: center; font-size: 13px; }
.themes { display: flex; gap: 9px; }
.sw {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  transition: .18s;
}
.sw[data-theme="day"] { background: #FBFAF8; }
.sw[data-theme="sepia"] { background: #F4ECDC; }
.sw[data-theme="night"] { background: #16171A; }
.sw:hover { transform: scale(1.12); }
.sw.on { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- 上传页 ---------- */
.up-main { max-width: 580px; margin: 0 auto; padding: 54px 26px 100px; }
.up-back { font-size: 13px; color: var(--sub); }
.up-back:hover { color: var(--accent); }
.up-main h1 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  margin: 26px 0 10px;
}
.up-desc { font-size: 13.5px; color: var(--sub); line-height: 1.75; margin: 0 0 28px; }
.up-desc b { color: var(--fg); font-weight: 500; }
.up-desc code {
  font-family: ui-monospace, monospace;
  font-size: .92em;
  padding: .1em .34em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--fg) 7%, transparent);
}
.up-tip { display: inline-block; margin-top: 8px; font-size: 12px; opacity: .78; }

.up-form { display: flex; flex-direction: column; gap: 16px; }

.mode-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--fg) 5%, transparent);
}
.mode-tab { flex: 1; position: relative; }
.mode-tab input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.mode-tab span {
  display: block;
  padding: 9px 0;
  text-align: center;
  font-size: 13.5px;
  border-radius: 9px;
  color: var(--sub);
  cursor: pointer;
  transition: .2s;
}
.mode-tab input:checked + span {
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
}

.overwrite-pane {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--fg) 2.5%, transparent);
}
.overwrite-pane[hidden] { display: none; }
.book-select { width: 100%; }
.mode-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.75;
  color: var(--sub);
}
.mode-hint b { color: var(--fg); font-weight: 500; }
.mode-hint-warn { color: var(--accent); }

.msg-note {
  margin: 9px 0 0 !important;
  font-size: 12px;
  font-weight: 400 !important;
  opacity: .82;
}

.merge-opt {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 3px 2px;
  font-size: 13.5px;
  line-height: 1.55;
  cursor: pointer;
}
.merge-opt input {
  flex: none;
  width: 15px;
  height: 15px;
  margin-top: 3px;
  accent-color: var(--accent);
  cursor: pointer;
}
.merge-opt[hidden] { display: none; }
.merge-hint {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--sub);
}
.merge-title-wrap[hidden] { display: none; }
.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 11px;
  padding: 52px 22px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  cursor: pointer;
  transition: .22s;
  text-align: center;
}
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 4%, transparent); }
.drop input { display: none; }
.drop-icon { font-size: 26px; color: var(--sub); font-weight: 300; }
.drop-text { font-size: 13.5px; color: var(--sub); line-height: 1.6; word-break: break-all; }

.key-input {
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.key-input:focus { border-color: var(--accent); }

.msg {
  padding: 15px 18px;
  border-radius: 11px;
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 18px;
}
.msg p { margin: 0 0 6px; font-weight: 500; }
.msg ul { margin: 0; padding-left: 18px; }
.msg-ok { background: #EDF5EE; color: #2E5B39; }
.msg-upd { background: #E9F0FA; color: #2B4C7A; }
.msg-warn { background: #FBF3E4; color: #7A5B21; }
.msg-err { background: #FBEBEB; color: #8C3232; }

/* ---------- 编辑页 ---------- */
.edit-main { max-width: 880px; margin: 0 auto; padding: 32px 26px 90px; }
.edit-main-narrow { max-width: 520px; padding-top: 54px; }
.edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}
.edit-book { font-size: 12.5px; color: var(--sub); }
.edit-form { display: flex; flex-direction: column; gap: 9px; }
.edit-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--sub);
}
.edit-fmt {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--fg) 7%, transparent);
}
.edit-area {
  width: 100%;
  min-height: 56vh;
  padding: 17px 19px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.9;
  resize: vertical;
  outline: none;
  transition: border-color .2s;
}
.edit-area:focus { border-color: var(--accent); }
.edit-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}
.edit-count { font-size: 12px; color: var(--sub); }
.edit-actions { display: flex; gap: 10px; }
.edit-lock-form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- 主题 ---------- */
body[data-theme="sepia"] {
  --bg: #F4ECDC;
  --fg: #3A2F23;
  --sub: #8A7A63;
  --line: #E2D5BE;
  --card: #FBF5E9;
  --accent: #8A6438;
}
body[data-theme="night"] {
  --bg: #16171A;
  --fg: #C9C5BC;
  --sub: #6E6A63;
  --line: #2A2C31;
  --card: #1E2024;
  --accent: #B08D5F;
}

@media (max-width: 640px) {
  .shelf-head { padding: 38px 20px 20px; }
  .shelf-main { padding: 0 20px 70px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 22px 16px; }
  .r-article { padding: 32px 22px 90px; }
  .r-title { font-size: 21px; margin-bottom: 30px; }
  :root { --fs: 18px; }
  .set-panel { right: 10px; left: 10px; width: auto; }
}
