:root {
  --bg: #f6f7fb; --card: #ffffff; --ink: #111827; --muted: #5b6474; --line: #e3e6ee;
  --pri: #1d4ed8; --pri-ink: #ffffff; --ok: #15803d; --ok-bg: #e8f6ee; --bad: #b91c1c; --bad-bg: #fdecec;
  --mid: #b45309; --mark: #7c3aed; --radius: 14px; --gap: 12px; --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --card: #171e2d; --ink: #e8ecf4; --muted: #9aa4b6; --line: #273043;
    --pri: #5b8cff; --pri-ink: #0b1020; --ok: #4ade80; --ok-bg: #12301f; --bad: #f87171; --bad-bg: #3a1717; --mid: #fbbf24; --mark: #b794f6;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  overflow-x: hidden;
}
h1 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.08rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: var(--pri); }
img { max-width: 100%; height: auto; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--card); padding: 8px; z-index: 50; }
.top { display: flex; align-items: center; height: 48px; padding: 0 16px; max-width: 560px; margin: 0 auto; }
.brand { font-weight: 800; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.view { display: block; max-width: 560px; margin: 0 auto; padding: 0 16px; outline: none; min-height: 60vh; }
.view > * + * { margin-top: var(--gap); }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: inherit; text-decoration: none; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.big { display: block; font-size: 1.6rem; line-height: 1.2; margin: 4px 0 6px; }
.warn { color: var(--mid); }
.hero h1 { font-size: 1.3rem; }
.hero p { color: var(--muted); }
.hero-sm h1 { font-size: 1.2rem; margin: 4px 0 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-k { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat-v { font-size: 1.1rem; overflow-wrap: anywhere; }
.acts { display: grid; gap: var(--gap); }
.act { display: flex; flex-direction: column; gap: 2px; }
.card-cta p { margin: 4px 0 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center; touch-action: manipulation; }
.btn-primary { background: var(--pri); color: var(--pri-ink); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-block { display: flex; width: 100%; }
.btn-link { background: none; border: 0; color: var(--pri); font: inherit; padding: 8px 0; cursor: pointer; min-height: 44px; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 1.4rem; text-decoration: none; cursor: pointer; flex: none; }

.bar { display: block; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; min-width: 40px; }
.bar > span { display: block; height: 100%; background: var(--pri); border-radius: 99px; }
.bar-thin { height: 4px; }
.bar-ok > span, .bar-good > span { background: var(--ok); }
.bar-mid > span { background: var(--mid); }
.bar-low > span { background: var(--bad); }

.ses-head { display: flex; gap: 10px; align-items: center; }
.ses-title { display: flex; flex-direction: column; min-width: 0; }

.q-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge { font-size: .76rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--line); }
.badge-enem { background: #dbe6ff; color: #1e3a8a; }
@media (prefers-color-scheme: dark) { .badge-enem { background: #1e2c55; color: #c7d6ff; } }
.q-text { overflow-wrap: anywhere; }
.q-text p { margin: 0 0 8px; }
.fig { margin: 10px 0; }
.fig img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 6px; background: #fff; }
.fig-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.fig-row .fig { margin: 0; }
.tbl { max-width: 100%; overflow-x: auto; margin: 8px 0; -webkit-overflow-scrolling: touch; }
/* scroll shadows: a table wider than the screen shows an edge shadow on the side that scrolls */
.tbl { background: linear-gradient(to right, var(--card) 30%, transparent) left / 32px 100% no-repeat local,
  linear-gradient(to left, var(--card) 30%, transparent) right / 32px 100% no-repeat local,
  radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .2), transparent) left / 10px 100% no-repeat scroll,
  radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .2), transparent) right / 10px 100% no-repeat scroll; }
.tbl table { border-collapse: collapse; font-size: .9rem; }
.tbl td, .tbl th { border: 1px solid var(--line); padding: 4px 6px; text-align: center; }
/* Cells break between words only (never "Depó-sit-o"); a table wider than the screen scrolls in .tbl. */
.tbl td, .tbl th { overflow-wrap: normal; word-break: normal; hyphens: manual; }
mjx-container[display="true"] { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
/* An inline formula wider than its box (mathjax.js marks it after typesetting) scrolls instead of overflowing. */
mjx-container.mj-wide { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; }
.mj-wait { visibility: hidden; }

.opts { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.opt { display: flex; gap: 10px; align-items: flex-start; width: 100%; min-height: 48px; padding: 10px 12px; text-align: left;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font: inherit; cursor: pointer; touch-action: manipulation; }
.opt:disabled { cursor: default; }
.opt-l { flex: none; width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--line); font-weight: 700; font-size: .9rem; }
.opt-t { min-width: 0; overflow-wrap: anywhere; padding-top: 1px; }
.opt.is-chosen { border-color: var(--pri); }
.opt.is-chosen .opt-l { background: var(--pri); color: var(--pri-ink); }
.opt.is-right { border-color: var(--ok); background: var(--ok-bg); }
.opt.is-right .opt-l { background: var(--ok); color: #fff; }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.is-wrong .opt-l { background: var(--bad); color: #fff; }
/* Image-only options (optionFigures): the whole button is the tap target; the image keeps its
   aspect ratio (width/height attributes → no layout shift) and never exceeds the button. */
.opt-fig { flex-direction: column; align-items: stretch; gap: 4px; padding: 8px 10px; }
.opt-f { min-width: 0; display: flex; justify-content: center; }
.opt-img { display: block; max-width: 100%; height: auto; max-height: 260px; object-fit: contain; background: #fff; border-radius: 6px; }
.hint { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.attr { margin: 12px 0 0; font-size: .78rem; color: var(--muted); }
.attr-src { font-style: italic; }

.fb { border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); background: var(--card); display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
.fb-ok { border-color: var(--ok); }
.fb-bad { border-color: var(--bad); }
.fb-title { font-weight: 700; margin: 0; }
.fb-ok .fb-title { color: var(--ok); }
.fb-bad .fb-title { color: var(--bad); }
.fb-h { font-size: .9rem; margin: 4px 0 0; color: var(--muted); }
.expl { overflow-wrap: anywhere; }
.why { border-top: 1px solid var(--line); padding-top: 4px; }
.why summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--pri); }
.why-list { list-style: none; padding: 0; margin: 2px 0 0; display: grid; gap: 6px; }
.why-list li { padding: 6px 10px; border-radius: 8px; background: var(--bg); overflow-wrap: anywhere; }
.why-list li.is-yours { box-shadow: inset 0 0 0 1.5px var(--bad); }
.why-l { display: inline-block; min-width: 1.1em; }
.why-you { color: var(--bad); font-size: .86rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 8px 0 0; }
.chip { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-size: .92rem; text-decoration: none; cursor: pointer; }
.chip-on { background: var(--pri); color: var(--pri-ink); border-color: var(--pri); }
.chip-ok { border-color: var(--ok); background: var(--ok-bg); }
.chip-bad { border-color: var(--bad); background: var(--bad-bg); }

.topic-list, .sim-list, .pt-list, .hist-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.topic-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 10px; align-items: center; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--ink); text-decoration: none; min-height: 52px; }
.topic-name { min-width: 0; overflow-wrap: anywhere; }
.topic-m { display: flex; flex-direction: column; align-items: stretch; text-align: right; }
.pt-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.pt-row:last-child { border-bottom: 0; }
.pt-row .topic-name { grid-column: 1 / -1; font-size: .95rem; }
.pt-row .bar { margin: 4px 0; }
.pt-row > .muted { grid-column: 1 / -1; }
.sim-row { display: flex; flex-direction: column; gap: 2px; }
.sim-hist { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.rules { padding-left: 18px; color: var(--muted); }

.sim-bar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--bg); padding: 8px 0; border-bottom: 1px solid var(--line); }
.clock { font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.sim-nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sim-nav .btn { padding: 8px 6px; font-size: .92rem; }
#sim-mark.is-on { border-color: var(--mark); color: var(--mark); }
.small-h { font-size: .95rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin: 8px 0; }
.cell { height: 44px; min-width: 0; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: .88rem; font-variant-numeric: tabular-nums; cursor: pointer; position: relative; }
.cell.is-answered { background: var(--pri); color: var(--pri-ink); border-color: var(--pri); }
.cell.is-marked { box-shadow: inset 0 0 0 3px var(--mark); }
.cell.is-current { outline: 2px solid var(--ink); outline-offset: 1px; }
.legend { margin: 0 0 10px; }
.confirm { margin-top: 10px; padding: 12px; border-radius: 12px; background: var(--bg); }

.rev { border-top: 1px solid var(--line); }
.rev summary { padding: 10px 0; cursor: pointer; min-height: 44px; }
.rev-ok summary { color: var(--ok); }
.rev-bad summary { color: var(--bad); }
.rev-body > * + * { margin-top: 10px; }
.rev-body .q-card, .rev-body .fb { padding: 10px 0 0; border: 0; border-radius: 0; }

.theory section + section { margin-top: 14px; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line); }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem;
  color: var(--muted); text-decoration: none; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.nav a[aria-current="page"] { color: var(--pri); font-weight: 700; }
.nav-i { font-size: 1.15rem; line-height: 1; }

.ai-panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; max-height: 80vh; display: flex; flex-direction: column; gap: 8px;
  background: var(--card); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .18); max-width: 560px; margin: 0 auto; }
