@font-face { font-family: "Literata"; src: url("fonts/literata.woff2") format("woff2"); font-weight: 200 900; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("fonts/atkinson-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("fonts/atkinson-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --f-serif: "Literata", Georgia, "Iowan Old Style", "Times New Roman", serif;
  --f-legivel: "Atkinson", Verdana, system-ui, sans-serif;
  --f-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* preferências de leitura (o app.js sobrescreve) */
  --read-font: var(--f-serif);
  --read-size: 19px;
  --read-lh: 1.6;
  --read-margin: 28px;
  --read-align: left;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ---------- cores de página ----------
   Papel impresso sob luz de ambiente é bem mais escuro que o branco de uma tela, então
   os fundos claros ficam na faixa de 75–85% de luminosidade e a tinta nunca é preto puro.
   A interface (--ui) é sempre um tom mais escura que a página, para nada brilhar mais que o texto. */
[data-theme="livro"]    { --bg:#d9d3c5; --fg:#2e2b26; --muted:#524c42; --line:#c2bbab; --ui:#cdc6b7; --accent:#6b4423; --on-accent:#f0eadc; --hl:#c9b27a; }
[data-theme="papel"]    { --bg:#c8c7c2; --fg:#262626; --muted:#444540; --line:#b1b0aa; --ui:#bcbbb5; --accent:#3a3f45; --on-accent:#e8e8e4; --hl:#a9a48c; }
[data-theme="sepia"]    { --bg:#e0d3b8; --fg:#40362a; --muted:#594c37; --line:#c9bb9d; --ui:#d4c6a9; --accent:#7d4419; --on-accent:#f6ecd6; --hl:#d1b56f; }
[data-theme="penumbra"] { --bg:#34322f; --fg:#c2bcb0; --muted:#a39d91; --line:#494642; --ui:#2a2826; --accent:#d0a070; --on-accent:#1c1b19; --hl:#6b5a36; }
[data-theme="escuro"]   { --bg:#1c1b19; --fg:#b8b1a3; --muted:#9a9488; --line:#34322e; --ui:#262422; --accent:#c99a66; --on-accent:#1c1b19; --hl:#5a4a2a; }
[data-theme="preto"]    { --bg:#000000; --fg:#9a9488; --muted:#8f897d; --line:#232323; --ui:#111111; --accent:#b98a58; --on-accent:#000; --hl:#4a3d22; }
[data-theme="penumbra"], [data-theme="escuro"], [data-theme="preto"] { color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--f-sans); font-size: 16px; line-height: 1.45;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2 { margin: 0; font-weight: 600; }

.btn {
  border: 1px solid var(--line); background: var(--ui); color: var(--fg);
  padding: 10px 16px; border-radius: 10px; min-height: 44px;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; font-family: var(--f-serif); font-size: 18px; }
.icon {
  width: 44px; height: 44px; flex: none; border: 0; background: transparent; border-radius: 10px;
  display: grid; place-items: center;
}
.icon svg, .edge svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.text { width: auto; min-width: 44px; padding: 0 10px; font-family: var(--f-serif); font-size: 17px; }
.icon[aria-pressed="true"] svg { fill: var(--accent); stroke: var(--accent); }
:is(.btn, .icon, .edge, .seg button, .tabs button, .swatches button, .stepper button, .list button, #footInfo, #backChip, #selBar button):focus-visible,
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) { .icon:hover { background: color-mix(in srgb, var(--fg) 9%, transparent); } }
@media (pointer: coarse) { .desktop-only { display: none !important; } }

/* ===================== BIBLIOTECA ===================== */
#library { max-width: 1080px; margin: 0 auto; padding: calc(20px + var(--safe-t)) 20px calc(40px + var(--safe-b)); }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 28px; }
.lib-head h1 { font-family: var(--f-serif); font-size: 30px; letter-spacing: -0.01em; }
.lib-actions { display: flex; gap: 8px; }

.empty { text-align: center; max-width: 420px; margin: 12vh auto 0; }
.empty h2 { font-family: var(--f-serif); font-size: 22px; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 0 0 20px; text-wrap: pretty; }
.empty .hint { margin-top: 14px; font-size: 14px; }
.empty-mark {
  width: 64px; height: 84px; margin: 0 auto 22px; border-radius: 4px 8px 8px 4px;
  border: 1.5px solid var(--muted); opacity: .55; position: relative;
}
.empty-mark::before { content: ""; position: absolute; inset: 0 auto 0 7px; border-left: 1.5px solid var(--muted); } /* lombada do livro */

.resume {
  display: grid; grid-template-columns: 120px 1fr; gap: 20px; align-items: center;
  padding: 18px; margin-bottom: 30px; background: var(--ui); border: 1px solid var(--line); border-radius: 14px;
}
.resume-body { display: grid; gap: 8px; min-width: 0; justify-items: start; }
.resume h2 { font-family: var(--f-serif); font-size: 21px; line-height: 1.25; overflow-wrap: anywhere; }
.resume p { margin: 0; }
#resumeWhere { font-size: 15px; font-variant-numeric: tabular-nums; }
.resume .book-bar { width: 100%; max-width: 360px; margin: 0; }
.resume .btn { margin-top: 6px; }
@media (max-width: 480px) { .resume { grid-template-columns: 84px 1fr; gap: 14px; padding: 14px; } .resume h2 { font-size: 18px; } }
.shelf-title { font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 14px; }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 26px 20px; }
.book { position: relative; }
.book-open { all: unset; cursor: pointer; display: block; width: 100%; }
.cover {
  aspect-ratio: 3 / 4; border-radius: 3px 6px 6px 3px; overflow: hidden;
  background: var(--ui); border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgb(0 0 0 / .14), 0 6px 14px rgb(0 0 0 / .12);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; filter: brightness(.86); }
:is([data-theme="penumbra"], [data-theme="escuro"], [data-theme="preto"]) .cover img { filter: brightness(.66); }
.book-name {
  margin-top: 10px; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.book-bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.book-bar i { display: block; height: 100%; background: var(--accent); }
.book-del {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: rgb(0 0 0 / .55); color: #fff; display: grid; place-items: center; font-size: 17px; line-height: 1;
}
@media (hover: hover) { .book-del { opacity: 0; } .book:hover .book-del, .book-del:focus-visible { opacity: 1; } }
.book-open:focus-visible .cover { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ===================== LEITOR ===================== */
#reader { position: fixed; inset: 0; background: var(--bg); overflow: hidden; }
#stage { position: absolute; inset: 0; touch-action: pan-y pinch-zoom; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* --- modo livro: paginação por colunas CSS --- */
#textView { position: absolute; inset: 0; display: flex; justify-content: center; }
#textPage {
  width: 100%; max-width: calc(34em + 2 * var(--read-margin));
  font-size: var(--read-size);
  padding: calc(42px + var(--safe-t)) var(--read-margin) calc(46px + var(--safe-b));
  overflow: hidden;
}
#textCol {
  height: 100%; column-fill: auto; /* column-count e column-gap vêm do app.js */
  font-family: var(--read-font); font-size: 1em; line-height: var(--read-lh);
  text-align: var(--read-align); hyphens: auto; -webkit-hyphens: auto;
  overflow-wrap: break-word; font-kerning: normal; text-rendering: optimizeLegibility;
  font-variant-ligatures: common-ligatures; -webkit-font-smoothing: antialiased;
  user-select: text; -webkit-user-select: text;
}
#textCol p { margin: 0 0 .75em; orphans: 2; widows: 2; }
#textCol h2, #textCol h3 { font-weight: 650; line-height: 1.25; margin: 0 0 .7em; break-after: avoid; text-align: left; hyphens: manual; text-wrap: balance; }
#textCol h2 { font-size: 1.4em; padding-top: .3em; }
#textCol h3 { font-size: 1.15em; padding-top: .2em; }
#textCol mark { background: var(--hl); color: inherit; border-radius: 2px; padding: .08em 0; cursor: pointer; }
#textCol ::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
#textCol.image { display: grid; place-items: center; overflow: hidden; }
#textCol .img-fallback { display: block; }

/* --- modo página: a página original tingida com a cor do tema --- */
#pageView { position: absolute; inset: 0; overflow: auto; display: flex; padding: calc(30px + var(--safe-t)) 0 calc(34px + var(--safe-b)); }
#pageWrap { margin: auto; background: var(--bg); isolation: isolate; line-height: 0; }
#pageCanvas { display: block; }
#pageCanvas, .pdf-ink { mix-blend-mode: multiply; }
:is([data-theme="penumbra"], [data-theme="escuro"], [data-theme="preto"]) :is(#pageCanvas, .pdf-ink) {
  filter: invert(1) hue-rotate(180deg) brightness(.74); mix-blend-mode: screen;
}

/* --- cabeçalho e rodapé de leitura (sempre à vista, como no e-reader) --- */
#headLine {
  position: absolute; z-index: 2; top: calc(12px + var(--safe-t)); left: 56px; right: 56px;
  text-align: center; font-size: 12.5px; color: var(--muted); pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#foot {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: calc(6px + var(--safe-b));
  display: flex; align-items: center; justify-content: space-between; padding: 0 14px;
  font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums;
}
#footInfo { border: 0; background: transparent; color: inherit; padding: 8px 6px; min-height: 32px; min-width: 120px; text-align: left; border-radius: 8px; }
#footPct { padding: 8px 6px; }
#track { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; height: 2px; background: var(--line); }
#track i { display: block; height: 100%; width: 0; background: var(--muted); }
#ribbon {
  position: absolute; z-index: 2; top: 0; right: 22px; width: 18px; height: calc(30px + var(--safe-t));
  background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); pointer-events: none;
}
#reader.bars :is(#headLine, #foot, #ribbon, .edge) { visibility: hidden; }

.edge {
  position: absolute; z-index: 3; top: 50%; translate: 0 -50%; width: 44px; height: 88px;
  border: 0; background: transparent; color: var(--muted); opacity: .35; border-radius: 12px;
  display: grid; place-items: center;
}
.edge.prev { left: 6px; } .edge.next { right: 6px; }
.edge:hover, .edge:focus-visible { opacity: 1; background: color-mix(in srgb, var(--fg) 8%, transparent); }

#backChip {
  position: absolute; z-index: 4; left: 50%; translate: -50% 0; bottom: calc(44px + var(--safe-b));
  border: 1px solid var(--line); background: var(--ui); color: var(--fg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px; min-height: 40px;
  box-shadow: 0 4px 14px rgb(0 0 0 / .18);
}

/* --- barras do menu --- */
.bar {
  position: absolute; left: 0; right: 0; z-index: 5;
  background: var(--ui); border: 0 solid var(--line);
  transition: transform .18s ease, opacity .18s ease;
}
.bar.top { top: 0; padding: var(--safe-t) 6px 0; border-bottom-width: 1px; display: flex; align-items: center; gap: 2px; min-height: 52px; }
.bar.bottom { bottom: 0; padding: 10px 18px calc(12px + var(--safe-b)); border-top-width: 1px; }
#reader:not(.bars) .bar.top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
#reader:not(.bars) .bar.bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; padding: 0 6px; }
.foot-row { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.foot-row span:first-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot-row span:last-child { flex: none; }
#chapLabel { color: var(--fg); }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; background: transparent; }

/* --- guia da primeira vez --- */
#guide {
  position: absolute; inset: 0; z-index: 8; display: grid; grid-template-columns: 30fr 40fr 30fr;
  background: color-mix(in srgb, var(--bg) 97%, transparent); color: var(--fg); text-align: center; cursor: pointer;
}
#guide div { display: grid; place-content: center; gap: 8px; padding: 12px; border-right: 1px dashed var(--muted); font-size: 14px; }
#guide div:nth-child(3) { border-right: 0; }
#guide b { font-family: var(--f-serif); font-size: 20px; font-weight: 600; }
#guide span { color: var(--muted); text-wrap: balance; }
#guide p { position: absolute; left: 0; right: 0; bottom: calc(28px + var(--safe-b)); margin: 0; font-size: 14px; color: var(--muted); }

/* --- seleção de texto --- */
#selBar {
  position: fixed; z-index: 30; display: flex; background: var(--fg); color: var(--bg);
  border-radius: 10px; overflow: hidden; box-shadow: 0 6px 20px rgb(0 0 0 / .28);
}
#selBar button { border: 0; background: transparent; color: inherit; padding: 10px 14px; font-size: 14px; min-height: 42px; }
#selBar button + button { border-left: 1px solid color-mix(in srgb, var(--bg) 30%, transparent); }

/* ===================== PAINÉIS ===================== */
#scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .32); z-index: 20; }
.panel {
  position: fixed; z-index: 21; background: var(--ui); color: var(--fg);
  border: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain;
}
.panel.side { top: 0; bottom: 0; left: 0; width: min(400px, 90vw); padding: calc(10px + var(--safe-t)) 16px calc(20px + var(--safe-b)); border-width: 0 1px 0 0; }
.panel.sheet {
  left: 0; right: 0; bottom: 0; max-height: 86dvh; border-radius: 18px 18px 0 0; border-bottom: 0;
  padding: 10px 20px calc(22px + var(--safe-b));
}
@media (min-width: 720px) {
  .panel.sheet { left: auto; right: 16px; top: 62px; bottom: auto; width: 380px; max-height: calc(100dvh - 80px); border-radius: 14px; border-bottom: 1px solid var(--line); box-shadow: 0 12px 40px rgb(0 0 0 / .22); }
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.panel-head h2 { font-size: 17px; }
.panel-head .icon { margin-right: -10px; }

.group { padding: 14px 0; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.group:first-of-type { border-top: 0; padding-top: 4px; }
.label { font-size: 13px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: 0; text-wrap: pretty; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; }
.row output { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatches button {
  background: var(--sw-bg); color: var(--sw-fg); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 0; font-size: 13px; min-height: 48px;
}
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ui), 0 0 0 4px var(--accent); }

.seg, .tabs { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
:is(.seg, .tabs) button { flex: 1; border: 0; background: transparent; padding: 10px 4px; min-height: 44px; font-size: 14px; }
:is(.seg, .tabs) button + button { border-left: 1px solid var(--line); }
:is(.seg, .tabs) button:is([aria-pressed="true"], [aria-selected="true"]) { background: var(--accent); color: var(--on-accent); }
.tabs { margin: 6px 0 14px; }
.tabs button { font-size: 13px; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 48px; height: 40px; border: 1px solid var(--line); background: transparent; border-radius: 10px; font-size: 15px; }
.stepper output { min-width: 52px; text-align: center; }

.check { display: flex; align-items: center; gap: 10px; font-size: 15px; min-height: 36px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

.goto { display: grid; grid-template-columns: 1fr 90px auto; gap: 8px; align-items: center; font-size: 14px; padding: 0 0 14px; border-bottom: 1px solid var(--line); }
.goto.search { grid-template-columns: 1fr auto; }
.goto input { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); width: 100%; min-height: 44px; }
#searchStatus { padding: 10px 2px 0; }

.list { padding-top: 8px; }
.list .item { display: flex; align-items: stretch; gap: 2px; }
.list button.go {
  flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; border-radius: 8px;
  padding: 10px 8px 10px calc(8px + var(--d, 0) * 16px); font-size: 15px; line-height: 1.35;
}
.list button.go small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.list button.go[aria-current="true"] { color: var(--accent); font-weight: 600; }
.list button.rm { flex: none; width: 40px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; font-size: 18px; }
@media (hover: hover) { .list button:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); } }
.list .none { color: var(--muted); font-size: 14px; padding: 12px 8px; margin: 0; text-wrap: pretty; }
.list b { font-weight: 600; background: var(--hl); border-radius: 2px; }

#toast {
  position: fixed; left: 50%; bottom: calc(56px + var(--safe-b)); transform: translateX(-50%); z-index: 40;
  background: var(--fg); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-size: 14.5px;
  max-width: min(440px, calc(100vw - 32px)); text-align: center; text-wrap: pretty;
}
#drop { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 88%, transparent); display: grid; place-items: center; }
#drop div { border: 2px dashed var(--accent); color: var(--accent); padding: 40px 56px; border-radius: 18px; font-size: 18px; }

/* ===================== FILTROS DE CONFORTO ===================== */
/* Sobreposição simples (sem mix-blend-mode). Só existe quando ligada. */
#warmLayer, #dimLayer { position: fixed; inset: 0; pointer-events: none; z-index: 90; display: none; }
#warmLayer { background: #ff8a1f; }
#dimLayer { background: #000; }

@media (prefers-reduced-motion: reduce) { .bar { transition: none; } }
