:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --panel: #ffffff;
  --panel-soft: #fafaf8;
  --text: #1e1f1c;
  --muted: #73746d;
  --line: #e4e4de;
  --line-strong: #d3d3cb;
  --accent: #22231f;
  --danger: #9d3b35;
  --radius: 20px;
  --shadow: 0 16px 40px rgba(32, 32, 27, 0.05);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 64px;
  padding: 0 max(22px, calc((100vw - 1160px) / 2));
  border-bottom: 1px solid rgba(228,228,222,.92);
  background: rgba(244,244,241,.9);
  backdrop-filter: blur(16px);
}

.brand { flex: 0 0 auto; font-size: 20px; font-weight: 800; letter-spacing: -.04em; }
.top-nav {
  display: flex;
  gap: 20px;
  max-width: calc(100vw - 150px);
  overflow-x: auto;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  scrollbar-width: none;
}
.top-nav::-webkit-scrollbar { display: none; }
.top-nav a { padding: 22px 0 18px; border-bottom: 2px solid transparent; }
.top-nav a:hover, .top-nav a.active { color: var(--text); border-color: var(--text); }

.page-shell { max-width: 1160px; margin: 0 auto; padding: 50px 22px 86px; }
.stack-lg > * + * { margin-top: 38px; }
.stack-md > * + * { margin-top: 20px; }
.stack-sm > * + * { margin-top: 10px; }
.narrow { max-width: 800px; margin: 0 auto; }

.hero-row, .section-heading, .reading-card, .meta-row, .toolbar, .category-row,
.book-hero, .note-meta, .save-state, .form-actions, .search-result, .editor-footer,
.inline-form, .category-card, .trash-card, .toggle-row, .danger-zone, .subheading {
  display: flex;
  align-items: center;
}

