:root {
  --paper: #f2f6f4;
  --sheet: #ffffff;
  --ink: #0b6b5a;
  --ink-deep: #0f3a34;
  --graphite: #252b29;
  --muted: #5b6662;
  --rule: #d3ddd9;
  --red: #c0312a;
  --green: #17734a;
  --blue: #1d4fae;
  --hl: #ffe45c;
  --hl-new: #c5efd3;
  --hl-del: #f9d5d1;
  --hl-cand: #cfe0ff;
  --tint: #e3efeb;
  --f-display: "Bricolage Grotesque", "Segoe UI Variable Display", "Segoe UI", sans-serif;
  --f-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}
* { box-sizing: border-box; }
html { font-size: 17px; }
body { margin: 0; background: var(--paper); color: var(--graphite); font-family: var(--f-body); line-height: 1.55; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--sheet); padding: 8px 12px; z-index: 9; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }
#nav { background: var(--ink-deep); color: #dcebe6; padding: 28px 0 40px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
#nav .brand { font-family: var(--f-display); font-weight: 700; font-size: 1.35rem; line-height: 1.15; color: #fff; padding: 0 24px 4px; margin: 0; }
#nav a.home { display: block; border: 0; padding: 0 24px 4px; }
#nav a.home::before { content: none; }
#nav a.home:hover { background: none; text-decoration: underline; }
#nav .sub { padding: 0 24px 18px; margin: 0; font-size: .85rem; color: #a5c6bd; }
#nav ol { list-style: none; margin: 0; padding: 0; counter-reset: t; }
#nav li { counter-increment: t; }
#nav a { display: grid; grid-template-columns: 26px 1fr auto; gap: 6px; align-items: baseline; padding: 9px 24px; color: inherit; text-decoration: none; border-left: 4px solid transparent; }
#nav a::before { content: counter(t); font-family: var(--f-mono); font-size: .8rem; color: #86b3a7; }
#nav a:hover { background: rgba(255, 255, 255, .07); }
#nav a[aria-current="page"] { background: var(--paper); color: var(--ink-deep); border-left-color: var(--hl); font-weight: 700; }
#nav a[aria-current="page"]::before { color: var(--ink); }
#nav .menu { display: none; }
#nav .count { font-family: var(--f-mono); font-size: .75rem; color: #86b3a7; }
#nav a[aria-current="page"] .count { color: var(--muted); }
#nav .count.full { color: #7fe0a8; }
#nav a[aria-current="page"] .count.full { color: var(--green); }

main { padding: 40px 48px 96px; max-width: 1100px; }
h1 { font-family: var(--f-display); font-weight: 700; font-size: 2.5rem; line-height: 1.05; letter-spacing: -.02em; margin: 0 0 10px; color: var(--ink-deep); }
h2 { font-family: var(--f-display); font-weight: 700; font-size: 1.3rem; margin: 32px 0 10px; color: var(--ink-deep); }
h3 { font-size: 1rem; margin: 18px 0 6px; }
.lead { font-size: 1.12rem; max-width: 64ch; margin: 0 0 22px; }
p { max-width: 72ch; }
code, .mono { font-family: var(--f-mono); font-size: .92em; }

