/* Читальня: the app's look. Tokens first (light, sepia, dark), then the shell, the library, the reader, the panels. */
:root {
  --bg: #f8f6f1; --bg2: #efece4; --panel: #ffffff; --line: #e2ddd2; --line2: #d3cdbf;
  --text: #22201c; --text2: #5f5a50; --text3: #8d877b;
  --accent: #1f5c4a; --accent2: #2f7a63; --accent-bg: #e3eee9; --on-accent: #ffffff;
  --danger: #a2342b; --warn: #8a5a00;
  --hl-yellow: rgba(255, 214, 10, .38); --hl-blue: rgba(80, 160, 255, .30); --hl-green: rgba(60, 190, 110, .30);
  --hl-red: rgba(255, 90, 90, .28); --hl-purple: rgba(170, 110, 255, .28); --hl-note: #b07d00;
  --find: rgba(255, 150, 0, .35); --find-current: rgba(255, 110, 0, .65);
  --shadow: 0 8px 30px rgba(30, 25, 15, .14), 0 1px 3px rgba(30, 25, 15, .08);
  --radius: 10px; --side: 232px; --bar: 52px;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #f3ead7; --bg2: #e9dec6; --panel: #f8f1e1; --line: #dccfb4; --line2: #cfbf9f;
  --text: #3d3020; --text2: #6b5a43; --text3: #957f62;
  --accent: #6d4c1d; --accent2: #87622c; --accent-bg: #eadcbf; --on-accent: #fff8ea;
  --hl-yellow: rgba(230, 180, 0, .34);
}
:root[data-theme="dark"] {
  --bg: #141716; --bg2: #1c201e; --panel: #202523; --line: #2d3330; --line2: #3a423e;
  --text: #dedbd3; --text2: #a9a59b; --text3: #7c7a72;
  --accent: #7cc4a8; --accent2: #96d3bb; --accent-bg: #23362f; --on-accent: #0c1512;
  --danger: #ef8a80; --warn: #e0b45c;
  --hl-yellow: rgba(255, 214, 10, .26); --hl-blue: rgba(80, 160, 255, .28); --hl-green: rgba(60, 190, 110, .26);
  --hl-red: rgba(255, 90, 90, .26); --hl-purple: rgba(170, 110, 255, .28); --hl-note: #e0b45c;
  --find: rgba(255, 150, 0, .30); --find-current: rgba(255, 130, 0, .55);
  --shadow: 0 8px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--ui); -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- buttons and controls ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); background: var(--panel);
  border-radius: 8px; padding: 7px 12px; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: var(--text3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.ib { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 0;
  background: transparent; border-radius: 9px; color: var(--text2); flex: none; }
.ib:hover, .ib.on { background: var(--bg2); color: var(--text); }
.ib.on { color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 9px; overflow: hidden; flex-wrap: nowrap; }
.seg button { border: 0; background: transparent; padding: 6px 11px; white-space: nowrap; color: var(--text2); }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
input[type=search], input[type=text], select { border: 1px solid var(--line2); background: var(--panel); border-radius: 8px;
  padding: 7px 10px; min-width: 0; }
input:focus-visible, button:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=range] { accent-color: var(--accent); width: 100%; }
kbd { font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--line2); border-bottom-width: 2px;
  border-radius: 5px; padding: 2px 5px; background: var(--panel); color: var(--text2); white-space: nowrap; }

/* ---- shell ---- */
#app { position: fixed; inset: 0; display: flex; }
#side { width: var(--side); flex: none; border-right: 1px solid var(--line); background: var(--bg2); display: flex;
  flex-direction: column; padding: calc(12px + var(--safe-t)) 10px calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; padding: 4px 8px 14px; letter-spacing: .2px; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text2);
  text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--line); color: var(--text); }
