/* ============================================================
   book.css — tema próprio, e-reader digital-first
   ============================================================ */

/* --- Reset mínimo --- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img, svg { max-width: 100%; height: auto; display: block; }
a { color: inherit; }

/* --- Tokens de tema --- */
:root {
  /* Cor */
  --ink:        #000000;
  --ink-soft:   #2a2a2a;
  --ink-muted:  #6b6b6b;
  --paper:      #fafaf7;
  --rule:       #e6e2da;
  --link:       #0b5fb0;
  --link-hover: #083f75;
  --mark:       #fff3a8;
  --code-bg:    #f1ede4;
  --code-ink:   #1a1a1a;

  /* Tipografia */
  --ff-serif: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  --ff-sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ff-mono:  "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;

  --fs-xs:    0.75rem;
  --fs-sm:    0.875rem;
  --fs-base:  1.0625rem;
  --fs-lg:    1.25rem;
  --fs-xl:    1.5rem;
  --fs-2xl:   2.25rem;
  --fs-3xl:   clamp(2.5rem, 5vw, 3.5rem);

  --lh-body:  1.65;
  --lh-tight: 1.2;

  --fw-body:  600;   /* semibold — decisão do autor */
  --fw-head:  700;

  --measure:  38rem;
  --space-flow: 1.2em;
}

html {
  font-size: 18px;
  color-scheme: light;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ff-serif);
  font-size: var(--fs-base);
  font-weight: var(--fw-body);
  line-height: var(--lh-body);
  font-feature-settings: "kern", "liga", "onum";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  hyphens: auto;
}

/* --- Skip link --- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.5rem 1rem;
  font-family: var(--ff-sans);
  font-size: var(--fs-sm);
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* --- Foco visível --- */
:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
  border-radius: 3px;
}

/* --- Redução de movimento --- */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}

/* ============================================================
   Layout
   ============================================================ */

.book-main {
  max-width: min(100% - 2rem, var(--measure));
  margin: 0 auto;
  padding: 4rem 0 6rem;
}

/* Ritmo vertical */
.book-main > * + *,
.chapter-body > * + * {
  margin-top: var(--space-flow);
}

/* ============================================================
   Header
   ============================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.site-header-inner {
  max-width: min(100% - 2rem, var(--measure));
  margin: 0 auto;
  padding: 0.875rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--ff-sans);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.site-id {
  text-decoration: none;
  color: var(--ink-soft);
}

.site-id:hover { color: var(--ink); }

.site-sep {
  margin: 0 0.35em;
  color: var(--ink-muted);
}

.site-nav a {
  text-decoration: none;
  color: var(--ink-soft);
}

.site-nav a:hover { color: var(--ink); }

/* ============================================================
   Footer
   ============================================================ */

.site-footer {
  border-top: 1px solid var(--rule);
  padding: 2rem 0;
  margin-top: 6rem;
}

.site-footer-inner {
  max-width: min(100% - 2rem, var(--measure));
  margin: 0 auto;
  font-family: var(--ff-sans);
  font-size: var(--fs-sm);
  color: var(--ink-muted);
}

.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--link); }

/* ============================================================
   Capítulo
   ============================================================ */

.chapter-header {
  margin-bottom: 2.5rem;
}

.chapter-eyebrow {
  margin: 0;
  font-family: var(--ff-sans);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.chapter-title {
  margin: 0.25rem 0 0;
  font-family: var(--ff-serif);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-head);
  line-height: var(--lh-tight);
  color: var(--ink);
  text-wrap: balance;
}

/* Headings dentro do corpo do capítulo */
.chapter-body h2 {
  font-family: var(--ff-serif);
  font-size: var(--fs-xl);
  font-weight: var(--fw-head);
  line-height: var(--lh-tight);
  margin-top: 2.5em;
  text-wrap: balance;
}

.chapter-body h3 {
  font-family: var(--ff-serif);
  font-size: var(--fs-lg);
  font-weight: var(--fw-head);
  line-height: var(--lh-tight);
  margin-top: 2em;
  text-wrap: balance;
}

/* Compatibilidade com padrão existente: "### **Texto**" — anula o bold duplicado */
.chapter-body h3 > strong:only-child {
  font-weight: inherit;
}

.chapter-body p {
  text-wrap: pretty;
}

.chapter-body ul,
.chapter-body ol {
  padding-left: 1.5em;
}

