:root {
  --fonte: 19px;
  --entrelinha: 1.62;
  --coluna: 36em;
  --topo: 52px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

html[data-tema="claro"] {
  --fundo: #fbfaf7; --texto: #1f1e1b; --suave: #77736a; --linha: #e6e2d9;
  --superficie: #ffffff; --realce: #8a5a2b;
  --h-amarelo: rgba(255, 214, 64, .45); --h-verde: rgba(120, 210, 120, .40);
  --h-azul: rgba(110, 170, 255, .38); --h-rosa: rgba(255, 130, 170, .38);
  --orig-fundo: #f2efe7;
}
html[data-tema="sepia"] {
  --fundo: #f3ead6; --texto: #3a2e1f; --suave: #8a7a60; --linha: #e0d3b6;
  --superficie: #f9f2e2; --realce: #8a4f1c;
  --h-amarelo: rgba(240, 190, 40, .45); --h-verde: rgba(110, 180, 90, .40);
  --h-azul: rgba(90, 150, 220, .35); --h-rosa: rgba(230, 110, 140, .35);
  --orig-fundo: #ebdfc4;
}
html[data-tema="escuro"] {
  --fundo: #141413; --texto: #d8d3c6; --suave: #8d887c; --linha: #2c2b28;
  --superficie: #1d1c1a; --realce: #d9a46a;
  --h-amarelo: rgba(220, 180, 40, .32); --h-verde: rgba(90, 170, 90, .32);
  --h-azul: rgba(80, 140, 230, .34); --h-rosa: rgba(220, 90, 130, .32);
  --orig-fundo: #1c1b19;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topo) + 12px); }
body {
  margin: 0; background: var(--fundo); color: var(--texto);
  font-family: var(--serif); transition: background .25s, color .25s;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- topo ---------- */
#topo {
  position: fixed; inset: 0 0 auto 0; height: var(--topo); z-index: 20;
  display: flex; align-items: center; gap: 2px; padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--fundo) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--linha);
  font-family: var(--sans); transition: transform .25s;
}
#topo.oculto { transform: translateY(-100%); }
.ico { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; color: var(--suave); position: relative; flex: none; }
.ico:hover { color: var(--texto); background: var(--linha); }
.lg { font-family: var(--sans); font-size: 12px; font-weight: 700; letter-spacing: .04em; border: 1.5px solid currentColor; border-radius: 5px; padding: 1px 4px; }
#btnIdioma.en .lg { color: var(--realce); }
.tag { font-family: var(--sans); font-size: 10px; font-weight: 700; color: var(--realce); border: 1px solid var(--realce); border-radius: 4px; padding: 0 4px; white-space: nowrap; align-self: center; }
.aa { font-family: var(--serif); font-size: 15px; }
.aa.grande { font-size: 21px; }
.titulo { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; padding: 0 6px; }
#tituloVol { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#secAtual { font-size: 12px; color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pct { font-size: 12px; color: var(--suave); font-variant-numeric: tabular-nums; padding: 0 6px; }
.badge { position: absolute; top: 4px; right: 2px; font-size: 10px; min-width: 16px; padding: 0 3px; border-radius: 8px; background: var(--realce); color: var(--fundo); line-height: 16px; }
.badge:empty { display: none; }
#barra { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
#barraFill { height: 100%; width: 0; background: var(--realce); transition: width .2s; }