.nav a.on { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.nav a .n { margin-left: auto; font-size: 12px; color: var(--text3); font-variant-numeric: tabular-nums; }
.nav .sep { height: 1px; background: var(--line); margin: 10px 6px; }
.nav .cap { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); padding: 8px 10px 4px; }
.side-foot { margin-top: auto; padding: 10px 8px 0; font-size: 12px; color: var(--text3); display: flex; gap: 8px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent2); flex: none; }
.dot.off { background: var(--text3); }
.dot.busy { background: var(--warn); }
#main { flex: 1; min-width: 0; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(18px + var(--safe-t)) calc(28px + var(--safe-r)) calc(40px + var(--safe-b)) 28px; }
.view-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.view-head h1 { font-size: 24px; margin: 0; font-weight: 700; white-space: nowrap; }
.view-head .grow { flex: 1; }
#tabs { display: none; }
@media (max-width: 760px) {
  #side { display: none; }
  #tabs { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--bg2);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + var(--safe-b)); }
  #tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text3);
    text-decoration: none; padding: 4px 0; white-space: nowrap; }
  #tabs a.on { color: var(--accent); }
  .view { padding: calc(14px + var(--safe-t)) 16px calc(80px + var(--safe-b)); }
  .view-head h1 { font-size: 21px; }
}

