/* Leticia's Reading Room — styles (light + dark) */
:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 248px;
  --bottom-nav: 64px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.18);
}
:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #faf9f7; --surface: #ffffff; --card: #f5f4f1; --card-hover: #efede9; --border: #e6e3dd; --border-strong: #d6d2ca;
  --text: #2b2926; --text-2: #55514b; --muted: #8a857c; --accent: #7a4b3a; --accent-2: #94604c; --accent-soft: #f3e9e4; --on-accent: #fff;
  --danger: #b4392f; --danger-soft: #fbe9e6; --ok: #2f7a4f; --warn: #a66a00; --input: #ffffff; --overlay: rgba(32,28,24,.38);
  --t-gray-bg: #e8e6e2; --t-gray: #45413b; --t-brown-bg: #eee0da; --t-brown: #5a3a2b; --t-orange-bg: #fadec9; --t-orange: #6a3a12;
  --t-yellow-bg: #fbecc4; --t-yellow: #5c4210; --t-green-bg: #dbeddb; --t-green: #1f4a32; --t-teal-bg: #d4ecea; --t-teal: #17423e;
  --t-blue-bg: #d6e6f1; --t-blue: #1d3f5a; --t-purple-bg: #e8deee; --t-purple: #4b2b62; --t-pink-bg: #f6e0ea; --t-pink: #5e2a43; --t-red-bg: #ffe1dc; --t-red: #6d221c;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #19191a; --surface: #202022; --card: #262628; --card-hover: #2d2d30; --border: #333336; --border-strong: #46464a;
  --text: #ecebe8; --text-2: #c9c7c2; --muted: #9a9790; --accent: #d9a88c; --accent-2: #e6b99f; --accent-soft: #3a2c25; --on-accent: #1d1714;
  --danger: #ef8a7f; --danger-soft: #3d2422; --ok: #7fcf9d; --warn: #e9b65a; --input: #1d1d1f; --overlay: rgba(0,0,0,.6);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  --t-gray-bg: #3a3a3c; --t-gray: #dcdad5; --t-brown-bg: #4a3328; --t-brown: #ecd4c7; --t-orange-bg: #5c3a1c; --t-orange: #f7d3b2;
  --t-yellow-bg: #5a4720; --t-yellow: #f6e2ae; --t-green-bg: #24442f; --t-green: #c3e8cf; --t-teal-bg: #1d4440; --t-teal: #bfe7e2;
  --t-blue-bg: #213c57; --t-blue: #c6def2; --t-purple-bg: #3e2b52; --t-purple: #e0cff0; --t-pink-bg: #4f2a3c; --t-pink: #f3cfe0; --t-red-bg: #5a2a26; --t-red: #f8cdc6;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; overflow-x: hidden;
  transition: background-color .2s, color .2s;
}
body.no-scroll { overflow: hidden; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: .005em; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; } .text-bad { color: var(--danger); } .text-warn { color: var(--warn); } .text-ok { color: var(--ok); display: inline-flex; gap: 4px; align-items: center; }
code { font-size: 12.5px; background: var(--card); padding: 1px 6px; border-radius: 5px; word-break: break-all; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 7px 14px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--card-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
[data-theme="dark"] .btn-danger { color: #1d1714; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-active { border-color: var(--accent); color: var(--accent); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.fav-on { color: #c2416b; border-color: #e7a9bd; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text-2); font-size: 18px;
}
.icon-btn:hover { background: var(--card-hover); color: var(--text); }
.icon-btn.sm { width: 32px; height: 32px; font-size: 15px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.mini-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; font-size: 12px; padding: 3px 8px; cursor: pointer; color: var(--text-2); min-height: 28px; }
.mini-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.mini-btn:disabled { opacity: .4; }

input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border); background: var(--input);
  font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s;
}
@media (min-width: 900px) { input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 14.5px; } }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 18px; height: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); letter-spacing: .02em; }
.field-error { display: block; color: var(--danger); font-size: 13px; font-style: normal; margin: 2px 0 6px; }
.ok-msg { color: var(--ok); font-size: 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; margin: 6px 0 10px; }
.self-end { align-self: end; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 14px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .grid-4 { grid-template-columns: 1fr 1fr; } }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.notice { background: var(--accent-soft); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }
.banner { padding: 9px 20px; font-size: 13.5px; }
.banner.warn { background: #fdf0d5; color: #6b4a00; }
[data-theme="dark"] .banner.warn { background: #4a3a14; color: #f6e2ae; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); padding: 22px 14px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px; overflow-y: auto; z-index: 20;
}
.brand { font-family: var(--serif); font-size: 21px; font-weight: 600; line-height: 1.2; text-decoration: none; padding: 0 8px; letter-spacing: .01em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-size: 14.5px; }
.nav-item svg { font-size: 17px; opacity: .85; }
.nav-item:hover { background: var(--card-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.sub { font-size: 13.5px; padding-left: 10px; margin-top: 6px; border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; padding-top: 12px; }
.main-col { flex: 1; min-width: 0; margin-left: var(--sidebar); }
.topbar {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 28px; background: var(--bg); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); min-height: 58px;
}
.brand-top { display: none; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.content { padding: 26px 28px 60px; max-width: 1500px; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text-2); min-height: 32px;
}
.sync-pill.ok svg { color: var(--ok); } .sync-pill.bad { color: var(--danger); border-color: var(--danger); } .sync-pill.demo { color: var(--warn); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bottom-nav { display: none; }

@media (max-width: 899px) {
  .sidebar { display: none; }
  .main-col { margin-left: 0; }
  .topbar { padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand-top { display: block; font-size: 18px; padding: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-add { display: none; }
  .sync-pill span { display: none; }
  .sync-pill { padding: 5px 9px; }
  .content { padding: 18px 14px calc(var(--bottom-nav) + 34px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--bottom-nav) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .bottom-nav > a, .bottom-nav > button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; text-decoration: none;
    color: var(--muted); background: none; border: 0; cursor: pointer; min-height: 48px;
  }
  .bottom-nav svg { font-size: 21px; }
  .bottom-nav .active { color: var(--accent); }
  .bottom-nav .bn-add { margin: 6px auto; width: 50px; height: 50px; border-radius: 16px; background: var(--accent); color: var(--on-accent); font-size: 24px; box-shadow: var(--shadow); }
  .bottom-nav .bn-add svg { font-size: 26px; }
}

.sheet-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 60; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow-lg); animation: up .2s ease-out; max-height: 85vh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sheet-grid a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; border-radius: 12px; background: var(--card); text-decoration: none; font-size: 12.5px; text-align: center; }
.sheet-grid a svg { font-size: 22px; color: var(--accent); }
.sheet-grid a.active { outline: 2px solid var(--accent); }

/* ---------- pages ---------- */
.page-title { font-size: 30px; margin-bottom: 18px; }
@media (max-width: 640px) { .page-title { font-size: 25px; } }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .page-title { margin-bottom: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.panel h2 { font-size: 19px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card.narrow { max-width: 460px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.card.narrow h2 { margin-bottom: 8px; }
.spinner-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.empty { text-align: center; padding: 46px 16px; color: var(--muted); }
.empty > svg { font-size: 34px; opacity: .6; }
.empty h3 { color: var(--text); margin: 8px 0 4px; font-size: 19px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  position: relative; display: flex; flex-direction: column; padding: 16px 18px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); text-decoration: none; transition: transform .12s, box-shadow .12s; overflow: hidden;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-n { font-family: var(--serif); font-size: 32px; font-weight: 600; line-height: 1.1; }
.stat-l { color: var(--text-2); font-size: 13.5px; }
.stat-icon { position: absolute; right: 14px; top: 14px; font-size: 22px; padding: 7px; box-sizing: content-box; border-radius: 10px; }
.st-gray .stat-icon { background: var(--t-gray-bg); color: var(--t-gray); } .st-blue .stat-icon { background: var(--t-blue-bg); color: var(--t-blue); }
.st-green .stat-icon { background: var(--t-green-bg); color: var(--t-green); } .st-yellow .stat-icon { background: var(--t-yellow-bg); color: var(--t-yellow); }
.st-red .stat-icon { background: var(--t-red-bg); color: var(--t-red); } .st-purple .stat-icon { background: var(--t-purple-bg); color: var(--t-purple); }
.st-pink .stat-icon { background: var(--t-pink-bg); color: var(--t-pink); }
@media (max-width: 640px) { .stat { padding: 12px 14px; } .stat-n { font-size: 26px; } .stat-icon { font-size: 18px; padding: 5px; right: 10px; top: 10px; } }
.shelf { margin-bottom: 28px; }
.shelf-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.shelf-head h2 { font-size: 20px; }
.see-all { font-size: 13.5px; color: var(--accent); text-decoration: none; }
.shelf-row { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 14px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.mini { display: flex; flex-direction: column; gap: 5px; text-decoration: none; scroll-snap-align: start; min-width: 0; }
.mini .cover { aspect-ratio: 2 / 3; width: 100%; border-radius: 9px; }
.mini-title { font-weight: 600; font-size: 13.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mini-sub { font-size: 12px; color: var(--muted); }

/* covers */
.cover { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--card); }
.cover-empty {
  display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden;
  background: linear-gradient(145deg, var(--accent-soft), var(--card) 70%);
}
.cover-initials { font-family: var(--serif); font-size: 34px; color: var(--accent); opacity: .75; letter-spacing: .05em; }
.cover-icon { position: absolute; right: 8px; bottom: 8px; font-size: 15px; color: var(--muted); opacity: .6; }

/* toolbar / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 260px; display: flex; align-items: center; }
.search > svg { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 36px !important; padding-right: 36px !important; }
.search .icon-btn { position: absolute; right: 3px; }
.narrow-search { max-width: 420px; margin-bottom: 8px; }
.sort-select select { min-width: 170px; }
.toolbar > select { width: auto; min-width: 170px; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 6px; margin-bottom: 12px; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; }
.genre-filter-search { max-width: 260px; margin-bottom: 6px; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); font-size: 13px; }
.chip button { border: 0; background: none; cursor: pointer; display: inline-flex; padding: 3px; color: var(--muted); }
.count { font-size: 13px; margin: 2px 0 12px; }

/* tags */
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tags.wrap { margin: 8px 0; gap: 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 3px; padding: 2px 9px; border-radius: 6px; font-size: 13px; line-height: 1.5;
  border: 1px solid transparent; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-weight: 500;
}
.tag-sm { font-size: 11.5px; padding: 1px 7px; }
.tag.clickable { cursor: pointer; }
.tag.clickable:hover { filter: brightness(.96); }
.tag.active { border-color: currentColor; box-shadow: 0 0 0 1px currentColor; }
.tag-x { border: 0; background: none; padding: 0 0 0 2px; cursor: pointer; display: inline-flex; color: inherit; opacity: .7; }
.c-gray { background: var(--t-gray-bg); color: var(--t-gray); } .c-brown { background: var(--t-brown-bg); color: var(--t-brown); }
.c-orange { background: var(--t-orange-bg); color: var(--t-orange); } .c-yellow { background: var(--t-yellow-bg); color: var(--t-yellow); }
.c-green { background: var(--t-green-bg); color: var(--t-green); } .c-teal { background: var(--t-teal-bg); color: var(--t-teal); }
.c-blue { background: var(--t-blue-bg); color: var(--t-blue); } .c-purple { background: var(--t-purple-bg); color: var(--t-purple); }
.c-pink { background: var(--t-pink-bg); color: var(--t-pink); } .c-red { background: var(--t-red-bg); color: var(--t-red); }
.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); color: var(--text-2); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px 2px 7px; border-radius: 999px; white-space: nowrap; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.s-gray { background: var(--t-gray-bg); color: var(--t-gray); } .s-blue { background: var(--t-blue-bg); color: var(--t-blue); }
.s-green { background: var(--t-green-bg); color: var(--t-green); } .s-yellow { background: var(--t-yellow-bg); color: var(--t-yellow); }
.s-red { background: var(--t-red-bg); color: var(--t-red); } .s-purple { background: var(--t-purple-bg); color: var(--t-purple); }

/* progress */
.progress-wrap { display: flex; align-items: center; gap: 8px; }
.progress { flex: 1; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.progress-fill.unknown { background: repeating-linear-gradient(45deg, var(--accent) 0 6px, transparent 6px 12px); opacity: .45; }
.progress-label { font-size: 12px; color: var(--muted); min-width: 32px; text-align: right; font-variant-numeric: tabular-nums; }

/* stars */
.stars { display: inline-flex; align-items: center; gap: 1px; font-size: 13px; }
.stars-lg { font-size: 20px; gap: 2px; }
.star { position: relative; display: inline-flex; }
.star-on { color: #d99a2b; fill: #d99a2b; }
.star-off { color: var(--border-strong); }
.star-btn .half { position: absolute; top: -4px; bottom: -4px; width: 50%; border: 0; background: transparent; cursor: pointer; padding: 0; z-index: 1; }
.star-btn .half.left { left: -2px; } .star-btn .half.right { right: -2px; }
.rating-row, .rating-line { display: flex; align-items: center; gap: 8px; min-height: 40px; }

/* ---------- gallery cards (Notion-style) ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 18px; }
@media (max-width: 640px) { .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }
.ccard {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s; min-width: 0;
}
.ccard:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.ccard-cover { position: relative; aspect-ratio: 3 / 4; background: var(--card); overflow: hidden; }
.ccard-cover .cover { position: absolute; inset: 0; }
.type-chip { position: absolute; left: 8px; top: 8px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: rgba(20,18,16,.62); color: #fff; backdrop-filter: blur(4px); }
.fav-btn {
  position: absolute; right: 8px; top: 8px; width: 34px; height: 34px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(20,18,16,.45); color: #fff; cursor: pointer; font-size: 17px; backdrop-filter: blur(4px);
}
.fav-btn.on { background: #fff; color: #c2416b; }
.fav-btn.on svg { fill: #c2416b; }
.ccard-body { padding: 12px 13px 12px; display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
.ccard-title { font-size: 16.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.ccard-sub { margin: -4px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard-meta { margin: -3px 0 0; font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.ccard-chapters { display: flex; justify-content: space-between; gap: 6px; font-size: 12.5px; flex-wrap: wrap; }
.ccard-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: auto; padding-top: 4px; border-top: 1px solid var(--border); padding-top: 9px; }
.src-btn {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 500; padding: 4px 9px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text-2); min-height: 30px; max-width: 100%;
}
.src-btn:hover { border-color: var(--accent); color: var(--accent); }
.src-btn.none { color: var(--muted); border-style: dashed; background: transparent; }
@media (max-width: 640px) {
  .ccard-body { padding: 9px 10px 10px; gap: 6px; }
  .ccard-title { font-size: 14.5px; }
  .ccard-meta { display: none; }
  .ccard-foot { flex-wrap: wrap; }
  .tags .tag-sm:nth-child(n+3) { display: none; }
}

/* popover + source list */
.popover { position: absolute; z-index: 70; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 12px; cursor: default; }
.popover.as-sheet { position: fixed; left: 0; right: 0; bottom: 0; top: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 80vh; overflow-y: auto; animation: up .2s ease-out; }
.srcpop-head { display: flex; flex-direction: column; margin-bottom: 8px; }
.srcpop-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.srcpop-link { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; padding: 8px 10px; border-radius: 9px; text-decoration: none; background: var(--card); }
.srcpop-link:hover { background: var(--card-hover); }
.srcpop-name { font-weight: 600; font-size: 14px; }
.srcpop-dom { font-size: 12px; color: var(--muted); grid-row: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srcpop-ext { grid-row: 1 / span 2; grid-column: 2; align-self: center; color: var(--muted); }
.srcpop-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.srcpop-form { display: flex; flex-direction: column; gap: 6px; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; z-index: 80; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 480px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); display: flex; flex-direction: column; max-height: 90vh; }
.modal-wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 10px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 21px; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.confirm-msg { margin-bottom: 12px; line-height: 1.55; }
@media (max-width: 640px) {
  .overlay { padding: 0; align-items: flex-end; }
  .modal { max-height: 94vh; border-radius: 18px 18px 0 0; }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
}

/* collection form */
.cform-top { display: grid; grid-template-columns: 190px 1fr; gap: 20px; }
@media (max-width: 640px) { .cform-top { grid-template-columns: 1fr; } }
.cover-edit { display: flex; flex-direction: column; gap: 8px; }
.cover-preview { aspect-ratio: 3 / 4; border-radius: 10px; border: 1px solid var(--border); }
@media (max-width: 640px) { .cover-edit .cover-preview { width: 150px; align-self: center; } }
.url-row { display: flex; gap: 6px; }
.url-row input { min-width: 0; }
.fs { border: 0; border-top: 1px solid var(--border); padding: 14px 0 4px; margin: 10px 0 0; min-width: 0; }
.fs legend { font-family: var(--serif); font-size: 17px; font-weight: 600; padding: 0 8px 0 0; }

/* genre picker */
.genre-picker { position: relative; }
.genre-box { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--input); min-height: 44px; cursor: text; }
.genre-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.genre-box input { border: 0 !important; box-shadow: none !important; flex: 1; min-width: 140px; padding: 4px !important; min-height: 30px !important; background: transparent !important; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 90; list-style: none; margin: 0; padding: 5px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; }
.suggest li { padding: 7px 9px; border-radius: 7px; cursor: pointer; }
.suggest li.hi { background: var(--card-hover); }
.create-genre { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; font-size: 14px; }

/* sources editor & lists */
.src-list, .sources-full { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
.src-row, .source-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); }
.src-main { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.src-dom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-actions { display: flex; gap: 2px; flex-shrink: 0; }
.src-edit { padding: 12px; border: 1px solid var(--accent); border-radius: 10px; background: var(--surface); }
.source-main { min-width: 0; flex: 1; }
.source-main p { margin: 4px 0 0; }
.source-name { font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; color: var(--accent); }
.source-name:hover { text-decoration: underline; }
.source-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; min-width: 0; }
.src-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; display: block; }
@media (max-width: 640px) { .source-item { flex-direction: column; align-items: stretch; } .src-actions { justify-content: flex-end; } }

/* ---------- detail ---------- */
.back { margin: -6px 0 12px -8px; }
.detail-grid { display: grid; grid-template-columns: 280px 1fr; gap: 32px; align-items: start; }
@media (max-width: 899px) { .detail-grid { grid-template-columns: 1fr; gap: 18px; } }
.detail-cover { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; }
.detail-cover .cover { aspect-ratio: 3 / 4; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--border); }
@media (max-width: 899px) { .detail-cover { position: static; } .detail-cover .cover { width: min(220px, 60vw); align-self: center; } }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-actions .btn { flex: 1 1 auto; }
.detail-badges { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.detail-title { font-size: 34px; line-height: 1.15; word-break: break-word; }
@media (max-width: 640px) { .detail-title { font-size: 27px; } }
.detail-sub { font-size: 17px; color: var(--text-2); margin: 4px 0 2px; font-family: var(--serif); }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 16px 0 8px; }
.meta div, .kv div { min-width: 0; }
.meta dt, .kv dt { font-size: 12px; color: var(--muted); }
.meta dd, .kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.tracker { margin-top: 16px; }
.tracker-top { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; }
.big-ch { font-family: var(--serif); font-size: 30px; }
.big-ch span { font-size: 20px; }
.pct b { font-family: var(--serif); font-size: 26px; color: var(--accent); }
.tracker .progress { height: 9px; }
.tracker-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ch-edit { display: inline-flex; gap: 6px; align-items: center; }
.ch-edit input { width: 100px !important; }
.extras-line { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.status-field { margin: 12px 0 0; max-width: 280px; }
.text-sec { margin: 22px 0; }
.text-sec h2 { font-size: 19px; margin-bottom: 6px; }
.prose { white-space: pre-wrap; margin: 0; line-height: 1.65; color: var(--text-2); }
.hist-mini { list-style: none; padding: 0; margin: 0; }
.hist-mini li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; flex-wrap: wrap; }

/* genres */
.genre-cloud { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 24px; }
.gcard { display: inline-flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 10px; border: 2px solid transparent; cursor: pointer; font-weight: 600; font-size: 14.5px; }
.gcard.active { border-color: currentColor; }
.gcount { font-size: 12px; background: rgba(255,255,255,.55); color: inherit; padding: 0 7px; border-radius: 999px; }
[data-theme="dark"] .gcount { background: rgba(0,0,0,.25); }
.genre-results { border-top: 1px solid var(--border); padding-top: 18px; }
.genre-results h2 { font-size: 22px; }
.inline-form { display: flex; gap: 8px; max-width: 520px; margin-bottom: 8px; }
.genre-table { list-style: none; padding: 0; margin: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.genre-table li { display: grid; grid-template-columns: 40px minmax(0,1fr) auto auto; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.genre-table li:last-child { border-bottom: 0; }
.gname { text-decoration: none; min-width: 0; }
.rename { display: flex; gap: 4px; min-width: 0; }
.color-cell { position: relative; }
.swatch { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border-strong); cursor: pointer; }
.swatch.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatches { position: absolute; z-index: 20; top: 32px; left: 0; display: grid; grid-template-columns: repeat(5, 26px); gap: 6px; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); }
@media (max-width: 640px) { .genre-table li { grid-template-columns: 34px minmax(0,1fr) auto; } .gused { grid-column: 2; grid-row: 2; margin-top: -6px; } .gactions { grid-row: 1 / span 2; grid-column: 3; display: flex; } }

/* history */
.hist-day { margin-bottom: 22px; }
.hist-day h2 { font-size: 16px; color: var(--text-2); margin-bottom: 8px; }
.hist-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.hist-list li { display: grid; grid-template-columns: 64px minmax(0, 220px) 1fr; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; align-items: baseline; }
.hist-list li:last-child { border-bottom: 0; }
.hist-time { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.hist-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.hist-title a { text-decoration: none; } .hist-title a:hover { text-decoration: underline; }
@media (max-width: 640px) { .hist-list li { grid-template-columns: 52px 1fr; } .hist-what { grid-column: 2; } }

/* settings */
.settings .panel h3 { font-size: 16px; margin-bottom: 4px; }
.theme-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 640px) { .theme-choices { grid-template-columns: 1fr; } }
.theme-choice { display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; }
.theme-choice.sel { border-color: var(--accent); background: var(--accent-soft); }
.theme-swatch { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border-strong); }
.ts-light { background: linear-gradient(135deg, #faf9f7 50%, #f0eee9 50%); }
.ts-dark { background: linear-gradient(135deg, #19191a 50%, #2a2a2c 50%); }
.ts-system { background: linear-gradient(135deg, #faf9f7 50%, #19191a 50%); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 0; }
.pw-form { display: flex; flex-direction: column; gap: 8px; max-width: 360px; margin-top: 12px; }
.usage { margin-top: 14px; }
.usage-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 500; margin-bottom: 5px; }
.usage-bar { height: 9px; background: var(--border); border-radius: 999px; overflow: hidden; }
.usage-bar div { height: 100%; background: var(--ok); border-radius: 999px; min-width: 3px; }
.usage-bar.warn div { background: var(--warn); } .usage-bar.bad div { background: var(--danger); }
.backup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px 24px; }
.backup-grid > div { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.backup-grid p { margin: 0 0 6px; }
.radio-cards { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.radio-card { display: grid; grid-template-columns: 24px 1fr; gap: 2px 8px; padding: 12px; border: 2px solid var(--border); border-radius: 10px; cursor: pointer; }
.radio-card span { grid-column: 2; }
.radio-card.sel { border-color: var(--accent); background: var(--accent-soft); }

/* auth */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: radial-gradient(ellipse at top, var(--accent-soft), var(--bg) 60%); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 480px; }
.auth-brand { font-family: var(--serif); font-size: 28px; font-weight: 600; text-align: center; margin-bottom: 18px; line-height: 1.2; }
.auth-card h1 { font-size: 19px; text-align: center; margin-bottom: 16px; color: var(--text-2); font-weight: 500; }
.auth-links { display: flex; justify-content: space-between; margin-top: 12px; flex-wrap: wrap; gap: 8px; font-size: 14px; }
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { padding-right: 42px !important; }
.pw-wrap .icon-btn { position: absolute; right: 4px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 24px)); }
@media (max-width: 899px) { .toasts { left: 12px; right: 12px; bottom: calc(var(--bottom-nav) + 12px + env(safe-area-inset-bottom)); max-width: none; } }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-radius: 11px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 14px; animation: up .2s ease-out; }
.toast-error { background: var(--danger); color: #fff; }
[data-theme="dark"] .toast-error { color: #1d1714; }
.toast-info { background: var(--accent); color: var(--on-accent); }
.toast-msg { flex: 1; }
.toast-btn { border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 7px; padding: 4px 10px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; }
.toast-x { border: 0; background: none; color: inherit; cursor: pointer; display: inline-flex; padding: 4px; opacity: .8; }

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