/* Layout: coluna de leitura (~68ch) com a escada fixa à esquerda; no celular, a escada vira faixa horizontal no topo.
   Identidade: caderno de análise — papel frio, tinta grafite, um único acento "giz verde" para o que é interativo,
   e um ocre discreto só para marcar o degrau atual da escada. */
:root {
  --bg: #f3f5f7;
  --paper: #ffffff;
  --fg: #1c2229;
  --muted: #5b6672;
  --rule: #d6dce3;
  --accent: #1f7a6d;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ee;
  --step: #c58a1a;
  --step-soft: #fbf1dc;
  --good: #2b7a3d; --good-soft: #e4f3e7;
  --bad: #b23a3a;  --bad-soft: #f8e4e4;
  --code: #eef1f4;
  --shadow: 0 1px 2px rgba(20,30,40,.06), 0 8px 24px -12px rgba(20,30,40,.18);
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --body: "IBM Plex Sans", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --measure: 68ch;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d; --paper: #1b2026; --fg: #e6eaee; --muted: #9aa5b1; --rule: #2d343c;
    --accent: #5cc2b1; --accent-ink: #0f1a18; --accent-soft: #1d3330;
    --step: #e0a93f; --step-soft: #3a2f16;
    --good: #6cc585; --good-soft: #1d3324; --bad: #ef8a8a; --bad-soft: #3b1f1f;
    --code: #232a31; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14181d; --paper: #1b2026; --fg: #e6eaee; --muted: #9aa5b1; --rule: #2d343c;
  --accent: #5cc2b1; --accent-ink: #0f1a18; --accent-soft: #1d3330;
  --step: #e0a93f; --step-soft: #3a2f16;
  --good: #6cc585; --good-soft: #1d3324; --bad: #ef8a8a; --bad-soft: #3b1f1f;
  --code: #232a31; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; animation: none !important; } }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--body); font-size: 16px; line-height: 1.6;
  margin: 0; min-height: 100%;
}
a { color: var(--accent); text-underline-offset: .15em; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, pre, .mono { font-family: var(--mono); font-size: .92em; }
pre { background: var(--code); border-radius: 6px; padding: .9rem 1rem; overflow-x: auto; line-height: 1.45; }
code { background: var(--code); padding: .08em .35em; border-radius: 4px; }
pre code { background: none; padding: 0; }
h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; line-height: 1.2; text-wrap: balance; letter-spacing: -.005em; }
h2 { font-size: 1.55rem; margin: 2.4rem 0 .8rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); }
h3 { font-size: 1.2rem; margin: 1.8rem 0 .5rem; }
h4 { font-size: 1.02rem; margin: 1.3rem 0 .4rem; font-family: var(--body); font-weight: 600; }
p, ul, ol { margin: 0 0 1rem; }
li { margin-bottom: .3rem; }
blockquote {
  margin: 1.2rem 0; padding: .9rem 1.1rem; border-left: 3px solid var(--step);
  background: var(--step-soft); border-radius: 0 6px 6px 0;
}
blockquote p:last-child { margin-bottom: 0; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem 0; }
.tbl { overflow-x: auto; margin: 1rem 0 1.4rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
table { border-collapse: collapse; width: 100%; font-size: .94rem; }
th, td { text-align: left; vertical-align: top; padding: .55rem .75rem; border-bottom: 1px solid var(--rule); }
th { font-family: var(--body); font-weight: 600; font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: var(--code); }
tr:last-child td { border-bottom: 0; }
td:first-child { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: .74rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .6rem 16px; background: var(--paper); border-bottom: 1px solid var(--rule);
}
.brand { font-family: var(--display); font-weight: 600; font-size: 1.1rem; text-decoration: none; color: var(--fg); white-space: nowrap; }
.brand small { font-family: var(--body); font-weight: 400; color: var(--muted); font-size: .8rem; margin-left: .5rem; }
.topbar .grow { flex: 1 1 auto; min-width: 0; }
.search { display: flex; align-items: center; gap: .4rem; flex: 1 1 220px; max-width: 420px; }
.search input {
  width: 100%; min-width: 0; padding: .45rem .7rem; border: 1px solid var(--rule); border-radius: 6px;
  background: var(--bg); color: var(--fg); font: inherit; font-size: .92rem;
}
.iconbtn {
  border: 1px solid var(--rule); background: var(--paper); border-radius: 6px; padding: .4rem .65rem; font-size: .85rem;
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap;
}
.iconbtn:hover { border-color: var(--accent); }
.iconbtn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 0; max-width: 1240px; margin: 0 auto; }
.side { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 58px); align-self: start; height: calc(100vh - 58px); overflow-y: auto; padding: 1.4rem 0 1.4rem 16px; }
.main { min-width: 0; padding: 1.6rem 16px 5rem; }
.reading { max-width: var(--measure); }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: .9rem 16px 0; }
}

