/*
 * LinguaLab — estilos da aplicação (mobile-first).
 *
 * Os estilos base valem para celulares; as media queries ampliam o layout:
 *   40em  (640px)  — celulares grandes em paisagem / tablets pequenos
 *   64em  (1024px) — tablets em paisagem e notebooks: menu lateral fixo
 *   80em  (1280px) — desktops
 *   120em (1920px) — monitores grandes
 * Controles têm no mínimo 44px de altura (alvo de toque). Somente em telas
 * grandes com mouse/trackpad (pointer: fine) os controles ficam mais compactos.
 */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e2e5ee;
  --text: #1c2233;
  --muted: #667085;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --primary-text: #ffffff;
  --good: #12805c;
  --good-soft: #e5f6ef;
  --mid: #b36b00;
  --mid-soft: #fff4e0;
  --bad: #c0362c;
  --bad-soft: #fdecea;
  --radius: .75rem;
  --radius-sm: .5rem;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar: 15rem;
  --gutter: 1rem;
  --gap: 1rem;
  --tap: 2.75rem;      /* 44px: alvo de toque mínimo */
  --tap-sm: 2.75rem;   /* botões "pequenos" também respeitam o mínimo no toque */
  --focus: 3px solid var(--primary);
  --series-1: #4f46e5;
  --series-2: #0ea5a4;
  --series-3: #f59e0b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1320;
    --surface: #171c2c;
    --surface-2: #1f2538;
    --border: #2b3248;
    --text: #e6e9f2;
    --muted: #98a2b8;
    --primary: #8b85ff;
    --primary-soft: #26274a;
    --primary-text: #0f1320;
    --good: #4ade9b;
    --good-soft: #143027;
    --mid: #fbbf4b;
    --mid-soft: #3a2c10;
    --bad: #ff7b70;
    --bad-soft: #3d1a19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --series-1: #7a72f2;
    --series-2: #14a898;
    --series-3: #b87d18;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-wrap: break-word;
  min-width: 20rem;
}
img, svg, video, audio, canvas, iframe, embed, object { max-width: 100%; }
img, video { height: auto; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; overflow-wrap: anywhere; }
h1 { font-size: clamp(1.35rem, 1.1rem + 1.1vw, 1.75rem); }
h2 { font-size: clamp(1.1rem, 1rem + .4vw, 1.25rem); }
h3 { font-size: 1.0625rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.narrow { max-width: 40rem; }
.note { font-size: .875rem; }

/* Foco visível para navegação por teclado */
:focus-visible { outline: var(--focus); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
.skip-link {
  position: absolute; left: .5rem; top: -3rem; z-index: 100; padding: .6rem 1rem; border-radius: var(--radius-sm);
  background: var(--primary); color: var(--primary-text); font-weight: 700;
}
.skip-link:focus { top: .5rem; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; min-height: 100dvh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: var(--gutter); width: 100%; max-width: 80rem; margin: 0 auto; }
.content:focus { outline: none; }

/* Menu lateral: gaveta fora da tela no celular/tablet, fixo a partir de 64em */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: min(85vw, var(--sidebar)); height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-right: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  padding: 1rem .75rem; padding-left: max(.75rem, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 1rem;
  transform: translateX(-100%); visibility: hidden;
  transition: transform .2s ease, visibility 0s linear .2s;
}
body.nav-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; }
body.nav-open { overflow: hidden; }
.nav-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(10, 12, 20, .45); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.brand { font-weight: 800; font-size: 1.2rem; display: flex; align-items: center; gap: .5rem; color: var(--text); padding: 0 .5rem; min-height: var(--tap); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 1.9rem; height: 1.9rem; border-radius: var(--radius-sm); background: var(--primary); color: var(--primary-text); display: grid; place-items: center; font-size: .95rem; flex-shrink: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .65rem; min-height: var(--tap); padding: .5rem .75rem;
  border-radius: var(--radius-sm); color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav svg { width: 1.15rem; height: 1.15rem; flex-shrink: 0; }
.sidebar-footer { margin-top: auto; font-size: .875rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .5rem var(--gutter); padding-left: max(var(--gutter), env(safe-area-inset-left)); padding-right: max(var(--gutter), env(safe-area-inset-right));
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.topbar-left, .user-box { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.user-box .username { display: none; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { font-size: 1.2rem; }
.timer {
  display: inline-flex; align-items: center; gap: .45rem; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); padding: .3rem .7rem; border-radius: 999px;
}
.timer-dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); flex-shrink: 0; }
.timer.idle .timer-dot { background: var(--mid); box-shadow: 0 0 0 3px var(--mid-soft); }

.page-header { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1.25rem; }
.page-header > div:first-child { min-width: 0; }
.page-header p { margin: .2rem 0 0; color: var(--muted); }
.breadcrumbs { font-size: .875rem; color: var(--muted); margin-bottom: .4rem; overflow-wrap: anywhere; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; min-width: 0; }
.card + .card, .section + .section { margin-top: 1.25rem; }
:where(.grid, .text-cards, .kpis, .library, .kind-grid) > .card + .card { margin-top: 0; }
.stack-top { margin-top: 1.25rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem .75rem; margin-bottom: .85rem; flex-wrap: wrap; }
.card-header h2 { margin: 0; }
.grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); align-items: start; }
.grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
.kpis { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 8rem), 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .75rem; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; overflow-wrap: normal; hyphens: auto; }
.kpi-value { font-size: clamp(1.3rem, 1.1rem + 1vw, 1.65rem); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .15rem; overflow-wrap: anywhere; }
.kpi-value.kpi-value-sm { font-size: 1.05rem; }
.kpi-hint { font-size: .8125rem; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-height: var(--tap); padding: .5rem .9rem; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; line-height: 1.2; text-align: center;
  cursor: pointer; text-decoration: none; touch-action: manipulation;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-danger-text { color: var(--bad); }
.btn-sm { min-height: var(--tap-sm); padding: .35rem .7rem; font-size: .9375rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { min-width: var(--tap); padding-left: .5rem; padding-right: .5rem; }
.btn[disabled], .btn.loading { opacity: .6; pointer-events: none; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; min-width: 0; }
.btn-group > form { display: contents; }
.btn-group-end { justify-content: flex-end; }
.btn-push { margin-left: auto; }
.row-between { justify-content: space-between; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8125rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); line-height: 1.35; overflow-wrap: anywhere; }
.tag { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
a.tag { display: inline-flex; align-items: center; min-height: 1.75rem; }
a.tag:hover { text-decoration: none; filter: brightness(.97); }
.badge-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge-mid { background: var(--mid-soft); color: var(--mid); border-color: transparent; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tags { display: flex; gap: .35rem; flex-wrap: wrap; }

.score-good { color: var(--good); font-weight: 700; }
.score-mid { color: var(--mid); font-weight: 700; }
.score-bad { color: var(--bad); font-weight: 700; }
.score-none { color: var(--muted); }

/* ---------- Tabelas ---------- */
/* Rolagem lateral apenas como último recurso (sem JS ou tabela ainda maior que a tela). */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; overflow-wrap: anywhere; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; overflow-wrap: normal; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }
.cell-sub { margin-top: .3rem; }

/*
 * Tabelas empilhadas: quando o espaço da tabela fica estreito, cada linha vira
 * um cartão com "rótulo: valor". O critério é a largura do contêiner da tabela
 * (container query), não a da tela: tabelas em colunas lado a lado também se
 * adaptam. O app.js copia o texto de cada <th> para data-label nas células e
 * marca a tabela com data-stack-ready (sem JS a tabela rola na horizontal).
 *   .table-stack        empilha abaixo de 36em de largura disponível
 *   .table-stack-wide   (6–8 colunas) empilha abaixo de 44em
 *   .table-stack-xwide  (9+ colunas) empilha abaixo de 56em
 */
.table-wrap { container: table / inline-size; }
@container table (max-width: 56em) {
  table.table-stack-xwide[data-stack-ready] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.table-stack-xwide[data-stack-ready], table.table-stack-xwide[data-stack-ready] tbody, table.table-stack-xwide[data-stack-ready] tr, table.table-stack-xwide[data-stack-ready] td { display: block; width: 100%; }
  table.table-stack-xwide[data-stack-ready] tr { padding: .5rem 0; border-bottom: 1px solid var(--border); }
  table.table-stack-xwide[data-stack-ready] tbody tr:hover { background: transparent; }
  table.table-stack-xwide[data-stack-ready] td {
    display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center;
    border: 0; padding: .3rem 0; text-align: left;
  }
  table.table-stack-xwide[data-stack-ready] td::before { content: attr(data-label); flex: 0 0 min(40%, 9rem); color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
  table.table-stack-xwide[data-stack-ready] td:not([data-label]), table.table-stack-xwide[data-stack-ready] td[data-label=""], table.table-stack-xwide[data-stack-ready] td.cell-actions, table.table-stack-xwide[data-stack-ready] td.empty { display: block; }
  table.table-stack-xwide[data-stack-ready] td:not([data-label])::before, table.table-stack-xwide[data-stack-ready] td[data-label=""]::before, table.table-stack-xwide[data-stack-ready] td.cell-actions::before { content: none; }
  table.table-stack-xwide[data-stack-ready] td.cell-title { display: block; font-size: 1.0625rem; }
  table.table-stack-xwide[data-stack-ready] td.cell-title::before { display: block; margin-bottom: .15rem; }
  table.table-stack-xwide[data-stack-ready] td.cell-actions { padding-top: .5rem; }
  table.table-stack-xwide[data-stack-ready] td.empty { text-align: center; }
}
@container table (max-width: 44em) {
  table.table-stack-wide[data-stack-ready] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.table-stack-wide[data-stack-ready], table.table-stack-wide[data-stack-ready] tbody, table.table-stack-wide[data-stack-ready] tr, table.table-stack-wide[data-stack-ready] td { display: block; width: 100%; }
  table.table-stack-wide[data-stack-ready] tr { padding: .5rem 0; border-bottom: 1px solid var(--border); }
  table.table-stack-wide[data-stack-ready] tbody tr:hover { background: transparent; }
  table.table-stack-wide[data-stack-ready] td {
    display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center;
    border: 0; padding: .3rem 0; text-align: left;
  }
  table.table-stack-wide[data-stack-ready] td::before { content: attr(data-label); flex: 0 0 min(40%, 9rem); color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
  table.table-stack-wide[data-stack-ready] td:not([data-label]), table.table-stack-wide[data-stack-ready] td[data-label=""], table.table-stack-wide[data-stack-ready] td.cell-actions, table.table-stack-wide[data-stack-ready] td.empty { display: block; }
  table.table-stack-wide[data-stack-ready] td:not([data-label])::before, table.table-stack-wide[data-stack-ready] td[data-label=""]::before, table.table-stack-wide[data-stack-ready] td.cell-actions::before { content: none; }
  table.table-stack-wide[data-stack-ready] td.cell-title { display: block; font-size: 1.0625rem; }
  table.table-stack-wide[data-stack-ready] td.cell-title::before { display: block; margin-bottom: .15rem; }
  table.table-stack-wide[data-stack-ready] td.cell-actions { padding-top: .5rem; }
  table.table-stack-wide[data-stack-ready] td.empty { text-align: center; }
}
@container table (max-width: 36em) {
  table.table-stack[data-stack-ready] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.table-stack[data-stack-ready], table.table-stack[data-stack-ready] tbody, table.table-stack[data-stack-ready] tr, table.table-stack[data-stack-ready] td { display: block; width: 100%; }
  table.table-stack[data-stack-ready] tr { padding: .5rem 0; border-bottom: 1px solid var(--border); }
  table.table-stack[data-stack-ready] tbody tr:hover { background: transparent; }
  table.table-stack[data-stack-ready] td {
    display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center;
    border: 0; padding: .3rem 0; text-align: left;
  }
  table.table-stack[data-stack-ready] td::before { content: attr(data-label); flex: 0 0 min(40%, 9rem); color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
  table.table-stack[data-stack-ready] td:not([data-label]), table.table-stack[data-stack-ready] td[data-label=""], table.table-stack[data-stack-ready] td.cell-actions, table.table-stack[data-stack-ready] td.empty { display: block; }
  table.table-stack[data-stack-ready] td:not([data-label])::before, table.table-stack[data-stack-ready] td[data-label=""]::before, table.table-stack[data-stack-ready] td.cell-actions::before { content: none; }
  table.table-stack[data-stack-ready] td.cell-title { display: block; font-size: 1.0625rem; }
  table.table-stack[data-stack-ready] td.cell-title::before { display: block; margin-bottom: .15rem; }
  table.table-stack[data-stack-ready] td.cell-actions { padding-top: .5rem; }
  table.table-stack[data-stack-ready] td.empty { text-align: center; }
}
@supports not (container-type: inline-size) {
  @media (max-width: 47.99em) {
    table.table-stack[data-stack-ready] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    table.table-stack[data-stack-ready], table.table-stack[data-stack-ready] tbody, table.table-stack[data-stack-ready] tr, table.table-stack[data-stack-ready] td { display: block; width: 100%; }
    table.table-stack[data-stack-ready] tr { padding: .5rem 0; border-bottom: 1px solid var(--border); }
    table.table-stack[data-stack-ready] tbody tr:hover { background: transparent; }
    table.table-stack[data-stack-ready] td {
      display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center;
      border: 0; padding: .3rem 0; text-align: left;
    }
    table.table-stack[data-stack-ready] td::before { content: attr(data-label); flex: 0 0 min(40%, 9rem); color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
    table.table-stack[data-stack-ready] td:not([data-label]), table.table-stack[data-stack-ready] td[data-label=""], table.table-stack[data-stack-ready] td.cell-actions, table.table-stack[data-stack-ready] td.empty { display: block; }
    table.table-stack[data-stack-ready] td:not([data-label])::before, table.table-stack[data-stack-ready] td[data-label=""]::before, table.table-stack[data-stack-ready] td.cell-actions::before { content: none; }
    table.table-stack[data-stack-ready] td.cell-title { display: block; font-size: 1.0625rem; }
    table.table-stack[data-stack-ready] td.cell-title::before { display: block; margin-bottom: .15rem; }
    table.table-stack[data-stack-ready] td.cell-actions { padding-top: .5rem; }
    table.table-stack[data-stack-ready] td.empty { text-align: center; }
  }
}

/* ---------- Formulários ---------- */
.form-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-full { grid-column: 1 / -1; }
label { font-weight: 600; font-size: .9375rem; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=date], input[type=number], select, textarea {
  width: 100%; max-width: 100%; min-height: var(--tap); font: inherit; font-size: 1rem; /* 16px evita zoom automático no iOS */
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem .65rem;
}
textarea { resize: vertical; min-height: 10rem; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; margin: 0; flex-shrink: 0; accent-color: var(--primary); }
input[type=range] { min-height: var(--tap); accent-color: var(--primary); }
.select-auto { width: auto; max-width: 100%; }
.helptext, .field small { color: var(--muted); font-size: .8125rem; }
.errorlist { list-style: none; margin: 0; padding: 0; color: var(--bad); font-size: .875rem; }
.checkbox-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.checkbox-list label, .chip-check {
  font-weight: 500; display: inline-flex; align-items: center; gap: .45rem; min-height: var(--tap); padding: .35rem .8rem;
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-size: .9375rem; background: var(--surface);
}
.chip-check:has(input:focus-visible) { outline: var(--focus); outline-offset: 2px; }
.checkbox-list input:checked + span, .chip-check:has(input:checked) { color: var(--primary); }
.chip-check:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); }
.filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; align-items: end; }
.filters .field-full { grid-column: 1 / -1; }
.filters > .btn-group .btn { flex: 1 1 auto; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.25rem; }
.form-actions .btn { flex: 1 1 auto; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-start; }
.inline-form .field { flex: 1 1 12rem; }
.filter-panel > summary {
  display: flex; align-items: center; gap: .5rem; min-height: var(--tap); cursor: pointer; font-weight: 700; list-style: none;
}
.filter-panel > summary::-webkit-details-marker { display: none; }
.filter-panel > summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .2s; }
.filter-panel[open] > summary::after { transform: rotate(180deg); }
.filter-panel[open] > summary { margin-bottom: .75rem; }
.char-count { font-size: .8125rem; color: var(--muted); text-align: right; }

/* ---------- Mensagens ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: .5rem; }
.message { padding: .7rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
.message.success { background: var(--good-soft); color: var(--good); border-color: transparent; }
.message.error { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.message.warning, .message.info { background: var(--mid-soft); color: var(--mid); border-color: transparent; }
.message-action { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

/* ---------- Biblioteca ---------- */
.library { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: start; }
/* No celular as tags ficam numa linha de chips com rolagem lateral (padrão de apps móveis). */
.tag-sidebar .card-header { margin-bottom: .5rem; }
.tag-sidebar ul {
  list-style: none; padding: 0 0 .25rem; margin: 0; display: flex; flex-wrap: nowrap; gap: .4rem;
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
}
.tag-sidebar li { flex-shrink: 0; scroll-snap-align: start; }
.tag-sidebar a {
  white-space: nowrap; display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: var(--tap);
  padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text);
}
.tag-sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.tag-sidebar a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; border-color: var(--primary); }
.text-cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 17.5rem), 1fr)); margin-top: 1rem; }
.text-card { display: flex; flex-direction: column; gap: .5rem; }
.text-card h3 { margin: 0; }
.text-card h3 a { color: var(--text); }
.text-card .excerpt { color: var(--muted); font-size: .9375rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin: 0; }
.text-card .meta { display: flex; gap: .25rem .75rem; font-size: .8125rem; color: var(--muted); flex-wrap: wrap; margin-top: auto; }
.text-card .card-badges { justify-content: space-between; }
.text-card .card-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 6.5rem), 1fr)); gap: .4rem; }
.pagination { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; align-items: center; margin-top: 1.25rem; text-align: center; }