.chapter-body li + li {
  margin-top: 0.4em;
}

.chapter-body blockquote {
  margin: 0;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  color: var(--ink-soft);
}

.chapter-body a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

.chapter-body a:hover {
  color: var(--link-hover);
}

/* ============================================================
   Código
   ============================================================ */

code, pre {
  font-family: var(--ff-mono);
  font-feature-settings: "calt", "liga" 0;
}

/* inline */
.chapter-body code {
  font-size: 0.92em;
  padding: 0.05em 0.35em;
  background: var(--code-bg);
  border-radius: 3px;
}

.chapter-body pre {
  margin: 1.5em 0;
  padding: 1rem 1.25rem;
  background: var(--code-bg);
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--code-ink);
  font-weight: 400;
}

.chapter-body pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  border-radius: 0;
}

/* Bloco estoura medida em telas largas */
@media (min-width: 50rem) {
  .chapter-body pre {
    margin-left: -2rem;
    margin-right: -2rem;
  }
}

/* Syntax highlight — Rouge (classes .hl) */
.hl .k, .hl .kt, .hl .kd, .hl .kn { font-weight: 700; }         /* keywords e tipos */
.hl .nc, .hl .nn                   { color: var(--link); }       /* classes e namespaces */
.hl .s, .hl .s1, .hl .s2,
.hl .sc, .hl .sb, .hl .sh          { color: #7a3e00; font-style: italic; }  /* strings */
.hl .mi, .hl .mf, .hl .mh,
.hl .mo                            { color: #7a3e00; }            /* números */
.hl .c, .hl .c1, .hl .cm, .hl .cp,
.hl .cs, .hl .cd                   { color: var(--ink-muted); font-style: italic; }  /* comentários */
/* qualquer outra classe .hl .* herda --code-ink naturalmente */

/* ============================================================
   Footer-nav (navegação entre seções)
   ============================================================ */

.footer-nav {
  max-width: min(100% - 2rem, var(--measure));
  margin: 5rem auto 0;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  font-family: var(--ff-sans);
  font-size: var(--fs-sm);
}

.footer-nav-slot {
  min-height: 3rem;   /* reserva espaço mesmo quando vazio */
}

.footer-nav-next {
  text-align: right;
}

.footer-nav a {
  text-decoration: none;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

.footer-nav-next a {
  justify-content: flex-end;
}

.footer-nav-num {
  color: var(--ink-muted);
  font-variant-numeric: oldstyle-nums;
}

.footer-nav-title {
  color: var(--ink);
  font-weight: 600;
}

.footer-nav a:hover .footer-nav-title {
  color: var(--link);
}

.footer-nav-arrow {
  color: var(--ink-muted);
  font-size: 1.1em;
}

/* ============================================================
   Sumário (index, layout: toc)
   ============================================================ */

.book-cover {
  text-align: center;
  margin: 4rem 0 5rem;
}

.book-cover-eyebrow {
  margin: 0;
  font-family: var(--ff-sans);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.book-cover-title {
  margin: 0.5rem 0 0.75rem;
  font-family: var(--ff-serif);
  font-size: var(--fs-3xl);
  font-weight: var(--fw-head);
  line-height: var(--lh-tight);
  color: var(--ink);
}

.book-cover-lede {
  margin: 0 auto;
  max-width: 30rem;
  font-family: var(--ff-serif);
  font-size: var(--fs-lg);
  font-weight: var(--fw-body);
  color: var(--ink-soft);
  text-wrap: balance;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-item + .toc-item {
  margin-top: 0.25rem;
}

.toc-item a {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: 0.5rem;
  padding: 0.35rem 0;
  text-decoration: none;
  color: var(--ink);
}

.toc-num {
  font-family: var(--ff-sans);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-muted);
  font-variant-numeric: oldstyle-nums;
  text-align: right;
}

.toc-title {
  font-family: var(--ff-serif);
  font-size: var(--fs-base);
  font-weight: var(--fw-body);
}

.toc-item a:hover .toc-title {
  color: var(--link);
}

/* Indentação por profundidade */
.toc-depth-2 .toc-title { padding-left: 0.75rem; }
.toc-depth-3 .toc-title { padding-left: 1.5rem; color: var(--ink-soft); }
.toc-depth-4 .toc-title { padding-left: 2.25rem; color: var(--ink-muted); font-size: var(--fs-sm); }
