/* ============================================================
   Portal IDEA · Questões — "caderno de estudos"
   Editorial, papel off-white, uma ênfase (roxo), régua de margem.
   Fonte do sistema (sem download). Ver DESIGN.md / UI-AUDIT.md.
   ============================================================ */

:root {
  --paper:       #fdfdfe;   /* branco quase absoluto (neve) */
  --paper-2:     #f4f5f7;   /* superfície alternada, cinza levíssimo */
  --surface:     #ffffff;
  --ink:         #1e1b2e;
  --ink-2:       #6a667c;
  --ink-3:       #94909f;
  --rule:        #ececef;
  --rule-2:      #dedee4;
  --accent:      #5b3ede;
  --accent-2:    #4526c4;
  --accent-soft: #efebff;
  --ok:      #1e7a46;  --ok-soft:  #e8f3ec;  --ok-line:  #bcdcc7;
  --no:      #b4322e;  --no-soft:  #f8ebe9;  --no-line:  #e7c2bf;

  --r-1: 4px; --r-2: 10px; --r-3: 14px;
  --sh:  0 10px 30px rgba(30,27,46,.10);   /* só para elevado real */

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;

  --t-display: clamp(2.6rem, 1.6rem + 3.4vw, 4.1rem);
  --t-h1: clamp(1.9rem, 1.4rem + 1.8vw, 2.7rem);
  --t-h2: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
  --t-lg: 1.15rem;
  --t-base: 1.0rem;
  --t-sm: .875rem;
  --t-xs: .78rem;

  --wrap: 1080px;
  --read: 680px;
  --gutter: clamp(1rem, .5rem + 3vw, 2rem);

  --dur: 180ms;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

* , *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: var(--t-base);
  line-height: 1.62;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.14; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-1); }
/* #app recebe foco programático a cada navegação (acessibilidade do "pular p/ conteúdo").
   Não deve desenhar o anel roxo em volta da página inteira. */
#app:focus, #app:focus-visible { outline: none; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: var(--gutter); }
.serif { font-family: var(--serif); }
.heart { color: var(--accent); }
.muted { color: var(--ink-2); }
.center { text-align: center; }
.stack > * + * { margin-top: 1.1rem; }

/* ---------- Botões (planos, sem gradiente) ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5em;
  padding: .68em 1.15em; border: 1px solid transparent; border-radius: var(--r-2);
  font-weight: 600; font-size: var(--t-sm); line-height: 1.1; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--rule-2); }
.btn-ghost:hover { background: var(--paper-2); border-color: var(--ink-3); text-decoration: none; }
.btn-teal { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-teal:hover { background: var(--accent-soft); text-decoration: none; }
.btn-lg { padding: .85em 1.5em; font-size: var(--t-base); }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Superfícies ---------- */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-3); }
.card-pad { padding: clamp(1.1rem, .8rem + 1vw, 1.6rem); }
.card-hover { transition: border-color var(--dur) var(--ease); }
.card-hover:hover { border-color: var(--rule-2); }

/* ---------- Chip (só filtro clicável) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .42em .8em; border-radius: var(--r-2);
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule-2);
  font-size: var(--t-sm); font-weight: 500;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
}
button.chip:hover { border-color: var(--accent); }
.chip.is-on, .chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip .dot { width: .5em; height: .5em; border-radius: 50%; background: currentColor; opacity: .5; }
.tag { font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); }
.tag-free { color: var(--accent); }

/* ---------- Nav ---------- */
.nav { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(8px); border-bottom: 1px solid var(--rule); }
.nav-inner { display: flex; align-items: center; gap: 1rem; height: 66px; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.08rem; color: var(--ink); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-size: .64rem; font-weight: 600; color: var(--ink-3); letter-spacing: .1em; text-transform: uppercase; }
.nav-links { display: flex; gap: .2rem; margin-left: auto; }
.nav-links a { padding: .5em .7em; color: var(--ink-2); font-weight: 500; font-size: var(--t-sm);
  border-bottom: 2px solid transparent; border-radius: 0; }
.nav-links a:hover { color: var(--ink); text-decoration: none; }
.nav-links a.active { color: var(--accent); border-bottom-color: var(--accent); }
.nav-burger { display: none; padding: .4em .6em; border: 1px solid var(--rule-2); border-radius: var(--r-2); background: var(--surface); }

/* ---------- Seletor de fonte (ENEM × concurso) — segmentado editorial ---------- */
.fonte-switch { display: inline-flex; margin-left: .8rem; border: 1px solid var(--rule-2);
  border-radius: var(--r-2); overflow: hidden; background: var(--surface); }