/* ---------- Texto / estudo ---------- */
.chunk { display: grid; grid-template-columns: minmax(0, 1fr); gap: .5rem; padding: .85rem 0; border-bottom: 1px dashed var(--border); }
.chunk:last-child { border-bottom: 0; }
.chunk-original, .chunk-translation { white-space: pre-wrap; margin: 0; }
.chunk-translation { color: var(--muted); }
.chunk-label { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .2rem; }
.chunk-label .btn { text-transform: none; letter-spacing: 0; font-size: .875rem; }
.mode-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .25rem; background: var(--surface-2); padding: .25rem; border-radius: .65rem; }
.mode-tabs a {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: var(--tap);
  padding: .35rem .5rem; border-radius: var(--radius-sm); color: var(--muted); font-weight: 600; font-size: .875rem; line-height: 1.2;
}
.mode-tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.mode-tabs a:hover { text-decoration: none; color: var(--text); }
.study-stage { font-size: clamp(1.0625rem, 1rem + .5vw, 1.2rem); line-height: 1.75; white-space: pre-wrap; min-height: 6rem; }
.study-translation { font-size: 1rem; color: var(--muted); white-space: pre-wrap; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.study-translation summary { min-height: var(--tap); display: flex; align-items: center; gap: .5rem; cursor: pointer; list-style: none; }
.study-translation summary::-webkit-details-marker { display: none; }
.study-translation summary::before { content: "▸"; transition: transform .2s; }
.study-translation[open] summary::before { transform: rotate(90deg); }
.study-nav { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: 1rem; }
.study-nav .chunk-dots { grid-column: 1 / -1; order: -1; justify-content: center; }
.chunk-dots { display: flex; gap: .35rem; flex-wrap: wrap; }
.chunk-dots button {
  min-width: var(--tap); height: var(--tap); border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font: inherit; font-size: .875rem;
}
.chunk-dots button.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.speaking { background: var(--primary-soft); border-radius: 4px; }
.term-mark { background: var(--bad-soft); color: inherit; border-bottom: 2px solid var(--bad); border-radius: 2px; padding: 0 .05em; }
a.term-mark { text-decoration: none; cursor: pointer; }
a.term-mark:hover { text-decoration: none; background: var(--bad); color: var(--surface); }
.term-detail-term { font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2rem); }
.term-context { margin: 0; padding: .75rem 1rem; border-left: 3px solid var(--bad); background: var(--surface-2); border-radius: var(--radius-sm); white-space: pre-wrap; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.term-hint { font-size: .8125rem; margin: .5rem 0 0; }
.term-popover { position: absolute; z-index: 60; filter: drop-shadow(0 4px 10px rgba(16, 24, 40, .18)); }
.term-cell-context { color: var(--muted); font-size: .875rem; font-weight: 400; }
.term-meaning { white-space: pre-wrap; }
.term-meaning-form textarea { min-height: 5rem; }
.hidden-text-note { display: flex; align-items: flex-start; gap: .75rem; padding: 1rem; background: var(--surface-2); border-radius: var(--radius); color: var(--muted); }
.hidden-text-note .icon { font-size: 1.6rem; line-height: 1; }
.spacer { height: 1rem; }
.quiz-pick { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }

/* Celular: grade de 6 colunas — Reproduzir | Pausar, Repetir | ⏮ ⏭ ■ | velocidade */
.player { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .5rem; align-items: center; padding: .75rem; background: var(--surface-2); border-radius: var(--radius); }
.player > * { grid-column: span 6; }
.player [data-action="pause"], .player [data-action="repeat"] { grid-column: span 3; }
.player [data-action="prev"], .player [data-action="next"], .player [data-action="stop"] { grid-column: span 2; }
.player .rate { display: flex; align-items: center; gap: .5rem; font-size: .9375rem; }
.player .rate input { flex: 1; min-width: 5rem; }
.player-status { font-size: .875rem; color: var(--muted); }

/* ---------- Criação de quiz ---------- */
.kind-grid { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr)); }
.kind-card { display: flex; flex-direction: column; gap: .5rem; transition: border-color .15s, background-color .15s; }
.kind-card.is-selected { border-color: var(--primary); background: linear-gradient(var(--primary-soft), var(--primary-soft)) padding-box; }
.kind-toggle { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); cursor: pointer; font-size: 1.0625rem; }
.kind-toggle input { width: 1.25rem; height: 1.25rem; }
.kind-toggle:has(input:focus-visible) { outline: var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.kind-icon { font-size: 1.35rem; line-height: 1; }
.kind-name { font-weight: 700; }
.kind-desc { color: var(--muted); font-size: .9375rem; margin: 0; flex: 1; }
.stepper { display: flex; align-items: center; gap: .4rem; }
.stepper input[type=number] { width: 4.5rem; text-align: center; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-unit { font-size: .875rem; }
.builder-bar { position: sticky; bottom: max(.5rem, env(safe-area-inset-bottom)); z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; box-shadow: 0 -4px 20px rgba(0, 0, 0, .12); }
.builder-bar .btn-group .btn { flex: 1 1 auto; }
.builder-total { margin: 0; }
.kind-summary { display: flex; flex-wrap: wrap; gap: .35rem; }
.question-kind { display: inline-flex; align-items: center; gap: .3rem; margin-bottom: .4rem; font-weight: 600; }
.question-title .question-kind { display: flex; width: fit-content; }
.question-text { display: block; }
.question-audio { display: grid; gap: .5rem; margin-bottom: .75rem; padding: .75rem; background: var(--surface-2); border-radius: var(--radius-sm); }
.question-audio audio { width: 100%; min-height: var(--tap); }

/* ---------- Quiz ---------- */
.quiz-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.question { padding: 1rem 0; border-bottom: 1px solid var(--border); border-width: 0 0 1px; margin: 0; min-width: 0; }
.question:last-of-type { border-bottom: 0; }
fieldset.question { padding-left: 0; padding-right: 0; }
.question-title { font-weight: 600; margin-bottom: .6rem; overflow-wrap: anywhere; padding: 0; }
.option {
  display: flex; gap: .65rem; align-items: flex-start; min-height: var(--tap); padding: .6rem .75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: .45rem; cursor: pointer; font-weight: 500;
}
.option:hover { background: var(--surface-2); }
.option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.option:has(input:focus-visible) { outline: var(--focus); outline-offset: 2px; }
.option input { margin-top: .2rem; }
.option-letter { font-weight: 700; color: var(--muted); }
.review-option { padding: .5rem .75rem; border-radius: var(--radius-sm); margin-bottom: .35rem; border: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: center; }
.review-option.correct { border-color: var(--good); background: var(--good-soft); }
.review-option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.review-option .markers { margin-left: auto; display: flex; flex-wrap: wrap; gap: .25rem .75rem; }
.review-option .marker { font-size: .8125rem; font-weight: 700; }
.explanation { margin-top: .5rem; font-size: .9375rem; color: var(--muted); background: var(--surface-2); padding: .6rem .8rem; border-radius: var(--radius-sm); }
.score-hero { display: flex; gap: 1rem 1.5rem; align-items: center; flex-wrap: wrap; }
.score-hero > div:last-child { flex: 1 1 14rem; min-width: 0; }
.score-ring {
  width: clamp(5.5rem, 22vw, 7.5rem); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2rem); font-weight: 800; flex-shrink: 0;
  background: conic-gradient(var(--ring-color, var(--primary)) calc(var(--score) * 1%), var(--surface-2) 0); position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: .6rem; border-radius: 50%; background: var(--surface); }
.score-ring span { position: relative; }
.answer-list { padding-left: 1.25rem; margin: 0; }
.answer-list li { margin-bottom: .6rem; }

/* ---------- Gráficos ---------- */
.chart { width: 100%; min-height: 12.5rem; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 12px; }
.chart .grid line { stroke: var(--border); }
.chart .line { fill: none; stroke-width: 2.5; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart-tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: .3rem .55rem; border-radius: 6px; font-size: .8125rem; white-space: nowrap; transform: translate(-50%, -120%); z-index: 2; }
.legend { display: flex; gap: .5rem 1rem; flex-wrap: wrap; font-size: .875rem; color: var(--muted); margin-top: .5rem; }
.legend span::before { content: ""; display: inline-block; width: .65rem; height: .65rem; border-radius: 2px; margin-right: .35rem; background: var(--c); vertical-align: -1px; }
.chart-empty { display: grid; place-items: center; min-height: 12.5rem; padding: 1rem; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: var(--radius); }
.meter-row { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.meter { flex: 1; height: .5rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 3rem; }
.meter > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 20, .55); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 1.25rem; width: 100%; max-width: 26rem;
  max-height: calc(100dvh - 2rem); overflow-y: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.modal h2 { margin-bottom: .5rem; }
.modal .btn { width: 100%; }

/* ---------- Autenticação ---------- */
.auth-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 25rem; }
.auth-card form { display: flex; flex-direction: column; gap: .9rem; }
.auth-card .brand { justify-content: center; margin-bottom: .5rem; padding: 0; }

