:root {
  --bg: #faf6f1; --card: #ffffff; --text: #3b2f2a; --muted: #8a7b73;
  --accent: #8d6e63; --error: #b3261e; --ok: #2e7d32; --field: #f1ebe5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1b18; --card: #2a2421; --text: #f0e6df; --muted: #a89b93;
    --accent: #bc9f93; --error: #f2b8b5; --ok: #a5d6a7; --field: #362f2b;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; display: grid; place-items: center;
  background: var(--bg); color: var(--text);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
}
.card {
  width: min(420px, 92vw); background: var(--card); border-radius: 24px;
  padding: 28px; box-shadow: 0 6px 24px rgba(0, 0, 0, .08);
}
h1 { margin: 0 0 6px; font-size: 26px; }
p.sub { margin: 0 0 20px; color: var(--muted); }
label { display: block; margin: 12px 0 6px; font-size: 14px; color: var(--muted); }
input {
  width: 100%; padding: 13px 14px; border: 0; border-radius: 14px;
  background: var(--field); color: var(--text); font-size: 16px;
}
button {
  width: 100%; margin-top: 18px; padding: 14px; border: 0; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 16px; cursor: pointer;
}
button.link {
  background: none; color: var(--accent); margin-top: 10px; padding: 8px; width: auto;
}
.msg { margin-top: 14px; min-height: 20px; font-size: 14px; }
.msg.error { color: var(--error); }
.msg.ok { color: var(--ok); }
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  background: var(--field); font-size: 13px; color: var(--accent);
}
.hidden { display: none; }
a { color: var(--accent); }

/* ===== Широкие страницы (каталог, админка) ===== */
body.wide { display: block; place-items: initial; }
.container { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }

nav.top {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  padding: 14px 20px; background: var(--card);
  box-shadow: 0 2px 14px rgba(0, 0, 0, .06);
}
nav.top a { text-decoration: none; color: var(--text); font-weight: 600; }
nav.top a:hover { color: var(--accent); }
nav.top .spacer { flex: 1; }

.search { margin: 8px 0 20px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }

.book {
  display: block; text-decoration: none; color: inherit; background: var(--card);
  border-radius: 20px; overflow: hidden; box-shadow: 0 4px 18px rgba(0, 0, 0, .06);
  transition: transform .15s;
}
.book:hover { transform: translateY(-3px); }
.book .info { padding: 12px 14px 16px; }
.book .title { font-weight: 700; margin-bottom: 4px; }
.book .author { color: var(--muted); font-size: 14px; }

.cover {
  aspect-ratio: 2 / 3; width: 100%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--field));
  color: #fff; font-size: 48px; font-weight: 700; object-fit: cover;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.panel { background: var(--card); border-radius: 24px; padding: 22px; margin-bottom: 24px; box-shadow: 0 4px 18px rgba(0,0,0,.06); }
textarea {
  width: 100%; padding: 13px 14px; border: 0; border-radius: 14px; min-height: 90px;
  background: var(--field); color: var(--text); font-size: 16px; font-family: inherit;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--field); }
button.danger { background: var(--error); width: auto; margin: 0; padding: 8px 14px; font-size: 14px; }
button.secondary { background: var(--field); color: var(--text); }
.detail { display: grid; gap: 24px; grid-template-columns: 220px 1fr; }
@media (max-width: 640px) { .detail { grid-template-columns: 1fr; } }

/* ===== Этап 3 ===== */
.book { position: relative; }
.book a.booklink { display: block; color: inherit; text-decoration: none; }
.book .actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
button.icon {
  width: 36px; height: 36px; padding: 0; margin: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .92); color: #777; font-size: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