/* ---------- texto ---------- */
#livro {
  max-width: var(--coluna); margin: 0 auto;
  padding: calc(var(--topo) + 28px) clamp(18px, 5vw, 40px) 40vh;
  font-size: var(--fonte); line-height: var(--entrelinha);
  hyphens: auto; -webkit-hyphens: auto;
}
.carregando { color: var(--suave); text-align: center; font-family: var(--sans); font-size: 14px; margin-top: 30vh; }
.cabeca-vol { text-align: center; margin: 1.5em 0 2.5em; }
.cabeca-vol .sobre { font-family: var(--sans); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--suave); margin: 0 0 1.2em; }
.cabeca-vol h1 { font-weight: 500; font-size: 1.9em; line-height: 1.1; margin: 0 0 .25em; }
.cabeca-vol .subtitulo { font-style: italic; font-size: 1.15em; margin: 0 0 .6em; }
.cabeca-vol .ed { color: var(--suave); font-size: .8em; margin: 0; }
.frente { margin: 0 0 2.5em; font-size: .86em; color: var(--suave); border-top: 1px solid var(--linha); border-bottom: 1px solid var(--linha); padding: .6em 0; }
.frente summary { cursor: pointer; font-family: var(--sans); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.frente p { text-align: justify; }

.tit { font-weight: 500; line-height: 1.3; text-align: center; text-wrap: balance; }
.tit.n1 { font-size: 1.05em; letter-spacing: .14em; text-transform: uppercase; margin: 3.4em 0 .4em; color: var(--suave); }
.tit.n2 { font-size: 1.3em; margin: 2.2em 0 1.1em; }
.tit.n1 + .tit.n2 { margin-top: .6em; }
.tit.n3 { font-size: .95em; font-style: italic; margin: 1.8em 0 .9em; }

.par { position: relative; }
.par .t { margin: 0 0 1em; text-align: justify; }
.par .t.pre { white-space: pre-line; text-align: left; }
.par.cont .t { text-indent: 1.4em; }
.par.flash .t { animation: flash 1.8s ease-out; border-radius: 4px; }
@keyframes flash { from { background: color-mix(in srgb, var(--realce) 22%, transparent); } to { background: transparent; } }

.cpn {
  font-family: var(--sans); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--suave); padding: 1px 5px; margin-right: .45em; border-radius: 4px;
  vertical-align: 2px; user-select: none; -webkit-user-select: none; line-height: 1.5;
}
.cpn:hover { color: var(--realce); background: var(--linha); }
@media (min-width: 900px) {
  .cpn { position: absolute; right: 100%; top: .28em; margin: 0 .9em 0 0; white-space: nowrap; }
  .par .t { text-indent: 1.4em; }
}

sup { line-height: 0; }
sup.fn { cursor: pointer; padding: 0 1px; user-select: none; -webkit-user-select: none; }
sup.fn::after { content: attr(data-l); font-family: var(--sans); font-size: .62em; color: var(--realce); font-weight: 600; }
sup.fn:not(.peirce)::after { opacity: .7; }

