:root {
  --bg: #f3eee4;
  --surface: #fbf8f2;
  --ink: #1d1a15;
  --muted: #776f62;
  --line: #e0d8c9;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(40, 30, 10, .08), 0 8px 24px rgba(40, 30, 10, .08);
  --serif: ui-serif, "New York", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #211e18;
    --ink: #efe8dc;
    --muted: #a0978a;
    --line: #34302a;
    --accent: #8cc3ae;
    --accent-ink: #10201a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); }
body { min-height: 100dvh; padding-top: var(--safe-t); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(110px + var(--safe-b)); }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 20px; gap: 12px; }
.top h1 { font-family: var(--serif); font-size: 34px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.back { text-decoration: none; display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-size: 17px; padding: 8px 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); border-radius: 999px;
  padding: 12px 20px; font-weight: 600; font-size: 16px; min-height: 48px;
}
.btn.ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.btn:disabled { opacity: .5; }
.round { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }

/* ---------- library ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 24px 18px; }
.tile { color: inherit; text-decoration: none; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.tile-cover { aspect-ratio: 2 / 3; width: 100%; border-radius: 6px; object-fit: cover; box-shadow: var(--shadow); background: var(--surface); }
.tile-title { font-weight: 600; font-size: 15px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-sub { color: var(--muted); font-size: 13px; }
.bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.placeholder {
  aspect-ratio: 2 / 3; border-radius: 6px; box-shadow: var(--shadow); padding: 14px;
  background: linear-gradient(160deg, var(--accent), #1d3a32); color: #f3eee4;
  font-family: var(--serif); font-size: 17px; line-height: 1.2; display: flex; align-items: flex-end;
}
.empty { text-align: center; color: var(--muted); padding: 60px 20px; line-height: 1.5; }
.empty h2 { font-family: var(--serif); color: var(--ink); font-size: 24px; margin: 0 0 8px; }

/* ---------- book ---------- */
.hero { display: grid; grid-template-columns: 120px 1fr; gap: 18px; align-items: end; margin-bottom: 20px; }
.hero img, .hero .placeholder { width: 120px; border-radius: 6px; box-shadow: var(--shadow); }
.hero h1 { font-family: var(--serif); font-size: 26px; line-height: 1.15; margin: 0 0 6px; }
.hero .author { color: var(--muted); margin-bottom: 10px; }
.chip { display: inline-block; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); margin: 0 6px 6px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 22px; }
.actions .btn { flex: 1 1 200px; }
.card { background: var(--surface); border-radius: 14px; box-shadow: inset 0 0 0 1px var(--line); padding: 14px 16px; margin-bottom: 20px; }
.card summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.card summary::-webkit-details-marker { display: none; }
.card summary::after { content: "Upraviť"; color: var(--accent); font-weight: 500; }
.card[open] summary::after { content: "Zavrieť"; }
.card p { color: var(--muted); margin: 8px 0 0; line-height: 1.45; font-size: 15px; }
.field { display: block; margin-top: 14px; font-size: 14px; color: var(--muted); }
.field select, .field textarea {
  display: block; width: 100%; margin-top: 6px; font: 15px/1.4 var(--sans); color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.field textarea { min-height: 170px; resize: vertical; }
.row-btns { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

.section-title { font-family: var(--serif); font-size: 21px; margin: 8px 0 10px; }
.chapters { list-style: none; padding: 0; margin: 0; }
.chapter {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; width: 100%;
  text-align: left; padding: 14px 4px; border-bottom: 1px solid var(--line); min-height: 56px;
}
.chapter .n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.chapter .t { font-size: 16px; line-height: 1.3; }
.chapter .d { color: var(--muted); font-size: 13px; white-space: nowrap; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.chapter .d > span:first-child { display: flex; align-items: center; gap: 6px; }
.chapter .cost { font-size: 12px; font-variant-numeric: tabular-nums; }
.chapter.minor .t { color: var(--muted); }
.chapter.current .t { color: var(--accent); font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; }
.danger { color: #b3412f; margin-top: 28px; font-size: 15px; padding: 10px 0; }

/* ---------- mini player ---------- */
.mini {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + var(--safe-b)); z-index: 10;
  max-width: 740px; margin: 0 auto; display: grid; grid-template-columns: 44px 1fr 52px; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 16px; padding: 10px 10px 10px 12px; box-shadow: var(--shadow), inset 0 0 0 1px var(--line);
}
.mini img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--line); }
.mini-text { text-align: left; min-width: 0; display: flex; flex-direction: column; }
.mini-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mini-title { font-weight: 600; font-size: 15px; }
#mini-sub { color: var(--muted); font-size: 13px; }
.icon-btn { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn svg { width: 30px; height: 30px; fill: currentColor; stroke: none; }

/* ---------- full player ---------- */
.player {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto;
  padding: calc(12px + var(--safe-t)) 24px calc(24px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.player-close { align-self: center; color: var(--muted); padding: 6px 24px; }
.player-cover { width: min(64vw, 300px, 26dvh); aspect-ratio: 2 / 3; object-fit: cover; border-radius: 10px; box-shadow: var(--shadow); background: var(--surface); }
.player-meta { text-align: center; width: 100%; max-width: 520px; }
.player-chapter { font-family: var(--serif); font-size: 24px; font-weight: 700; line-height: 1.2; }
.player-book { color: var(--muted); margin-top: 6px; }
.scrub { width: 100%; max-width: 520px; }
.scrub input { width: 100%; accent-color: var(--accent); height: 32px; }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.player-status { min-height: 20px; color: var(--accent); font-size: 15px; text-align: center; }
.controls { display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%; max-width: 520px; }
.ctl { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; position: relative; }
.ctl svg { width: 30px; height: 30px; }
.ctl span { position: absolute; font-size: 10px; font-weight: 700; top: 50%; left: 50%; transform: translate(-50%, -38%); }
.ctl-main { width: 88px; height: 88px; background: var(--accent); color: var(--accent-ink); }
.ctl-main svg { width: 40px; height: 40px; fill: currentColor; stroke: none; }
.speed { font-weight: 700; font-size: 16px; padding: 10px 20px; border-radius: 999px; box-shadow: inset 0 0 0 1.5px var(--line); }

/* ---------- misc ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); padding: 24px; text-align: center; }
.overlay h2 { font-family: var(--serif); margin: 16px 0 6px; }
.overlay p { color: var(--muted); margin: 0; max-width: 320px; line-height: 1.45; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 16px; right: 16px; top: calc(12px + var(--safe-t)); z-index: 40; margin: 0 auto; max-width: 480px; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 15px; box-shadow: var(--shadow); }
.welcome { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.welcome-icon { width: 76px; height: 76px; border-radius: 18px; box-shadow: var(--shadow); }
.welcome h1 { font-family: var(--serif); font-size: 44px; letter-spacing: -.02em; margin: 18px 0 8px; }
.welcome-lead { color: var(--muted); font-size: 17px; line-height: 1.45; margin: 0 0 28px; }
.welcome-points { list-style: none; padding: 0; margin: 0 0 28px; text-align: left; display: grid; gap: 16px; }
.welcome-points li { display: grid; gap: 3px; padding-left: 18px; border-left: 2px solid var(--accent); }
.welcome-points b { font-size: 16px; }
.welcome-points span { color: var(--muted); font-size: 15px; line-height: 1.4; }
.welcome-hint { color: var(--muted); font-size: 13px; margin-top: 16px; }
.login input { width: 100%; font-size: 17px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); margin-bottom: 12px; }
.login .btn { width: 100%; }
.quiet { display: block; margin: 40px auto 0; color: var(--muted); font-size: 15px; padding: 10px; }
