/* Leitor do livro — Centro Cultural Sobral. Sem CSS inline nas páginas (CSP: style-src 'self'). */
:root {
  --fs: 1.15;            /* escala do corpo do texto, multiplica o rem do sistema */
  --lh: 1.7;
  --measure: 68ch;       /* 60–75 caracteres por linha */
  --bar-h: 3.25rem;
  /* tema claro (padrão) — contrastes ≥ 4.5:1 */
  --bg: #fbf9f5; --fg: #26211c; --muted: #5f564c; --accent: #8a4b0f;
  --surface: #ffffff; --line: #e3dbcf; --mark: #ffe08a; --mark-fg: #26211c; --focus: #1a5fb4;
  --font-body: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-fonte="sans"] { --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

@media (prefers-color-scheme: dark) {
  :root[data-tema="auto"] {
    --bg: #16130f; --fg: #d8d0c4; --muted: #a89f92; --accent: #e0a96a;
    --surface: #211d18; --line: #38322a; --mark: #6b5320; --mark-fg: #fff3d6; --focus: #8ab4f8;
    color-scheme: dark;
  }
}
:root[data-tema="claro"] { color-scheme: light; }
:root[data-tema="sepia"] {
  --bg: #f1e4c8; --fg: #3b2f1e; --muted: #66563f; --accent: #7a3f08;
  --surface: #f8eed8; --line: #dac9a4; --mark: #f3c969; --mark-fg: #3b2f1e; --focus: #1a4f9c;
}
:root[data-tema="escuro"] {
  --bg: #16130f; --fg: #d8d0c4; --muted: #a89f92; --accent: #e0a96a;
  --surface: #211d18; --line: #38322a; --mark: #6b5320; --mark-fg: #fff3d6; --focus: #8ab4f8;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 1rem); }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-ui); line-height: 1.5; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: .5rem; top: -4rem; background: var(--surface); color: var(--fg); padding: .6rem 1rem; border: 2px solid var(--accent); z-index: 100; }
.skip:focus { top: .5rem; }
[hidden] { display: none !important; }

/* ---------- barras ---------- */
.bar { position: fixed; left: 0; right: 0; z-index: 20; background: var(--surface); border-color: var(--line); display: flex; align-items: center; gap: .25rem; padding: 0 .5rem; transition: transform .2s ease; }
.bar-top { top: 0; height: var(--bar-h); border-bottom: 1px solid var(--line); }
.bar-bottom { bottom: 0; min-height: 2.6rem; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); padding: .35rem .75rem; justify-content: space-between; flex-wrap: wrap; }
.bar-title { flex: 1; min-width: 0; text-align: center; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); padding: 0 .5rem; }
.btn { font: inherit; color: var(--fg); background: transparent; border: 1px solid transparent; border-radius: .5rem; min-width: 2.75rem; min-height: 2.75rem; padding: 0 .65rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none; }
.btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn[aria-pressed="true"], .btn[aria-expanded="true"] { border-color: var(--accent); }
.btn-solid { background: var(--accent); color: var(--bg); border-color: var(--accent); padding: .6rem 1.2rem; font-weight: 600; }
.btn-solid:hover { background: var(--accent); filter: brightness(1.08); }
.btn-line { border-color: var(--line); background: var(--surface); }
.progress { position: fixed; top: var(--bar-h); left: 0; right: 0; height: 4px; background: var(--line); z-index: 19; transition: transform .2s ease; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); }
.immersive .bar-top { transform: translateY(-110%); }
.immersive .bar-bottom { transform: translateY(110%); }
.immersive .progress { transform: translateY(calc(-1 * var(--bar-h) - 4px)); }

/* ---------- texto ---------- */
.reader main { padding: calc(var(--bar-h) + 2rem) 1rem 5rem; }
.prose { max-width: var(--measure); margin: 0 auto; font-family: var(--font-body); font-size: calc(1rem * var(--fs)); line-height: var(--lh); hyphens: auto; overflow-wrap: break-word; }
.prose h1 { font-size: 1.7em; line-height: 1.2; margin: 0 0 1.5rem; text-wrap: balance; }
.prose p { margin: 0 0 1em; text-align: left; }
.prose figure { margin: 1.5rem auto; text-align: center; }
.prose img { max-width: 100%; height: auto; border-radius: 4px; border: 1px solid var(--line); background: var(--surface); }
.prose mark, mark.hl { background: var(--mark); color: var(--mark-fg); border-radius: 2px; padding: 0 .08em; }
.prose mark.found { outline: 2px solid var(--accent); }
.prose .pgmark { display: block; height: 0; overflow: hidden; }
.pager { max-width: var(--measure); margin: 3rem auto 0; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-family: var(--font-ui); }
.pager .btn { flex: 1 1 12rem; text-align: center; border-color: var(--line); background: var(--surface); }
.pager .btn small { display: block; color: var(--muted); }

