/* ============================================================
   Leitor de livros — tiagopereira.com.br
   Compartilhado por todas as obras em /livros/{slug}/
   ============================================================ */

:root {
  --fs: 19px;
  --larg: 42rem;
  --verde: #10b981;
  --verde-claro: #34d399;
  --ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: Charter, 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
}

/* Temas */
html[data-tema="claro"]  { --fundo: #fdfbf7; --papel: #ffffff; --texto: #1f2937; --suave: #6b7280; --linha: #e5e7eb; --cita: #f8fafc; --topo: rgba(255,255,255,.92); }
html[data-tema="sepia"]  { --fundo: #f1e7d0; --papel: #f8f0de; --texto: #3b2f20; --suave: #7a6a52; --linha: #e0d2b4; --cita: #efe4c9; --topo: rgba(248,240,222,.94); }
html[data-tema="escuro"] { --fundo: #0b1220; --papel: #0f172a; --texto: #e2e8f0; --suave: #94a3b8; --linha: #1e293b; --cita: #111c33; --topo: rgba(15,23,42,.94); }

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; }
body { margin: 0; background: var(--fundo); color: var(--texto); font-family: var(--ui); transition: background .3s, color .3s; }
a { color: var(--verde); }
img { max-width: 100%; height: auto; display: block; }

/* Barra de progresso */
.progresso { position: fixed; inset: 0 0 auto; height: 3px; z-index: 60; background: transparent; }
.progresso span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--verde), var(--verde-claro)); }

/* Topo */
.topo { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
        padding: .6rem 1rem; background: var(--topo); backdrop-filter: blur(10px); border-bottom: 1px solid var(--linha); }
.voltar { display: inline-flex; align-items: center; gap: .3rem; color: var(--suave); text-decoration: none; font-size: .85rem; font-weight: 600; }
.voltar:hover { color: var(--verde); }
.voltar svg { width: 20px; height: 20px; fill: currentColor; }
.controles { display: flex; gap: .35rem; }
.btn-ic { display: inline-flex; align-items: center; gap: .35rem; min-width: 2.4rem; height: 2.4rem; padding: 0 .6rem; justify-content: center;
          border: 1px solid var(--linha); border-radius: .6rem; background: var(--papel); color: var(--texto); font: 600 .85rem var(--ui); cursor: pointer; }
.btn-ic:hover { border-color: var(--verde); color: var(--verde); }
.btn-ic svg { width: 18px; height: 18px; fill: currentColor; }