.ai-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.ai-msgs { overflow-y: auto; display: grid; gap: 8px; min-height: 60px; }
.ai-msg { padding: 8px 10px; border-radius: 10px; background: var(--bg); overflow-wrap: anywhere; }
.ai-user { background: #dbe6ff; color: #1e3a8a; justify-self: end; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-form { display: flex; gap: 8px; }
.ai-form textarea { flex: 1; min-width: 0; min-height: 48px; border-radius: 10px; border: 1px solid var(--line); padding: 10px; font: inherit;
  background: var(--bg); color: var(--ink); resize: none; }
.ai-left { margin: 0; }
.loading { color: var(--muted); }

/* Learning engine: continue card, review/remediation marks, knowledge delta, plan time */
.cont-name { display: block; font-size: 1.1rem; margin: 2px 0 0; overflow-wrap: anywhere; }
.btn-2nd { margin-top: 8px; }
.plan-note { margin: 8px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--ok-bg); font-size: .92rem; }
.note-remed { margin: 0; padding: 9px 12px; border-left: 3px solid var(--mid); border-radius: 8px; background: var(--bad-bg); font-size: .92rem; }
.badge-rev { background: #fde68a; color: #78350f; }
.remed-count { white-space: nowrap; }
.delta-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.delta-row:last-child { border-bottom: 0; }
.delta-row .up { color: var(--ok); white-space: nowrap; }
.delta-row .down { color: var(--bad); white-space: nowrap; }
.tag-next { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--pri); color: var(--pri-ink); }
.plan-list { margin: 8px 0 0; padding-left: 22px; display: grid; gap: 6px; }
.ok-text { color: var(--ok); margin: 8px 0 0; }
.center { text-align: center; }
.plan-list .chip { border-radius: 12px; }
/* streak protection, per-topic train link, mistake notebook */
.shield { display: block; margin-top: 4px; color: var(--muted); overflow-wrap: anywhere; }
.pt-row .pt-train { grid-column: 1 / -1; justify-self: start; min-height: 32px; display: inline-flex; align-items: center; }
.mk summary { overflow-wrap: anywhere; }
