:root {
  --bg: #f6f4ef; --paper: #ffffff; --ink: #1d2129; --muted: #626875; --line: #e2ded5;
  --accent: #2448a8; --accent-soft: #e6ecfa; --wheat: #a8740c; --wheat-soft: #f7ecd4; --ok: #2f7a4b; --ok-soft: #e3f2e8; --danger: #b3261e;
  --f-book: "Literata", Georgia, "Times New Roman", serif;
  --f-ui: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --top: env(safe-area-inset-top, 0px); --bot: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #14161b; --paper: #1c1f26; --ink: #e8e9ec; --muted: #9ba1ad; --line: #2d313b;
  --accent: #8eaaff; --accent-soft: #232d48; --wheat: #e2b44f; --wheat-soft: #3a2f17; --ok: #6fcf94; --ok-soft: #1d3326; --danger: #ff8a80; color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #14161b; --paper: #1c1f26; --ink: #e8e9ec; --muted: #9ba1ad; --line: #2d313b;
  --accent: #8eaaff; --accent-soft: #232d48; --wheat: #e2b44f; --wheat-soft: #3a2f17; --ok: #6fcf94; --ok-soft: #1d3326; --danger: #ff8a80; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-ui); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.wrap { max-width: 760px; margin: 0 auto; padding: calc(var(--top) + 8px) max(16px, env(safe-area-inset-right)) calc(var(--bot) + 56px) max(16px, env(safe-area-inset-left)); }
.bar { position: sticky; top: 0; z-index: 5; background: var(--bg); margin: 0 -16px; padding: calc(var(--top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px; }
.wrap > .bar { margin-top: calc(-8px - var(--top)); }
.bar h1 { margin: 0; font: 600 1.5rem/1.2 var(--f-book); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px 0; }
.icon-btn { border: 1px solid var(--line); background: var(--paper); border-radius: 10px; min-width: 40px; height: 40px; padding: 0 12px; font-weight: 600; }

.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--paper); border-radius: 10px; padding: 10px 16px; font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn:disabled { opacity: .5; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.search { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 5px 12px; font-size: .85rem; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.chip .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

.sec { margin: 24px 0 10px; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }

/* обкладинки */
.cover { position: relative; aspect-ratio: 2 / 3; border-radius: 6px 10px 10px 6px; overflow: hidden; background: var(--c, #5b6b8c); color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 6px 16px -8px rgba(0,0,0,.35); display: flex; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover .gen { padding: 12% 10%; display: flex; flex-direction: column; justify-content: space-between; width: 100%;
  background: linear-gradient(90deg, rgba(0,0,0,.18) 0 4%, transparent 4% 100%); }
.cover .gen b { font: 600 clamp(.8rem, 3.6vw, 1.05rem)/1.2 var(--f-book); text-wrap: balance; overflow-wrap: break-word; hyphens: auto; }
.cover .gen span { font-size: clamp(.62rem, 2.6vw, .78rem); opacity: .85; }
.cover .fmt { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.45); color: #fff; font-size: .62rem; font-weight: 700; padding: 1px 6px; border-radius: 4px; text-transform: uppercase; }
.cover .bar-p { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.25); }
.cover .bar-p i { display: block; height: 100%; background: var(--wheat); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 18px 14px; }
.tile { border: 0; background: none; padding: 0; text-align: left; display: grid; gap: 6px; min-width: 0; }
.tile .t { font-weight: 600; font-size: .86rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .a { font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.now { display: grid; gap: 10px; }
.now-item { display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center; border: 1px solid var(--line); background: var(--paper); border-radius: 14px; padding: 10px; text-align: left; width: 100%; }
.now-item .t { font: 600 1.02rem/1.25 var(--f-book); }
.prog { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.prog i { display: block; height: 100%; background: var(--wheat); border-radius: 99px; }

.memo { display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--paper); border-radius: 14px; padding: 14px; margin-top: 10px; }
.memo .big { font: 600 1.6rem/1 var(--f-book); color: var(--wheat); min-width: 2ch; text-align: center; }
.week { display: flex; gap: 6px; align-items: flex-end; height: 44px; margin-top: 8px; }
.week div { flex: 1; display: grid; gap: 3px; justify-items: center; font-size: .65rem; color: var(--muted); }
.week i { width: 100%; max-width: 26px; background: var(--accent); border-radius: 4px 4px 1px 1px; min-height: 2px; opacity: .85; }

.empty { color: var(--muted); padding: 32px 0; text-align: center; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 28px 16px; text-align: center; color: var(--muted); }

/* сторінка книжки */
.book-head { display: grid; grid-template-columns: 120px 1fr; gap: 18px; align-items: start; margin-top: 8px; }
.book-head h2 { margin: 0; font: 600 1.4rem/1.25 var(--f-book); text-wrap: balance; }
.book-head .au { color: var(--muted); margin-top: 4px; }
.meta { font-size: .8rem; color: var(--muted); margin-top: 8px; }
.actions { display: grid; gap: 8px; margin-top: 18px; }
.actions .btn { justify-content: center; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.seg button { border: 0; background: none; border-radius: 7px; padding: 7px 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.quote { border-left: 3px solid var(--wheat); padding: 2px 0 2px 12px; margin: 12px 0; font-family: var(--f-book); }
.quote .x { border: 0; background: none; color: var(--muted); font-size: .78rem; padding: 0; margin-top: 4px; font-family: var(--f-ui); }
details.card summary { cursor: pointer; font-weight: 600; }
.field { display: grid; gap: 4px; margin-top: 10px; }
.field input, .field textarea { padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); width: 100%; }
.kindle ol { margin: 8px 0 0; padding-left: 1.2em; color: var(--muted); font-size: .88rem; display: grid; gap: 4px; }

/* читалка */
.reader { position: fixed; inset: 0; background: var(--rbg); color: var(--rink); z-index: 20; display: flex; flex-direction: column; }
.reader[data-rt="light"] { --rbg: #ffffff; --rink: #1d2129; }
.reader[data-rt="sepia"] { --rbg: #f4ecd8; --rink: #3b2f20; }
.reader[data-rt="dark"] { --rbg: #121212; --rink: #d8d6d0; }
.r-top, .r-bot { position: absolute; left: 0; right: 0; z-index: 3; background: var(--rbg); transition: transform .2s, opacity .2s; }
.r-top { top: 0; padding: calc(var(--top) + 6px) 12px 8px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid color-mix(in srgb, var(--rink) 12%, transparent); }
.r-bot { bottom: 0; padding: 10px 16px calc(var(--bot) + 10px); border-top: 1px solid color-mix(in srgb, var(--rink) 12%, transparent); display: grid; gap: 8px; }
.reader.chrome-off .r-top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader.chrome-off .r-bot { transform: translateY(100%); opacity: 0; pointer-events: none; }
.r-top .ttl { flex: 1; min-width: 0; font-size: .85rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.r-btn { border: 0; background: none; color: var(--rink); font-weight: 600; padding: 8px 10px; border-radius: 8px; }
.r-view { flex: 1; position: relative; margin: calc(var(--top) + 14px) 0 calc(var(--bot) + 22px); }
.r-view.epub > div { height: 100%; }
.r-foot { position: absolute; left: 0; right: 0; bottom: calc(var(--bot) + 2px); text-align: center; font-size: .72rem; opacity: .5; pointer-events: none; z-index: 1; }
.r-zone { position: absolute; top: 0; bottom: 0; width: 22%; z-index: 2; }
.r-zone.l { left: 0; } .r-zone.r { right: 0; }
.r-slider { width: 100%; accent-color: var(--wheat); }
.r-panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; background: var(--rbg); color: var(--rink); border-top: 1px solid color-mix(in srgb, var(--rink) 15%, transparent);
  padding: 14px 16px calc(var(--bot) + 14px); max-height: 70vh; overflow: auto; box-shadow: 0 -10px 30px -12px rgba(0,0,0,.35); border-radius: 14px 14px 0 0; }
.r-panel h3 { margin: 0 0 10px; font-size: 1rem; }
.r-panel .opts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.r-panel .opt { border: 1px solid color-mix(in srgb, var(--rink) 25%, transparent); background: none; color: var(--rink); border-radius: 9px; padding: 8px 14px; font-weight: 600; }
.r-panel .opt[aria-pressed="true"] { border-color: var(--wheat); box-shadow: inset 0 0 0 1px var(--wheat); }
.toc a { display: block; padding: 8px 0; color: var(--rink); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--rink) 10%, transparent); }
.toc a.sub { padding-left: 16px; font-size: .92em; }
.r-sel { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--bot) + 28px); z-index: 5; }
.html-book { height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 max(20px, env(safe-area-inset-left)); }
.html-book .in { max-width: 38em; margin: 0 auto; font-family: var(--rf); font-size: var(--rfs); line-height: 1.6; padding: 30px 0 60px; }
.html-book h2 { font-size: 1.3em; margin: 2em 0 1em; text-align: center; }
.html-book p { margin: 0 0 .6em; text-indent: 1.2em; }
.html-book .poem p, .html-book .stanza { text-indent: 0; margin: 0 0 1em 1.5em; }
.html-book blockquote { margin: 1em 0 1em 2em; font-style: italic; }

/* вірші */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 11px 2px; }
.item .t { font-family: var(--f-book); font-size: 1.02rem; min-width: 0; }
.item .m { color: var(--muted); font-size: .78rem; display: block; font-family: var(--f-ui); }
.pill { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.learning { background: var(--accent-soft); color: var(--accent); }
.pill.due { background: var(--wheat); color: var(--paper); }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.ptitle { font: 600 1.5rem/1.25 var(--f-book); margin: 12px 0 4px; text-wrap: balance; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-top: 14px; position: sticky; top: calc(var(--top) + 62px); z-index: 4; }
.modes button { border: 0; background: none; border-radius: 7px; padding: 7px 4px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.modes button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.hint { color: var(--muted); font-size: .82rem; margin: 8px 0 0; min-height: 1.2em; }
.poem { font: 1.12rem/1.6 var(--f-book); margin-top: 18px; }
.st { margin: 0 0 1.1em; }
.ln { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 1px 0; font: inherit; color: var(--ink); border-radius: 4px; }
.ln.masked { color: var(--muted); }
.ln.blank { min-height: 1.6em; border-bottom: 1px dashed var(--line); border-radius: 0; margin-bottom: 2px; }
.pdate { text-align: right; font-style: italic; color: var(--muted); font-family: var(--f-book); font-size: .9rem; }
.learnbar { margin-top: 22px; display: grid; gap: 10px; }
.learnbar p { margin: 0; font-size: .88rem; color: var(--muted); }
.nav2 { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.nav2 button { border: 0; background: none; color: var(--accent); padding: 0; font-size: .88rem; max-width: 48%; text-align: left; }
.nav2 button:last-child { text-align: right; }

.login { max-width: 360px; margin: 18vh auto 0; display: grid; gap: 12px; text-align: center; }
.login h1 { font: 600 1.8rem var(--f-book); margin: 0 0 8px; }
.login input { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); text-align: center; }

#toast { position: fixed; left: 50%; bottom: calc(var(--bot) + 20px); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100% - 32px); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.offline { background: var(--wheat-soft); color: var(--wheat); border-radius: 10px; padding: 6px 12px; font-size: .82rem; margin-bottom: 8px; }
@media (min-width: 560px) { .book-head { grid-template-columns: 160px 1fr; } .actions { grid-template-columns: 1fr 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