/* ---- library ---- */
.filters { display: flex; gap: 8px 16px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters .tools { display: flex; gap: 8px; align-items: center; flex: 1 1 440px; justify-content: flex-end; min-width: 0; }
.filters .tools input { flex: 1 1 120px; min-width: 90px; max-width: 260px; }
.filters .tools select { flex: 0 1 auto; min-width: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line2); background: var(--panel); border-radius: 999px; padding: 4px 11px; font-size: 13px;
  color: var(--text2); white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.list { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 46px 1fr auto; gap: 14px; align-items: center; padding: 10px 10px; border-radius: 10px;
  cursor: pointer; border: 1px solid transparent; }
.row:hover { background: var(--bg2); }
.row.sel { border-color: var(--accent); background: var(--accent-bg); }
.cover { width: 46px; height: 62px; border-radius: 4px; object-fit: cover; background: var(--bg2); display: flex; align-items: center;
  justify-content: center; overflow: hidden; color: var(--text3); font-size: 18px; font-weight: 700; border: 1px solid var(--line); }
.cover.gen { color: #fff; font-family: Literata, Georgia, serif; text-align: center; line-height: 1.12; padding: 6px; container-type: inline-size; }
.cover.gen .ini { font-size: 24px; }
.cover.gen .ttl { display: none; font-size: clamp(11px, 12cqw, 19px); overflow-wrap: normal; word-break: keep-all; hyphens: none; overflow: hidden; max-height: 100%; }
.card .cover.gen .ini { display: none; }
.card .cover.gen .ttl { display: block; }
.row .t { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.row .m { font-size: 13px; color: var(--text3); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row .m span { white-space: nowrap; }
.row .acts { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.row:hover .acts, .row.sel .acts { opacity: 1; }
@media (hover: none) { .row .acts { display: none; } }
.bar { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; width: 70px; display: inline-block; vertical-align: middle; }
.bar i { display: block; height: 100%; background: var(--accent2); }
.badge { font-size: 11px; border-radius: 5px; padding: 1px 6px; background: var(--bg2); color: var(--text2); white-space: nowrap; }
.badge.ok { background: var(--accent-bg); color: var(--accent); }
.empty { color: var(--text3); padding: 40px 10px; text-align: center; }
.home-sec { margin-bottom: 26px; }
.home-sec h2 { font-size: 15px; color: var(--text2); margin: 0 0 10px; font-weight: 600; text-transform: none; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 16px; }
.shelf > * { max-width: 190px; }
.card { cursor: pointer; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.card .cover { width: 100%; height: auto; aspect-ratio: 2 / 3; font-size: 20px; border-radius: 6px; }
.card .t { font-weight: 600; font-size: 14px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .m { font-size: 12px; color: var(--text3); display: flex; align-items: center; gap: 6px; }
.card .bar { width: 100%; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
  text-decoration: none; color: inherit; display: block; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--text2); }
.hits .hit { padding: 10px; border-radius: 10px; cursor: pointer; }
.hits .hit:hover { background: var(--bg2); }
.hits .hit .s { font-size: 14px; color: var(--text2); margin-top: 3px; }
mark.q { background: var(--find); color: inherit; border-radius: 2px; }

/* ---- reader ---- */
#reader { position: fixed; inset: 0; z-index: 30; background: var(--page-bg, var(--bg)); display: flex; flex-direction: column; }
.rbar { height: calc(var(--bar) + var(--safe-t)); padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l));
  display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); background: var(--page-bg, var(--bg));
  flex: none; z-index: 3; transition: transform .2s, opacity .2s; }
.rbar .title { flex: 1; min-width: 0; text-align: center; font-size: 14px; color: var(--text2); overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; padding: 0 6px; }
#reader.immersive .rbar { transform: translateY(-100%); opacity: 0; pointer-events: none; }
#reader.immersive .rfoot { opacity: 0; }
.rbody { flex: 1; position: relative; min-height: 0; display: flex; }
.rmain { flex: 1; position: relative; min-width: 0; overflow: hidden; }
.rfoot { height: calc(30px + var(--safe-b)); padding: 0 16px var(--safe-b); display: flex; align-items: center; gap: 12px; font-size: 12px;
  color: var(--text3); flex: none; transition: opacity .2s; font-variant-numeric: tabular-nums; }
.rfoot .chap { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rfoot .prog { width: 120px; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.rfoot .prog i { display: block; height: 100%; background: var(--accent2); }
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text3); gap: 10px; }
.spin { width: 18px; height: 18px; border: 2px solid var(--line2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* the document itself; --font, --size, --lh, --width, --align come from the typography settings */
.doc { font-family: var(--font, Literata, Georgia, serif); font-size: var(--size, 19px); line-height: var(--lh, 1.6);
  text-align: var(--align, left); hyphens: var(--hyph, manual); -webkit-hyphens: var(--hyph, manual); color: var(--text);
  overflow-wrap: break-word; font-kerning: normal; font-variant-ligatures: common-ligatures; }
.doc :is(h1, h2, h3, h4, h5, h6) { line-height: 1.25; text-align: left; hyphens: manual; margin: 1.3em 0 .6em; break-after: avoid; }
.doc h1 { font-size: 1.6em; } .doc h2 { font-size: 1.35em; } .doc h3 { font-size: 1.18em; } .doc :is(h4, h5, h6) { font-size: 1.05em; }
.doc p { margin: 0 0 .8em; }
.doc img, .doc svg, .doc video { max-width: 100%; height: auto; }
.doc img { border-radius: 3px; break-inside: avoid; }
.doc figure { margin: 1.2em 0; break-inside: avoid; }
.doc figcaption { font-size: .85em; color: var(--text2); margin-top: .4em; text-align: center; }
.doc blockquote { margin: 1em 0; padding: 0 0 0 1em; border-left: 3px solid var(--line2); color: var(--text2); }
.doc pre, .doc code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em; }
.doc pre { white-space: pre-wrap; background: var(--bg2); padding: .8em 1em; border-radius: 6px; overflow-x: auto; }
.doc table { border-collapse: collapse; margin: 1em 0; font-size: .9em; display: block; overflow-x: auto; max-width: 100%; }
.doc td, .doc th { border: 1px solid var(--line2); padding: .3em .5em; vertical-align: top; }
.doc hr { border: 0; border-top: 1px solid var(--line2); margin: 1.6em 0; }
.doc a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.doc a.fn { text-decoration: none; }
.doc sup, .doc sub { line-height: 0; }
.doc annotation, .doc annotation-xml { display: none; }
.doc .embed::before { content: attr(data-label); display: block; padding: .7em 1em; border: 1px dashed var(--line2); border-radius: 6px;
  color: var(--text2); font-family: var(--ui); font-size: .8em; }
.doc ::selection { background: rgba(31, 92, 74, .25); }
::highlight(hl-yellow) { background-color: var(--hl-yellow); }
::highlight(hl-blue) { background-color: var(--hl-blue); }
::highlight(hl-green) { background-color: var(--hl-green); }
::highlight(hl-red) { background-color: var(--hl-red); }
::highlight(hl-purple) { background-color: var(--hl-purple); }
::highlight(hl-note) { text-decoration: underline dotted var(--hl-note) 2px; text-underline-offset: 3px; }
::highlight(hl-focus) { background-color: var(--find-current); }
::highlight(find) { background-color: var(--find); }
::highlight(find-current) { background-color: var(--find-current); }
::highlight(transcript-now) { background-color: var(--accent-bg); }
mark.hl { background: var(--hl-yellow); color: inherit; }

/* scroll: one long column */
.scroller { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.scroller .doc { max-width: var(--width, 680px); margin: 0 auto; padding: 32px max(20px, var(--margin, 24px)) 40vh; }
.scroller .sec { position: relative; }
.scroller .sec.empty { contain: strict; }
.scroller .chapter-start { margin-top: 2.2em; }
/* pages: CSS columns of one section, moved by a transform inside a clipping box */
.tview { position: absolute; inset: 0; }
.pager { position: absolute; inset: 0; overflow: hidden; touch-action: pan-y; outline: none; }
.pager .clip { position: absolute; overflow: hidden; }
.pager .doc { position: absolute; top: 0; left: 8px; column-fill: auto; will-change: transform;
  transition: transform .28s cubic-bezier(.2, .7, .2, 1); }
.pager .doc.instant { transition: none; }
.pager .doc img, .pager .doc svg { max-height: var(--page-h, 80vh); object-fit: contain; }
.pager .doc .sec-body > :first-child, .pager .doc .doc-head + .sec-body > :first-child { margin-top: 0; }
.endmark { height: 0; margin: 0; padding: 0; break-before: avoid; }
.scroller { overflow-anchor: none; outline: none; }
.hl-pic { outline: 3px solid rgba(240, 190, 0, .85); outline-offset: 3px; border-radius: 3px; }
.doc-head { margin: 0 0 1.8em; text-align: left; }
.doc-head h1 { margin: 0 0 .35em; font-size: 1.55em; line-height: 1.2; }
.doc-head .m { font-family: var(--ui); font-size: .72em; color: var(--text2); margin-bottom: .5em; }
.doc-head .orig-link { font-family: var(--ui); font-size: .7em; display: inline-flex; align-items: center; gap: 5px; text-decoration: none; }
.doc-head .orig-link svg { width: 15px; height: 15px; }

/* side panels (contents, notes, find) and sheets */
.rside { width: 340px; flex: none; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column;
  min-height: 0; }
.rside-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.rside-head h3 { flex: 1; margin: 0; font-size: 15px; white-space: nowrap; }
.rside-body { flex: 1; overflow-y: auto; padding: 8px; }
@media (max-width: 900px) {
  .rside { position: absolute; z-index: 5; right: 0; top: 0; bottom: 0; width: min(380px, 92vw); box-shadow: var(--shadow); }
}
.toc a { display: block; padding: 7px 10px; border-radius: 7px; color: var(--text); text-decoration: none; font-size: 14px; line-height: 1.3; }
.toc a:hover { background: var(--bg2); }
.toc a.on { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.toc a.d1 { padding-left: 24px; font-size: 13.5px; } .toc a.d2 { padding-left: 38px; font-size: 13px; color: var(--text2); }
.toc a.d3 { padding-left: 52px; font-size: 13px; color: var(--text2); }
.note { padding: 11px 12px; border-radius: 9px; cursor: pointer; border-left: 3px solid var(--hl-note-c, #e2b400); margin: 4px 2px 10px; background: var(--bg); }
.note:hover { background: var(--bg2); }
.note .q { font-family: var(--font, Literata, Georgia, serif); font-size: 14.5px; line-height: 1.45; }
.note .c { margin-top: 7px; font-size: 14px; color: var(--text); background: var(--accent-bg); border-radius: 6px; padding: 6px 8px; white-space: pre-wrap; }
.note .m { margin-top: 6px; font-size: 12px; color: var(--text3); display: flex; gap: 8px; flex-wrap: wrap; }
.note.lost { border-left-color: var(--text3); }
.find-in { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.find-in input { flex: 1; }
.find-res { font-size: 14px; padding: 8px 10px; border-radius: 7px; cursor: pointer; line-height: 1.4; }
.find-res:hover, .find-res.on { background: var(--bg2); }
.find-res .w { font-size: 12px; color: var(--text3); }

.sheet-back { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .25); display: flex; align-items: flex-start; justify-content: center;
  padding: calc(10vh + var(--safe-t)) 12px 12px; }
.sheet { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: 80vh; display: flex;
  flex-direction: column; overflow: hidden; }
.sheet-head { display: flex; align-items: center; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); gap: 8px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 16px; }
.sheet-body { overflow-y: auto; padding: 14px 18px 18px; }
.pop { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  max-width: min(420px, 92vw); padding: 12px 14px; font-size: 14px; }
.pop .q { font-family: var(--font, Literata, Georgia, serif); max-height: 40vh; overflow-y: auto; line-height: 1.45; }
.pop .c { margin-top: 8px; white-space: pre-wrap; background: var(--accent-bg); border-radius: 6px; padding: 6px 8px; }
.pop .acts { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* typography panel */
.typo { display: grid; gap: 14px; }
.typo .row2 { display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 10px; }
.typo .row2 > span { font-size: 13px; color: var(--text2); white-space: nowrap; }
.fonts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.fonts button { border: 1px solid var(--line2); background: var(--bg); border-radius: 8px; padding: 6px 10px; text-align: left; font-size: 15px;
  line-height: 1.2; min-height: 44px; overflow-wrap: normal; hyphens: none; }
.fonts button.on { border-color: var(--accent); background: var(--accent-bg); }
.themes { display: flex; gap: 8px; flex-wrap: wrap; }
.themes button { width: 64px; height: 42px; border-radius: 9px; border: 2px solid var(--line2); font-size: 13px; }
.themes button.on { border-color: var(--accent); }
.themes .t-light { background: #f8f6f1; color: #22201c; } .themes .t-sepia { background: #f3ead7; color: #3d3020; }
.themes .t-dark { background: #141716; color: #dedbd3; } .themes .t-auto { background: linear-gradient(135deg, #f8f6f1 50%, #141716 50%); }
.themes .t-auto span { background: rgba(248, 246, 241, .92); color: #22201c; border-radius: 5px; padding: 1px 5px; }

/* palette */
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 14px 18px; font-size: 16px; background: transparent; }
.palette input:focus-visible { outline: none; }
.palette .items { overflow-y: auto; max-height: 55vh; padding: 6px; }
.palette .it { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.palette .it.on { background: var(--accent-bg); }
.palette .it .k { margin-left: auto; display: flex; gap: 4px; }
.palette .it .g { font-size: 12px; color: var(--text3); }

/* login */
.login { max-width: 420px; margin: 12vh auto 0; text-align: center; padding: 0 20px; }
.login img { width: 84px; height: 84px; border-radius: 20px; box-shadow: var(--shadow); }
.login h1 { font-size: 26px; margin: 18px 0 6px; }
.login p { color: var(--text2); }
.login .code { font-size: 34px; letter-spacing: .25em; font-weight: 700; font-variant-numeric: tabular-nums; margin: 14px 0; }

/* settings and report */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.panel h2 { font-size: 16px; margin: 0 0 12px; }
.kv { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: 6px 16px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--text2); }
.keys { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; font-size: 14px; }
.keys button.kb { border: 1px solid var(--line2); background: var(--bg); border-radius: 7px; padding: 3px 8px; min-width: 70px; }
.keys button.kb.wait { border-color: var(--accent); color: var(--accent); }
.rep-item { border-top: 1px solid var(--line); padding: 10px 0; font-size: 14px; }
.rep-item .q { font-family: var(--font, Literata, Georgia, serif); margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 80; background: var(--text);
  color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); max-width: 90vw; }
@media (max-width: 760px) { .toast { bottom: calc(76px + var(--safe-b)); } }

/* pdf */
.pdfwrap { position: absolute; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch; background: var(--bg2); }
.pdfwrap .pdfViewer .page { margin: 10px auto; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
:root[data-theme="dark"] .pdfwrap.invert .page canvas { filter: invert(.88) hue-rotate(180deg); }
.pdfwrap .textLayer ::highlight(hl-yellow) { background-color: rgba(255, 214, 10, .45); }
.zoom { display: flex; align-items: center; gap: 2px; font-size: 13px; color: var(--text2); font-variant-numeric: tabular-nums; }

/* video */
.video { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); height: 100%; }
.video .player { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.video .player .frame { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; }
.video .player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video .script { position: relative; min-width: 0; border-left: 1px solid var(--line); }
.video .doc span[data-rw-start] { cursor: pointer; }
@media (max-width: 900px) {
  .video { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .video .script { border-left: 0; border-top: 1px solid var(--line); }
}

/* reader extras */
.rfoot .lbl { white-space: nowrap; }
.rfoot .pct { min-width: 36px; text-align: right; }
.backchip { position: absolute; left: calc(14px + var(--safe-l)); bottom: calc(40px + var(--safe-b)); z-index: 6; display: inline-flex;
  align-items: center; gap: 4px; border: 1px solid var(--line2); background: var(--panel); color: var(--text); border-radius: 999px;
  padding: 6px 14px 6px 8px; box-shadow: var(--shadow); font-size: 14px; }
.backchip svg { width: 18px; height: 18px; }
.menu { display: flex; flex-direction: column; min-width: 220px; margin: -6px -8px; }
.menu button { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; text-align: left; white-space: nowrap; }
.menu button:hover { background: var(--bg2); }
.menu button span { flex: 1; }
.menu button.on { color: var(--accent); font-weight: 600; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 6px; }
.pop .m { margin-top: 6px; font-size: 12px; color: var(--text3); }
.pop .fn { font-size: 15px; }
.pop .fn p { margin: 0 0 .5em; }
.sheet.lightbox { width: 100%; max-width: none; max-height: 100%; height: 100%; background: transparent; box-shadow: none; }
.sheet-back:has(.lightbox) { padding: 0; background: rgba(0, 0, 0, .85); align-items: stretch; }
.sheet.lightbox .sheet-body { padding: 0; height: 100%; display: flex; align-items: center; justify-content: center; overflow: auto; }
.sheet.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
.sheet.lightbox.big .sheet-body { display: block; }
.sheet.lightbox.big img { max-width: none; max-height: none; cursor: zoom-out; }
.video .vctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.video .script .tview { position: absolute; inset: 0; }
.row .s { font-size: 14px; color: var(--text2); margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.filters select { max-width: 180px; }

/* phones: the list tools and the typography rows stack, covers get smaller */
@media (max-width: 600px) {
  .filters .tools { flex-wrap: wrap; flex-basis: 100%; }
  .filters .tools input { flex: 1 1 100%; max-width: none; }
  .filters .tools select { flex: 1 1 0; font-size: 14px; padding-left: 8px; padding-right: 4px; }
  .rfoot .chap:has(+ .lbl:not(:empty)) { display: none; }
  .rfoot .lbl { flex: 1; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
  .typo .row2 { grid-template-columns: 1fr; gap: 6px; }
  .fonts { grid-template-columns: 1fr 1fr; }
}