details.recipe { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 0 18px; margin: 0 0 22px; max-width: 780px; }
details.recipe summary { cursor: pointer; padding: 12px 0; font-weight: 700; color: var(--ink-deep); }
details.recipe ol, details.recipe ul { margin: 0 0 14px; padding-left: 22px; }
details.recipe li { margin: 4px 0; }
.trap { border-left: 4px solid var(--red); padding: 2px 0 2px 12px; margin: 0 0 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--ink-deep); margin: 0 0 22px; flex-wrap: wrap; }
.tabs button { font: inherit; font-weight: 700; border: 0; background: transparent; color: var(--muted); padding: 10px 18px; cursor: pointer; border-radius: 6px 6px 0 0; }
.tabs button[aria-selected="true"] { background: var(--ink-deep); color: #fff; }

label { display: block; font-weight: 700; font-size: .9rem; margin: 0 0 4px; }
textarea, input[type=text], select { font-family: var(--f-mono); font-size: .95rem; width: 100%; border: 1.5px solid var(--rule); border-radius: 6px; padding: 9px 11px; background: var(--sheet); color: var(--graphite); }
textarea { min-height: 128px; resize: vertical; line-height: 1.6; }
select { font-family: var(--f-body); }
textarea:focus, input:focus, select:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(11, 107, 90, .18); }
.hint { font-size: .85rem; color: var(--muted); margin: 4px 0 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-bottom: 16px; }
.field { margin-bottom: 14px; }
.narrow { max-width: 560px; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 20px; }
button.go { font: inherit; font-weight: 700; background: var(--ink); color: #fff; border: 0; border-radius: 6px; padding: 10px 18px; cursor: pointer; }
button.go:hover { background: var(--ink-deep); }
button.alt { font: inherit; background: var(--sheet); color: var(--ink-deep); border: 1.5px solid var(--ink-deep); border-radius: 6px; padding: 9px 16px; cursor: pointer; }
button.alt:hover { background: var(--tint); }
button, summary, #nav a { touch-action: manipulation; }
button:disabled { opacity: .45; cursor: default; }
button.link { font: inherit; background: none; border: 0; color: var(--ink); text-decoration: underline; cursor: pointer; padding: 0; }
.err { color: var(--red); font-weight: 700; margin: 8px 0; }

.stage { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; padding: 18px 22px 22px; margin: 0 0 24px; }
.st-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.st-bar .n { font-family: var(--f-mono); font-size: .85rem; color: var(--muted); }
.st-bar .keys { margin-left: auto; font-size: .8rem; color: var(--muted); }
.prog { display: flex; gap: 3px; margin-bottom: 14px; }
.prog i { flex: 1; height: 5px; background: var(--rule); border-radius: 2px; }
.prog i.on { background: var(--ink); }
.cap { font-size: 1.05rem; min-height: 3.2em; margin: 0 0 14px; max-width: 78ch; }
.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 22px; align-items: start; }
.side h3:first-child { margin-top: 0; }

