:root {
  --bg: #121418;
  --surface: #1b1e24;
  --surface-2: #242831;
  --line: #2e333d;
  --text: #ecebe6;
  --muted: #9a9ca3;
  --accent: #f2a93b;
  --accent-ink: #1a1307;
  --ok: #5cc98a;
  --warn: #e7b04a;
  --err: #ef6b6b;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f2ec; --surface: #ffffff; --surface-2: #efebe3; --line: #e0dbd1;
    --text: #1f1d1a; --muted: #6f6a62; --accent: #c7771a; --accent-ink: #ffffff;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { min-height: 100vh; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

header.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
header.top h1 { font-family: var(--serif); font-size: 20px; margin: 0; flex: 1; font-weight: 600; }
header.top h1 a { color: var(--text); text-decoration: none; }
.nav-btn { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.nav-btn.badge { position: relative; }
.nav-btn .count { background: var(--err); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 12px; margin-left: 4px; }

main { max-width: 900px; margin: 0 auto; padding: 16px 16px 140px; }
h2 { font-family: var(--serif); font-weight: 600; margin: 8px 0 16px; }
h3 { margin: 24px 0 10px; font-size: 16px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.auth { max-width: 380px; margin: 8vh auto 0; }
.auth h2 { text-align: center; }
.auth p.lead { text-align: center; color: var(--muted); margin-top: -8px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=url], select {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--err); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.msg { margin-top: 12px; font-size: 14px; min-height: 1em; }
.msg.err { color: var(--err); } .msg.ok { color: var(--ok); }
.muted { color: var(--muted); }
.center { text-align: center; }

/* библиотека */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.book { cursor: pointer; text-decoration: none; color: var(--text); }
.cover { aspect-ratio: 2/3; border-radius: 10px; overflow: hidden; background: var(--surface-2); position: relative;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .gen { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 14px;
  font-family: var(--serif); color: #fff; }
.cover .gen b { font-size: 17px; line-height: 1.2; }
.cover .gen small { opacity: .85; font-size: 12px; }
.cover .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.35); }
.cover .bar i { display: block; height: 100%; background: var(--accent); }
.cover .tag { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 3px 7px; border-radius: 6px; }
.book .t { font-weight: 600; margin-top: 8px; font-size: 14px; line-height: 1.3; }
.book .a { color: var(--muted); font-size: 13px; }

.continue { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; cursor: pointer; }
.continue .cover { width: 72px; flex: none; }
.continue .info { flex: 1; min-width: 0; }
.continue .info b { display: block; font-family: var(--serif); font-size: 18px; }

/* книга / плейър */
.book-head { display: flex; gap: 18px; align-items: flex-end; }
.book-head .cover { width: 130px; flex: none; }
.book-head h2 { margin: 0 0 4px; font-size: 24px; }
.player { margin-top: 20px; }
.player .now { font-weight: 600; margin-bottom: 10px; }
.seek { width: 100%; accent-color: var(--accent); height: 28px; }
.times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.controls { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 14px 0; }
.ctl { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.ctl.play { width: 72px; height: 72px; background: var(--accent); color: var(--accent-ink); border: none; }
.ctl svg { width: 26px; height: 26px; fill: currentColor; }
.ctl.play svg { width: 34px; height: 34px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:last-child { border-bottom: none; }
.list li.cur { color: var(--accent); font-weight: 600; }
.list li.dis { opacity: .45; cursor: default; }
.list .n { width: 28px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.list .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list .d { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }

/* мини плейър */
.mini { position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 20; max-width: 884px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.mini img, .mini .ph { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; }
.mini .txt { flex: 1; min-width: 0; cursor: pointer; }
.mini .txt b, .mini .txt span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini .txt span { font-size: 12px; color: var(--muted); }
.mini .ctl { width: 44px; height: 44px; }
.mini .prog { position: absolute; left: 16px; right: 16px; bottom: 3px; height: 2px; background: var(--line); border-radius: 2px; overflow: hidden; }
.mini .prog i { display: block; height: 100%; background: var(--accent); }

/* админ */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.pill.ready, .pill.approved { color: var(--ok); } .pill.processing, .pill.queued, .pill.pending { color: var(--warn); }
.pill.error, .pill.rejected { color: var(--err); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.progressbar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progressbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
pre.logs { margin: 0; max-height: 360px; overflow: auto; background: var(--surface-2); border-radius: 10px; padding: 12px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.code-new { margin-top: 16px; padding: 16px; border-radius: 12px; border: 1px dashed var(--accent); text-align: center;
  background: color-mix(in srgb, var(--accent) 8%, transparent); }
.code-big { font: 700 34px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .08em; margin: 6px 0 10px; color: var(--accent); }
.code-mono { white-space: nowrap; font: 600 15px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .05em; }
.code-input { font: 600 20px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; letter-spacing: .12em; text-transform: uppercase; text-align: center; }
.pill.inv-active { color: var(--ok); } .pill.inv-used { color: var(--muted); } .pill.inv-expired, .pill.inv-revoked { color: var(--err); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.worker-status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; padding: 10px 14px;
  margin-bottom: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.worker-status .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ok); }
.worker-status.warn .dot { background: var(--warn); } .worker-status.err .dot { background: var(--err); }
.worker-status.err { border-color: var(--err); }
.worker-status code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 20px rgba(0,0,0,.3); font-size: 14px; }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .book-head .cover { width: 100px; }
  .book-head h2 { font-size: 20px; }
  .two { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