/* ---------- escada ---------- */
.ladder { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 4px; }
.ladder a {
  display: grid; grid-template-columns: 2rem 1fr; align-items: center; gap: .5rem;
  padding: .45rem .6rem; border-radius: 6px; text-decoration: none; color: var(--fg); font-size: .9rem;
  border: 1px solid transparent;
}
.ladder a:hover { background: var(--paper); border-color: var(--rule); }
.ladder a .n { font-family: var(--display); font-weight: 600; font-size: 1.05rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ladder a .t { line-height: 1.2; }
.ladder a .t small { display: block; color: var(--muted); font-size: .76rem; }
.ladder li.current a { background: var(--step-soft); border-color: var(--step); }
.ladder li.current a .n { color: var(--step); }
.ladder li.done a .n::after { content: " ✓"; color: var(--good); font-size: .8rem; }
.ladder li.locked a { opacity: .55; }
.side .eyebrow { margin: 0 0 .6rem .6rem; }
.side .extra { margin-top: 1.2rem; display: flex; flex-direction: column; gap: 4px; }
.side .extra a { display: block; padding: .4rem .6rem; border-radius: 6px; text-decoration: none; color: var(--fg); font-size: .88rem; }
.side .extra a:hover, .side .extra a.current { background: var(--paper); }
@media (max-width: 860px) {
  .ladder { flex-direction: row; flex-wrap: wrap; }
  .ladder a { grid-template-columns: auto; padding: .35rem .55rem; }
  .ladder a .t { display: none; }
  .side .extra { flex-direction: row; flex-wrap: wrap; }
}

/* ---------- cabeçalho de capítulo ---------- */
.chapter-head { margin-bottom: 1.4rem; }
.chapter-head .eyebrow { display: flex; gap: .6rem; align-items: center; margin-bottom: .5rem; }
.chapter-head .eyebrow .pill { background: var(--step-soft); color: var(--step); border-radius: 999px; padding: .1em .6em; font-weight: 700; }
.chapter-head h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); margin: 0 0 .4rem; }
.chapter-head .sub { color: var(--muted); font-size: 1.05rem; margin: 0; }
.chapter-meta { display: flex; gap: 1.2rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; margin-top: .8rem; }

/* tabela de abertura (Você precisa de / Ao final / Teste de entrada) vira cartão */
.prereq { border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); padding: .2rem 1rem; margin: 1.2rem 0 1.6rem; box-shadow: var(--shadow); }
.prereq table { font-size: .95rem; }
.prereq th { display: none; }
.prereq td:first-child { width: 11rem; color: var(--muted); font-weight: 600; }
.prereq td { padding: .7rem .4rem; border-bottom: 1px dashed var(--rule); }
.prereq tr:last-child td { border-bottom: 0; }
.prereq .entry-cta { margin-top: .4rem; }
@media (max-width: 560px) { .prereq td { display: block; width: auto; padding: .3rem .2rem; } .prereq td:first-child { border: 0; padding-top: .8rem; } }

/* gabarito recolhido */
details.gab { border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); margin: 1rem 0 1.6rem; }
details.gab summary { cursor: pointer; padding: .75rem 1rem; font-weight: 600; list-style: none; display: flex; align-items: center; gap: .6rem; }
details.gab summary::-webkit-details-marker { display: none; }
details.gab summary::before { content: "▸"; color: var(--accent); transition: transform .15s; }
details.gab[open] summary::before { transform: rotate(90deg); }
details.gab .inner { padding: 0 1rem 1rem; border-top: 1px solid var(--rule); }

/* caixa "Por trás do nome" e "Cena do tropeço" */
.box-name { border-left-color: var(--accent); background: var(--accent-soft); }
.callout-trip { border: 1px solid var(--bad); border-left-width: 4px; border-radius: 6px; padding: .2rem 1rem; margin: 1.2rem 0; background: var(--paper); }
.callout-trip h3 { margin-top: .8rem; color: var(--bad); }

/* navegação pé de capítulo */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3rem; padding-top: 1.4rem; border-top: 1px solid var(--rule); }
.pager a { display: block; text-decoration: none; color: var(--fg); padding: .9rem 1rem; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); }
.pager a:hover { border-color: var(--accent); }
.pager a .eyebrow { display: block; margin-bottom: .2rem; }
.pager a.next { text-align: right; }
.pager a .ttl { font-family: var(--display); font-weight: 600; }
.chapter-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1.2rem 0 0; }

/* sumário lateral do capítulo */
.toc { font-size: .85rem; margin: .8rem 0 0; padding: 0; list-style: none; }
.toc li a { color: var(--muted); text-decoration: none; display: block; padding: .18rem .6rem; border-left: 2px solid transparent; }
.toc li a:hover, .toc li a.active { color: var(--fg); border-left-color: var(--accent); }

