/* Полка: the in-browser reader. Colors follow the site; themes: light, sepia, dark (auto by default). */
:root {
  --bg: #f6f3ee; --text: #1f1d1a; --muted: #7a726a; --line: #e4ddd3; --panel: #fffdf9; --accent: #e2583e;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bar: 52px;
  color-scheme: light;
}
:root[data-theme="sepia"] { --bg: #f1e7d0; --text: #3b2f22; --muted: #85735c; --line: #dccdaf; --panel: #f7efdc; }
:root[data-theme="dark"] { --bg: #161514; --text: #e6e0d8; --muted: #9b938a; --line: #2f2c29; --panel: #1f1e1c; --accent: #f06c50; color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]), :root[data-theme="auto"] { --bg: #161514; --text: #e6e0d8; --muted: #9b938a; --line: #2f2c29; --panel: #1f1e1c; --accent: #f06c50; color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); }
body { overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.r-app { position: fixed; inset: 0; display: block; }
.r-stage { position: absolute; inset: 0; }
.r-stage foliate-view { display: block; width: 100%; height: 100%; }

.r-top, .r-bottom {
  position: absolute; left: 0; right: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  background: var(--bg); transition: opacity .2s, transform .2s;
}
.r-top { top: 0; height: calc(var(--bar) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left)); }
.r-bottom { bottom: 0; height: calc(44px + env(safe-area-inset-bottom)); padding: 0 max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left)); gap: 12px; color: var(--muted); font-size: 13px; }
.r-app.immersive .r-top { opacity: 0; transform: translateY(-100%); pointer-events: none; }
.r-app.immersive .r-bottom { opacity: 0; transform: translateY(100%); pointer-events: none; }

.r-icon { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--text); flex: none; text-decoration: none; }
.r-icon:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.r-icon:disabled { opacity: .35; cursor: default; background: none; }
.r-icon[aria-pressed="true"] svg { fill: var(--accent); stroke: var(--accent); }
.r-aa { font: 600 17px/1 Georgia, serif; }
.r-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.2; }
.r-title strong, .r-title span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-title strong { font-weight: 600; font-size: 14px; }
.r-title span { color: var(--muted); font-size: 12px; }

.r-chapter { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-percent { flex: none; min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
#progress { flex: 2; min-width: 80px; accent-color: var(--accent); }

.r-loading { position: absolute; inset: var(--bar) 0 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); text-align: center; padding: 0 24px; }
.r-loading.err .r-spin { display: none; }
.r-loading a { color: var(--accent); font-weight: 600; }
.r-spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: r-spin 0.9s linear infinite; }
@keyframes r-spin { to { transform: rotate(360deg); } }