/* ---------- gaveta (sumário/marcadores) e painéis ---------- */
.drawer { position: fixed; top: var(--bar-h); bottom: 0; left: 0; width: min(24rem, 92vw); background: var(--surface); border-right: 1px solid var(--line); z-index: 30; overflow-y: auto; padding: .75rem; box-shadow: 4px 0 18px rgba(0,0,0,.18); }
.drawer h2 { font-size: 1rem; margin: .75rem .25rem .5rem; }
.drawer ol, .drawer ul { list-style: none; margin: 0; padding: 0; }
.drawer li a { display: block; padding: .55rem .6rem; border-radius: .4rem; color: var(--fg); text-decoration: none; font-size: .95rem; }
.drawer li a:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.drawer li a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 20%, transparent); font-weight: 700; border-left: 4px solid var(--accent); }
.drawer small { color: var(--muted); display: block; }
.drawer li a[aria-current="page"] small, .drawer li a:hover small { color: var(--fg); } /* contraste sobre o fundo destacado */
.panel { position: fixed; top: calc(var(--bar-h) + .25rem); right: .5rem; width: min(22rem, calc(100vw - 1rem)); background: var(--surface); border: 1px solid var(--line); border-radius: .75rem; z-index: 30; padding: 1rem; box-shadow: 0 8px 28px rgba(0,0,0,.25); }
.panel h2 { font-size: 1rem; margin: 0 0 .75rem; }
.panel .row { display: flex; align-items: center; gap: .5rem; margin-bottom: .85rem; flex-wrap: wrap; }
.panel .row > span { flex: 0 0 5.5rem; color: var(--muted); font-size: .9rem; }
.panel .seg { display: flex; gap: .35rem; flex: 1; }
.panel .seg .btn { flex: 1; border-color: var(--line); min-width: 2.75rem; }
.panel .seg .btn[aria-pressed="true"] { background: var(--accent); color: var(--bg); }
.scrim { position: fixed; inset: var(--bar-h) 0 0 0; z-index: 25; background: rgba(0,0,0,.35); }
.search-box { display: flex; gap: .4rem; }
.search-box input { flex: 1; min-height: 2.75rem; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: .5rem; padding: 0 .75rem; }
.results li a { white-space: normal; }
.results em { background: var(--mark); color: var(--mark-fg); font-style: normal; border-radius: 2px; }

.selbar { position: absolute; z-index: 40; display: flex; gap: .25rem; background: var(--fg); color: var(--bg); border-radius: .6rem; padding: .25rem; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.selbar .btn { color: var(--bg); min-height: 2.5rem; font-size: .9rem; }
.selbar .btn:hover { background: rgba(255,255,255,.18); }
.toast { position: fixed; left: 50%; bottom: 4rem; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: .6rem 1rem; border-radius: .6rem; z-index: 60; font-size: .9rem; max-width: 90vw; }

.fs-label { flex: 0 0 3.5rem; text-align: center; }
.muted-sm { font-size: .85rem; color: var(--muted); }
.results { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.hero h1 .sub { font-weight: 400; }

/* ---------- página de entrada do livro ---------- */
.home { max-width: 62rem; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.home .top { display: flex; justify-content: space-between; gap: .75rem; align-items: center; flex-wrap: wrap; font-size: .95rem; }
.hero { display: grid; gap: 2rem; grid-template-columns: 1fr; margin: 1.5rem 0 2.5rem; }
.hero img { width: 100%; max-width: 22rem; height: auto; border-radius: 6px; box-shadow: 0 10px 34px rgba(0,0,0,.28); justify-self: center; background: var(--surface); }
.hero h1 { font-family: var(--font-body); font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.1; margin: 0 0 .25rem; }
.hero .autor { color: var(--muted); font-size: 1.1rem; margin: 0 0 1rem; }
.hero p { font-family: var(--font-body); max-width: 60ch; }
.hero .acoes { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.25rem; }
.toc-list { columns: 1; column-gap: 2rem; list-style: none; padding: 0; margin: 0; }
.toc-list li { break-inside: avoid; border-bottom: 1px solid var(--line); }
.toc-list a { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem .25rem; color: var(--fg); text-decoration: none; }
.toc-list a:hover { color: var(--accent); }
.toc-list small { color: var(--muted); white-space: nowrap; }
.home footer { margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.aviso-int { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: .4rem; padding: .75rem 1rem; font-size: .9rem; margin-bottom: 1.5rem; }
.creditos { max-width: var(--measure); margin: 0 auto; padding: 2rem 1rem 4rem; font-family: var(--font-body); line-height: 1.7; }

@media (min-width: 48rem) {
  .hero { grid-template-columns: 22rem 1fr; align-items: center; }
  .toc-list { columns: 2; }
  .reader main { padding-left: 2rem; padding-right: 2rem; }
}
@media (min-width: 64rem) {
  /* desktop: sumário fixo ao lado do texto */
  .reader.toc-pinned .drawer { box-shadow: none; }
  .reader.toc-pinned main { margin-left: 24rem; }
  .reader.toc-pinned .scrim { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print { .bar, .progress, .drawer, .panel, .pager, .selbar { display: none !important; } }