.fonte-switch button { border: 0; background: transparent; padding: .42em .85em; line-height: 1.1;
  font-size: var(--t-xs); font-weight: 700; letter-spacing: .04em; color: var(--ink-2);
  border-right: 1px solid var(--rule-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }
.fonte-switch button:last-child { border-right: 0; }
.fonte-switch button:hover { color: var(--ink); }
.fonte-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* selo da fonte ativa (rótulo em texto, não pílula decorativa) */
.fonte-selo { display: inline-flex; align-items: center; padding: .12em .5em; border-radius: var(--r-1);
  background: var(--accent-soft); color: var(--accent-2); font-weight: 700; font-size: .82em;
  letter-spacing: .02em; text-transform: none; }
.fonte-selo.sm { font-size: .72rem; padding: .05em .4em; }
.mast-eyebrow { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }

/* ---------- Masthead (home) ---------- */
.masthead { position: relative; overflow: hidden;
  padding: clamp(2.4rem, 1.4rem + 5vw, 5rem) 0 clamp(1.6rem, 1rem + 3vw, 3rem);
  border-bottom: 1px solid var(--rule); }
.masthead .mast-content { position: relative; z-index: 1; max-width: 42rem; }
.masthead h1 { font-family: var(--serif); font-size: var(--t-display); font-weight: 700; line-height: 1.04; letter-spacing: -.02em; }
.masthead .lead { font-size: var(--t-lg); color: var(--ink-2); max-width: 42ch; margin-top: 1.1rem; }
.masthead .actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.5rem; }
.masthead .facts { margin-top: 1.5rem; color: var(--ink-2); font-size: var(--t-sm); }
.masthead .facts b { color: var(--ink); font-variant-numeric: tabular-nums; }
/* logo como marca de fundo, atrás do conteúdo (sem moldura) */
.hero-logo { position: absolute; z-index: 0; right: clamp(-30px, -1vw, 10px); top: 50%;
  width: min(380px, 44%); transform: translateY(-48%); opacity: .5; pointer-events: none; user-select: none; }
.hl { color: var(--accent); }
.sb-ic { color: var(--ink-3); font-size: 1.15rem; }

/* ---------- Busca ---------- */
.searchbar { display: flex; gap: .5rem; align-items: center; background: var(--surface);
  border: 1px solid var(--rule-2); border-radius: var(--r-2); padding: .35rem .4rem .35rem .9rem; }
.searchbar:focus-within { border-color: var(--accent); }
.searchbar input { flex: 1; border: 0; background: transparent; font: inherit; color: var(--ink); padding: .5em 0; }
.searchbar input:focus { outline: none; }

