/* ultra_library — o leitor ---------------------------------------------- */

:root {
  --paper: #f2f0ea;
  --paper-2: #e9e6dd;
  --ink: #1b2621;
  --ink-soft: #5c6560;
  --rule: rgba(27,38,33,.14);
  --accent: hsl(var(--hue) 45% 38%);
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --body: "Literata", "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --font-religiao: "Cormorant Garamond", "Cinzel", "Fraunces", Georgia, serif;
  --font-historia: "Cinzel", "Marcellus", "Fraunces", Georgia, serif;
  --font-estrategia: "Bodoni Moda", "Prata", "Cinzel", Georgia, serif;
  --font-literatura: "Playfair Display", "Fraunces", Georgia, serif;
  --font-filosofia: "Spectral", "Newsreader", Georgia, serif;
  --font-ciencia: "BioRhyme", "Space Grotesk", Georgia, serif;
  --font-economia: "Libre Baskerville", "Baskervville", Georgia, serif;

  --bar-h: 3.4rem;
  --tabs-h: 3.6rem;
  color-scheme: light;
}
body.dark {
  --paper: #131816;
  --paper-2: #1b211e;
  --ink: #d8d4c8;
  --ink-soft: #8f958f;
  --rule: rgba(216,212,200,.14);
  --accent: hsl(var(--hue) 45% 62%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body.reader {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.125rem;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button { font: inherit; color: inherit; }

/* barra ------------------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  height: var(--bar-h);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem;
  padding: 0 1.2rem;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.back {
  text-decoration: none; font-family: var(--mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-soft);
}
.back:hover { color: var(--accent); }
.bar-title { min-width: 0; display: flex; gap: .7rem; align-items: baseline; overflow: hidden; white-space: nowrap; }
.bar-title b { font-family: var(--display); font-weight: 500; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; }
.bar-title span { font-size: .8rem; color: var(--ink-soft); font-style: italic; overflow: hidden; text-overflow: ellipsis; }

[data-shelf="religiao"] .bar-title b, [data-shelf="religiao"] h1, [data-shelf="religiao"] h2, [data-shelf="religiao"] h3 { font-family: var(--font-religiao); }
[data-shelf="historia"] .bar-title b, [data-shelf="historia"] h1, [data-shelf="historia"] h2, [data-shelf="historia"] h3 { font-family: var(--font-historia); }
[data-shelf="estrategia"] .bar-title b, [data-shelf="estrategia"] h1, [data-shelf="estrategia"] h2, [data-shelf="estrategia"] h3 { font-family: var(--font-estrategia); }
[data-shelf="literatura"] .bar-title b, [data-shelf="literatura"] h1, [data-shelf="literatura"] h2, [data-shelf="literatura"] h3 { font-family: var(--font-literatura); }
[data-shelf="filosofia"] .bar-title b, [data-shelf="filosofia"] h1, [data-shelf="filosofia"] h2, [data-shelf="filosofia"] h3 { font-family: var(--font-filosofia); }
[data-shelf="ciencia"] .bar-title b, [data-shelf="ciencia"] h1, [data-shelf="ciencia"] h2, [data-shelf="ciencia"] h3 { font-family: var(--font-ciencia); }
[data-shelf="economia"] .bar-title b, [data-shelf="economia"] h1, [data-shelf="economia"] h2, [data-shelf="economia"] h3 { font-family: var(--font-economia); }

.bar-tools { display: flex; gap: .3rem; }
.bar-tools button {
  background: none; border: 1px solid var(--rule); border-radius: 50%;
  width: 34px; height: 34px; cursor: pointer; font-size: 1rem; line-height: 1;
}
.bar-tools button:hover { border-color: var(--accent); color: var(--accent); }
.btn-toc { display: none; }

/* abas de profundidade ---------------------------------------------------- */
.tabs {
  position: sticky; top: var(--bar-h); z-index: 19;
  display: flex; justify-content: center; gap: 0;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto; scrollbar-width: none;
}
.tab {
  flex: none;
  background: none; border: 0; border-bottom: 3px solid transparent;
  padding: .7rem 1.1rem .55rem; cursor: pointer; text-align: left;
  color: var(--ink-soft);
  transition: color .15s;
}
.tab b { display: block; font-family: var(--display); font-weight: 500; font-size: 1rem; line-height: 1.1; }
.tab-meta { display: block; font-family: var(--mono); font-size: .62rem; letter-spacing: .06em; margin-top: .25rem; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.level-desc {
  text-align: center; margin: .6rem 1rem 0; font-style: italic; font-size: .9rem; color: var(--ink-soft);
}

/* página ------------------------------------------------------------------ */
.page { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.2rem 6rem; }
.level { display: grid; grid-template-columns: 240px minmax(0, 40rem); gap: 3rem; justify-content: center; }
.level[hidden] { display: none; }

.toc {
  position: sticky; top: calc(var(--bar-h) + var(--tabs-h) + 1rem);
  align-self: start;
  max-height: calc(100vh - var(--bar-h) - var(--tabs-h) - 2rem);
  overflow-y: auto; scrollbar-width: thin;
  font-size: .82rem; line-height: 1.35;
  padding-right: .5rem;
}
.toc-title { margin: 0 0 .8rem; font-family: var(--display); font-weight: 500; font-size: 1rem; }
.toc-title span { display: block; font-family: var(--mono); font-size: .62rem; letter-spacing: .06em; color: var(--ink-soft); margin-top: .3rem; font-weight: 400; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
.toc li a {
  display: block; padding: .3rem 0 .3rem .8rem; text-decoration: none; color: var(--ink-soft);
  border-left: 2px solid transparent; margin-left: -1px;
}
.toc li a:hover { color: var(--ink); }
.toc li a.active { color: var(--ink); border-left-color: var(--accent); }

.text { min-width: 0; }
.text h1 {
  font-family: var(--display); font-weight: 400; font-size: 2rem; line-height: 1.12; letter-spacing: -.015em;
  margin: 3.2rem 0 1.3rem; text-wrap: balance;
  scroll-margin-top: calc(var(--bar-h) + var(--tabs-h) + 1.2rem);
}
.text h1:first-child { margin-top: .6rem; }
.text h1::before {
  content: ""; display: block; width: 3rem; height: 3px; background: var(--accent); margin-bottom: 1.1rem;
}
.text h2 { font-family: var(--display); font-weight: 500; font-size: 1.25rem; margin: 2.2rem 0 .8rem; text-transform: none; letter-spacing: 0; scroll-margin-top: calc(var(--bar-h) + var(--tabs-h) + 1rem); }
.text h3, .text h4 { font-family: var(--display); font-weight: 500; font-size: 1.05rem; margin: 1.6rem 0 .5rem; }
.text p { margin: 0 0 1.1em; text-wrap: pretty; hyphens: auto; }
.text p + p { text-indent: 0; }
.text blockquote { margin: 1.2rem 0; padding-left: 1rem; border-left: 2px solid var(--accent); font-style: italic; color: var(--ink-soft); }
.text ul, .text ol { padding-left: 1.4rem; }
.text hr { border: 0; border-top: 1px solid var(--rule); margin: 2.4rem auto; width: 6rem; }
.text em { font-style: italic; }

/* L3/L4 ficam mais amplos e centrados */
.level[data-chapters="0"] { grid-template-columns: minmax(0, 40rem); }
.level[data-chapters="0"] .toc ol { display: none; }
.level[data-chapters="0"] .toc { position: static; max-height: none; margin-bottom: 1rem; }
.level[data-level="L4"] .text p { font-size: 1.35rem; line-height: 1.6; font-family: var(--display); font-weight: 300; }
.level[data-level="L4"] .text h1, .level[data-level="L3"] .text h1 { font-size: 2.4rem; }

/* variantes (ficção) ------------------------------------------------------ */
.text-col { min-width: 0; }
.variant-switch {
  display: flex; gap: .4rem; margin: .6rem 0 1.4rem;
  font-family: var(--mono); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase;
}
.variant-switch button {
  background: none; border: 1px solid var(--rule); border-radius: 999px;
  padding: .4rem .9rem; cursor: pointer; color: var(--ink-soft); text-align: left;
}
.variant-switch button span { display: block; font-size: .58rem; letter-spacing: .04em; text-transform: none; opacity: .8; margin-top: .1rem; }
.variant-switch button:hover { border-color: var(--accent); color: var(--ink); }
.variant-switch button[aria-pressed="true"] { border-color: var(--accent); color: var(--ink); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* elenco e lugares (ficção) ---------------------------------------------- */
.cast-panel {
  position: fixed; top: var(--bar-h); right: 0; bottom: 0; z-index: 25;
  width: min(360px, 90vw); overflow-y: auto; scrollbar-width: thin;
  background: var(--paper-2); padding: 1.2rem 1.4rem 2rem;
  box-shadow: -20px 0 40px -10px rgba(0,0,0,.4);
  font-size: .9rem; line-height: 1.5;
}
.cast-panel[hidden] { display: none; }
.cast-close { position: absolute; top: .6rem; right: .8rem; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--ink-soft); }
.cast-body h1 { font-family: var(--display); font-weight: 500; font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
.cast-body h1:first-child { margin-top: .2rem; }
.cast-body ul { list-style: none; margin: 0; padding: 0; }
.cast-body li { padding: .35rem 0; border-top: 1px solid var(--rule); text-wrap: pretty; }
.cast-body li strong { font-weight: 500; }

/* progresso --------------------------------------------------------------- */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 30; pointer-events: none; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

/* mobile ------------------------------------------------------------------ */
@media (max-width: 900px) {
  body.reader { font-size: 1.05rem; }
  .btn-toc { display: inline-block; }
  .level { grid-template-columns: minmax(0, 40rem); }
  .toc {
    position: fixed; top: var(--bar-h); left: 0; bottom: 0; z-index: 25;
    width: min(320px, 85vw); max-height: none;
    background: var(--paper-2); padding: 1.2rem; box-shadow: 20px 0 40px -10px rgba(0,0,0,.4);
    transform: translateX(-100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  }
  body.toc-open .level:not([hidden]) .toc { transform: none; }
  .level[data-chapters="0"] .toc { display: none; }
  .bar-title span { display: none; }
  .tabs { justify-content: flex-start; }
  .text h1 { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .toc, .progress i, body.reader { transition: none; }
}