mark { color: inherit; border-radius: 2px; padding: .05em 0; cursor: pointer; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
mark.amarelo { background: var(--h-amarelo); }
mark.verde { background: var(--h-verde); }
mark.azul { background: var(--h-azul); }
mark.rosa { background: var(--h-rosa); }
mark.nota-fim::after {
  content: "✎"; font-family: var(--sans); font-size: .62em; vertical-align: super;
  color: var(--realce); margin-left: 1px;
}
mark.ativo { outline: 2px solid var(--realce); outline-offset: 1px; }

/* ---------- barras flutuantes ---------- */
.flutuante {
  position: fixed; z-index: 40; display: flex; align-items: center; gap: 4px;
  padding: 6px; border-radius: 12px; background: var(--superficie);
  border: 1px solid var(--linha); box-shadow: 0 6px 24px rgba(0,0,0,.18);
  font-family: var(--sans); font-size: 13px;
}
.flutuante[hidden] { display: none; }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; flex: none; }
.dot.amarelo { background: #f5cf3c; } .dot.verde { background: #79c879; }
.dot.azul { background: #6ea9f5; } .dot.rosa { background: #f287a9; }
.dot.ativo { border-color: var(--texto); }
.flutuante .sep { width: 1px; align-self: stretch; background: var(--linha); margin: 0 2px; }
.flutuante .txt { padding: 6px 8px; border-radius: 7px; }
.flutuante .txt:hover { background: var(--linha); }
.perigo { color: #c94a3a; }
.pop { display: block; max-width: min(420px, calc(100vw - 16px)); max-height: 45vh; overflow: auto; padding: 12px 14px; }
.pop small { display: block; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--suave); margin-bottom: 6px; }
.pop .notaTxt { font-family: var(--serif); font-size: 15px; line-height: 1.5; white-space: pre-line; }

/* ---------- painel ---------- */
#veu { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 29; }
#painel {
  position: fixed; top: 0; bottom: 0; right: 0; width: min(440px, 100vw); z-index: 30;
  background: var(--superficie); border-left: 1px solid var(--linha);
  transform: translateX(102%); transition: transform .25s ease;
  display: flex; flex-direction: column; font-family: var(--sans); font-size: 14px;
  padding-top: env(safe-area-inset-top);
}
#painel.aberto { transform: none; box-shadow: -10px 0 40px rgba(0,0,0,.15); }
.abas { display: flex; align-items: center; gap: 4px; padding: 8px 8px 0 12px; border-bottom: 1px solid var(--linha); }
.abas button[data-aba] { padding: 10px 10px 12px; color: var(--suave); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.abas button[data-aba].ativa { color: var(--texto); border-color: var(--realce); }
.abas .fechar { margin-left: auto; }
.aba { flex: 1; overflow: auto; padding: 14px 16px 30px; -webkit-overflow-scrolling: touch; }
.aba[hidden] { display: none; }

#continuar { margin-bottom: 12px; padding: 12px; border-radius: 10px; background: var(--orig-fundo); }
#continuar:empty { display: none; }
#continuar small { color: var(--suave); display: block; margin-bottom: 4px; }
#continuar button { color: var(--realce); font-weight: 600; padding: 0; }
#continuar .quando { color: var(--suave); font-size: 12px; }
#irCP { display: flex; gap: 6px; margin-bottom: 14px; }
#irCP input { flex: 1; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--linha); background: var(--fundo); color: var(--texto); font: inherit; outline: none; }
#irCP input:focus { border-color: var(--realce); }
#irCP button { padding: 0 14px; border-radius: 9px; background: var(--realce); color: var(--fundo); font-weight: 600; }
.vol { border-top: 1px solid var(--linha); }
.volCab { width: 100%; display: flex; gap: 10px; align-items: baseline; padding: 12px 4px; text-align: left; }
.volCab .vn { font-family: var(--serif); color: var(--suave); width: 2.2em; flex: none; }
.volCab .vt { font-weight: 600; flex: 1; }
.volCab .va { color: var(--suave); font-size: 12px; }
.vol.atual .volCab .vt { color: var(--realce); }
.toc { list-style: none; margin: 0 0 10px; padding: 0; }
.toc button { width: 100%; text-align: left; padding: 6px 8px; border-radius: 7px; display: flex; gap: 10px; align-items: baseline; }
.toc button:hover { background: var(--linha); }
.toc .tt { flex: 1; }
.toc .n { color: var(--suave); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.toc .n1 button { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--suave); margin-top: 8px; }
.toc .n2 button { padding-left: 14px; font-weight: 500; }
.toc .n3 button { padding-left: 28px; font-size: 13px; color: var(--suave); }
.toc li.aqui > button { background: color-mix(in srgb, var(--realce) 14%, transparent); color: var(--texto); }

.filtros { position: sticky; top: -14px; background: var(--superficie); padding: 0 0 10px; margin-top: -14px; padding-top: 14px; z-index: 1; }
#buscaDestaques { width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--linha); background: var(--fundo); color: var(--texto); font: inherit; outline: none; }
#buscaDestaques:focus { border-color: var(--realce); }
.linha { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.cores { display: flex; gap: 6px; align-items: center; }
.cores .dot { width: 20px; height: 20px; }
.cores button:not(.dot) { font-size: 12px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--linha); color: var(--suave); }
.cores button.ativo:not(.dot) { color: var(--texto); border-color: var(--texto); }
.soNotas { font-size: 12px; color: var(--suave); display: flex; gap: 4px; align-items: center; }
#ordem { margin-left: auto; font: inherit; font-size: 12px; background: var(--fundo); color: var(--texto); border: 1px solid var(--linha); border-radius: 7px; padding: 4px 6px; }
#resumoDestaques { font-size: 12px; color: var(--suave); margin: 4px 0 8px; }

#listaDestaques { list-style: none; margin: 0; padding: 0; }
#listaDestaques li { padding: 12px 0; border-bottom: 1px solid var(--linha); }
#listaDestaques .cap { font-size: 11px; color: var(--suave); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
#listaDestaques .cap .dot { width: 9px; height: 9px; border: 0; }
#listaDestaques .cap b { color: var(--texto); letter-spacing: 0; }
#listaDestaques .cap .sec { text-transform: none; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#listaDestaques li.grupo { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--realce); font-weight: 600; padding: 16px 0 4px; border: 0; }
#listaDestaques .cit {
  font-family: var(--serif); font-size: 15.5px; line-height: 1.45; cursor: pointer;
  border-left: 3px solid var(--cor); padding-left: 10px; display: block; width: 100%; text-align: left;
}
#listaDestaques .nota { margin: 8px 0 0 13px; padding: 8px 10px; border-radius: 8px; background: var(--orig-fundo); white-space: pre-wrap; font-size: 13.5px; }
#listaDestaques .acoes { display: flex; gap: 2px; margin: 6px 0 0 8px; }
#listaDestaques .acoes button { font-size: 12px; color: var(--suave); padding: 4px 6px; border-radius: 6px; }
#listaDestaques .acoes button:hover { color: var(--texto); background: var(--linha); }
#listaDestaques .orfao { color: #c94a3a; font-size: 11px; }
#listaDestaques em.achado { font-style: normal; background: var(--h-amarelo); border-radius: 2px; }
.vazio { color: var(--suave); text-align: center; padding: 40px 10px; line-height: 1.5; }

.backup { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 22px; }
.backup button { font-size: 12px; color: var(--suave); border: 1px solid var(--linha); padding: 6px 10px; border-radius: 8px; }
.backup button:hover { color: var(--texto); }

/* ---------- diálogo ---------- */
#notaDlg {
  width: min(520px, calc(100vw - 24px)); border: 1px solid var(--linha); border-radius: 14px;
  background: var(--superficie); color: var(--texto); padding: 18px; font-family: var(--sans);
}
#notaDlg::backdrop { background: rgba(0,0,0,.35); }
#notaCitacao { margin: 0 0 12px; padding-left: 10px; border-left: 3px solid var(--realce); font-family: var(--serif); font-size: 15px; max-height: 9em; overflow: auto; color: var(--suave); }
#notaTexto { width: 100%; font: inherit; font-size: 15px; padding: 10px; border-radius: 9px; border: 1px solid var(--linha); background: var(--fundo); color: var(--texto); resize: vertical; outline: none; }
#notaTexto:focus { border-color: var(--realce); }
#notaDlg .acoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#notaDlg .acoes button { padding: 8px 16px; border-radius: 9px; background: var(--realce); color: var(--fundo); font-weight: 600; }
#notaDlg .acoes button.sec { background: none; color: var(--suave); }