.hero-row, .section-heading, .subheading { justify-content: space-between; gap: 24px; }
.hero-row h1, h1 { margin: 5px 0 10px; font-size: clamp(36px, 5vw, 54px); line-height: 1.02; letter-spacing: -.055em; }
h2 { margin: 0; font-size: 24px; letter-spacing: -.03em; }
h3 { margin: 0; font-size: 17px; letter-spacing: -.015em; }
p { margin: 0; line-height: 1.65; }
.eyebrow { margin: 0; color: #8a8b83; font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.notice {
  padding: 13px 16px;
  border: 1px solid #cdd8cd;
  border-radius: 13px;
  background: #f4f8f3;
  color: #526451;
  font-size: 13px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.button:hover { transform: translateY(-1px); border-color: #b9bab1; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.ghost { background: transparent; }
.button.danger { border-color: #d9b6b2; background: #fff8f7; color: var(--danger); }
.button.danger:hover { border-color: #bd7770; background: #fff3f1; }
.button.full { width: 100%; }

.panel, .editor-card {
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.reading-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.reading-card {
  gap: 18px;
  padding: 18px;
  border: 1px solid #ecece6;
  border-radius: 18px;
  background: var(--panel-soft);
  transition: border-color .15s ease, transform .15s ease;
}
.reading-card:hover { border-color: #c8c9c0; transform: translateY(-2px); }
.reading-content { flex: 1; min-width: 0; }
.reading-content > * + * { margin-top: 12px; }

.cover {
  display: grid;
  place-items: center;
  width: 66px;
  aspect-ratio: 2 / 3;
  flex: 0 0 auto;
  padding: 8px;
  border-radius: 9px;
  color: #fff;
  font-weight: 800;
  text-align: center;
  letter-spacing: .03em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.1), 0 8px 20px rgba(20,20,16,.12);
}
.cover.large { width: 100%; min-height: 220px; }
.cover.xlarge { width: 154px; }
.cover-three { background: linear-gradient(145deg, #172026, #46555d); }
.cover-history { background: linear-gradient(145deg, #7a5a38, #b58b59); }
.cover-life { background: linear-gradient(145deg, #6f2329, #b24a50); }
.cover-sapiens { background: linear-gradient(145deg, #8c6e50, #c2a17c); }
.cover-custom { background: linear-gradient(145deg, #4a514a, #828a7d); }

.progress-line { height: 5px; overflow: hidden; border-radius: 999px; background: #dedfd8; }
.progress-line span { display: block; height: 100%; border-radius: inherit; background: #5c665b; }
.meta-row { justify-content: space-between; gap: 14px; color: var(--muted); font-size: 12px; }

.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.stats-grid article {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}
.stats-grid strong { font-size: 28px; letter-spacing: -.035em; }
.stats-grid span { color: var(--muted); font-size: 13px; }

.toolbar { gap: 14px; align-items: flex-start; margin: 22px 0 14px; }
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  flex: 1;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
}
.search-box:focus-within { border-color: #999a91; box-shadow: 0 0 0 3px rgba(40,40,35,.05); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }

.chips, .category-row, .view-switch { display: flex; gap: 8px; flex-wrap: wrap; }
.category-row { margin-bottom: 22px; }
.chip, .icon-button {
  border: 1px solid #dedfd8;
  border-radius: 999px;
  background: #fff;
  color: #64655e;
  cursor: pointer;
  font-size: 13px;
}
.chip { padding: 8px 12px; }
.icon-button { padding: 7px 11px; }
.chip:hover, .icon-button:hover { border-color: #bebfb6; }
.chip.active, .icon-button.active { border-color: var(--accent); background: var(--accent); color: #fff; }

.library-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px; }
.library-grid.list-view { grid-template-columns: 1fr; gap: 10px; }
.book-card { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.book-card .book-info p { margin-top: 4px; color: var(--muted); font-size: 14px; }
.book-card .book-info span { display: block; margin-top: 6px; color: #8b8c84; font-size: 12px; }
.book-card:hover .cover { transform: translateY(-2px); }
.book-card .cover { transition: transform .16s ease; }
.list-view .book-card { flex-direction: row; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 14px; }
.list-view .book-card .cover { width: 52px; min-height: auto; }
.empty-state { padding: 34px; color: var(--muted); text-align: center; }

.input, .textarea, .select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.textarea { min-height: 150px; resize: vertical; line-height: 1.7; }
.input:focus, .textarea:focus, .select:focus { border-color: #999a91; box-shadow: 0 0 0 3px rgba(40,40,35,.05); }
.field-label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 750; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full-span { grid-column: 1 / -1; }
.form-actions { justify-content: flex-end; gap: 10px; }

.search-results { display: grid; gap: 12px; }
.search-result { gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.search-result .result-copy { flex: 1; }
.search-result .result-copy p { color: var(--muted); font-size: 13px; }

.back-link { display: inline-flex; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.book-hero { align-items: flex-start; gap: 28px; }
.book-hero-copy { flex: 1; }
.book-actions { display: flex; flex-direction: column; gap: 8px; }
.meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin-top: 18px; }
.meta-grid div { padding: 12px 0; border-top: 1px solid var(--line); }
.meta-grid span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.meta-grid strong { font-size: 14px; }
.note-list { display: grid; gap: 0; }
.note-card { padding: 20px 0; border-top: 1px solid var(--line); }
.note-card:first-child { border-top: 0; }
.note-meta { gap: 10px; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.note-card p { margin-top: 8px; }
.note-actions { margin-top: 12px; color: var(--muted); font-size: 12px; }
.local-notes-block { margin-top: 8px; padding-top: 18px; border-top: 1px dashed var(--line-strong); }
.local-empty { padding: 16px 0 4px; }
.saved-note p { white-space: normal; }

.editor-toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line-strong); border-bottom: 0; border-radius: 12px 12px 0 0; background: var(--panel-soft); }
.editor-toolbar button { padding: 5px 8px; border: 0; background: transparent; cursor: pointer; }
.editor-area { min-height: 320px; border-radius: 0 0 12px 12px; }
.save-state { justify-content: flex-end; gap: 7px; color: var(--muted); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #62976b; }
.editor-footer { justify-content: space-between; gap: 16px; }

.inline-form { gap: 10px; align-items: stretch; }
.inline-form .input { flex: 1; }
.category-list { display: grid; gap: 10px; }
.category-card {
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
}
.category-actions { display: flex; gap: 8px; }

.trash-list { display: grid; gap: 10px; }
.trash-card {
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.trash-card:first-child { border-top: 0; }
.trash-copy { flex: 1; min-width: 0; }
.trash-copy p { margin-top: 5px; }
.trash-actions { display: flex; gap: 8px; }
.empty-panel { padding: 34px 14px; color: var(--muted); text-align: center; }
.empty-panel strong { display: block; margin-bottom: 5px; color: var(--text); }

.settings-form { max-width: 560px; }
.toggle-row {
  justify-content: space-between;
  gap: 20px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.toggle-row span { display: grid; gap: 4px; }
.toggle-row small { color: var(--muted); }
.toggle-row input { width: 18px; height: 18px; }
.data-overview { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.data-overview article { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-soft); }
.data-overview strong { display: block; margin-bottom: 4px; font-size: 26px; }
.data-overview span { color: var(--muted); font-size: 13px; }
.danger-zone { justify-content: space-between; gap: 20px; padding-top: 18px; border-top: 1px solid var(--line); }

.site-footer { padding: 28px 20px 44px; color: #96978f; font-size: 12px; text-align: center; }

@media (max-width: 860px) {
  .page-shell { padding: 34px 16px 68px; }
  .site-header { padding: 0 16px; }
  .top-nav { gap: 16px; }
  .reading-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { flex-direction: column; }
  .toolbar .chips { width: 100%; }
  .book-hero { flex-direction: column; }
  .book-actions { width: 100%; flex-direction: row; }
  .book-actions .button { flex: 1; }
  .cover.xlarge { width: 112px; }
}

@media (max-width: 560px) {
  .site-header { gap: 16px; }
  .brand { font-size: 18px; }
  .top-nav { max-width: calc(100vw - 120px); gap: 14px; }
  .top-nav a { font-size: 13px; }
  .hero-row { align-items: flex-start; flex-direction: column; }
  .hero-row .button { width: 100%; }
  .panel, .editor-card { padding: 19px; }
  .stats-grid article:last-child { grid-column: 1 / -1; }
  .library-grid { gap: 14px; }
  .cover.large { min-height: 170px; }
  .category-row { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .category-row > * { flex: 0 0 auto; }
  .form-grid, .meta-grid, .data-overview { grid-template-columns: 1fr; }
  .form-grid .full-span { grid-column: auto; }
  .search-result { align-items: flex-start; flex-wrap: wrap; }
  .search-result .button { width: 100%; }
  .editor-footer, .inline-form, .category-card, .trash-card, .danger-zone { align-items: stretch; flex-direction: column; }
  .editor-footer .button, .inline-form .button { width: 100%; }
  .category-actions, .trash-actions { width: 100%; }
  .category-actions .button, .trash-actions .button { flex: 1; }
}
