:root {
  --bg: #ffffff;
  --bg-soft: #f4f4f6;
  --surface: #ffffff;
  --text: #0b0b0c;
  --muted: #6b6b73;
  --line: #e8e8ec;
  --accent: #5b4cf0;
  --accent-soft: #eeecfe;
  --accent-text: #ffffff;
  --mark: #fff1a8;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 16, 24, .06), 0 2px 8px rgba(16, 16, 24, .05);
  --shadow-book: 0 2px 4px rgba(16, 16, 24, .08), 0 14px 32px -8px rgba(16, 16, 24, .35);
  --reader-size: 19px;
  --reader-leading: 1.7;
  --reader-font: "Literata", Georgia, serif;
  --ui-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
/* Motivy čtečky – výchozí je čistě bílá s černým textem */
:root[data-theme="sepia"] {
  --bg: #f8f1e3; --bg-soft: #efe5d0; --surface: #fbf6ea; --text: #2b2216; --muted: #7d6c55; --line: #e5d8bd; --mark: #f1d97c;
}
:root[data-theme="dark"] {
  --bg: #0e0e10; --bg-soft: #1a1a1e; --surface: #16161a; --text: #ececf0; --muted: #9a9aa3; --line: #26262c;
  --accent: #9d93ff; --accent-soft: #24223d; --accent-text: #0e0e10; --mark: #5c4f12;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow-book: 0 14px 32px -8px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--ui-font); font-size: 16px; line-height: 1.5; letter-spacing: -.005em;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px 56px; }

/* ---------- Horní lišta ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + var(--safe-top)) 12px 8px 20px; min-height: 60px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.8) blur(20px); -webkit-backdrop-filter: saturate(1.8) blur(20px);
  transition: transform .3s cubic-bezier(.2,.8,.2,1), box-shadow .2s;
}
.topbar.scrolled { box-shadow: 0 1px 0 var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.brand img { border-radius: 9px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; font-weight: 600; font-size: 15px; color: var(--text);
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn:active { transform: scale(.94); }
.bar-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ---------- Knihovna ---------- */
.greeting { margin: 12px 0 18px; }
.greeting h1 { font-size: clamp(30px, 8vw, 44px); line-height: 1.05; letter-spacing: -.035em; margin: 0; font-weight: 750; }
.greeting p { margin: 6px 0 0; color: var(--muted); }

.search { position: relative; margin: 0 0 8px; }
.search .i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 20px; height: 20px; }
.search input {
  width: 100%; height: 52px; padding: 0 18px 0 48px;
  border: 1px solid transparent; border-radius: 999px; background: var(--bg-soft); color: var(--text);
  font: inherit; font-size: 16px; /* 16px = iOS při psaní nezoomuje */
  outline: none; -webkit-appearance: none; appearance: none; transition: background .2s, border-color .2s, box-shadow .2s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 36px 0 16px; }
.section-title { font-size: 21px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.section-head span { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

/* Řazení */
.sort { display: flex; gap: 8px; margin: -4px 0 20px; overflow-x: auto; scrollbar-width: none; }
.sort::-webkit-scrollbar { display: none; }
.sort a { flex-shrink: 0; padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 550; background: var(--bg-soft); color: var(--muted); }
.sort a.active { background: var(--text); color: var(--bg); }

/* Pokračovat ve čtení – velká karta */
.continue { margin-top: 24px; }
.continue-card {
  position: relative; overflow: hidden; display: flex; gap: 18px; align-items: center;
  padding: 18px; border-radius: 24px; color: #fff; isolation: isolate; min-height: 170px;
  background: #222;
}
.continue-card .bg { position: absolute; inset: -30px; z-index: -2; background-size: cover; background-position: center; filter: blur(30px) saturate(1.5); transform: scale(1.2); }
.continue-card::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(110deg, rgba(0,0,0,.55), rgba(0,0,0,.25)); }
.continue-card .cover-img { width: 92px; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.continue-card .info { flex: 1; min-width: 0; }
.eyebrow { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; opacity: .8; }
.continue-book { font-weight: 700; font-size: 19px; line-height: 1.25; margin: 4px 0 2px; letter-spacing: -.015em; }
.continue-chapter { font-size: 14px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-foot { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.progress { flex: 1; height: 6px; background: rgba(255,255,255,.25); border-radius: 3px; overflow: hidden; }
.progress span { display: block; height: 100%; background: #fff; width: 0; border-radius: 3px; }
.continue-pct { font-size: 13px; font-weight: 600; }

/* Mřížka knih */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 18px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 36px 28px; } }
.card { display: block; }
.cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; background: var(--bg-soft);
  box-shadow: var(--shadow-book); transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s;
}
.cover::after { /* jemný lesk + hřbet */
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(90deg, rgba(0,0,0,.18) 0, rgba(255,255,255,.18) 2.5%, transparent 6%),
              linear-gradient(160deg, rgba(255,255,255,.14), transparent 40%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
@media (hover: hover) { .card:hover .cover { transform: translateY(-6px) scale(1.015); } }
.card:active .cover { transform: scale(.98); }
.card-title { margin-top: 14px; font-weight: 650; font-size: 15px; line-height: 1.3; letter-spacing: -.01em; }
.card-author { color: var(--muted); font-size: 14px; margin-top: 2px; }
.card-tag { display: inline-block; margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 3px 9px; border-radius: 999px; }

/* Výsledky fulltextu */
.hits { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.hits a { display: block; padding: 16px 18px; background: var(--bg-soft); border-radius: var(--radius); transition: background .2s; }
.hits a:hover { background: var(--line); }
.hit-head { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.hit-head strong { font-weight: 650; }
.hit-head span { color: var(--muted); text-align: right; flex-shrink: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hits p { margin: 8px 0 0; font-family: var(--reader-font); font-size: 15px; line-height: 1.55; color: var(--muted); }
mark { background: var(--mark); color: var(--text); border-radius: 4px; padding: 0 2px; }

/* ---------- Detail knihy ---------- */
.book-page .topbar { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; position: absolute; left: 0; right: 0; }
.hero { position: relative; overflow: hidden; isolation: isolate; padding-top: calc(60px + var(--safe-top)); }
.hero-bg { position: absolute; inset: -60px; z-index: -2; background-size: cover; background-position: center; filter: blur(60px) saturate(1.6); opacity: .55; transform: scale(1.2); }
.hero::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 20%, transparent) 0%, var(--bg) 92%); }
.hero-inner {
  max-width: 1120px; margin: 0 auto; padding: 12px 20px 8px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 26px;
}
@media (min-width: 800px) { .hero-inner { flex-direction: row; align-items: flex-end; text-align: left; gap: 48px; padding: 40px 20px 24px; } }
.hero-cover { width: min(58vw, 230px); aspect-ratio: 2/3; border-radius: 12px; overflow: hidden; box-shadow: 0 30px 60px -15px rgba(0,0,0,.45), 0 0 0 1px rgba(0,0,0,.05); position: relative; }
.hero-cover img { width: 100%; height: 100%; object-fit: cover; }
@media (min-width: 800px) { .hero-cover { width: 260px; } }
.series { color: var(--accent); font-weight: 650; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.hero h1 { font-size: clamp(30px, 8vw, 52px); line-height: 1.05; letter-spacing: -.035em; margin: 8px 0 8px; font-weight: 750; }
.author { font-size: 17px; color: var(--muted); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 22px; justify-content: center; }
@media (min-width: 800px) { .chips { justify-content: flex-start; } }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 550; padding: 7px 12px; border-radius: 999px; background: color-mix(in srgb, var(--surface) 70%, transparent); box-shadow: inset 0 0 0 1px var(--line); }
.chip .i { width: 15px; height: 15px; color: var(--muted); }
.actions { display: flex; gap: 10px; justify-content: center; }
@media (min-width: 800px) { .actions { justify-content: flex-start; } }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 26px;
  border-radius: 999px; background: var(--text); color: var(--bg); font-weight: 650; font-size: 16px; border: 0;
  transition: transform .15s, opacity .2s; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn .i { width: 20px; height: 20px; }
.btn.secondary { background: var(--bg-soft); color: var(--text); }
.description { font-family: var(--reader-font); font-size: 18px; line-height: 1.65; max-width: 680px; margin: 28px 0 0; color: color-mix(in srgb, var(--text) 85%, transparent); }

/* Obsah */
.toc { list-style: none; padding: 0; margin: 0; max-width: 760px; counter-reset: toc; }
.toc a { display: flex; align-items: center; gap: 16px; padding: 12px 8px; min-height: 64px; border-radius: 14px; transition: background .15s; }
.toc a:hover { background: var(--bg-soft); }
.toc-num {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center;
  background: var(--bg-soft); font-size: 14px; font-weight: 650; color: var(--muted); font-variant-numeric: tabular-nums;
}
.toc-title { flex: 1; min-width: 0; font-weight: 550; line-height: 1.3; }
.toc-title small { display: block; font-weight: 450; color: var(--muted); font-size: 13px; margin-top: 2px; }
.toc-time { color: var(--muted); font-size: 13px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.toc li.done .toc-num { background: var(--text); color: var(--bg); }
.toc li.reading .toc-num, .toc li.current .toc-num { background: var(--accent); color: #fff; }
.toc li.current a { background: var(--accent-soft); }

/* Plovoucí tlačítko na mobilu */
.sticky-cta { display: none; }
@media (max-width: 799px) {
  .sticky-cta {
    display: flex; position: fixed; left: 16px; right: 16px; bottom: calc(12px + var(--safe-bottom)); z-index: 30;
    transform: translateY(150%); transition: transform .35s cubic-bezier(.2,.8,.2,1);
  }
  .sticky-cta.show { transform: none; }
  .sticky-cta .btn { flex: 1; box-shadow: 0 12px 30px -6px rgba(0,0,0,.35); }
  .book-page main { padding-bottom: calc(100px + var(--safe-bottom)); }
}

/* ---------- Přihlášení ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 20px; background: var(--bg-soft); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 28px; padding: 36px 28px 28px; box-shadow: var(--shadow-sm); text-align: center; }
.login-card img { margin: 0 auto 18px; border-radius: 16px; }
.login-card h1 { font-size: 26px; letter-spacing: -.03em; margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.field { position: relative; margin-bottom: 14px; }
.field input {
  width: 100%; height: 54px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg-soft);
  padding: 0 52px 0 18px; font: inherit; font-size: 17px; color: var(--text); outline: none; -webkit-appearance: none;
}
.field input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
.field button { position: absolute; right: 5px; top: 5px; width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; display: grid; place-items: center; }
.login-card .btn { width: 100%; }
.error { color: #d92d20; font-size: 14px; font-weight: 550; margin: -4px 0 14px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- Čtečka ---------- */
.reader-bar { padding-left: 6px; }
.reader.bar-hidden .reader-bar { transform: translateY(-110%); }
.reader-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.reader-title img { width: 26px; height: 39px; object-fit: cover; border-radius: 4px; box-shadow: 0 2px 6px rgba(0,0,0,.2); flex-shrink: 0; }
.reader-title div { min-width: 0; line-height: 1.2; }
.reader-title strong { display: block; font-size: 14px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-title span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.read-progress { position: fixed; top: 0; left: 0; right: 0; height: calc(3px + var(--safe-top)); z-index: 25; pointer-events: none; display: flex; align-items: flex-end; }
.read-progress span { display: block; height: 3px; width: 0; background: var(--accent); border-radius: 0 3px 3px 0; transition: width .1s linear; }

.chapter {
  max-width: 660px; margin: 0 auto; padding: 28px 22px 16px;
  font-family: var(--reader-font); font-size: var(--reader-size); line-height: var(--reader-leading);
  color: var(--text); hyphens: auto; -webkit-hyphens: auto; overflow-wrap: break-word;
  font-optical-sizing: auto;
}
:root[data-font="sans"] .chapter { font-family: var(--ui-font); letter-spacing: 0; }
:root[data-leading="tight"] { --reader-leading: 1.5; }
:root[data-leading="loose"] { --reader-leading: 1.95; }
:root[data-align="justify"] .chapter p { text-align: justify; }
.chapter p { margin: 0 0 .85em; }
.chapter-head { margin: 20px 0 40px; text-align: left; }
.chapter-label { font-family: var(--ui-font); font-size: 13px; color: var(--accent); font-weight: 650; text-transform: uppercase; letter-spacing: .08em; }
.chapter-head h1 { font-family: var(--ui-font); font-size: 2em; line-height: 1.1; margin: 10px 0 12px; font-weight: 750; letter-spacing: -.03em; }
.chapter-meta { font-family: var(--ui-font); font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.chapter-meta .i { width: 15px; height: 15px; }
.chapter p.found { background: var(--mark); border-radius: 6px; box-shadow: 0 0 0 6px var(--mark); }

.chapter-end { max-width: 660px; margin: 0 auto; padding: 16px 22px calc(110px + var(--safe-bottom)); }
.next-card { display: flex; align-items: center; gap: 16px; padding: 20px; border-radius: 20px; background: var(--bg-soft); transition: transform .15s; }
.next-card:active { transform: scale(.98); }
.next-card div { flex: 1; min-width: 0; }
.next-card small { display: block; font-size: 13px; color: var(--muted); font-weight: 550; }
.next-card strong { display: block; font-size: 18px; font-weight: 700; letter-spacing: -.015em; margin-top: 2px; }
.next-card .arrow { width: 44px; height: 44px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; flex-shrink: 0; }

/* Spodní plovoucí navigace */
.dock {
  position: fixed; left: 50%; bottom: calc(14px + var(--safe-bottom)); z-index: 30;
  transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 5px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.8) blur(20px); -webkit-backdrop-filter: saturate(1.8) blur(20px);
  border-radius: 999px; box-shadow: 0 8px 30px -6px rgba(0,0,0,.25), 0 0 0 1px var(--line);
  transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .3s;
}
.reader.bar-hidden .dock { transform: translate(-50%, 160%); opacity: 0; }
.dock a, .dock button { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; border: 0; background: transparent; color: var(--text); }
.dock a.disabled { opacity: .3; pointer-events: none; }
.dock a:active, .dock button:active { background: var(--bg-soft); }
.dock-count { padding: 0 10px; white-space: nowrap; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }

/* Spodní panely (bottom sheet) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .25s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: 80vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 28px 28px 0 0; padding: 8px 20px calc(24px + var(--safe-bottom));
  transform: translateY(105%); transition: transform .35s cubic-bezier(.2,.8,.2,1);
  font-family: var(--ui-font);
}
@media (min-width: 760px) { .sheet { left: 50%; right: auto; width: 480px; margin-left: -240px; } }
.sheet.open { transform: none; box-shadow: 0 -10px 40px rgba(0,0,0,.18); }
body.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 8px; font-size: 18px; letter-spacing: -.02em; }
.setting { padding: 14px 0; }
.setting > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .05em; }
.seg, .stepper { display: flex; background: var(--bg-soft); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button, .stepper button { flex: 1; border: 0; background: transparent; min-height: 44px; border-radius: 10px; font-size: 15px; font-weight: 550; }
.seg button.active { background: var(--surface); box-shadow: var(--shadow-sm); font-weight: 650; }
.seg button.serif { font-family: var(--reader-font); }
.seg.themes button { display: flex; align-items: center; justify-content: center; gap: 8px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.swatch.light { background: #fff; } .swatch.sepia { background: #f8f1e3; } .swatch.dark { background: #0e0e10; }
.stepper output { flex: 1.2; display: grid; place-items: center; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stepper button { font-weight: 700; }
.stepper button:first-child { font-size: 14px; } .stepper button:last-child { font-size: 20px; }
.toc.compact a { min-height: 54px; padding: 8px; }
