/* Painel de acessibilidade — botão flutuante (canto inferior esquerdo) e preferências aplicadas no <html>.
   Usa os tokens do "caderno" (index.html e assets/publicacoes.css têm os mesmos nomes; os que só existem
   num dos dois têm valor reserva). Carregar DEPOIS do CSS da página: os ajustes sobrescrevem o visual. */

/* ============================================================ botão e painel */
.a11y-raiz {
  --a11y-verde: var(--accent-real, var(--accent, #1d9371));
  --a11y-sobre-verde: var(--accent-ink, #06120e);
  --a11y-corpo: var(--body, 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif);
  font-family: var(--a11y-corpo);
  /* o painel não é afetado pelo espaçamento de texto nem pelo aumento de texto do site */
  line-height: 1.4;
  letter-spacing: normal;
  word-spacing: normal;
}
/* O painel acompanha o aumento de texto até 130% (mesma regra do site da CriAugu); além disso, não sai da tela. */
html[data-a11y-texto="1"] .a11y-raiz { --a11y-p: 1.15; }
html[data-a11y-texto="2"] .a11y-raiz,
html[data-a11y-texto="3"] .a11y-raiz,
html[data-a11y-texto="4"] .a11y-raiz { --a11y-p: 1.3; }
.a11y-oculto {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.a11y-botao {
  position: fixed; left: 16px; bottom: 16px; z-index: 95;
  width: 48px; height: 48px; padding: 0; margin: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--pencil, #33383d);
  border-radius: 58% 42% 55% 45% / 48% 56% 44% 52%;
  background: var(--paper-2, #fffdf8);
  color: var(--ink, #1e2124);
  box-shadow: 2px 3px 0 var(--pencil, #33383d);
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}
.a11y-botao svg { display: block; }
.a11y-botao:hover { background: var(--hl-real, var(--hl, rgba(29, 147, 113, 0.22))); transform: rotate(-6deg); }
.a11y-botao[aria-expanded="true"] { background: var(--a11y-verde); color: var(--a11y-sobre-verde); }

.a11y-painel {
  position: fixed; left: 16px; bottom: 76px; z-index: 96;
  width: min(calc(340px * var(--a11y-p, 1)), calc(100vw - 32px));
  max-height: calc(100vh - 92px);
  max-height: calc(100dvh - 92px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 16px;
  background: var(--paper-2, #fffdf8);
  color: var(--ink, #1e2124);
  border: 2px solid var(--pencil, #33383d);
  border-radius: 14px 18px 12px 20px / 18px 12px 20px 14px;
  box-shadow: 3px 4px 0 var(--pencil, #33383d), 0 18px 34px -18px rgba(0, 0, 0, 0.45);
  font-size: calc(15px * var(--a11y-p, 1));
  text-align: left;
}
.a11y-painel[hidden] { display: none; }
.a11y-painel:focus { outline: none; }
.a11y-painel:focus-visible { outline: 3px solid var(--focus, #0f5c44); outline-offset: 3px; }
.a11y-raiz :focus-visible { outline: 3px solid var(--focus, #0f5c44); outline-offset: 2px; }

.a11y-topo { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.a11y-titulo {
  margin: 0; padding: 0;
  font-family: var(--hand, var(--a11y-corpo)); font-weight: 700; font-size: calc(28px * var(--a11y-p, 1)); line-height: 1.1;
  color: var(--ink, #1e2124);
}
.a11y-titulo::after { content: none !important; } /* sem o sublinhado dos títulos de seção */
.a11y-intro { margin: 0 0 10px; font-size: calc(13.5px * var(--a11y-p, 1)); line-height: 1.4; color: var(--ink-dim, #4d5257); }

/* todos os botões do painel: alvo mínimo de 44 × 44 px */
:where(.a11y-painel) button {
  font: inherit; color: var(--ink, #1e2124); margin: 0;
  min-height: 44px; min-width: 44px;
  border: 1.6px solid var(--pencil, #33383d);
  background: var(--paper-2, #fffdf8);
  cursor: pointer;
}
:where(.a11y-painel) button:hover { background: var(--hl-real, var(--hl, rgba(29, 147, 113, 0.22))); }
.a11y-painel button[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.a11y-painel button[aria-disabled="true"]:hover { background: var(--paper-2, #fffdf8); }
.a11y-fechar {
  width: 44px; height: 44px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50% 46% 52% 48%;
}
.a11y-fechar svg { display: block; }

/* opções liga/desliga (button aria-pressed) */
.a11y-opcao {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 6px 10px 6px 12px;
  margin-top: 6px !important;
  border-radius: 10px 6px 12px 7px / 7px 12px 6px 10px;
  text-align: left; font-size: calc(15px * var(--a11y-p, 1)); line-height: 1.3;
}
.a11y-chave {
  position: relative; flex: none;
  width: 40px; height: 22px;
  border: 2px solid var(--pencil, #33383d); border-radius: 999px;
  background: transparent;
}
.a11y-chave::after { /* bolinha: esquerda = desligado, direita com ✓ = ligado (não depende só da cor) */
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink, #1e2124);
  transition: transform 0.15s ease;
}
.a11y-opcao[aria-pressed="true"] { border-width: 2.4px; }
.a11y-opcao[aria-pressed="true"] .a11y-chave { background: var(--a11y-verde); }
.a11y-opcao[aria-pressed="true"] .a11y-chave::after {
  transform: translateX(18px);
  background: var(--a11y-sobre-verde) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3.5 7.2 6 9.6l4.6-5' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px 12px no-repeat;
}

.a11y-rotulo { display: block; font-weight: 600; font-size: calc(15px * var(--a11y-p, 1)); }
.a11y-tamanho, .a11y-leitura {
  margin-top: 6px; padding: 8px 10px 10px 12px;
  border: 1.6px dashed var(--pencil-soft, rgba(51, 56, 61, 0.42));
  border-radius: 10px 6px 12px 7px / 7px 12px 6px 10px;
}
.a11y-tamanho-controles, .a11y-botoes { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.a11y-mini {
  padding: 0 10px; border-radius: 10px 7px 11px 8px / 8px 11px 7px 10px;
  font-size: calc(16px * var(--a11y-p, 1)); font-weight: 600; line-height: 1;
}
.a11y-mini-texto { font-size: calc(14.5px * var(--a11y-p, 1)); font-weight: 500; }
.a11y-mini-maior { font-size: calc(19px * var(--a11y-p, 1)); }
.a11y-valor { min-width: 52px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.a11y-ajuda { margin: 4px 0 0; font-size: calc(13.5px * var(--a11y-p, 1)); line-height: 1.45; color: var(--ink-dim, #4d5257); }
.a11y-status { margin: 6px 0 0; font-size: calc(13.5px * var(--a11y-p, 1)); line-height: 1.4; color: var(--ink, #1e2124); }
.a11y-status:empty { display: none; }
.a11y-restaurar {
  width: 100%; margin-top: 10px !important; padding: 8px 12px;
  border-radius: 12px 7px 10px 6px / 6px 10px 7px 12px;
  font-weight: 600 !important; font-size: calc(15px * var(--a11y-p, 1));
  box-shadow: 2px 3px 0 var(--pencil, #33383d);
}
.a11y-painel p, .a11y-painel span { -webkit-text-fill-color: currentColor; } /* o "rascunho" do caderno não pega o painel */
.a11y-painel p::after { content: none !important; }

/* trecho sendo lido em voz alta */
.a11y-lendo {
  outline: 2px dashed var(--accent-real, var(--accent, #1d9371)) !important;
  outline-offset: 4px;
  border-radius: 4px;
  background-color: var(--hl-real, var(--hl, rgba(29, 147, 113, 0.22)));
}

/* no celular/tablet: espaço no fim da página para o botão não cobrir o rodapé */
@media (max-width: 960px) {
  html.a11y-pronto body { padding-bottom: 80px; }
}

/* ============================================================ preferências */

/* --- Tamanho do texto (WCAG 1.4.4 / 1.4.10): o JS regrava os tamanhos; aqui só evitamos cortes --- */
/* "anywhere" (e não "break-word") também reduz a largura mínima dos itens de flex/grade: uma palavra longa
   em 200% quebra em vez de alargar a coluna e empurrar o conteúdo para fora da tela (1.4.10). */
html[data-a11y-texto] body *:not(.a11y-raiz, .a11y-raiz *),
html.a11y-espacamento body *:not(.a11y-raiz, .a11y-raiz *) { overflow-wrap: anywhere !important; }
html[data-a11y-texto] :is(h1, h2, h3, h4, h5, h6),
html.a11y-espacamento :is(h1, h2, h3, h4, h5, h6) { hyphens: auto; -webkit-hyphens: auto; }
html[data-a11y-texto] :is(.btn, .tag, .mono, .brand span),
html.a11y-espacamento :is(.btn, .tag, .mono, .brand span) { white-space: normal !important; max-width: 100%; }
html[data-a11y-texto] :is(.icon-btn, .back-to-top),
html.a11y-espacamento :is(.icon-btn, .back-to-top) { width: auto !important; min-width: 44px; height: auto !important; min-height: 44px; padding-left: 6px; padding-right: 6px; }

/* --- Espaçamento de texto (WCAG 1.4.12) --- */
html.a11y-espacamento body :not(.a11y-raiz, .a11y-raiz *, svg, svg *) {
  line-height: 1.5 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}
html.a11y-espacamento body p:not(.a11y-raiz *) { margin-bottom: 2em !important; }

/* --- Alto contraste: texto e bordas mais fortes, nos dois temas --- */
html.a11y-contraste:not([data-theme="dark"]) {
  --paper: #ffffff; --paper-2: #ffffff; --bg: #ffffff; --bg-raised: #ffffff;
  --grid: rgba(66, 112, 160, 0.16);
  --margin-line: rgba(190, 40, 34, 0.75);
  --ink: #000000; --ink-dim: #111417; --wf-ink: #1b1e21;
  --pencil: #000000; --pencil-soft: #000000; --line: #000000; --hatch: rgba(0, 0, 0, 0.55);
  --accent: #0b5e46; --accent-real: #0b5e46; --accent-text-real: #05432f; --link: #05432f;
  --accent-ink: #ffffff; --accent-dim: #c9eadd;
  --hl: rgba(11, 94, 70, 0.22); --hl-real: rgba(11, 94, 70, 0.22);
  --quote-bg: rgba(0, 0, 0, 0.06);
  --focus: #05432f;
}
html.a11y-contraste[data-theme="dark"] {
  --paper: #000000; --paper-2: #0b0d0c; --bg: #000000; --bg-raised: #0b0d0c;
  --grid: rgba(255, 255, 255, 0.09);
  --margin-line: rgba(255, 130, 120, 0.7);
  --ink: #ffffff; --ink-dim: #f0f0ea; --wf-ink: #e4e4de;
  --pencil: #ffffff; --pencil-soft: #ffffff; --line: #ffffff; --hatch: rgba(255, 255, 255, 0.5);
  --accent: #5fe0b8; --accent-real: #5fe0b8; --accent-text-real: #8ff5d4; --link: #8ff5d4;
  --accent-ink: #000000; --accent-dim: #12352b;
  --hl: rgba(95, 224, 184, 0.28); --hl-real: rgba(95, 224, 184, 0.28);
  --quote-bg: rgba(255, 255, 255, 0.08);
  --focus: #ffe066;
}
html.a11y-contraste .sk-note { opacity: 1; }

/* --- Fonte mais legível: sem serifa do sistema (nada baixado de fora) --- */
html.a11y-fonte-legivel {
  --a11y-fonte: 'Atkinson Hyperlegible', Verdana, Tahoma, 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --hand: var(--a11y-fonte); --label: var(--a11y-fonte); --body: var(--a11y-fonte);
}
html.a11y-fonte-legivel body,
html.a11y-fonte-legivel body *:not(svg, svg *) { font-family: var(--a11y-fonte) !important; font-style: normal; }

/* --- Destacar links: sublinhado em todos; realce nos links de texto, contorno nos botões/cartões --- */
html.a11y-destacar-links { --a11y-realce: #fff0a0; }
html.a11y-destacar-links[data-theme="dark"] { --a11y-realce: #4a4413; }
html.a11y-destacar-links a[href]:not(.a11y-raiz *) {
  text-decoration-line: underline !important;
  text-decoration-thickness: 2px !important;
  text-underline-offset: 0.18em !important;
}
html.a11y-destacar-links a[href]:not(.btn, .card, .icon-btn, .pub-home-card, .a11y-raiz *) {
  background-color: var(--a11y-realce) !important;
  color: var(--ink) !important;
  -webkit-text-fill-color: var(--ink);
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
  padding: 0 2px; border-radius: 2px;
}
html.a11y-destacar-links a[href]:is(.btn, .card, .icon-btn, .pub-home-card) {
  outline: 2px dashed var(--ink) !important;
  outline-offset: 3px;
}
html.a11y-destacar-links a[href]:is(.btn, .card, .icon-btn, .pub-home-card):focus-visible {
  outline: 3px solid var(--focus) !important;
}

/* --- Pausar animações: o mesmo que prefers-reduced-motion --- */
html.a11y-sem-animacao,
html.a11y-sem-animacao *,
html.a11y-sem-animacao *::before,
html.a11y-sem-animacao *::after {
  transition-duration: 0s !important;
  transition-delay: 0s !important;
  animation: none !important;
  scroll-behavior: auto !important;
}

@media (prefers-reduced-motion: reduce) {
  .a11y-botao, .a11y-chave::after { transition: none; }
  .a11y-botao:hover { transform: none; }
}

@media print {
  .a11y-raiz { display: none !important; }
  .a11y-lendo { outline: none !important; background: none !important; }
  html.a11y-pronto body { padding-bottom: 0; }
}