/* ---------- home ---------- */
.hero { max-width: 760px; margin: 1rem 0 2.4rem; }
.hero h1 { font-size: clamp(2.2rem, 5.2vw, 3.4rem); margin: 0 0 .8rem; }
.hero .lede { font-size: 1.15rem; color: var(--muted); max-width: 60ch; }
.hero .cta { display: flex; gap: .7rem; flex-wrap: wrap; margin-top: 1.3rem; }
.bigladder { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: .5rem; max-width: 760px; }
.bigladder a {
  display: grid; grid-template-columns: 3rem 1fr auto; gap: 1rem; align-items: center; text-decoration: none; color: var(--fg);
  padding: .9rem 1.1rem; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px;
  margin-left: calc(var(--i) * 1.6rem);
}
.bigladder a:hover { border-color: var(--accent); }
.bigladder .n { font-family: var(--display); font-size: 1.6rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.bigladder .t { font-weight: 600; }
.bigladder .t small { display: block; font-weight: 400; color: var(--muted); font-size: .86rem; }
.bigladder .dep { font-size: .78rem; color: var(--muted); text-align: right; white-space: nowrap; }
.bigladder li.done a { border-color: var(--good); }
.bigladder li.done .n { color: var(--good); }
@media (max-width: 620px) { .bigladder a { margin-left: calc(var(--i) * .5rem); grid-template-columns: 2.4rem 1fr; } .bigladder .dep { display: none; } }
.section-title { margin-top: 2.6rem; }
.thesis { font-family: var(--display); font-size: 1.3rem; font-style: italic; color: var(--fg); border: 0; background: none; padding: 0; margin: 1.6rem 0; }
.fio { border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); padding: 1rem 1.2rem; margin: 1rem 0; max-width: 760px; }
.fio .sentence { font-family: var(--display); font-size: 1.35rem; margin: .3rem 0 .8rem; }
.fio .w { display: inline-block; padding: .05em .3em; border-radius: 4px; transition: background .15s; cursor: default; }
.fio .w:hover, .fio .w.on { background: var(--accent-soft); outline: 1px solid var(--accent); }
.fio .legend { font-size: .9rem; color: var(--muted); min-height: 2.6em; }
.fio .legend b { color: var(--fg); }

/* ---------- quiz ---------- */
.quiz { max-width: 760px; }
.quiz .q { background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 1.1rem 1.2rem; margin: 0 0 .9rem; }
.quiz .q .stem { font-weight: 600; margin: 0 0 .7rem; }
.quiz .q .stem .num { color: var(--muted); font-weight: 400; margin-right: .4rem; font-variant-numeric: tabular-nums; }
.opts { display: flex; flex-direction: column; gap: .45rem; }
.opt { display: flex; gap: .7rem; align-items: flex-start; padding: .55rem .75rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); text-align: left; width: 100%; }
.opt:hover { border-color: var(--accent); }
.opt .k { font-family: var(--mono); font-size: .8rem; color: var(--muted); min-width: 1.2rem; padding-top: .15rem; }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt[disabled] { cursor: default; }
.why { margin-top: .7rem; font-size: .93rem; padding: .6rem .8rem; border-radius: 6px; background: var(--code); }
.why.ok { background: var(--good-soft); }
.why.err { background: var(--bad-soft); }
.why a { font-weight: 600; }
.verdict { border: 1px solid var(--rule); border-radius: 8px; padding: 1.2rem 1.3rem; background: var(--paper); margin-top: 1.2rem; box-shadow: var(--shadow); }
.verdict h3 { margin-top: 0; }
.verdict.pass { border-color: var(--good); }
.verdict.fail { border-color: var(--step); }
.verdict ul { margin-bottom: .6rem; }
.progressbar { height: 6px; background: var(--rule); border-radius: 3px; overflow: hidden; margin: .6rem 0 1.2rem; }
.progressbar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.diag-intro { max-width: 68ch; }
.diag-level { margin: 1.6rem 0 .5rem; display: flex; align-items: baseline; gap: .6rem; }
.diag-level .pill { font-size: .75rem; background: var(--step-soft); color: var(--step); border-radius: 999px; padding: .1em .6em; font-weight: 700; letter-spacing: .04em; }

/* ---------- busca ---------- */
.results { max-width: 760px; }
.hit { display: block; text-decoration: none; color: var(--fg); padding: .9rem 1rem; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); margin-bottom: .6rem; }
.hit:hover { border-color: var(--accent); }
.hit .eyebrow { display: block; margin-bottom: .2rem; }
.hit mark { background: var(--step-soft); color: inherit; padding: 0 .1em; }
.empty { color: var(--muted); padding: 2rem 0; }

/* progresso */
.progress-card { border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); padding: 1rem 1.1rem; margin-top: 1.2rem; max-width: 760px; }
.progress-card .row { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; padding: .35rem 0; border-bottom: 1px dashed var(--rule); }
.progress-card .row:last-child { border: 0; }
.tag { font-size: .75rem; border-radius: 999px; padding: .1em .6em; font-weight: 600; }
.tag.ok { background: var(--good-soft); color: var(--good); }
.tag.todo { background: var(--code); color: var(--muted); }
.tag.redo { background: var(--step-soft); color: var(--step); }
.sr { position: absolute; left: -9999px; }

/* caixa "Como outras gramáticas chamam isto": nota de referência, discreta */
blockquote.box-alt { border-left: 3px solid var(--rule); background: var(--paper); border-top: 1px solid var(--rule); border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); font-size: .94rem; }
blockquote.box-alt > p:first-child strong { font-family: var(--body); font-size: .74rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
blockquote.box-alt ul { margin: .4rem 0 0; padding-left: 1.1rem; }
