:root {
  --bg: #f5f6fa; --card: #fff; --ink: #1f2430; --muted: #6b7280;
  --brand: #4f46e5; --brand-ink: #fff; --user: #4f46e5; --ai: #fff;
  --warn: #fff7e6; --warn-ink: #8a5a00; --line: #e5e7eb;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11131a; --card: #1b1e29; --ink: #eceef4; --muted: #9aa1b2; --ai: #232738;
          --warn: #3a2f12; --warn-ink: #ffd27a; --line: #2c3142; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; max-width: 820px; margin: 0 auto;
}
.topbar { display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--brand); color: var(--brand-ink); }
.brand { font-weight: 700; font-size: 1.15rem; }
.icon-btn { background: transparent; border: 0; font-size: 1.3rem; cursor: pointer; }

.topics { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; scrollbar-width: none; }
.topics::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 12px; border-radius: 999px; cursor: pointer; font-size: .9rem; white-space: nowrap; }
.chip.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.chat { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 10px 12px; border-radius: 16px; line-height: 1.4; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--ai); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .trans { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.msg .fix { background: var(--warn); color: var(--warn-ink); border-radius: 10px; padding: 6px 8px; margin-top: 8px; font-size: .85rem; }
.msg .tip { margin-top: 6px; font-size: .85rem; color: var(--muted); }
.msg .tools { margin-top: 6px; display: flex; gap: 8px; }
.msg .tools button { background: transparent; border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 2px 8px; cursor: pointer; }
.msg.error { align-self: center; background: #fee2e2; color: #991b1b; }
.typing { color: var(--muted); font-style: italic; align-self: flex-start; padding: 4px 12px; }

.suggestions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 12px 6px; }
.suggestions button { border: 1px dashed var(--brand); background: transparent; color: var(--brand);
  border-radius: 12px; padding: 6px 10px; cursor: pointer; font-size: .85rem; }

.composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); }
.composer input { flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 1rem; }
.mic, .send { width: 48px; border: 0; border-radius: 12px; font-size: 1.2rem; cursor: pointer; }
.mic { background: #e0e7ff; }
.mic.listening { background: #ef4444; animation: pulse 1s infinite; }
.send { background: var(--brand); color: #fff; }
@keyframes pulse { 50% { transform: scale(1.08); } }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(92vw, 460px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.settings { padding: 18px; display: flex; flex-direction: column; gap: 12px; max-height: 85vh; overflow-y: auto; }
.settings h2, .settings h3 { margin: 0; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.settings label.row { flex-direction: row; align-items: center; gap: 8px; }
.settings select, .settings input[type=text] { padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 1rem; }
.settings button { padding: 10px 14px; border-radius: 10px; border: 0; background: var(--brand); color: #fff; cursor: pointer; font-size: 1rem; }
.settings button.secondary { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.actions { display: flex; justify-content: space-between; gap: 8px; }
.vocab { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; max-height: 160px; overflow-y: auto; }
.vocab div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 4px 0; }

/* v2: conta, histórico, utilitários */
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.err { color: #dc2626; min-height: 1em; }
.account { display: flex; flex-direction: column; gap: 8px; }
.account input { padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 1rem; }
#accLogged { flex-direction: row; justify-content: space-between; align-items: center; }
.vocab .link { cursor: pointer; flex: 1; }
.vocab button { padding: 2px 8px; font-size: .85rem; }

/* v3: streaming, mãos livres, revisão */
.top-actions { display: flex; gap: 6px; }
.mic.active { background: #22c55e; color: #fff; }
.msg.streaming { opacity: .92; }
.rev-card { display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; }
.rev-word { font-size: 1.8rem; font-weight: 700; margin: 6px 0; word-break: break-word; }
.rev-meaning { font-size: 1.15rem; color: var(--muted); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; width: 100%; }
.grades button { padding: 10px 4px; font-size: .9rem; }
.grades .g0 { background: #ef4444; } .grades .g1 { background: #f59e0b; }
.grades .g2 { background: #22c55e; } .grades .g3 { background: #0ea5e9; }

/* v4: missão, pronúncia, resumo, progresso */
.mission { margin: 0 12px 4px; padding: 8px 10px; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line); font-size: .85rem; }
.mission .bar { height: 6px; border-radius: 4px; background: var(--line); margin-top: 6px; overflow: hidden; }
.mission .bar > i { display: block; height: 100%; background: #22c55e; transition: width .4s; }
.mission.done { border-color: #22c55e; }
.chip.mode { border-style: dashed; }
.chip.dim { opacity: .45; }
.pron { margin-top: 8px; padding: 8px; border-radius: 10px; background: var(--bg); font-size: .9rem; }
.pron .w-ok { color: #16a34a; font-weight: 600; }
.pron .w-miss { color: #dc2626; text-decoration: underline wavy; }
.pron .score { font-weight: 700; margin-bottom: 4px; }
.pron .heard { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.pron button { margin-top: 6px; margin-right: 6px; background: transparent; border: 1px solid var(--line);
  color: var(--ink); border-radius: 8px; padding: 2px 8px; cursor: pointer; }
.sum-score { font-size: 2rem; font-weight: 800; text-align: center; }
.sum-sec { margin-top: 10px; }
.sum-sec h3 { margin: 0 0 4px; font-size: 1rem; }
.sum-sec ul { margin: 0; padding-left: 18px; }
.mistake { border-left: 3px solid #f59e0b; padding-left: 8px; margin-bottom: 8px; font-size: .9rem; }
.mistake .w { color: #dc2626; text-decoration: line-through; }
.mistake .r { color: #16a34a; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; }
.stat small { color: var(--muted); }
.week { display: flex; align-items: flex-end; gap: 6px; height: 80px; margin-top: 6px; }
.week div { flex: 1; text-align: center; font-size: .7rem; color: var(--muted); display: flex; flex-direction: column;
  justify-content: flex-end; height: 100%; }
.week i { display: block; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; margin-bottom: 2px; }
.trow { display: flex; justify-content: space-between; font-size: .9rem; border-bottom: 1px solid var(--line); padding: 4px 0; }

/* v5 */
.msg.notice { align-self: center; background: transparent; color: var(--muted); font-size: .8rem; padding: 2px 8px; }

/* v6 */
.mic.processing { background: #f59e0b; animation: pulse 1s infinite; }

/* v7 */
.links { display: flex; gap: 12px; flex-wrap: wrap; }
.settings button.linklike { background: transparent; color: var(--brand); padding: 0; border: 0;
  font-size: .85rem; text-decoration: underline; }

/* v6: administração / backups */
.settings input[type=time], .settings input[type=number] { padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 1rem; }
.bklist { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.bkitem { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 6px 0; font-size: .85rem; }
.bkitem .bkinfo { display: flex; flex-direction: column; min-width: 0; }
.bkitem .bkbtns { display: flex; gap: 4px; flex-shrink: 0; }
.bkitem .bkbtns a, .bkitem .bkbtns button { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  color: var(--ink); text-decoration: none; cursor: pointer; font-size: 1rem; line-height: 1; }
.muted { color: var(--muted, #888); }

/* v8: gamificação */
.xpbar { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.xpbar i { display: block; height: 100%; background: var(--brand); }
.achs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.ach { background: var(--bg); border-radius: 12px; padding: 8px; font-size: .8rem; display: flex; flex-direction: column; gap: 2px; }
.ach.locked { opacity: .5; filter: grayscale(1); }
.ach b { font-size: .9rem; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--card);
  padding: 10px 16px; border-radius: 20px; font-size: .95rem; z-index: 50; max-width: 90vw; text-align: center; }
.rank { display: flex; justify-content: space-between; font-size: .9rem; border-bottom: 1px solid var(--line); padding: 4px 0; }
.rank.me { font-weight: 700; }

/* v9: versão falada */
.spoken { margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: #eef2ff; color: #3730a3; font-size: .9rem; }
.spoken .ipa { font-family: "Noto Sans", "DejaVu Sans", system-ui, sans-serif; opacity: .8; margin-top: 2px; }
@media (prefers-color-scheme: dark) { .spoken { background: #25285a; color: #c7d2fe; } }

/* v10: IA e fallback (admin) */
.aibox { display: flex; flex-direction: column; gap: 10px; }
.aicard { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.aicard h4 { margin: 0; font-size: .95rem; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.aicard label { display: flex; flex-direction: column; gap: 3px; font-size: .8rem; }
.aicard input, .aicard select { padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: .95rem; width: 100%; }
.airow { display: flex; gap: 6px; flex-wrap: wrap; }
.airow button { padding: 8px 10px; font-size: .85rem; }
.aires { font-size: .8rem; }
.aires.ok { color: #15803d; }
.aires.bad { color: #b91c1c; }

/* v15: administração em abas */
#dlgAdmin { width: min(96vw, 560px); }
#dlgAdmin .settings { max-height: 92vh; }
#dlgAdmin section { display: flex; flex-direction: column; gap: 10px; }
.admtabs { display: flex; gap: 6px; position: sticky; top: 0; background: var(--card); padding: 2px 0 6px; z-index: 1; }
.admtabs button { flex: 1; background: var(--bg) !important; color: var(--ink) !important; border: 1px solid var(--line) !important; font-size: .95rem; }
.admtabs button.on { background: var(--brand) !important; color: #fff !important; border-color: var(--brand) !important; }
