:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --fg: #23201b;
  --muted: #776f63;
  --border: #e3ddd2;
  --accent: #8a4b2a;
  --accent-fg: #ffffff;
  --accent-soft: #f3e6dc;
  --ok: #2f7a4a;
  --warn: #9a6a12;
  --danger: #b03a32;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --surface: #211e18;
    --surface-2: #2a261f;
    --fg: #ece6db;
    --muted: #a69c8c;
    --border: #39342b;
    --accent: #d98e62;
    --accent-fg: #1b1610;
    --accent-soft: #3a2b20;
    --ok: #6cc08a;
    --warn: #e0b04f;
    --danger: #ec7d74;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin-top: 1.6em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.top-in { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 1.1rem; color: var(--fg); letter-spacing: 0.01em; }
.logo span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--muted); padding: 5px 10px; border-radius: 8px; }
.nav a:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--fg); }
.syncbox { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
@media (max-width: 640px) {
  .top-in { gap: 8px 12px; }
  .syncbox { margin-left: auto; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav a { white-space: nowrap; }
}
main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 60px; }
footer { max-width: 1120px; margin: 0 auto; padding: 0 16px 30px; color: var(--muted); font-size: 12px; }

/* ---------- элементы ---------- */
.btn, button {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
}
.btn:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.small, .btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; height: auto; }
input[type=text], input[type=search], input[type=password], input[type=number], select, textarea {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input[type=file] { font: inherit; max-width: 100%; }
label.f { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--fg); font-size: 13px; }
a.chip:hover { background: var(--accent-soft); text-decoration: none; }
.chip.on { background: var(--accent); color: var(--accent-fg); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.badge.reading { background: var(--accent-soft); color: var(--accent); }
.badge.done { color: var(--ok); }
.badge.dropped { color: var(--danger); }

.flash { border-radius: 8px; padding: 9px 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); }
.flash.error { border-color: var(--danger); color: var(--danger); }
.flash.warn { border-color: var(--warn); color: var(--warn); }
.flash.ok { border-color: var(--ok); }

/* ---------- список книг ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.tabs a:hover { text-decoration: none; }
.tabs .n { opacity: 0.7; font-size: 12px; margin-left: 4px; }
details.filters { margin-bottom: 16px; }
details.filters summary { cursor: pointer; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.book-card { display: block; color: var(--fg); }
.book-card:hover { text-decoration: none; }
.book-card:hover .cover { transform: translateY(-2px); box-shadow: 0 6px 18px rgb(0 0 0 / 0.15); }
.cover {
  aspect-ratio: 2 / 3; width: 100%; border-radius: 6px; overflow: hidden; position: relative;
  background: var(--surface-2); box-shadow: var(--shadow); transition: transform 0.15s, box-shadow 0.15s;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; padding: 14px;
  /* each book its own colour, like spines on a shelf */
  background: linear-gradient(160deg, hsl(var(--h, 25) 45% 86%), hsl(calc(var(--h, 25) + 25) 35% 74%));
  color: hsl(var(--h, 25) 40% 18%);
  font-weight: 600; line-height: 1.25; word-break: break-word;
}
.cover .ph small { font-weight: 400; opacity: 0.7; margin-top: 6px; }
@media (prefers-color-scheme: dark) {
  .cover .ph { background: linear-gradient(160deg, hsl(var(--h, 25) 30% 30%), hsl(calc(var(--h, 25) + 25) 25% 20%)); color: hsl(var(--h, 25) 40% 90%); }
}
.cover .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgb(0 0 0 / 0.25); }
.cover .bar i { display: block; height: 100%; background: var(--accent); }
.book-card .t { margin-top: 8px; font-weight: 600; font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card .a { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--muted); padding: 50px 10px; }

/* ---------- книга ---------- */
.book { display: grid; grid-template-columns: 240px 1fr; gap: 28px; align-items: start; }
.book .side .cover { max-width: 240px; }
@media (max-width: 720px) {
  .book { grid-template-columns: 1fr; }
  .book .side .cover { max-width: 180px; margin: 0 auto; }
}
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); }
.files li { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain > li + li { margin-top: 6px; }
.desc { white-space: pre-wrap; }

/* ---------- заметки ---------- */
.note { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; }
.note.removed { opacity: 0.55; border-left-color: var(--border); }
.note blockquote { margin: 0; font-style: italic; }
.note .meta { color: var(--muted); font-size: 12px; }
.note .text { white-space: pre-wrap; margin-top: 4px; }
.note details summary { cursor: pointer; color: var(--muted); font-size: 13px; }

/* ---------- сводка и проверка ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat b { display: block; font-size: 1.6rem; }
.bars .b { display: grid; grid-template-columns: 80px 1fr 36px; gap: 8px; align-items: center; font-size: 13px; }
.bars .b i { display: block; height: 10px; border-radius: 4px; background: var(--accent); }
.lvl-error { color: var(--danger); }
.lvl-warn { color: var(--warn); }

/* ---------- вход ---------- */
.login { max-width: 340px; margin: 12vh auto 0; }

/* ---------- ссылки между приложениями (static/suite.js) ---------- */
a.suite-link { color: var(--fg); font-weight: 500; background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 2px; padding: 0 0.3em; }
a.suite-link:hover { background: var(--accent-soft); text-decoration: none; }
a.suite-link.gone { color: var(--muted); text-decoration: line-through; }
a.suite-link .st { margin-left: 0.3em; font-size: 0.8em; font-weight: 400; color: var(--muted); }
.suite-wrap { position: relative; }
.suite-pop { position: absolute; z-index: 30; width: min(22rem, 90vw); max-height: 16rem; overflow-y: auto; margin: 0; padding: 4px 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; }
.suite-pop li { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; cursor: pointer; }
.suite-pop li[aria-selected="true"] { background: var(--accent-soft); }
.suite-pop i, .backlinks i { width: 8px; height: 8px; border-radius: 50%; flex: none; align-self: center; display: inline-block; }
.suite-pop .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suite-pop .k { color: var(--muted); font-size: 12px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backlinks a { display: inline-flex; align-items: baseline; gap: 6px; }
.backlinks .ctx { padding-left: 14px; }
