/* =========================================================
   Ex Libris — estética editorial / papel & tinta
   ========================================================= */
:root {
  --paper: #f6f1e7;
  --paper-2: #efe7d8;
  --card: #fbf8f2;
  --ink: #2b2520;
  --ink-soft: #6e6255;
  --ink-faint: #9c8f80;
  --line: #e3d9c7;
  --line-strong: #d3c6af;
  --accent: #8b3a2b;
  --accent-ink: #fff8ee;
  --accent-soft: #f1ddd3;
  --green: #3f6b52;
  --green-soft: #dde9df;
  --gold: #b5832f;
  --gold-soft: #f4e6c8;
  --neutral-soft: #ebe3d4;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 18px rgba(60, 40, 20, .07);
  --shadow-lg: 0 20px 60px rgba(40, 25, 10, .22);
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --topbar-h: 62px;
  --tabbar-h: 66px;
  color-scheme: light;
}
[data-theme="dark"] {
  --paper: #1a1714;
  --paper-2: #221e1a;
  --card: #26211d;
  --ink: #ede5d7;
  --ink-soft: #b3a695;
  --ink-faint: #85796b;
  --line: #3a332c;
  --line-strong: #4a4138;
  --accent: #d98b70;
  --accent-ink: #1a1714;
  --accent-soft: #3d2a23;
  --green: #8fbf9f;
  --green-soft: #26372d;
  --gold: #dcb26a;
  --gold-soft: #3b3020;
  --neutral-soft: #322c26;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(rgba(120, 90, 50, .035) 1px, transparent 1px);
  background-size: 4px 4px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s, color .3s;
}
button, input, select, textarea { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-xl { width: 40px; height: 40px; stroke-width: 1.3; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; margin-right: auto; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: .01em; }
.brand-text small { font-size: 11px; color: var(--ink-faint); letter-spacing: .06em; text-transform: lowercase; }
.topnav { display: none; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 11px;
  border-radius: 99px; border: 1px solid var(--line); background: var(--card);
  font-size: 12px; font-weight: 500; color: var(--ink-soft); transition: all .15s;
}
.sync-pill:hover { border-color: var(--line-strong); color: var(--ink); }
.sync-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft); transition: background .2s, box-shadow .2s;
}
.sync-pill.syncing .sync-dot { background: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); animation: pulse 1s infinite; }
.sync-pill.offline .sync-dot { background: var(--ink-faint); box-shadow: none; }
@keyframes pulse { 50% { opacity: .45; } }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 10px; color: var(--ink-soft);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.ic-sun { display: none; }
[data-theme="dark"] .ic-sun { display: block; }
[data-theme="dark"] .ic-moon { display: none; }