/* ---------- Seções / sumário ---------- */
.section { padding-block: clamp(2rem, 1.2rem + 3vw, 3.5rem); }
.section + .section { border-top: 1px solid var(--rule); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.section-head h2 { font-family: var(--serif); font-size: var(--t-h2); }
.eyebrow { font-size: var(--t-xs); font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.chips-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Índice de matérias (sumário de livro) */
.index { border-top: 1px solid var(--rule); }
.index a, .index button { display: flex; align-items: baseline; gap: 1rem; width: 100%; text-align: left;
  padding: .85rem .3rem; border: 0; border-bottom: 1px solid var(--rule); background: transparent; color: var(--ink);
  font-size: var(--t-lg); transition: color var(--dur) var(--ease), padding var(--dur) var(--ease); }
.index a:hover, .index button:hover { color: var(--accent); text-decoration: none; padding-left: .6rem; }
.index .num { color: var(--ink-3); font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.index .dots { flex: 1; border-bottom: 1px dotted var(--rule-2); transform: translateY(-.25em); }

/* Chip-atalho de matéria na home */
.matchips { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Filtros (praticar) ---------- */
.filters { display: grid; gap: 1.5rem; }
.filter-group h4 { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); margin-bottom: .7rem; font-weight: 600; }
.count-pill { font-family: var(--serif); font-size: 1.9rem; color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Sessão de questão (a "folha" com régua de margem) ---------- */
.q-wrap { max-width: var(--read); margin-inline: auto; }
.q-sheet { border-left: 2px solid var(--accent); padding-left: clamp(1rem, 3vw, 1.8rem); }
.q-meta { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.q-metaline { color: var(--ink-2); font-size: var(--t-sm); }
.q-metaline b { color: var(--ink); font-weight: 600; }
.q-progress { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-bottom: 1.6rem; }
.q-progress > i { display: block; height: 100%; background: var(--accent); transition: width var(--dur) var(--ease); }
.q-texto { background: var(--paper-2); padding: 1rem 1.2rem; border-radius: var(--r-2); color: var(--ink-2);
  font-size: var(--t-sm); margin-bottom: 1.2rem; white-space: pre-wrap; border: 1px solid var(--rule); }
.q-enunciado { font-size: var(--t-lg); line-height: 1.6; margin-bottom: 1.5rem; white-space: pre-wrap; }
.q-figuras { display: flex; flex-direction: column; gap: .8rem; margin: 0 0 1.5rem; }
.q-figura { max-width: 100%; height: auto; align-self: center; border: 1px solid var(--rule);
  border-radius: var(--r-2); background: #fff; padding: .4rem; }
.options { display: grid; gap: .6rem; }
.opt { display: flex; gap: .8rem; align-items: flex-start; text-align: left; width: 100%;
  padding: .9rem 1rem; border: 1px solid var(--rule-2); border-radius: var(--r-2); background: var(--surface);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease); }
.opt:hover:not([disabled]) { border-color: var(--accent); }
.opt .key { flex: none; width: 26px; height: 26px; border-radius: var(--r-1); display: grid; place-items: center;
  background: var(--paper-2); color: var(--ink-2); font-weight: 700; font-size: .82rem; border: 1px solid var(--rule-2); }
.opt .txt { white-space: pre-wrap; }
.opt.correct { border-color: var(--ok-line); background: var(--ok-soft); }
.opt.correct .key { background: var(--ok); color: #fff; border-color: var(--ok); }
.opt.wrong { border-color: var(--no-line); background: var(--no-soft); }
.opt.wrong .key { background: var(--no); color: #fff; border-color: var(--no); }
.opt.dim { opacity: .5; }
.ce-row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.ce-btn { padding: 1rem; border-radius: var(--r-2); border: 1px solid var(--rule-2); background: var(--surface); font-weight: 600; font-size: var(--t-lg); }
.ce-btn:hover:not([disabled]) { border-color: var(--accent); }
.ce-btn.correct { border-color: var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.ce-btn.wrong { border-color: var(--no-line); background: var(--no-soft); color: var(--no); }

/* Feedback + comentário */
.feedback { margin-top: 1.5rem; }
.verdict { font-weight: 700; display: flex; align-items: center; gap: .5rem; font-size: var(--t-lg); }
.feedback.ok .verdict { color: var(--ok); }
.feedback.no .verdict { color: var(--no); }
.comentario { margin-top: 1rem; padding: 1.2rem 1.3rem; background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-2); white-space: pre-wrap; line-height: 1.68; color: var(--ink); }
.comentario h5 { color: var(--ink-3); margin: 0 0 .7rem; font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.comentario strong { font-weight: 700; }
.comentario code { background: var(--paper-2); padding: .1em .35em; border-radius: var(--r-1); font-size: .92em; }
.q-actions { display: flex; gap: .7rem; margin-top: 1.6rem; flex-wrap: wrap; align-items: center; }
.fav { background: none; border: 0; font-size: 1.25rem; line-height: 1; padding: .2em; color: var(--ink-3); margin-left: auto; }
.fav:hover { color: var(--accent); }
.fav.on { color: var(--accent); }

/* ---------- Desempenho ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border: 1px solid var(--rule); border-radius: var(--r-3); overflow: hidden; }
.kpi { padding: 1.3rem 1.1rem; border-right: 1px solid var(--rule); }
.kpi:last-child { border-right: 0; }
.kpi b { display: block; font-family: var(--serif); font-size: 2rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi span { font-size: var(--t-sm); color: var(--ink-2); }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: .35rem .8rem; align-items: baseline; padding: .55rem 0; border-bottom: 1px solid var(--rule); }
.bar-row:last-child { border-bottom: 0; }
.bar-row b { font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 600; font-size: var(--t-sm); }
.bar { height: 5px; background: var(--rule); border-radius: 3px; overflow: hidden; grid-column: 1 / -1; margin-top: .1rem; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* legado: .stats/.stat/.tile ainda referenciados por algumas views — estilo contido */
.stats { display: flex; flex-wrap: wrap; gap: 0 1.6rem; color: var(--ink-2); }
.stat { padding: .2rem 0; }
.stat b { font-family: var(--serif); color: var(--ink); font-weight: 700; margin-right: .3rem; }
.tile { display: block; text-align: left; color: var(--ink); padding: 1rem; }
.tile b { font-size: 1.05rem; } .tile span { font-size: var(--t-sm); color: var(--ink-2); }

/* ---------- Rodapé ---------- */
.footer { margin-top: 3rem; border-top: 1px solid var(--rule); }
.footer-inner { display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: space-between; padding-block: 2rem; align-items: center; }
.footer small { color: var(--ink-3); }

/* ---------- Estados ---------- */
.loading { display: flex; align-items: center; gap: .7rem; color: var(--ink-2); justify-content: center; padding: 3rem 1rem; }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--rule); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-2); }
.empty .big { font-size: 2.2rem; margin-bottom: .5rem; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(16px); opacity: 0;
  background: var(--ink); color: var(--paper); padding: .7em 1.2em; border-radius: var(--r-2); box-shadow: var(--sh);
  font-size: var(--t-sm); z-index: 100; transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease); pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.seg { display: inline-flex; border: 1px solid var(--rule-2); border-radius: var(--r-2); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .55em 1.1em; font-weight: 600; font-size: var(--t-sm); color: var(--ink-2); border-right: 1px solid var(--rule-2); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }

.field { display: flex; flex-direction: column; gap: .4rem; }
.field label { font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); }
.field input, .field select { padding: .65em .8em; border: 1px solid var(--rule-2); border-radius: var(--r-2); font: inherit; background: var(--surface); color: var(--ink); }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }

/* ---------- Home: modos (índice) ---------- */
.modes a { display: flex; align-items: center; gap: 1rem; }
.modes a > .num { align-self: flex-start; padding-top: .2rem; }
.modes a b { font-size: var(--t-lg); display: block; }
.modes a small { display: block; color: var(--ink-2); font-size: var(--t-sm); font-weight: 400; margin-top: .1rem; }
.modes a .go { margin-left: auto; color: var(--ink-3); font-size: 1.2rem; }
.modes a:hover .go { color: var(--accent); }

/* ---------- Home: faixa institucional ---------- */
.inst-quote { font-size: clamp(1.6rem, 1.1rem + 2vw, 2.4rem); line-height: 1.14; max-width: 18ch; margin: .5rem 0 1.1rem; color: var(--ink); }
.inst-body { max-width: 62ch; color: var(--ink-2); font-size: var(--t-lg); line-height: 1.6; }
.inst-facts { margin-top: 1.1rem; color: var(--ink-3); font-size: var(--t-sm); }
.inst .btn { margin-top: 1.5rem; }

/* ---------- Praticar: filtros + resumo ---------- */
.praticar-grid { display: grid; grid-template-columns: 1fr 320px; gap: 2.2rem; align-items: start; margin-top: 1.6rem; }
.pr-filters { display: grid; gap: 1.6rem; }
.pr-resumo { position: sticky; top: 84px; }
.resumo-card { border: 1px solid var(--rule); border-radius: var(--r-3); padding: 1.4rem; background: var(--surface); }
.resumo-count { display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; }
.resumo-sel { margin-top: .5rem; font-size: var(--t-sm); color: var(--ink-2); }
.chip.preset { border-style: dashed; color: var(--ink-2); }
.chip.preset:hover { color: var(--accent); }

/* ---------- Sessão de prática ---------- */
.sess-top { display: flex; align-items: center; gap: 1rem; margin-bottom: .9rem; font-size: var(--t-sm); }
.sess-top .back { color: var(--ink-2); }
.sess-top .back:hover { color: var(--ink); }
.sess-count { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.sess-score { margin-left: auto; color: var(--accent); font-weight: 600; }
.sess-result { text-align: center; padding: 1.2rem 0; }
.sess-emoji { font-size: 2.6rem; }
.sess-result h1 { margin-top: .3rem; font-size: var(--t-h1); }
.sess-big { font-size: 1.5rem; margin-top: .5rem; }
.sess-big b { font-family: var(--serif); }
.sess-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .praticar-grid { grid-template-columns: 1fr; }
  .pr-resumo { position: static; }
  .hero-logo { opacity: .12; width: 62%; right: -14%; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi:nth-child(2) { border-right: 0; } .kpi:nth-child(1), .kpi:nth-child(2) { border-bottom: 1px solid var(--rule); }
  .nav-links { display: none; }
  .nav-links.open { display: flex; position: absolute; top: 66px; left: 0; right: 0; flex-direction: column;
    background: var(--surface); border-bottom: 1px solid var(--rule); padding: .5rem var(--gutter); gap: 0; box-shadow: var(--sh); }
  .nav-links.open a { border-bottom: 1px solid var(--rule); padding: .8em .2em; }
  .nav-burger { display: inline-flex; }
  /* nav-links (âncora à direita no desktop) some no mobile -> o seletor de
     fonte assume a âncora e fica sempre visível, ao lado do menu. */
  .fonte-switch { margin-left: auto; }
}
@media (max-width: 560px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .ce-row { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