/* =====================================================================
   40em (640px): mais espaço horizontal
   ===================================================================== */
@media (min-width: 40em) {
  :root { --gutter: 1.25rem; }
  .card { padding: 1.15rem 1.25rem; }
  .user-box .username { display: inline; }
  .page-header { flex-direction: row; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; }
  .page-header > div:first-child { flex: 1 1 20rem; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { display: flex; flex-wrap: wrap; }
  .filter-panel > summary { display: none; }
  .filters .field { flex: 1 1 10rem; }
  .filters .field-full { flex-basis: 100%; }
  .filters > .btn-group .btn, .form-actions .btn { flex: 0 0 auto; }
  .player { display: flex; flex-wrap: wrap; }
  .player .rate { flex: 1 1 14rem; justify-content: flex-end; }
  .player-status { width: 100%; }
  .player .rate input { flex: 0 1 8rem; }
  .study-nav { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; }
  .study-nav .chunk-dots { order: 0; flex: 1 1 auto; }
  .mode-tabs { display: flex; flex-wrap: wrap; }
  .mode-tabs a { padding: .35rem .9rem; }
  .modal .btn { width: auto; }
  .hidden-text-note { padding: 1.5rem; }
  .text-card .card-actions { display: flex; flex-wrap: wrap; }
}

/* =====================================================================
   48em (768px): tabelas voltam ao formato normal; texto e tradução lado a lado
   ===================================================================== */
@media (min-width: 48em) {
  .chunk { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
  th, td { padding: .6rem .65rem; }
  .kpis { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
}

/* =====================================================================
   64em (1024px): menu lateral fixo e layouts em colunas
   ===================================================================== */
@media (min-width: 64em) {
  :root { --gutter: 1.5rem; }
  .sidebar {
    position: sticky; top: 0; z-index: auto; flex-shrink: 0; width: var(--sidebar);
    transform: none; visibility: visible; transition: none; box-shadow: none; padding: 1.25rem .9rem;
  }
  body.nav-open { overflow: auto; }
  .nav-backdrop, .menu-toggle, .sidebar-close { display: none !important; }
  .topbar { padding: .65rem var(--gutter); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .library { grid-template-columns: 15rem minmax(0, 1fr); gap: 1.25rem; }
  .tag-sidebar ul { flex-direction: column; gap: 2px; overflow: visible; padding: 0; }
  .tag-sidebar a { border-radius: 6px; border-color: transparent; }
  .quiz-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); }
  .reference { position: sticky; top: 5rem; max-height: calc(100vh - 6.5rem); max-height: calc(100dvh - 6.5rem); overflow: auto; }
}

/* Telas grandes com mouse/trackpad: controles mais compactos (como o visual original) */
@media (min-width: 64em) and (pointer: fine) {
  :root { --tap: 2.375rem; --tap-sm: 2rem; }
  body { font-size: .9375rem; }
  .btn-sm { font-size: .875rem; padding: .3rem .6rem; }
  .chip-check, .checkbox-list label { min-height: 2.125rem; padding: .25rem .65rem; font-size: .875rem; }
  .tag-sidebar a { min-height: 2.125rem; }
  .chunk-dots button { min-width: 2rem; height: 2rem; }
}

/* =====================================================================
   80em (1280px) e 120em (1920px)
   ===================================================================== */
@media (min-width: 80em) {
  :root { --gutter: 2rem; --gap: 1.25rem; }
}
@media (min-width: 120em) {
  .content { max-width: 96rem; }
}

/* ---------- Preferências do usuário ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .btn, .chip-check, .option, .mode-tabs a { border: 1px solid ButtonText; }
  .chunk-dots button.active, .mode-tabs a.active, .nav a.active { outline: 2px solid Highlight; }
}
@media print {
  .sidebar, .topbar, .nav-backdrop, .player, .btn, form.filters { display: none !important; }
  .content { max-width: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