/* ---------- Tabbar (mobile) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; font-size: 11px; font-weight: 500; color: var(--ink-faint);
}
.tabbar a.active { color: var(--accent); }
.tabbar .tab-add .ic {
  width: 44px; height: 32px; padding: 6px 12px; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink); stroke-width: 2.2;
}

/* ---------- Layout ---------- */
main {
  max-width: 1280px; margin: 0 auto;
  padding: 18px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
}
.view { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.eyebrow {
  margin: 0 0 2px; font-size: 11px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--accent);
}
.page-title { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
.page-title .count { font-family: var(--sans); font-size: 14px; font-weight: 500; color: var(--ink-faint); margin-left: 6px; vertical-align: middle; }
.shelf-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 500; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-soft { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn-soft:hover { border-color: var(--line-strong); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--paper-2); color: var(--ink); }
.btn-danger { background: transparent; color: #b4412f; border-color: color-mix(in srgb, #b4412f 35%, transparent); }
[data-theme="dark"] .btn-danger { color: #ef8c78; }
.btn-danger:hover { background: color-mix(in srgb, #b4412f 10%, transparent); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.pill-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- Segmented ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 11px; }
.seg button {
  border: 0; background: transparent; height: 34px; min-width: 38px; padding: 0 10px; border-radius: 8px;
  color: var(--ink-faint); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; font-weight: 500;
}
.seg button.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Toolbar ---------- */
.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.search {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search .ic { color: var(--ink-faint); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; min-width: 0; font-size: 16px; }
.sort {
  display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 10px 0 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px; color: var(--ink-soft);
}
.sort select { border: 0; outline: 0; background: transparent; font-size: 15px; color: var(--ink); padding-right: 4px; cursor: pointer; }
.sort select option { background: var(--card); }
.toolbar .btn-soft { justify-self: start; }

.status-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 10px; padding: 2px 16px; }
.status-tabs::-webkit-scrollbar { display: none; }
.status-tabs button {
  flex: none; height: 34px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: transparent; font-size: 13px; font-weight: 500; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 6px;
}
.status-tabs button small { color: var(--ink-faint); font-weight: 500; }
.status-tabs button.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.status-tabs button.active small { color: inherit; opacity: .7; }

.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.active-filters:empty { display: none; }
.chip-x {
  display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 6px 0 11px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); border: 0; font-size: 12px; font-weight: 500;
}
.chip-x .ic { width: 14px; height: 14px; }
.chip-x em { font-style: normal; opacity: .7; margin-right: 2px; }

/* ---------- Cover ---------- */
.cover {
  position: relative; aspect-ratio: 2 / 3; width: 100%;
  border-radius: 3px 7px 7px 3px; overflow: hidden;
  background: var(--paper-2);
  box-shadow: 0 1px 1px rgba(0,0,0,.08), 0 8px 18px -6px rgba(50, 30, 10, .35);
  container-type: inline-size;
}
.cover::after { /* lombada */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.22) 0, rgba(255,255,255,.14) 2.5%, rgba(0,0,0,.08) 5%, transparent 9%, transparent 94%, rgba(0,0,0,.06));
  z-index: 3;
}
.cover img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .35s ease; z-index: 2; background: var(--paper-2);
}
.cover img.in, .cover.has-img img { opacity: 1; }
.cover.has-img .tcover { opacity: 0; pointer-events: none; }
.tcover {
  position: absolute; inset: 0; z-index: 1;
  background:
    radial-gradient(120% 80% at 30% 0%, rgba(255,255,255,.12), transparent 60%),
    var(--c, #6b4e3d);
  color: #f7f0e3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 16cqw 11cqw;
}
.tcover::before {
  content: ""; position: absolute; inset: 5.5cqw 5.5cqw 5.5cqw 8cqw;
  border: 1px solid rgba(247, 240, 227, .38); pointer-events: none;
}
.tc-genre {
  position: absolute; top: 9cqw; left: 0; right: 0; padding: 0 12cqw;
  font-size: 5.4cqw; letter-spacing: .18em; text-transform: uppercase; opacity: .75;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tc-title {
  font-family: var(--serif); font-weight: 600; font-size: 11.5cqw; line-height: 1.12;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
  text-wrap: balance;
}
.tc-rule { width: 18cqw; height: 1px; background: rgba(247, 240, 227, .6); margin: 7cqw 0 6cqw; flex: none; }
.tc-author {
  font-size: 6.2cqw; letter-spacing: .12em; text-transform: uppercase; opacity: .9;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- Shelf: grid ---------- */
.shelf.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 14px; }
@media (min-width: 480px) {
  .shelf.grid { grid-template-columns: repeat(auto-fill, minmax(144px, 1fr)); gap: 26px 16px; }
}
@media (max-width: 380px) {
  .page-title { font-size: 24px; }
  .dates { grid-template-columns: 1fr; }
  .stat-value { font-size: 28px; }
}
.card { position: relative; cursor: pointer; outline: none; border-radius: 10px; }
.shelf.grid .card .cover { transition: transform .25s ease, box-shadow .25s ease; }
.shelf.grid .card:hover .cover, .shelf.grid .card:focus-visible .cover {
  transform: translateY(-4px) rotate(-.4deg);
  box-shadow: 0 1px 1px rgba(0,0,0,.08), 0 18px 28px -10px rgba(50, 30, 10, .45);
}
.card:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
.card-body { padding: 10px 2px 0; min-width: 0; }
.card-title {
  font-family: var(--serif); font-weight: 600; font-size: 15.5px; line-height: 1.22; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-author { margin: 3px 0 0; font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-genre { display: none; }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 8px; }
.card-icons { display: inline-flex; gap: 2px; color: var(--ink-faint); }
.card-icons .ic { width: 17px; height: 17px; stroke-width: 1.6; }
.card-icons span { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; }
.card-icons span:hover { background: var(--paper-2); color: var(--ink); }
.mini-stars { display: inline-flex; gap: 1px; margin-top: 6px; color: var(--gold); }
.mini-stars .ic { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.mini-stars .off { color: var(--line-strong); }

/* status badge */
.status {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px 0 8px;
  border-radius: 99px; border: 0; font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  white-space: nowrap; transition: transform .12s, filter .15s;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status:hover { filter: brightness(.96); }
.status:active { transform: scale(.94); }
.status .ic { width: 12px; height: 12px; opacity: 0; margin-left: -2px; transition: opacity .15s; stroke-width: 2.2; }
.status:hover .ic { opacity: .7; }
.s-naolido { background: var(--neutral-soft); color: var(--ink-soft); }
.s-lendo { background: var(--gold-soft); color: var(--gold); }
.s-lido { background: var(--green-soft); color: var(--green); }
.status.pop { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(1.12); } }

/* ---------- Shelf: list ---------- */
.shelf.list { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.shelf.list .card {
  display: grid; grid-template-columns: 46px 1fr; gap: 14px; align-items: center;
  padding: 10px 14px; border-radius: 0; border-bottom: 1px solid var(--line);
  transition: background .15s;
}
.shelf.list .card:last-child { border-bottom: 0; }
.shelf.list .card:hover { background: var(--paper-2); }
.shelf.list .cover { box-shadow: 0 1px 1px rgba(0,0,0,.1), 0 3px 6px -2px rgba(50,30,10,.3); border-radius: 2px 4px 4px 2px; }
.shelf.list .tcover { padding: 10cqw 8cqw; }
.shelf.list .tc-genre, .shelf.list .tc-rule, .shelf.list .tc-author { display: none; }
.shelf.list .tc-title { font-size: 15cqw; -webkit-line-clamp: 4; }
.shelf.list .tcover::before { inset: 6cqw; }
.shelf.list .card-body { padding: 0; display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; }
.shelf.list .card-title { font-size: 15px; -webkit-line-clamp: 1; grid-column: 1; }
.shelf.list .card-author { grid-column: 1; margin-top: 1px; }
.shelf.list .card-meta { grid-column: 1 / -1; margin-top: 6px; justify-content: flex-start; gap: 10px; }
.shelf.list .mini-stars { display: none; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty .ic { color: var(--line-strong); }
.empty h3 { font-family: var(--serif); font-weight: 600; font-size: 21px; color: var(--ink); margin: 12px 0 4px; }
.empty p { margin: 0 0 16px; }

/* ---------- Welcome ---------- */
.welcome { max-width: 620px; margin: 4vh auto 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.display { font-family: var(--serif); font-weight: 600; font-size: clamp(34px, 8vw, 54px); line-height: 1.05; margin: 0; letter-spacing: -.02em; }
.display em { font-weight: 400; color: var(--accent); }
.lead { font-size: 16px; color: var(--ink-soft); margin: 0; max-width: 480px; }
.dropzone {
  width: 100%; margin-top: 10px; padding: 34px 20px; border: 1.5px dashed var(--line-strong); border-radius: 18px;
  background: var(--card); display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer;
  color: var(--ink-soft); transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .ic { color: var(--accent); }
.dropzone strong { color: var(--ink); }
.dropzone small { color: var(--ink-faint); }
.hint { font-size: 12.5px; color: var(--ink-faint); max-width: 440px; margin: 6px 0 0; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 100; display: none; place-items: center;
  background: color-mix(in srgb, var(--paper) 85%, transparent); backdrop-filter: blur(4px);
}
.drop-overlay > div { border: 2px dashed var(--accent); border-radius: 24px; padding: 50px 70px; text-align: center; color: var(--accent); font-family: var(--serif); font-size: 22px; }
body.dragging .drop-overlay { display: grid; }

/* ---------- Dialogs ---------- */
dialog { color: var(--ink); }
dialog::backdrop { background: rgba(25, 18, 10, .45); backdrop-filter: blur(3px); }
dialog[open] { animation: rise .28s cubic-bezier(.2, .8, .3, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

.modal {
  border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  background: var(--paper); overflow-y: auto; overscroll-behavior: contain;
}
.sheet {
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 88vh;
  background: var(--paper); border-radius: 20px 20px 0 0; display: none; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet[open] { display: flex; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 21px; }
.sheet-body { overflow-y: auto; padding: 8px 20px 18px; flex: 1; }
.sheet-foot { display: flex; gap: 8px; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); }
.sheet-foot .btn-primary { flex: 1; max-width: 240px; }

.facet { padding: 14px 0 6px; border-bottom: 1px solid var(--line); }
.facet:last-child { border-bottom: 0; }
.facet h3 { margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); display: flex; justify-content: space-between; }
.facet h3 button { border: 0; background: none; color: var(--accent); font-size: 12px; text-transform: none; letter-spacing: 0; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--card); font-size: 13px; color: var(--ink);
  transition: all .12s;
}
.chip small { color: var(--ink-faint); font-size: 11px; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip.on small { color: inherit; opacity: .65; }
.chip .ic { width: 15px; height: 15px; }

.menu-list { display: flex; flex-direction: column; gap: 4px; padding-top: 10px; }
.menu-list button {
  display: flex; align-items: center; gap: 14px; text-align: left; border: 0; background: transparent;
  padding: 12px 10px; border-radius: 12px;
}
.menu-list button:hover { background: var(--paper-2); }
.menu-list button .ic { color: var(--accent); width: 22px; height: 22px; }
.menu-list span { display: flex; flex-direction: column; }
.menu-list small { color: var(--ink-faint); font-size: 12.5px; }
.menu-list .danger .ic, .menu-list .danger strong { color: #b4412f; }
[data-theme="dark"] .menu-list .danger .ic, [data-theme="dark"] .menu-list .danger strong { color: #ef8c78; }

.confirm {
  border: 0; border-radius: 18px; padding: 24px; width: min(440px, calc(100% - 32px));
  background: var(--paper); box-shadow: var(--shadow-lg);
}
.confirm h3 { margin: 0 0 8px; font-family: var(--serif); font-weight: 600; font-size: 21px; }
.confirm p { margin: 0 0 20px; color: var(--ink-soft); }
.confirm .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

/* ---------- Detail ---------- */
.detail { position: relative; padding: 0 0 40px; }
.detail-hero {
  position: relative; padding: calc(56px + env(safe-area-inset-top)) 20px 22px;
  display: flex; justify-content: center;
  background: linear-gradient(180deg, color-mix(in srgb, var(--dc, #6b4e3d) 22%, var(--paper)), var(--paper));
}
.detail-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; z-index: 5; background: color-mix(in srgb, var(--card) 80%, transparent); }
.detail-cover { width: 170px; }
.detail-cover .cover { box-shadow: 0 2px 2px rgba(0,0,0,.1), 0 22px 40px -14px rgba(40, 20, 5, .55); }
.cover-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 14px; }
.cover-col { display: flex; flex-direction: column; align-items: center; }
.cover-url-form { display: flex; gap: 6px; margin-top: 10px; width: 100%; max-width: 320px; }
.cover-url-form input { flex: 1; min-width: 0; }
.detail-main { padding: 6px 20px 0; max-width: 640px; margin: 0 auto; }
.detail-title { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.12; margin: 2px 0 4px; letter-spacing: -.01em; text-wrap: balance; }
.detail-author { margin: 0 0 18px; font-size: 16px; color: var(--ink-soft); font-family: var(--serif); font-style: italic; }
.detail .seg { width: 100%; }
.detail .seg button { flex: 1; height: 40px; }
.detail .seg button.active.st-lido { color: var(--green); }
.detail .seg button.active.st-lendo { color: var(--gold); }
.block { margin-top: 22px; }
.block-label { display: block; font-size: 11.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 8px; }
.stars { display: inline-flex; gap: 2px; }
.stars button { border: 0; background: none; padding: 3px; color: var(--line-strong); transition: transform .12s, color .12s; }
.stars button .ic { width: 30px; height: 30px; fill: currentColor; stroke: none; }
.stars button.on { color: var(--gold); }
.stars button:hover { transform: scale(1.12); }
.stars-note { margin-left: 8px; font-size: 13px; color: var(--ink-faint); vertical-align: middle; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.field.full { grid-column: 1 / -1; }
.input, .field input, .field select, .field textarea, .cover-url-form input {
  height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 16px; outline: 0; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; min-height: 120px; padding: 12px; resize: vertical; line-height: 1.6; font-family: var(--serif); font-size: 16px; }
.field input:focus, .field select:focus, .field textarea:focus, .cover-url-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.notes-area { font-family: var(--serif); }
.saved-tag { font-size: 12px; color: var(--green); opacity: 0; transition: opacity .3s; margin-left: 8px; text-transform: none; letter-spacing: 0; font-weight: 500; }
.saved-tag.show { opacity: 1; }

.meta { margin-top: 26px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.meta-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 12px 16px; border-bottom: 1px solid var(--line); }
.meta-head h4 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 17px; }
.meta dl { margin: 0; display: grid; grid-template-columns: 1fr; }
.meta dl > div { display: grid; grid-template-columns: 42% 1fr; gap: 10px; padding: 10px 16px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.meta dl > div:last-child { border-bottom: 0; }
.meta dt { color: var(--ink-faint); font-size: 12.5px; }
.meta dd { margin: 0; color: var(--ink); word-break: break-word; display: flex; align-items: center; gap: 6px; }
.meta dd .ic { width: 16px; height: 16px; color: var(--ink-faint); }
.meta-form { padding: 14px 16px 16px; display: grid; grid-template-columns: 1fr; gap: 12px; }
.meta-form .actions { display: flex; gap: 8px; justify-content: flex-end; }
.detail-foot { display: flex; justify-content: center; margin-top: 28px; }

/* ---------- Add form ---------- */
.form-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: grid; grid-template-columns: 1fr; gap: 14px; max-width: 860px; }
.form-card h3 { grid-column: 1 / -1; margin: 10px 0 -2px; font-family: var(--serif); font-weight: 600; font-size: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.form-card h3:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.form-card .actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.req { color: var(--accent); }
.id-note { grid-column: 1 / -1; font-size: 13px; color: var(--ink-faint); margin: -4px 0 0; }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat-label { font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.stat-value { font-family: var(--serif); font-size: 34px; font-weight: 600; line-height: 1.1; letter-spacing: -.02em; }
.stat-value small { font-family: var(--sans); font-size: 14px; color: var(--ink-faint); font-weight: 500; letter-spacing: 0; }
.stat-sub { font-size: 12.5px; color: var(--ink-soft); }
.stat-hero { grid-column: 1 / -1; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.stat-hero .stat-label { color: color-mix(in srgb, var(--paper) 65%, transparent); }
.stat-hero .stat-sub { color: color-mix(in srgb, var(--paper) 75%, transparent); }
.stat-hero .stat-value small { color: color-mix(in srgb, var(--paper) 60%, transparent); }
.progress { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--paper) 18%, transparent); overflow: hidden; margin: 10px 0 6px; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), #e2b866); transition: width .8s cubic-bezier(.2, .8, .3, 1); }
.progress-row { display: flex; justify-content: space-between; align-items: baseline; }
.pct { font-family: var(--serif); font-size: 22px; font-weight: 600; color: #e9c47c; }
[data-theme="dark"] .pct { color: #8b5a12; }

.reading-now { margin: 4px 0 16px; }
.reading-now h2, .chart-card h2 { font-family: var(--serif); font-weight: 600; font-size: 19px; margin: 0 0 12px; }
.rn-strip { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 12px; scrollbar-width: thin; }
.rn-item { flex: none; width: 92px; cursor: pointer; }
.rn-item p { margin: 6px 0 0; font-size: 12px; font-family: var(--serif); font-weight: 600; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.charts { display: grid; grid-template-columns: 1fr; gap: 14px; }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 12px; min-width: 0; }
.chart-card header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.chart-card header small { color: var(--ink-faint); font-size: 12px; }
.chart-wrap { position: relative; width: 100%; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-soft); margin-bottom: 14px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100% - 32px); }
.toast {
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; pointer-events: auto;
  animation: toastIn .3s ease;
}
.toast .ic { width: 18px; height: 18px; color: #e9c47c; }
.toast button { border: 0; background: none; color: #e9c47c; font-weight: 600; padding: 0 0 0 6px; }
.toast.out { opacity: 0; transform: translateY(8px); transition: all .3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

.hide-xs { display: none; }

/* =========================================================
   ≥ 560px
   ========================================================= */
@media (min-width: 560px) {
  .hide-xs { display: inline; }
  .toolbar { grid-template-columns: 1fr auto auto; }
  .search { grid-column: auto; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat-hero { grid-column: span 3; }
  .form-card { grid-template-columns: 1fr 1fr; padding: 24px; }
  .meta-form { grid-template-columns: 1fr 1fr; }
  .meta-form .actions { grid-column: 1 / -1; }
  .meta dl { grid-template-columns: 1fr 1fr; }
  .meta dl > div { grid-template-columns: 1fr; gap: 2px; border-right: 1px dashed var(--line); }
  .meta dl > div:nth-child(2n) { border-right: 0; }
}

/* =========================================================
   ≥ 860px (desktop)
   ========================================================= */
@media (min-width: 860px) {
  :root { --topbar-h: 68px; }
  .topbar { padding: 0 28px; }
  .topnav { display: flex; gap: 4px; position: absolute; left: 50%; transform: translateX(-50%); }
  .topnav a {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 10px;
    text-decoration: none; font-size: 14px; font-weight: 500; color: var(--ink-soft);
  }
  .topnav a .ic { width: 18px; height: 18px; }
  .topnav a:hover { background: var(--paper-2); color: var(--ink); }
  .topnav a.active { background: var(--ink); color: var(--paper); }
  .tabbar { display: none; }
  main { padding: 30px 28px 60px; }
  .page-title { font-size: 36px; }
  .toast-wrap { bottom: 28px; }
  .shelf.grid { grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); gap: 34px 24px; }
  .status-tabs { margin: 0 0 12px; padding: 2px 0; }

  .shelf.list .card { grid-template-columns: 42px 1fr; padding: 10px 18px; }
  .shelf.list .card-body { grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.3fr) auto; column-gap: 20px; }
  .shelf.list .card-title { grid-column: 1; grid-row: 1; }
  .shelf.list .card-author { grid-column: 1; grid-row: 2; }
  .shelf.list .card-genre { display: block; margin: 0; font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-column: 2; grid-row: 1 / span 2; }
  .shelf.list .card-meta { grid-column: 3; grid-row: 1 / span 2; margin: 0; justify-content: flex-end; }
  .shelf.list .card-meta .card-icons { order: -1; }
  .shelf.list .mini-stars { display: none; }

  .modal {
    width: min(960px, 94vw); height: auto; max-height: 90vh; margin: auto;
    border-radius: 22px; box-shadow: var(--shadow-lg);
  }
  .detail { display: grid; grid-template-columns: 320px 1fr; padding: 0; min-height: 560px; }
  .detail-hero { padding: 40px 28px; align-items: flex-start; border-radius: 22px 0 0 22px; position: sticky; top: 0; align-self: start; min-height: 100%; }
  .detail-cover { width: 220px; }
  .detail-main { padding: 40px 36px 32px 8px; max-width: none; }
  .detail-title { font-size: 34px; }
  .detail-close { top: 14px; right: 14px; }
  .detail-foot { justify-content: flex-start; }

  .sheet {
    margin: 0 0 0 auto; height: 100%; max-height: 100%; width: 420px; border-radius: 22px 0 0 22px;
  }
  .sheet[open] { animation: slideIn .3s cubic-bezier(.2, .8, .3, 1); }
  @keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }
  .sheet-menu { height: auto; margin: 70px 20px auto auto; border-radius: 18px; width: 380px; box-shadow: var(--shadow-lg); }

  .stats { grid-template-columns: 2fr repeat(4, 1fr); }
  .stat-hero { grid-column: auto; grid-row: span 1; }
  .charts { grid-template-columns: 1fr 1fr; gap: 18px; }
  .chart-card.wide { grid-column: 1 / -1; }
}
@media (min-width: 1200px) {
  .charts { grid-template-columns: repeat(6, 1fr); }
  .chart-card { grid-column: span 3; }
  .chart-card.third { grid-column: span 2; }
  .chart-card.wide { grid-column: 1 / -1; }
}

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