:root {
  --bg: #1d1a17;
  --surface: #2a2622;
  --surface-2: #36312c;
  --text: #f4eee6;
  --muted: #b3a99c;
  --accent: #e0a458;
  --accent-ink: #1d1a17;
  --line: #463f38;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

#view { max-width: 920px; margin: 0 auto; padding: 24px 16px calc(120px + var(--safe-b)); }

/* ---------- Вход ---------- */
.login { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 16px; }
.login h1 { font-size: 34px; margin-bottom: 8px; }
.login label { display: grid; gap: 6px; color: var(--muted); font-size: 16px; }
.login input {
  font: inherit; font-size: 20px; color: var(--text);
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px;
  padding: 14px 16px;
}
.login input:focus { border-color: var(--accent); outline: none; }
.btn {
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 20px;
  border-radius: 14px; padding: 16px 20px; text-align: center;
}
.btn:disabled { opacity: .6; }
.error { color: #ff9b8a; min-height: 1.4em; margin: 0; }

/* ---------- Библиотека ---------- */
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.top h1 { font-size: 30px; }
.link { color: var(--muted); font-size: 16px; padding: 8px; }

.continue {
  display: grid; grid-template-columns: 120px 1fr; gap: 18px; align-items: center;
  width: 100%; text-align: left; background: var(--surface); border-radius: var(--radius);
  padding: 16px; margin-bottom: 32px;
}
.continue img { width: 120px; aspect-ratio: 1; object-fit: cover; border-radius: 12px; }
.continue .label { color: var(--accent); font-weight: 700; font-size: 15px; text-transform: uppercase; letter-spacing: .04em; }
.continue h2 { font-size: 24px; margin: 4px 0; }
.continue .sub { color: var(--muted); font-size: 16px; }
.continue .go {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  border-radius: 999px; padding: 10px 18px;
}
.continue .go svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }

.section-title { font-size: 20px; color: var(--muted); margin: 0 0 14px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 18px; }
.card { text-align: left; display: grid; gap: 8px; }
.card img, .cover-ph {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 14px;
  background: var(--surface-2); box-shadow: 0 6px 18px rgb(0 0 0 / .35);
}
.cover-ph { display: grid; place-items: center; padding: 12px; text-align: center; font-weight: 700; color: var(--muted); }
.card .t { font-weight: 650; font-size: 17px; line-height: 1.25; }
.card .a { color: var(--muted); font-size: 15px; }
.bar { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* ---------- Страница на книга ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); padding: 8px 0; margin-bottom: 12px; }
.back svg { width: 22px; height: 22px; }
.book-head { display: grid; gap: 20px; }
@media (min-width: 640px) { .book-head { grid-template-columns: 260px 1fr; align-items: end; } }
.book-head img, .book-head .cover-ph { width: min(260px, 70vw); aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); box-shadow: 0 10px 30px rgb(0 0 0 / .45); }
.book-head h1 { font-size: 30px; }
.book-head .meta { color: var(--muted); margin: 6px 0 0; }
.langs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.lang { border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; font-size: 16px; }
.lang[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.book-head .btn { display: inline-flex; align-items: center; gap: 10px; margin-top: 18px; }
.book-head .btn svg { width: 22px; height: 22px; fill: currentColor; stroke: none; }
.resume-note { color: var(--muted); font-size: 16px; margin: 8px 0 0; }

.chapter-list { list-style: none; margin: 28px 0 0; padding: 0; }
.chapter-list li + li { border-top: 1px solid var(--line); }
.chapter-list button { width: 100%; display: flex; gap: 14px; align-items: center; text-align: left; padding: 16px 4px; font-size: 18px; }
.chapter-list .n { color: var(--muted); min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
.chapter-list .current { color: var(--accent); font-weight: 700; }
.chapter-list .current .n { color: var(--accent); }

/* ---------- Мини-плейър ---------- */
.mini {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b));
  max-width: 896px; margin: 0 auto;
  display: grid; grid-template-columns: 52px 1fr 52px; gap: 12px; align-items: center;
  background: var(--surface-2); border-radius: 16px; padding: 8px; text-align: left;
  box-shadow: 0 8px 30px rgb(0 0 0 / .5);
}
.mini[hidden] { display: none; }
.mini img { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; }
.mini-text { display: grid; min-width: 0; }
.mini-title, .mini-chapter { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-title { font-weight: 650; font-size: 16px; }
.mini-chapter { color: var(--muted); font-size: 14px; }
.mini-toggle { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.mini-toggle svg { width: 24px; height: 24px; fill: currentColor; stroke: none; }

/* ---------- Плейър на цял екран ---------- */
.player {
  position: fixed; inset: 0; z-index: 10; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: max(12px, env(safe-area-inset-top)) 20px calc(20px + var(--safe-b));
  overflow-y: auto;
}
.player[hidden] { display: none; }
.player-top { width: 100%; max-width: 520px; display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; }
.player-book { text-align: center; color: var(--muted); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; }
.icon-btn:active { background: var(--surface); }
.player-cover {
  width: min(82vw, 380px, 42dvh); aspect-ratio: 1; object-fit: cover;
  border-radius: 20px; box-shadow: 0 16px 40px rgb(0 0 0 / .55); background: var(--surface-2);
  margin-top: 8px;
}
.player-info { text-align: center; max-width: 520px; }
.player-info h2 { font-size: 24px; }
.player-info p { color: var(--muted); margin: 6px 0 0; }

.seek { width: 100%; max-width: 520px; }
.seek input { width: 100%; height: 36px; margin: 0; accent-color: var(--accent); }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }

.controls { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; max-width: 520px; }
.ctl { position: relative; width: 68px; height: 68px; display: grid; place-items: center; border-radius: 50%; }
.ctl:active { background: var(--surface); }
.ctl svg { width: 38px; height: 38px; }
.ctl span { position: absolute; font-size: 12px; font-weight: 800; top: 50%; left: 50%; transform: translate(-50%, -38%); }
.ctl-sm svg { width: 28px; height: 28px; }
.ctl-sm svg path:last-child { fill: currentColor; }
.ctl-play { width: 92px; height: 92px; background: var(--accent); color: var(--accent-ink); }
.ctl-play:active { background: var(--accent); filter: brightness(.9); }
.ctl-play svg { width: 40px; height: 40px; fill: currentColor; stroke: none; }

.extras { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.pill { background: var(--surface); border-radius: 999px; padding: 12px 20px; font-size: 17px; }
.pill.on { color: var(--accent); font-weight: 700; }

.sheet {
  position: fixed; inset: auto 0 0 0; max-height: 75dvh; overflow-y: auto; z-index: 11;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 12px 20px calc(20px + var(--safe-b));
  box-shadow: 0 -10px 40px rgb(0 0 0 / .5);
}
.sheet[hidden] { display: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -12px; background: var(--surface); padding-top: 4px; }
.sheet .chapter-list { margin-top: 4px; }

.empty { color: var(--muted); text-align: center; margin-top: 15vh; }
