:root {
  --bg: #f7f3ec; --paper: #fffdf8; --ink: #2a2622; --muted: #7a7168; --line: #e6dfd3;
  --accent: #e0902b; --accent-ink: #fff; --accent-soft: #fbecd6; --q: #3b6fb6; --note: #4f8a5b; --danger: #b8463c;
  --shadow: 0 6px 24px rgba(60, 40, 10, .12); --radius: 14px;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --read: "Literata", Georgia, serif;
}
[data-theme="dark"] {
  --bg: #17150f; --paper: #1f1c16; --ink: #e9e2d6; --muted: #9b9184; --line: #343027;
  --accent: #f0a443; --accent-ink: #1d1407; --accent-soft: #3a2c17; --q: #7fa6e0; --note: #85bf8f;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 15px; }
a { color: var(--accent); }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 10px; padding: 8px 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-danger { color: var(--danger); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }

/* page shell */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 20px; }
.brand { font-weight: 700; font-size: 20px; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px var(--accent); }
.spacer { flex: 1; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px 60px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.flash { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.muted { color: var(--muted); }
h1 { font-size: 26px; margin: 10px 0 18px; }
h2 { font-size: 18px; margin: 0 0 8px; }

/* login */
.auth { max-width: 380px; margin: 8vh auto; }
.legal-links { text-align: center; font-size: 13px; margin: 18px 0; }
.legal { max-width: 760px; margin: 10px auto 40px; line-height: 1.6; }
.legal h2 { font-size: 18px; margin: 24px 0 6px; }
.legal li { margin: 4px 0; }

/* library */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.book { display: flex; flex-direction: column; gap: 10px; color: var(--ink); }
.book .open { display: flex; flex-direction: column; gap: 6px; flex: 1; text-decoration: none; color: var(--ink); }
.book .cover { position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; margin-bottom: 4px;
  background: linear-gradient(150deg, var(--accent), #b8641a); box-shadow: 0 4px 14px rgba(60, 40, 10, .18); }
.book .cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.book .cover-fallback { position: absolute; inset: 0; padding: 18px 14px; color: #fff; font-family: var(--read);
  font-weight: 600; font-size: 18px; line-height: 1.25; display: flex; align-items: flex-end; }
.book .fin-link { font-size: 13px; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.book .t { font-weight: 650; font-family: var(--read); font-size: 17px; line-height: 1.25; }
.progress { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: auto; }
.progress span { display: block; height: 100%; background: var(--accent); }
.upload { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.upload input[type=file] { width: auto; flex: 1; min-width: 200px; }

/* settings */
.keyrow { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; align-items: center; margin: 6px 0; }
.keyrow .saved { color: var(--note); font-size: 13px; white-space: nowrap; }
table.usage { width: 100%; border-collapse: collapse; font-size: 14px; }
table.usage td, table.usage th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
@media (max-width: 560px) { .keyrow { grid-template-columns: 1fr; } }

@media (max-width: 480px) { .topbar { gap: 6px; padding: 12px; } .topbar .btn { padding: 6px 10px; font-size: 14px; white-space: nowrap; } }

/* library upload: many books, drag and drop, progress per file */
.upload { margin-bottom: 18px; }
.drop { position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; margin: 0; padding: 18px 12px;
  border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; color: var(--ink); font-size: 15px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .ph { font-size: 30px; color: var(--accent); }
.drop .muted { font-size: 13px; }
.upload .drop input { position: absolute; width: 1px; height: 1px; min-width: 0; opacity: 0; }
.up-list { width: 100%; list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.up-list li { display: grid; grid-template-columns: 1fr 90px; gap: 2px 10px; font-size: 14px; }
.up-list .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-list .bar { grid-column: 2; grid-row: 1; align-self: center; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.up-list .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-list .s { grid-column: 1 / -1; font-size: 12px; }
.up-list li.ok .s { color: var(--note); } .up-list li.bad .s { color: var(--danger); }

/* library: folders and tags */
.libbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.libbar .spacer { flex: 1; }
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 15px; }
.crumbs a { text-decoration: none; color: var(--ink); padding: 4px 8px; border-radius: 8px; display: inline-flex; align-items: center; gap: 5px; }
.crumbs a:hover, .crumbs a.on { background: var(--accent-soft); }
.crumbs > span { color: var(--muted); }
.crumbs b { padding: 4px 2px; }
.libbar button { display: inline-flex; align-items: center; gap: 6px; }
.tagbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 0 0 14px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px;
  font-size: 13px; color: var(--ink); text-decoration: none; background: var(--paper); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.small { font-size: 11px; padding: 1px 7px; background: var(--accent-soft); border-color: transparent; }
.booktags { display: flex; gap: 4px; flex-wrap: wrap; }
.book, .folder { position: relative; }
.book .more, .folder .more { position: absolute; top: 8px; right: 8px; z-index: 2; padding: 2px 8px; font-size: 18px; line-height: 1;
  border-radius: 8px; background: var(--paper); border: 1px solid var(--line); }
.book.dragging { opacity: .45; }
.folder .open { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink); height: 100%; }
.folder .ph-folder { font-size: 64px; color: var(--accent); }
.folder .t { font-weight: 650; font-size: 16px; line-height: 1.25; padding-right: 30px; }
.drop-on { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--accent-soft) !important; }
.dlg { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(420px, 92vw); background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0, 0, 0, .3); }
.dlg form { display: flex; flex-direction: column; gap: 12px; }
.dlg label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.dlg .row { display: flex; gap: 8px; align-items: center; }
.dlg .spacer { flex: 1; }
.dlg .danger { color: var(--danger); display: inline-flex; align-items: center; gap: 5px; }
.dlg .small { font-size: 12px; margin: 0; }
.tagpick { display: flex; gap: 6px; flex-wrap: wrap; }
.shelf > p.muted { grid-column: 1 / -1; }
.dlg .dlg-title { font-size: 16px; }
.dlg .dlg-text { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.dlg .btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
/* library: covers only (the cover already shows title and author) */
.hide-titles .book .t, .hide-titles .book .au { display: none; }
.flag-row { border-top: 1px solid var(--line); padding: 10px 0; }
.flag-row p { margin: 4px 0; }
.flag-row pre { white-space: pre-wrap; font-size: 13px; background: var(--bg); padding: 8px; border-radius: 8px; max-height: 300px; overflow: auto; }