/* Layout */
/* minmax(0, 1fr): impede que conteúdo largo (ex.: tabela) estique a página além da tela */
.leitor { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 78rem; margin: 0 auto; }
.leitor > *, .rosto > * { min-width: 0; }
@media (min-width: 1100px) { .leitor { grid-template-columns: 17rem minmax(0, 1fr); gap: 2rem; padding: 0 1.5rem; } #btn-indice { display: none; } }

/* Índice */
.indice { font-size: .88rem; }
.indice-titulo { font-weight: 800; text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; color: var(--suave); margin: 0 0 .75rem; }
.indice ol { list-style: none; margin: 0; padding: 0; }
.indice li a { display: block; padding: .35rem .6rem; border-left: 2px solid var(--linha); color: var(--suave); text-decoration: none; line-height: 1.35; }
.indice li.n3 a { padding-left: 1.4rem; font-size: .82rem; }
.indice li a:hover, .indice li a.ativo { color: var(--verde); border-left-color: var(--verde); }
@media (min-width: 1100px) { .indice { position: sticky; top: 4.5rem; align-self: start; max-height: calc(100vh - 6rem); overflow: auto; padding: 2rem 0; } }
@media (max-width: 1099px) {
  .indice { position: fixed; z-index: 55; top: 3.6rem; right: .75rem; left: .75rem; max-height: 70vh; overflow: auto; padding: 1.25rem;
            background: var(--papel); border: 1px solid var(--linha); border-radius: 1rem; box-shadow: 0 20px 50px rgba(0,0,0,.25);
            opacity: 0; visibility: hidden; transform: translateY(-8px); transition: .2s; }
  .indice.aberto { opacity: 1; visibility: visible; transform: none; }
}

/* Página do livro */
.livro { background: var(--papel); max-width: calc(var(--larg) + 6rem); width: 100%; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
@media (min-width: 700px) { .livro { padding: 3rem 3rem 5rem; margin: 2rem auto; border-radius: 1rem; box-shadow: 0 10px 40px rgba(0,0,0,.08); } }

/* Folha de rosto */
.rosto { display: grid; gap: 2rem; padding-bottom: 2.5rem; margin-bottom: 2.5rem; border-bottom: 1px solid var(--linha); }
@media (min-width: 640px) { .rosto { grid-template-columns: 220px 1fr; align-items: start; } }
.capa { width: 100%; max-width: 260px; margin: 0 auto; border-radius: .4rem .9rem .9rem .4rem; box-shadow: 0 18px 45px rgba(0,0,0,.35); }
.selo { display: inline-block; margin: 0 0 .75rem; padding: .25rem .75rem; border-radius: 999px; background: rgba(16,185,129,.12); color: var(--verde);
        font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.rosto h1 { font-family: var(--serif); font-size: clamp(1.9rem, 5vw, 2.6rem); line-height: 1.1; margin: 0; }
.rosto h1 span { display: block; font-size: .6em; font-weight: 400; color: var(--suave); margin-top: .4rem; }
.autor { font-weight: 700; margin: 1rem 0 0; }
.disponivel { margin: .4rem 0 0; font-size: .82rem; color: var(--verde); font-weight: 600; }
.ficha { margin: 1.25rem 0 0; display: grid; gap: .4rem; font-size: .85rem; }
.ficha div { display: grid; grid-template-columns: 6.5rem 1fr; gap: .5rem; }
.ficha dt { color: var(--suave); font-weight: 600; }
.ficha dd { margin: 0; }
.acoes { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.5rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .7rem 1.1rem; border-radius: .7rem;
       border: 1px solid var(--linha); background: var(--papel); color: var(--texto); font: 700 .88rem var(--ui); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--verde); color: var(--verde); }
.btn-pri { background: var(--verde); border-color: var(--verde); color: #fff; }
.btn-pri:hover { background: var(--verde-claro); color: #052e1f; }
.kindle { margin-top: 1rem; border: 1px solid var(--linha); border-radius: .8rem; padding: .75rem 1rem; font-size: .88rem; }
.kindle summary { cursor: pointer; font-weight: 700; color: var(--verde); }
.kindle ol { padding-left: 1.2rem; margin: .75rem 0 .5rem; }
.kindle li { margin-bottom: .35rem; }
.kindle p { margin: 0; color: var(--suave); }

/* Texto */
.texto { font-family: var(--serif); font-size: var(--fs); line-height: 1.75; max-width: var(--larg); margin: 0 auto; hyphens: auto; }
.texto section + section { margin-top: 3.5rem; }
.texto h2 { font-family: var(--ui); font-size: 1.35em; line-height: 1.3; letter-spacing: -.01em; margin: 0 0 1.25rem; padding-bottom: .5rem; border-bottom: 2px solid var(--linha); }
.texto h3 { font-family: var(--ui); font-size: 1.05em; line-height: 1.35; margin: 2.25rem 0 .9rem; }
.texto p { margin: 0 0 1.1em; text-align: justify; text-indent: 1.5em; }
.texto p.destaque { text-indent: 0; margin: -.4em 0 .6em; font-family: var(--ui); font-size: .9em; color: var(--suave); }
/* Coluna estreita: justificado cria "buracos" entre as palavras — alinha à esquerda */
@media (max-width: 600px) { .texto p { text-align: left; } }
.texto blockquote { margin: 1.5em 0; padding: 1rem 1.25rem; background: var(--cita); border-left: 3px solid var(--verde); border-radius: 0 .6rem .6rem 0;
                    font-size: .9em; font-style: italic; line-height: 1.65; }
.texto blockquote cite { display: block; margin-top: .6em; text-align: right; font-family: var(--ui); font-style: normal; font-size: .85em; font-weight: 600; color: var(--suave); }
.texto ul, .texto ol { padding-left: 1.4em; margin: 0 0 1.2em; }
.texto li { margin-bottom: .45em; }
.texto section[lang="en"] p { font-style: italic; color: var(--suave); }

/* Grades (ex.: quadro P-D-C-A) */
.texto ul.grade { list-style: none; padding: 0; margin: 1.75em auto; max-width: 30rem; display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.texto ul.grade li { margin: 0; padding: .9rem 1rem; text-align: center; border: 1px solid var(--linha); border-radius: .7rem; background: var(--cita);
                     font-family: var(--ui); font-size: .8em; text-transform: uppercase; letter-spacing: .06em; color: var(--suave); }
.texto ul.grade li strong { display: block; font-size: 1.9em; line-height: 1.1; color: var(--verde); letter-spacing: 0; }

/* Tabelas (rolam na horizontal no celular, sem quebrar a página) */
.texto table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 1.75em 0;
               font-family: var(--ui); font-size: .78em; line-height: 1.45; border: 1px solid var(--linha); border-radius: .6rem; }
.texto th, .texto td { padding: .7em .9em; text-align: left; vertical-align: top; border-bottom: 1px solid var(--linha); }
.texto thead th { background: var(--cita); text-transform: uppercase; letter-spacing: .05em; font-size: .85em; color: var(--suave); white-space: nowrap; }
.texto tbody tr:last-child td { border-bottom: 0; }
.texto tbody td:nth-child(2) { font-weight: 600; white-space: nowrap; }

/* Referências bibliográficas (ABNT: alinhadas à esquerda, recuo deslocado) */
.texto .referencias p { text-align: left; text-indent: -1.5em; padding-left: 1.5em; font-size: .9em; line-height: 1.6; hyphens: none; word-break: break-word; }
.texto hr { border: 0; border-top: 1px solid var(--linha); margin: 2.5rem 0; }

/* Fim */
.fim { max-width: var(--larg); margin: 4rem auto 0; padding-top: 2rem; border-top: 1px solid var(--linha); font-size: .9rem; }
.fim h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .08em; color: var(--suave); }
.abnt { font-family: var(--serif); padding: 1rem 1.25rem; background: var(--cita); border-radius: .6rem; line-height: 1.6; }
.licenca { color: var(--suave); }
.outras { list-style: none; padding: 0; margin: 1rem 0 2rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1.25rem; }
.outras a { display: flex; flex-direction: column; gap: .35rem; text-decoration: none; color: var(--texto); }
.outras img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; object-position: top; border-radius: .3rem .6rem .6rem .3rem; box-shadow: 0 8px 20px rgba(0,0,0,.2); transition: transform .2s; }
.outras a:hover img { transform: translateY(-3px); }
.o-tipo { font-size: .7rem; color: var(--suave); text-transform: uppercase; letter-spacing: .05em; margin-top: .3rem; }
.o-titulo { font-weight: 700; font-size: .9rem; line-height: 1.3; }
.outras a:hover .o-titulo { color: var(--verde); }

/* Selo da licença Creative Commons */
.cc { display: inline-block; padding: .1rem .5rem; margin-right: .3rem; border: 1px solid var(--linha); border-radius: .4rem;
      font: 700 .72rem var(--ui); color: var(--texto); text-decoration: none; letter-spacing: .03em; }
.cc:hover { border-color: var(--verde); color: var(--verde); }

/* Biblioteca (livros/index.html) */
.biblioteca { max-width: 60rem; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }
.bib-topo { text-align: center; margin-bottom: 2.5rem; }
.bib-topo h1 { font-family: var(--serif); font-size: clamp(2.2rem, 6vw, 3rem); margin: .2rem 0 .5rem; }
.bib-topo p:last-child { color: var(--suave); max-width: 34rem; margin: 0 auto; line-height: 1.6; }
.bib-lista { list-style: none; padding: 0; margin: 0; display: grid; gap: 1.5rem; }
.bib-item { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 1.75rem; align-items: start; background: var(--papel);
            border: 1px solid var(--linha); border-radius: 1rem; padding: 1.5rem; box-shadow: 0 6px 24px rgba(0,0,0,.05); }
.bib-capa img { width: 100%; border-radius: .3rem .7rem .7rem .3rem; box-shadow: 0 12px 30px rgba(0,0,0,.25); transition: transform .2s; }
.bib-capa:hover img { transform: translateY(-3px) rotate(-1deg); }
.bib-tipo { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--verde); margin: 0 0 .4rem; }
.bib-info h2 { font-family: var(--serif); font-size: 1.6rem; line-height: 1.2; margin: 0; }
.bib-info h2 a { color: var(--texto); text-decoration: none; }
.bib-info h2 a:hover { color: var(--verde); }
.bib-sub { color: var(--suave); font-family: var(--serif); font-size: 1.05rem; margin: .3rem 0 .8rem; }
.bib-desc { line-height: 1.65; margin: 0 0 .9rem; }
.bib-temas { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.bib-temas li { font-size: .72rem; padding: .2rem .6rem; border-radius: 999px; background: var(--cita); border: 1px solid var(--linha); color: var(--suave); }
.biblioteca .acoes { margin-top: 1.1rem; }
.biblioteca .fim { margin-top: 2.5rem; }
@media (max-width: 560px) {
  .bib-item { grid-template-columns: 1fr; text-align: center; }
  .bib-capa { width: 55%; margin: 0 auto; }
  .bib-temas, .biblioteca .acoes { justify-content: center; }
}

/* Impressão / PDF */
@media print {
  @page { size: A4; margin: 2.2cm 2cm; }
  .topo, .progresso, .indice, .acoes, .kindle, .fim .btn, .outras, #outras-obras { display: none !important; }
  .rosto { display: block; text-align: center; }
  .capa { max-width: 11cm; margin: 0 auto 1cm; box-shadow: none; }
  .selo { border: 1px solid #000; background: none; color: #000; }
  html, body, .livro { background: #fff !important; color: #000 !important; box-shadow: none !important; }
  .livro { max-width: none; margin: 0; padding: 0; }
  .texto { font-size: 12pt; }
  .texto section { break-before: page; }
  .rosto { break-after: page; }
  a { color: #000; text-decoration: none; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