/* panels */
.r-scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .3); }
.r-panel { position: fixed; z-index: 21; top: 0; bottom: 0; left: 0; width: min(380px, 88vw); background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); box-shadow: 0 0 40px rgba(0, 0, 0, .15); }
.r-tabs { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--line); }
.r-tabs [role=tab] { padding: 10px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.r-tabs [role=tab].on { color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); }
.r-close { margin-left: auto; font-size: 26px; }
.r-list { flex: 1; overflow: auto; padding: 8px 0 calc(16px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.r-list ul { list-style: none; margin: 0; padding: 0; }
.r-list ul ul { padding-left: 16px; }
.r-list button.item, .r-list .mark { display: block; width: 100%; text-align: left; padding: 10px 18px; line-height: 1.35; }
.r-list button.item:hover, .r-list .mark:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.r-list button.item.on { color: var(--accent); font-weight: 600; }
.r-list .mark { display: flex; gap: 10px; align-items: flex-start; }
.r-list .mark-go { flex: 1; text-align: left; min-width: 0; }
.r-list .mark-go small { display: block; color: var(--muted); }
.r-list .mark-del { color: var(--muted); font-size: 20px; line-height: 1; padding: 2px 6px; }
.r-empty { padding: 16px 18px; color: var(--muted); }

.r-sheet { position: fixed; z-index: 21; right: max(8px, env(safe-area-inset-right)); top: calc(var(--bar) + env(safe-area-inset-top) + 4px); width: min(360px, calc(100vw - 16px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
  max-height: calc(100dvh - var(--bar) - 24px); overflow: auto; }
.r-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.r-row + .r-row { border-top: 1px solid var(--line); }
.r-label { color: var(--muted); font-size: 13px; flex: none; }
.r-seg { display: flex; align-items: center; gap: 6px; }
.r-seg button { min-width: 44px; height: 36px; border-radius: 8px; border: 1px solid var(--line); font-weight: 600; }
.r-seg output { min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums; }
.r-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.r-chips button { padding: 7px 11px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; }
.r-chips button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.r-chips .sw { width: 34px; height: 34px; padding: 0; border-radius: 50%; }
.r-chips .sw.on { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--line); }
.r-note { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }
.r-note a { color: var(--accent); }

.r-toast { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(56px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px);
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; display: flex; gap: 12px; align-items: center; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); font-size: 14px; }
.r-toast button, .r-toast a { color: var(--accent); font-weight: 700; white-space: nowrap; text-decoration: none; }
.r-toast[hidden] { display: none; }

/* the beginning of the book as plain HTML: shown while the reader loads and if it can't */
.r-excerpt { display: none; }
body.r-wait .r-excerpt, body.r-failed .r-excerpt { display: block; position: fixed; z-index: 2; inset: calc(var(--bar) + env(safe-area-inset-top)) 0 44px; overflow: auto;
  padding: 24px max(20px, calc((100vw - 680px) / 2)) 40px; font: 19px/1.6 "Literata", Georgia, serif; background: var(--bg); }
body.r-wait .r-loading { inset: auto 0 52px; z-index: 3; flex-direction: row; justify-content: center; }
body.r-wait .r-loading p { margin: 0; }
.r-excerpt h1 { font-size: 1.6em; line-height: 1.2; margin: 0 0 .2em; }
.r-excerpt h2, .r-excerpt h3, .r-excerpt h4 { font-size: 1.15em; margin: 1.6em 0 .6em; }
.r-excerpt p { margin: 0 0 .6em; text-align: justify; hyphens: auto; }
.r-ex-author { color: var(--muted); margin-bottom: 1.4em !important; text-align: left !important; }
.r-ex-more a { color: var(--accent); font: 600 15px var(--sans); }
body:not(.r-wait):not(.r-failed) .r-excerpt { display: none; }
@media (max-width: 600px) {
  .r-chapter { display: none; }
  .r-excerpt { font-size: 18px; }
}

/* search in the book */
.r-search form { padding: 8px 14px 4px; }
.r-search input { width: 100%; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: 16px var(--sans); }
.r-search input:focus { outline: none; border-color: var(--accent); }
.r-search .grp { padding: 12px 18px 4px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.r-search button.hit { display: block; width: 100%; text-align: left; padding: 8px 18px; line-height: 1.4; font-size: 14px; }
.r-search button.hit:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.r-search mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 2px; }
/* time left */
.r-time { color: var(--muted); white-space: nowrap; }

/* comics (CBZ): page images, so no text settings and no search */
.r-comic-row { display: none !important; }
.r-comic .r-comic-row { display: flex !important; }
.r-comic .r-text-row, .r-comic .r-text-tab { display: none !important; }
.r-comic .r-stage { top: calc(var(--bar) + env(safe-area-inset-top)); bottom: calc(44px + env(safe-area-inset-bottom)); transition: top .2s, bottom .2s; }
.r-comic .r-app.immersive .r-stage { top: 0; bottom: 0; }

/* translation of a tapped word or selected phrase: a panel docked at the bottom */
.r-trans { position: fixed; z-index: 26; left: 0; right: 0; bottom: 0; background: var(--panel); color: var(--text); border-top: 1px solid var(--line);
  padding: 12px max(48px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .12); max-height: 45dvh; overflow: auto; animation: r-up .18s ease-out; }
@keyframes r-up { from { transform: translateY(100%); } to { transform: none; } }
.r-trans > * { max-width: 700px; margin-left: auto; margin-right: auto; }
.r-trans-x { position: absolute; top: 4px; right: max(4px, env(safe-area-inset-right)); width: 44px; height: 44px; font-size: 26px; color: var(--muted); }
.r-trans-src { margin: 0 0 2px; color: var(--muted); font-size: 14px; }
.r-trans-dst { margin: 0; font: 19px/1.4 "Literata", Georgia, serif; }
.r-trans-dst.wait { color: var(--muted); font: 15px var(--sans); }
.r-trans-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 8px; font-size: 13px; }
.r-trans-acts button, .r-trans-acts a { color: var(--accent); font-weight: 600; padding: 6px 0; text-decoration: none; }
.r-trans-by { color: var(--muted); margin-left: auto; font-size: 12px; }