#cpDlg {
  width: min(720px, calc(100vw - 16px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--linha); border-radius: 14px; background: var(--superficie); color: var(--texto);
  display: none; flex-direction: column;
}
#cpDlg[open] { display: flex; }
#cpDlg::backdrop { background: rgba(0,0,0,.4); }
.cpCab { display: flex; gap: 10px; align-items: flex-start; padding: 14px 10px 10px 20px; border-bottom: 1px solid var(--linha); font-family: var(--sans); }
.cpCab > div { flex: 1; min-width: 0; }
.cpCab strong { font-size: 17px; display: block; }
.cpCab small { color: var(--suave); font-size: 12.5px; }
#cpCorpo { overflow: auto; padding: 6px 22px 10px; font-family: var(--serif); font-size: calc(var(--fonte) * .9); line-height: 1.55; }
#cpCorpo p { text-align: justify; margin: .8em 0; hyphens: auto; }
#cpCorpo p.pre { white-space: pre-line; text-align: left; }
#cpCorpo .num { font-weight: 600; }
#cpCorpo .cpSub { font-family: var(--sans); font-size: 12px; color: var(--realce); margin: 1.4em 0 0; letter-spacing: .04em; }
#cpCorpo sup.fnc { font-family: var(--sans); font-size: .62em; color: var(--realce); font-weight: 600; }
.cpNotas { border-top: 1px solid var(--linha); margin-top: 1.4em; padding-top: .4em; font-size: .88em; }
.cpNotas h6 { font-family: var(--sans); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--suave); margin: .8em 0 0; font-weight: 600; }
.cpNotas p { text-align: left !important; white-space: pre-line; }
.cpNotas .quem { font-family: var(--sans); font-size: 11px; color: var(--suave); }
.cpAcoes { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 14px; border-top: 1px solid var(--linha); font-family: var(--sans); font-size: 14px; }
.cpAcoes button { padding: 9px 14px; border-radius: 9px; background: var(--realce); color: var(--fundo); font-weight: 600; }
.cpAcoes button.sec { background: none; color: var(--texto); border: 1px solid var(--linha); }

.fim-vol { text-align: center; color: var(--suave); margin-top: 4em; font-family: var(--sans); font-size: 14px; }
.fim-vol button { margin-top: .6em; padding: 12px 18px; border-radius: 10px; border: 1px solid var(--linha); color: var(--texto); font-family: var(--serif); font-size: 16px; }
.fim-vol button:hover { border-color: var(--realce); color: var(--realce); }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--texto); color: var(--fundo); font-family: var(--sans); font-size: 13.5px;
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50;
  max-width: calc(100vw - 32px);
}
#toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { color: var(--fundo); text-decoration: underline; margin-left: 8px; padding: 0; }

@media (max-width: 520px) {
  :root { --fonte: 18px; }
  #topo .ico { width: 36px; }
  #pct { display: none; }
  .par .t { text-align: left; }
  #cpDlg { max-height: calc(100vh - 16px); }
}
@media print {
  #topo, #painel, .cpn, .flutuante { display: none !important; }
  #livro { padding-top: 0; }
}
