/* ---------- cores (tema claro) ---------- */
:root {
  color-scheme: light;
  --ink: #12263f;
  --muted: #5b6878;
  --paper: #f4f7f5;
  --card: #ffffff;
  --soft: #f2f5f4;
  --line: #dce5e2;
  --accent: #ef6c44;
  --green: #14866d;
  --btn: #12263f;
  --btnText: #ffffff;
  --pillBg: #e4f4ef;
  --warnBg: #fdebd3;
  --warnInk: #8a4b00;
  --barBg: #e6ecea;
  --okBg: #dff5ec;
  --badBg: #fee6df;
  --feedBg: #fff4ef;
  --danger: #c0392b;
  --shadow: 0 12px 36px #18344a18;
  --backdrop: #0b1c2acc;
  /* gráfico: par validado para daltonismo */
  --vizOk: #14866d;
  --vizBad: #f08a5c;
}
/* ---------- tema escuro: pelo aparelho ou pela escolha em Ajustes ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #e8eef2; --muted: #9fadb9; --paper: #0e1a26; --card: #172736; --soft: #1e3142; --line: #2b4054;
    --accent: #f07f5b; --green: #45c4a5; --btn: #e8eef2; --btnText: #0e1a26; --pillBg: #173d36;
    --warnBg: #4a3413; --warnInk: #ffd08a; --barBg: #26394a; --okBg: #153f35; --badBg: #4b241a; --feedBg: #2a2420;
    --danger: #ff8a7a; --shadow: 0 12px 36px #00000040; --backdrop: #050b11cc; --vizOk: #2fa98c; --vizBad: #d95926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8eef2; --muted: #9fadb9; --paper: #0e1a26; --card: #172736; --soft: #1e3142; --line: #2b4054;
  --accent: #f07f5b; --green: #45c4a5; --btn: #e8eef2; --btnText: #0e1a26; --pillBg: #173d36;
  --warnBg: #4a3413; --warnInk: #ffd08a; --barBg: #26394a; --okBg: #153f35; --badBg: #4b241a; --feedBg: #2a2420;
  --danger: #ff8a7a; --shadow: 0 12px 36px #00000040; --backdrop: #050b11cc; --vizOk: #2fa98c; --vizBad: #d95926;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-text-size-adjust: 100%; }
header, main { width: min(920px, calc(100% - 32px)); margin: auto; }
header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 24px 0 6px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(26px, 6vw, 42px); line-height: 1.05; margin-bottom: 0; }
h2 { font-size: 22px; margin-bottom: 12px; }
h3 { font-size: 17px; margin-bottom: 6px; }
header small, .eyebrow { font-weight: 800; font-size: 12px; letter-spacing: .12em; color: var(--green); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.prompt { white-space: pre-line; overflow-wrap: anywhere; }
.error { color: var(--danger); font-weight: 700; }
.subhead { margin: 22px 0 8px; font-size: 15px; }

button, .fileBtn { border: 0; border-radius: 14px; background: var(--btn); color: var(--btnText); font: inherit; font-weight: 750; padding: 12px 16px; min-height: 44px; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, .fileBtn:focus-within, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.mini { padding: 6px 12px; min-height: 36px; border-radius: 10px; font-size: 14px; }
.wide { width: 100%; margin-top: 12px; }
.danger, .ghost.danger { color: var(--danger); border-color: var(--danger); }
.dangerBtn { background: #c0392b; color: #fff; }
.fileBtn { display: inline-flex; align-items: center; }
label { display: grid; gap: 6px; font-weight: 700; margin: 12px 0; }
label.fileBtn { margin: 0; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px; background: var(--card); color: var(--ink); font: inherit; }
textarea { resize: vertical; }

/* ---------- navegação ---------- */
nav { display: flex; gap: 8px; overflow: auto; padding: 16px 0 18px; }
.tab { background: transparent; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.tab svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.view { display: none; padding-bottom: 60px; }
.view.active { display: block; }

/* ---------- Hoje ---------- */
.hero { background: linear-gradient(135deg, #12263f, #204f63); color: #fff; border-radius: 28px; padding: 26px; display: flex; align-items: end; justify-content: space-between; gap: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.hero strong { font-size: 64px; display: block; line-height: 1; }
.hero p { max-width: 450px; color: #d8e8e7; margin-bottom: 0; }
.hero .eyebrow { color: #7fe0c8; }
.hero button { background: var(--accent); color: #fff; white-space: nowrap; }
.notice { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--warnBg); color: var(--warnInk); border-radius: 16px; padding: 12px 16px; margin-bottom: 14px; font-weight: 600; }
.timerPanel { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 20px; margin-bottom: 14px; box-shadow: var(--shadow); }
.timerPanel strong { display: block; font-size: clamp(32px, 8vw, 52px); font-variant-numeric: tabular-nums; line-height: 1.1; }
.timerActions { display: flex; gap: 8px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 28px; }
.kpis div { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.kpis span, .kpis b, .kpis small { display: block; }
.kpis span { font-size: 12px; color: var(--muted); }
.kpis b { font-size: 26px; font-variant-numeric: tabular-nums; }
.kpis small { font-size: 12px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 28px; }
.mode { min-height: 118px; text-align: left; background: var(--card); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.mode b { font-size: 18px; line-height: 1.2; }
.mode span { font-weight: 500; color: var(--muted); font-size: 14px; flex: 1; }
.mode small { font-weight: 700; color: var(--green); font-size: 12px; }
.mode.empty { box-shadow: none; }
.mode.empty b, .mode.empty small { color: var(--muted); }
.panel, .item { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.panel p { margin-bottom: 10px; }
.stack { display: grid; gap: 12px; }
.stack > .kpis { margin-bottom: 4px; }
.pill { display: inline-block; padding: 4px 9px; border-radius: 999px; background: var(--pillBg); color: var(--green); font-size: 12px; font-weight: 800; margin: 0 6px 6px 0; }
.pill.warn { background: var(--warnBg); color: var(--warnInk); }
.bar { height: 9px; background: var(--barBg); border-radius: 99px; overflow: hidden; margin: 8px 0 14px; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .25s; }

/* ---------- listas ---------- */
.titleRow { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.titleRow h2 { margin-bottom: 0; }
.titleRow select { width: auto; max-width: 60%; }
.rowActions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.rowActions.left { justify-content: flex-start; align-items: center; }
.rowActions input[type=time] { width: auto; }
.filters { display: grid; grid-template-columns: 2fr 1.2fr 1fr; gap: 8px; margin-bottom: 8px; }
.itemTop { margin-bottom: 2px; }
.itemFoot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.item.slim { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; box-shadow: none; }
.item.slim b, .item.slim small { display: block; overflow-wrap: anywhere; }
.fold { margin-top: 14px; }
.fold summary { cursor: pointer; font-weight: 700; padding: 8px 0; }
.fold .stack { margin-top: 8px; }

/* ---------- edital ---------- */
.legend { display: flex; gap: 6px 14px; flex-wrap: wrap; margin: 4px 0 14px; color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.none { background: #7d8a97; }
.critical { background: #c8443e; }
.attention { background: #b97a10; }
.good { background: #2f74b8; }
.strong { background: #16856f; }
.syllabus { display: grid; gap: 10px; }
.topicRow { display: grid; grid-template-columns: minmax(170px, 2fr) minmax(92px, .6fr) repeat(3, minmax(64px, .5fr)) 92px 128px; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.topicRow.header { background: transparent; border: 0; color: var(--muted); font-size: 12px; font-weight: 800; padding-block: 0; }
.topicName b, .topicName small { display: block; }
.topicName small { color: var(--muted); }
.cell { font-variant-numeric: tabular-nums; }
.score { font-weight: 800; }
.status { border-radius: 99px; color: #fff; padding: 5px 9px; font-size: 12px; font-weight: 700; text-align: center; }
.practice { white-space: nowrap; }

/* ---------- flashcards ---------- */
.cardFront { font-weight: 700; font-size: 17px; margin: 6px 0 12px; }
.cardBack { background: var(--soft); border-left: 5px solid var(--green); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.cardActions { display: flex; gap: 8px; flex-wrap: wrap; }
.rate { flex: 1; min-width: 92px; display: grid; gap: 0; padding: 8px 10px; background: var(--soft); color: var(--ink); border: 1px solid var(--line); }
.rate small { font-weight: 500; color: var(--muted); font-size: 12px; }
.rate.again { border-bottom: 4px solid var(--accent); }
.rate.hard { border-bottom: 4px solid #b97a10; }
.rate.good { border-bottom: 4px solid var(--green); }

/* ---------- progresso ---------- */
.viz .vizLegend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.okSw, .okSeg { background: var(--vizOk); }
.badSw, .badSeg { background: var(--vizBad); }
.chart { position: relative; padding-top: 4px; }
.chart .yMax { position: absolute; top: 0; left: 0; font-size: 11px; color: var(--muted); }
.chart::before { content: ""; position: absolute; left: 22px; right: 0; top: 8px; border-top: 1px dashed var(--line); }
.cols { display: flex; align-items: flex-end; gap: 4px; padding-left: 22px; }
.col { flex: 1; min-width: 0; min-height: 0; background: transparent; color: var(--muted); padding: 4px 0 2px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.col.active { background: var(--soft); color: var(--ink); }
.colStack { height: 122px; width: 100%; max-width: 26px; display: flex; flex-direction: column-reverse; gap: 2px; border-bottom: 1px solid var(--line); }
.seg { display: block; width: 100%; }
.seg.top { border-radius: 4px 4px 0 0; }
.col small { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
#chartRead { margin: 10px 0 0; font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.sumRow { display: flex; justify-content: space-between; gap: 12px; }
.sumList { display: grid; gap: 6px; margin: 4px 0 6px; }
.subjectRow .bar { margin-top: 4px; }
.wrongList { padding-left: 18px; margin: 0 0 6px; display: grid; gap: 6px; font-size: 14px; }

/* ---------- janelas ---------- */
dialog { width: min(640px, calc(100% - 22px)); max-height: calc(100dvh - 24px); overflow: auto; border: 0; border-radius: 24px; padding: 0; background: var(--card); color: var(--ink); box-shadow: 0 24px 80px #08131c66; }
dialog::backdrop { background: var(--backdrop); }
.dialogBody { padding: 24px; }
.close { float: right; background: transparent; color: var(--ink); font-size: 28px; line-height: 1; padding: 0 10px; min-height: 40px; margin: -6px -8px 0 8px; }
.progressLine { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 700; padding-top: 4px; }
#qText { font-size: 19px; line-height: 1.35; margin: 6px 0 16px; }
.answers { display: grid; gap: 10px; }
.answer { background: var(--soft); color: var(--ink); text-align: left; border: 1px solid var(--line); font-weight: 600; }
.answer:disabled { opacity: 1; }
.answer.correct { background: var(--okBg); border-color: var(--green); }
.answer.wrong { background: var(--badBg); border-color: var(--accent); }
#feedback { margin-top: 16px; padding: 14px 16px; border-left: 5px solid var(--accent); background: var(--feedBg); border-radius: 10px; }
#feedback.ok { border-left-color: var(--green); background: var(--okBg); }
#feedback p { margin: 8px 0 0; }
.dialogActions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
#importPreview { margin-top: 8px; }
.previewQ { margin-bottom: 8px; }

#toast { position: fixed; inset: auto auto 96px 50%; transform: translateX(-50%); margin: 0; width: max-content; max-width: min(520px, calc(100% - 32px)); background: var(--btn); color: var(--btnText); border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: 1; }

/* ---------- celular ---------- */
@media (max-width: 700px) {
  header { padding-top: 16px; }
  main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; gap: 0; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); overflow: visible; }
  .tab { flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 11px; border-radius: 12px; min-width: 0; }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { box-shadow: none; background: var(--soft); color: var(--green); }
  .view { padding-top: 14px; padding-bottom: 24px; }
  .hero { align-items: stretch; flex-direction: column; padding: 22px; }
  .hero button { width: 100%; }
  .notice { flex-direction: column; align-items: stretch; }
  .timerPanel { align-items: stretch; flex-direction: column; }
  .timerActions button { flex: 1; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .mode { min-height: 112px; padding: 12px; }
  .mode b { font-size: 16px; }
  .mode span { font-size: 13px; }
  .titleRow { align-items: flex-start; }
  #questions .titleRow h2 { display: none; }
  #questions .titleRow .rowActions { flex: 1; flex-wrap: nowrap; }
  #questions .titleRow .rowActions button { flex: 1; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  .item.slim { flex-direction: column; align-items: stretch; }
  .topicRow.header { display: none; }
  .topicRow { grid-template-columns: repeat(4, 1fr); gap: 8px 6px; }
  .topicName { grid-column: 1 / -1; }
  .cell::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
  .status { grid-column: 1 / 3; justify-self: start; }
  .practice { grid-column: 3 / 5; }
  .dialogBody { padding: 20px 16px; }
  .cols { gap: 2px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