/* grafo */
.gwrap { overflow-x: auto; }
svg.g { display: block; width: 100%; max-width: 560px; height: auto; }
svg.g .e { stroke: #9aa7a2; stroke-width: 2; fill: none; }
svg.g .e.cand { stroke: var(--blue); stroke-width: 2.6; stroke-dasharray: 6 4; }
svg.g .e.look { stroke: var(--blue); stroke-width: 3; }
svg.g .e.tree { stroke: var(--ink); stroke-width: 4.5; }
svg.g .e.pick { stroke: #d39e00; stroke-width: 6; }
svg.g .e.bad { stroke: var(--red); stroke-width: 3.5; stroke-dasharray: 3 4; }
svg.g .e.off { stroke: #dbe2df; }
svg.g .e.fresh { stroke: #d39e00; stroke-width: 5; }
svg.g .wt { font-family: var(--f-mono); font-size: 14px; fill: var(--graphite); paint-order: stroke; stroke: var(--sheet); stroke-width: 5px; stroke-linejoin: round; text-anchor: middle; dominant-baseline: central; }
svg.g .wt.on { font-weight: 700; fill: var(--ink-deep); }
svg.g .nd { fill: var(--sheet); stroke: var(--ink-deep); stroke-width: 2; }
svg.g .nd.fix { fill: var(--ink); }
svg.g .nd.cur { fill: var(--hl); }
svg.g .nd.new { fill: var(--hl-new); }
svg.g .nd.in { fill: var(--tint); }
svg.g .nd.dim { stroke: #b8c4bf; }
svg.g .nl { font-family: var(--f-mono); font-size: 15px; font-weight: 700; fill: var(--ink-deep); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
svg.g .nd.fix + .nl { fill: #fff; }
svg.g .tag { font-family: var(--f-mono); font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: central; fill: var(--red); paint-order: stroke; stroke: var(--sheet); stroke-width: 4px; }
svg.g .c1 { fill: #ffd166; } svg.g .c2 { fill: #8ecae6; } svg.g .c3 { fill: #f4a3a8; } svg.g .c4 { fill: #b7e4a7; }
svg.g .c5 { fill: #cdb4f6; } svg.g .c6 { fill: #f6c38b; } svg.g .c7 { fill: #a0e7e5; } svg.g .c8 { fill: #e0e0e0; }
.chip { display: inline-block; min-width: 1.6em; text-align: center; border-radius: 4px; padding: 0 5px; font-family: var(--f-mono); font-weight: 700; }
.chip.c1 { background: #ffd166; } .chip.c2 { background: #8ecae6; } .chip.c3 { background: #f4a3a8; } .chip.c4 { background: #b7e4a7; }
.chip.c5 { background: #cdb4f6; } .chip.c6 { background: #f6c38b; } .chip.c7 { background: #a0e7e5; } .chip.c8 { background: #e0e0e0; }

/* tabelas */
table.t { border-collapse: collapse; font-family: var(--f-mono); font-size: .95rem; margin: 4px 0 10px; }
table.t th, table.t td { border-bottom: 1px solid var(--rule); padding: 5px 12px 5px 0; text-align: left; }
table.t th { font-family: var(--f-body); font-size: .82rem; color: var(--muted); font-weight: 700; }
table.t td.ch { background: var(--hl-new); }
table.t tr.cur td { background: var(--hl); }
table.t tr.fix td { color: var(--ink); font-weight: 700; }
table.t input { width: 4.6em; padding: 4px 6px; font-size: .95rem; }
table.t td.ok input { border-color: var(--green); background: var(--hl-new); }
table.t td.no input { border-color: var(--red); background: var(--hl-del); }
.elist { font-family: var(--f-mono); display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 4px 0 10px; }
.elist span { border: 1.5px solid var(--rule); border-radius: 4px; padding: 1px 6px; background: var(--sheet); }
.elist span.tree { border-color: var(--ink); background: var(--tint); font-weight: 700; }
.elist span.bad { color: var(--red); text-decoration: line-through; }
.elist span.cur { background: var(--hl); border-color: #c9a900; }
.elist span.cand { border-color: var(--blue); background: var(--hl-cand); }
.sets { font-family: var(--f-mono); }
.sets div { margin: 2px 0; }
.big { font-family: var(--f-mono); font-size: 1.2rem; }
.big .cur { background: var(--hl); padding: 0 3px; border-radius: 3px; }
.big .done { color: var(--muted); text-decoration: line-through; }
.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 14px; }
.legend i { display: inline-block; width: 22px; height: 6px; border-radius: 3px; vertical-align: 3px; margin-right: 5px; }
.legend i.dot { width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; border: 2px solid var(--ink-deep); }

/* linha do tempo (intervalos) */
svg.tl { display: block; width: 100%; max-width: 640px; height: auto; }
svg.tl .bar { fill: var(--sheet); stroke: #9aa7a2; stroke-width: 1.5; }
svg.tl .bar.pick { fill: var(--ink); stroke: var(--ink-deep); }
svg.tl .bar.gone { fill: var(--hl-del); stroke: var(--red); }
svg.tl .bar.cur { stroke: #c9a900; stroke-width: 3.5; }
svg.tl .lb { font-family: var(--f-mono); font-size: 13px; font-weight: 700; dominant-baseline: central; fill: var(--graphite); }
svg.tl .lb.pick { fill: #fff; }
svg.tl .ax { stroke: var(--rule); }
svg.tl .tick { font-family: var(--f-mono); font-size: 11px; fill: var(--muted); text-anchor: middle; }
svg.tl .lim { stroke: #c9a900; stroke-width: 2; stroke-dasharray: 4 3; }

/* árvores de Huffman */
svg.hf { display: block; height: auto; max-width: 100%; }
svg.hf .ln { stroke: #9aa7a2; stroke-width: 1.6; }
svg.hf .bt { font-family: var(--f-mono); font-size: 11px; fill: var(--ink); font-weight: 700; text-anchor: middle; dominant-baseline: central; }
svg.hf .nd { fill: var(--sheet); stroke: var(--ink-deep); stroke-width: 1.8; }
svg.hf .nd.leaf { fill: var(--tint); }
svg.hf .nd.new { fill: var(--hl); }
svg.hf .tx { font-family: var(--f-mono); font-size: 12px; text-anchor: middle; dominant-baseline: central; fill: var(--ink-deep); font-weight: 700; }
svg.hf .sb { font-family: var(--f-mono); font-size: 12px; text-anchor: middle; fill: var(--graphite); }

.task { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; padding: 18px 22px; margin-bottom: 18px; }
.task .q { font-size: 1.05rem; margin: 0 0 10px; }
.fb { border-radius: 8px; padding: 14px 18px; margin: 0 0 18px; background: var(--sheet); border: 1px solid var(--rule); }
.fb.ok { border-left: 6px solid var(--green); }
.fb.no { border-left: 6px solid var(--red); }
.fb h3 { margin: 0 0 6px; }
.fb ul { margin: 6px 0; padding-left: 20px; }
.good { color: var(--green); font-weight: 700; }
.bad { color: var(--red); font-weight: 700; }
.choice { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.choice button.pick-ok { border-color: var(--green); background: var(--hl-new); color: var(--green); font-weight: 700; }
.choice button.pick-no { border-color: var(--red); background: var(--hl-del); color: var(--red); text-decoration: line-through; }

.cards { display: grid; gap: 12px; max-width: 820px; }
.card { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.card summary { cursor: pointer; padding: 14px 18px; font-weight: 700; }
.card .a { padding: 0 18px 14px; border-top: 1px dashed var(--rule); }
.road { list-style: none; padding: 0; margin: 0; max-width: 780px; counter-reset: r; }
.road li { counter-increment: r; border-bottom: 1px solid var(--rule); }
.road a { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 14px 4px; text-decoration: none; color: inherit; align-items: baseline; }
.road a::before { content: counter(r); font-family: var(--f-display); font-weight: 700; font-size: 1.3rem; color: var(--ink); }
.road a:hover b { text-decoration: underline; }
.road small { display: block; color: var(--muted); font-size: .9rem; }
.road .count { font-family: var(--f-mono); font-size: .85rem; color: var(--muted); }
.road .count.full { color: var(--green); font-weight: 700; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 40px; padding-top: 20px; border-top: 2px solid var(--rule); max-width: 780px; }
.pager a { display: block; background: var(--sheet); border: 1.5px solid var(--rule); border-radius: 8px; padding: 12px 16px; text-decoration: none; color: var(--ink-deep); touch-action: manipulation; }
.pager a:hover { border-color: var(--ink); }
.pager a.next { text-align: right; background: var(--ink); border-color: var(--ink); color: #fff; }
.pager a.next:hover { background: var(--ink-deep); }
.pager small { display: block; font-size: .8rem; opacity: .8; }

@media (max-width: 860px) {
  html { font-size: 16px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  #nav { padding: 0; position: sticky; top: 0; z-index: 10; height: auto; max-height: 100vh; }
  #nav .brand { font-size: 1.05rem; }
  #nav a.home { display: none; padding: 12px 16px 4px; }
  #nav.open a.home { display: block; }
  #nav .sub { display: none; }
  /* no celular a lista de tópicos abre e fecha num toque */
  #nav .menu { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; font: inherit; font-weight: 700; text-align: left; color: #fff; background: rgba(255, 255, 255, .1); border: 0; padding: 0 16px; min-height: 50px; cursor: pointer; }
  #nav .menu .now { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #nav .menu .now i { font-style: normal; font-family: var(--f-mono); font-size: .8rem; color: #a5c6bd; margin-right: 10px; }
  #nav .menu .lbl { flex: none; font-weight: 400; font-size: .85rem; color: #dcebe6; border: 1px solid rgba(255, 255, 255, .35); border-radius: 999px; padding: 3px 12px; }
  #nav .menu .lbl::after { content: " ▾"; }
  #nav.open .menu .lbl::after { content: " ▴"; }
  #nav ol { display: none; padding: 6px 0 12px; }
  #nav.open ol { display: block; }
  #nav a { padding: 12px 16px; }
  main { padding: 20px 14px 72px; }
  h1 { font-size: 1.65rem; }
  .lead { font-size: 1.02rem; margin-bottom: 16px; }
  .cap { font-size: 1rem; min-height: 0; overflow-wrap: anywhere; }
  .row, .split { grid-template-columns: 1fr; }
  .tabs button { flex: 1; padding: 12px 8px; }
  button.go, button.alt { min-height: 46px; }
  .btns button.go { flex: 1 1 100%; }
  .btns button.alt { flex: 1; }
  details.recipe { padding: 0 14px; }
  .stage { padding: 0 14px 16px; }
  .task, .fb { padding: 14px; }
  .stage .body, .fb { overflow-x: auto; }
  /* botões do passo a passo ficam presos no topo enquanto a página rola */
  .st-bar { position: sticky; top: 50px; z-index: 5; display: grid; grid-template-columns: auto 1fr auto; gap: 8px; background: var(--sheet); margin: 0 -14px 12px; padding: 10px 14px 8px; border-bottom: 1px solid var(--rule); border-radius: 8px 8px 0 0; }
  .st-bar button { padding-left: 12px; padding-right: 12px; white-space: nowrap; font-size: .94rem; }
  .st-bar .n { grid-column: 1 / -1; text-align: center; }
  .st-bar .keys { display: none; }
  table.t { font-size: .88rem; }
  table.t th, table.t td { padding-right: 8px; }
  .road a { grid-template-columns: 30px 1fr auto; padding: 14px 2px; }
  .pager { margin-top: 28px; }
  .pager a { padding: 12px; }
}
