:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --accent: #2f7d3a;
  --accent-soft: #e6f2e8;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .inner {
  max-width: 1100px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 8px; height: 56px;
}
.brand { font-weight: 700; font-size: 18px; margin-right: 16px; }
.brand span { color: var(--accent); }
nav.tabs { display: flex; gap: 4px; flex: 1; }
nav.tabs a {
  padding: 8px 14px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
nav.tabs a.active, nav.tabs a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
nav.tabs + .navlink, .navlink { color: var(--muted); font-weight: 500; padding: 8px 10px; border-radius: 8px; }
.navlink:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.site-footer {
  max-width: 1100px; margin: 0 auto; padding: 20px;
  text-align: center; color: var(--muted); font-size: 13px;
  border-top: 1px solid var(--border);
}
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--muted); }

.section { margin-top: 28px; }
.section h2 { font-size: 16px; margin: 0 0 12px; }
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .chart-grid { grid-template-columns: 1fr; } }
canvas { max-width: 100%; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 18px; }
.book {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
  color: inherit; text-decoration: none; transition: box-shadow .15s, transform .15s;
}
a.book:hover { text-decoration: none; box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-2px); }
.book .cover { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: #eee; display: block; }
.book .meta { padding: 8px 10px; }
.book .title { font-size: 13px; font-weight: 600; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.book .author { font-size: 12px; color: var(--muted); margin-top: 2px; }
.progress { height: 5px; background: var(--border); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }

.folder-title { font-size: 15px; font-weight: 600; margin: 24px 0 12px; display: flex; gap: 8px; align-items: center; }
.folder-title .count { color: var(--muted); font-weight: 400; font-size: 13px; }

table.notes { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
table.notes th, table.notes td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.notes th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
table.notes tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.chapter { margin-top: 22px; }
.chapter h3 { font-size: 15px; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.mark { border-left: 3px solid var(--accent); padding: 6px 12px; margin: 8px 0; background: var(--accent-soft); border-radius: 0 6px 6px 0; }
.thought { padding: 6px 12px; margin: 8px 0; }
.thought .quote { color: var(--muted); font-size: 13px; border-left: 2px solid var(--border); padding-left: 8px; margin-bottom: 4px; }
.thought .body { white-space: pre-wrap; }

.empty { color: var(--muted); text-align: center; padding: 60px 20px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 2px 9px; border-radius: 12px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2328; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .3s; pointer-events: none; }
.toast.show { opacity: 1; }

/* book detail */
.book-head { display: flex; gap: 18px; margin: 6px 0 20px; }
.book-head-cover { width: 96px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; background: #eee; box-shadow: var(--shadow); flex: none; }
.book-head-meta h1 { margin: 0 0 6px; }
.book-head-stats { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 10px; font-size: 13px; color: var(--muted); }
.intro { color: var(--ink); white-space: pre-wrap; margin: 4px 0 16px; }
.info-table { border-collapse: collapse; font-size: 14px; }
.info-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 5px 18px 5px 0; vertical-align: top; white-space: nowrap; }
.info-table td { padding: 5px 0; }
.toc { margin-top: 26px; }
.toc-title { font-size: 15px; margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.toc-count { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 6px; }
.toc-list { list-style: none; margin: 0; padding: 0; font-size: 14px; max-height: 460px; overflow-y: auto; }
.toc-item { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 4px; border-bottom: 1px solid var(--border); }
.toc-item:last-child { border-bottom: none; }
.toc-ch-title { color: var(--ink); }
.toc-ch-words { color: var(--muted); font-size: 12px; white-space: nowrap; flex: none; }
.period-nav { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 4px 0 18px; }
.period-btn { border: 1px solid var(--border); background: #fff; color: var(--ink); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 18px; line-height: 1; }
.period-btn:disabled { color: var(--border); cursor: default; }
.period-label { font-weight: 600; min-width: 140px; text-align: center; }

.subtabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.subtab { border: none; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* admin + auth forms */
.admin-card, .auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.admin-card h2 { font-size: 16px; margin: 0 0 12px; }
.auth-card { max-width: 360px; margin: 40px auto; }
.auth-card h1 { margin-bottom: 16px; }
form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
form label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
form input[type=text], form input[type=password], form input[type=number], form select { display: block; width: 100%; max-width: 360px; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; color: var(--ink); }
form label.check input { width: auto; margin: 0; }
.btn-primary { background: var(--accent); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger { color: #c0392b; background: #fff; border: 1px solid var(--border); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input[type=text], .inline-form input[type=password] { display: inline-block; width: auto; max-width: none; margin: 0; flex: 1 1 150px; }
.inline-form button:not(.btn-primary) { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); margin-bottom: 16px; font-size: 14px; }
.notice-bad { background: #fdecea; color: #c0392b; }
.form-error { color: #c0392b; font-size: 14px; margin-bottom: 12px; }