button.icon.on { background: var(--accent); color: #fff; }
.muted { color: var(--muted); font-size: 13px; }
.stars-text { color: #f5b301; letter-spacing: 2px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 20px; }
button.chip {
  width: auto; margin: 0; padding: 8px 16px; border-radius: 999px; font-size: 14px;
  background: var(--field); color: var(--text);
}
button.chip.on { background: var(--accent); color: #fff; }
.review { border-bottom: 1px solid var(--field); padding: 14px 0; }
.review .head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.review p { margin: 6px 0 0; white-space: pre-wrap; }
button.small { width: auto; margin: 0; padding: 4px 10px; font-size: 13px; }

.modal-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: grid; place-items: center; z-index: 50; padding: 16px;
}
.modal {
  width: min(440px, 100%); max-height: 90vh; overflow: auto;
  background: var(--card); border-radius: 24px; padding: 24px;
}
.modal h2 { margin: 0 0 4px; }
.pick { display: flex; gap: 4px; font-size: 34px; line-height: 1; }
.pick span { cursor: pointer; color: var(--muted); opacity: .35; }
.pick span.on { color: #f5b301; opacity: 1; }

/* ===== Этап 4 ===== */
.goal { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.ring {
  --p: 0; width: 120px; height: 120px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--field) 0);
}
.ring > div {
  width: 92px; height: 92px; border-radius: 50%; background: var(--card);
  display: grid; place-items: center; text-align: center;
  font-weight: 700; font-size: 22px; line-height: 1.15;
}
.badge.warn { background: #fff0cf; color: #8a5a00; }
.badge.bad { background: #fde7e5; color: var(--error); }
.badge.good { background: #e3f3e4; color: #2e7d32; }
.book .info .badge { margin-top: 6px; }
.pending-item { display: flex; gap: 16px; flex-wrap: wrap; }
.pending-item img { width: 90px; height: 135px; object-fit: cover; border-radius: 12px; }
.pending-item .body { flex: 1; min-width: 220px; }
.pending-item .btns { display: flex; gap: 10px; margin-top: 10px; }
.pending-item .btns button { width: auto; margin: 0; padding: 10px 18px; }

/* ===== Часть 1: профиль и аватар ===== */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--accent); color: #fff; font-weight: 700;
  display: inline-grid; place-items: center; vertical-align: middle;
}
.avatar.big { width: 110px; height: 110px; font-size: 44px; }
nav.top a.me { display: inline-flex; align-items: center; gap: 8px; }
.profile-head { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.profile-head .btns { display: flex; gap: 10px; flex-wrap: wrap; }
.profile-head .btns button { width: auto; margin: 0; padding: 10px 18px; }

/* ===== Часть 2: друзья ===== */
.dot {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: #c62828; color: #fff; font-size: 12px; margin-left: 4px;
}
.person {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--field); flex-wrap: wrap;
}
.person .name { flex: 1; min-width: 140px; font-weight: 700; color: var(--text); text-decoration: none; }
a.name:hover { color: var(--accent); }
.person .btns { display: flex; gap: 8px; align-items: center; }
.person .btns button { width: auto; margin: 0; padding: 8px 14px; font-size: 14px; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 18px 0; }
.stat { background: var(--field); border-radius: 18px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 28px; }
.stat span { color: var(--muted); font-size: 13px; }

/* ===== Часть 3: поделиться ===== */
.share-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
a.share-btn, button.share-btn {
  flex: 1; min-width: 120px; width: auto; margin: 0; padding: 12px 14px;
  border: 0; border-radius: 14px; text-align: center; font-size: 15px;
  color: #fff; text-decoration: none; cursor: pointer;
}
a.share-btn.tg { background: #229ed9; }
a.share-btn.vk { background: #0077ff; }
button.share-btn.copy { background: var(--field); color: var(--text); }

/* ===== Часть 4: админка и красивые кнопки ===== */
button { transition: filter .15s, transform .1s, box-shadow .15s; }
button:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 4px 12px rgba(0, 0, 0, .15); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button.danger { background: #c62828; color: #fff; }
button.success { background: #2e7d32; color: #fff; }
button.sm {
  width: auto; margin: 0; padding: 8px 14px; font-size: 14px; border-radius: 12px;
}
button.link:hover { box-shadow: none; text-decoration: underline; }
button.icon:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }

nav.top a { padding: 6px 12px; border-radius: 12px; transition: background .15s; }
nav.top a:hover { background: var(--field); color: var(--text); }

a.button {
  display: inline-block; padding: 12px 20px; border-radius: 14px;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 600;
  transition: filter .15s, transform .1s;
}
a.button:hover { filter: brightness(1.08); transform: translateY(-1px); }
a.button.secondary { background: var(--field); color: var(--text); }
.btn-links { display: flex; gap: 12px; flex-wrap: wrap; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn-row button { flex: 1; margin: 0; min-width: 140px; }
.btn-row.compact { margin-top: 10px; }
.btn-row.compact button { flex: none; min-width: 0; }

/* плитки сводки */
.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin: 20px 0 28px; }
.tile {
  display: block; text-decoration: none; color: var(--text); background: var(--card);
  border-radius: 22px; padding: 20px; box-shadow: 0 4px 18px rgba(0, 0, 0, .06);
}
a.tile { transition: transform .15s; }
a.tile:hover { transform: translateY(-3px); }
.tile .num { font-size: 40px; font-weight: 800; line-height: 1.1; }
.tile .lbl { color: var(--muted); font-size: 14px; margin-top: 4px; }
.tile.alert { background: linear-gradient(135deg, #ef8f00, #f5b301); color: #fff; }
.tile.alert .lbl { color: rgba(255, 255, 255, .92); font-weight: 600; }

/* таблица книг и список пользователей */
.thumb {
  width: 44px; height: 66px; border-radius: 8px; object-fit: cover; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--field));
  color: #fff; display: grid; place-items: center; font-weight: 700;
}
img.thumb { display: block; }
td.actions-cell { white-space: nowrap; }
td.actions-cell button + button { margin-left: 6px; }
.urow {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 14px 0; border-bottom: 1px solid var(--field);
}
.urow .main { flex: 1; min-width: 220px; }
.urow .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.urow.blocked { opacity: .65; }
details.panel > summary { cursor: pointer; font-weight: 700; font-size: 18px; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }

/* окно редактирования книги */
.modal.wide { width: min(660px, 100%); }
.cover-edit { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.cover-edit .preview {
  width: 90px; height: 135px; border-radius: 12px; object-fit: cover; display: grid;
  place-items: center; text-align: center; font-size: 12px; color: var(--muted); background: var(--field);
}

/* ===== Часть 6: подвал, поддержка ===== */
body.wide { display: flex; flex-direction: column; min-height: 100vh; }
body.wide > .container { width: 100%; flex: 1 0 auto; }
body:not(.wide) { grid-template-rows: 1fr auto; }

.site-footer {
  display: flex; gap: 10px 26px; justify-content: center; flex-wrap: wrap;
  width: 100%; margin-top: 30px; padding: 22px 16px;
  border-top: 1px solid var(--field); color: var(--muted); font-size: 14px;
}
body:not(.wide) .site-footer { grid-column: 1 / -1; margin-top: 0; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
select {
  width: 100%; padding: 13px 14px; border: 0; border-radius: 14px;
  background: var(--field); color: var(--text); font-size: 16px; font-family: inherit;
}
.counter { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }
.badge.kind-problem { background: #fde7e5; color: #b3261e; }
.badge.kind-suggestion { background: #e3f3e4; color: #2e7d32; }
.prose { line-height: 1.65; }
.prose h2 { margin-top: 28px; }
.draft { border: 2px dashed var(--field); border-radius: 16px; padding: 14px 18px; color: var(--muted); }
.msg-text { white-space: pre-wrap; margin: 10px 0; }

/* ===== Логотип ===== */
.brand { display: inline-flex; align-items: center; gap: 10px; }
img.logo { height: 34px; width: auto; display: block; }   /* в меню */
img.logo.big { height: 58px; }                             /* на странице входа */
h1.brand { gap: 14px; justify-content: center; width: 100%; }

/* ===== Часть 7: фильтры каталога ===== */
.filters {
  display: grid; gap: 14px; align-items: end; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.filters label { margin-top: 0; }
.filters .f-wide { grid-column: 1 / -1; }
.filters button { margin: 0; }