:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e2e5ea;
  --text: #1c2230; --muted: #667085; --accent: #2f6fde; --accent-soft: #e6eefc;
  --ok: #1f9d55; --ok-soft: #e3f5ea; --bad: #d64545; --bad-soft: #fbe9e9; --warn: #c98a00;
  --c1: #2f6fde; --c2: #13a39a; --c3: #8a5cf6; --c4: #e8833a; --c5: #d64590;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --surface: #171b23; --surface-2: #1f2430; --border: #2b3240;
    --text: #e6e9ef; --muted: #98a2b3; --accent: #6b9bff; --accent-soft: #1d2a45;
    --ok: #3ccf7f; --ok-soft: #14301f; --bad: #ff6b6b; --bad-soft: #3a1b1b;
    --c1: #6b9bff; --c2: #34c6bb; --c3: #a98bff; --c4: #ffa463; --c5: #ff7ab8;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; gap: 10px; align-items: center; color: var(--text); }
.brand small { display: block; color: var(--muted); font-size: .75rem; }
.logo { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 700; }
.topnav { display: flex; gap: 6px; align-items: center; }
.topnav a { padding: 6px 10px; border-radius: 8px; color: var(--text); }
.topnav a:hover { background: var(--surface-2); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, minmax(0,1fr)); }
.charts { grid-template-columns: 1.1fr 1fr; margin-top: 16px; }
.charts-2 { grid-template-columns: 1fr 1fr; margin-top: 16px; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; }
.kpi .sub { color: var(--muted); font-size: .8rem; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* course outline */
.subject { margin-top: 22px; }
.subject-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.subject-head h2 { margin: 0; }
details.subject > summary { list-style: none; cursor: pointer; padding: 6px 0; }
details.subject > summary::-webkit-details-marker { display: none; }
details.subject > summary .chev { color: var(--muted); transition: transform .2s; }
details.subject[open] > summary .chev { transform: rotate(90deg); }
details.subject { margin-top: 14px; }
.section-block { margin-bottom: 12px; padding: 0; overflow: hidden; }
.section-block summary { list-style: none; cursor: pointer; padding: 14px 18px; display: flex; gap: 12px; align-items: center; }
.section-block summary::-webkit-details-marker { display: none; }
.section-block summary .chev { transition: transform .2s; color: var(--muted); }
.section-block[open] summary .chev { transform: rotate(90deg); }
.lesson-row { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-top: 1px solid var(--border); color: var(--text); }
.lesson-row:hover { background: var(--surface-2); }
.check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; flex: none; font-size: 12px; color: #fff; }
.check.done { background: var(--ok); border-color: var(--ok); }
.check.partial { border-color: var(--accent); }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--ok-soft); color: var(--ok); } .badge.bad { background: var(--bad-soft); color: var(--bad); }

/* lesson page */
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 36%); grid-template-areas: "main notes" "side notes"; gap: 20px; align-items: start; }
.lesson-layout.no-notes { grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "main side"; }
.lesson-layout.no-notes .notes-pane { display: none; }
.lesson-main { grid-area: main; min-width: 0; }
.lesson-layout > .side { grid-area: side; }
.lesson-layout:not(.no-notes) > .side { grid-template-columns: 1fr 1fr; }
main:has(.lesson-layout:not(.no-notes)) { max-width: none; }
/* anotações à esquerda: ficam paradas na tela e rolam por dentro, o vídeo continua visível */
.notes-pane { grid-area: notes; position: sticky; top: 70px; height: calc(100vh - 86px); min-width: 0; }
.notes-card { height: 100%; display: flex; flex-direction: column; padding: 12px; }
.notes-head { margin: 0 0 8px; font-size: 1rem; }
.notes-card .toolbar { position: static; }
.notes-card .editor { flex: 1; min-height: 0; max-height: none; }
.notes-card > .row { flex-wrap: wrap; gap: 6px; }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.crumbs { color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.video-wrap { background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16/9; }
.video-wrap video { width: 100%; height: 100%; display: block; }
.lesson-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0; }
.lesson-title h1 { margin: 0; flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 18px 0 14px; overflow-x: auto; }
.tab { padding: 10px 14px; border: none; background: none; color: var(--muted); font: inherit; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.side .card { padding: 0; overflow: hidden; }
.side h3 { padding: 14px 16px 6px; margin: 0; }
.side .lesson-row { padding: 9px 16px; font-size: .9rem; }
.side .lesson-row.current { background: var(--accent-soft); font-weight: 600; }
.pdf-list a { display: flex; gap: 8px; align-items: center; padding: 9px 16px; border-top: 1px solid var(--border); color: var(--text); font-size: .9rem; }
.pdf-list a:hover { background: var(--surface-2); }
textarea, input[type=text], input[type=password], select { width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
textarea { min-height: 220px; resize: vertical; line-height: 1.5; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
label input, label select { margin-top: 6px; font-weight: 400; }

/* quiz */
.q { margin-bottom: 16px; }
.q-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 8px; }
.q-num { font-weight: 700; color: var(--accent); }
.q-stem { white-space: pre-wrap; }
.opts { display: grid; gap: 6px; margin: 10px 0; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-weight: 400; margin: 0; }
.opt:hover { background: var(--surface-2); }
.opt input { margin-top: 4px; }
.opt .L { font-weight: 700; min-width: 1.4em; }
.opt.struck > span { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--muted); }
.opt input { cursor: pointer; width: 18px; height: 18px; flex: none; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.letters { display: flex; flex-wrap: wrap; gap: 6px; }
.letters .opt { min-width: 52px; justify-content: center; }
.q-img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); margin: 8px 0; }
.expl { background: var(--surface-2); border-radius: 9px; padding: 12px 14px; margin-top: 8px; font-size: .93rem; }
.expl p { margin: 0 0 8px; }
.score-box { display: flex; gap: 18px; align-items: center; }
.score-ring { flex: none; }
.wrong-list li { margin-bottom: 4px; }
details.orig summary { cursor: pointer; color: var(--accent); font-size: .85rem; }

/* AI output */
.ai-out { background: var(--surface-2); border-radius: 9px; padding: 14px 16px; margin-top: 12px; }
.ai-out h1, .ai-out h2, .ai-out h3 { font-size: 1rem; margin-top: .8em; }
.ai-out ul { padding-left: 1.2em; }
.history-item { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* charts */
.chart-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
svg text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: 170px 1fr 48px; gap: 10px; align-items: center; margin: 7px 0; font-size: .88rem; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .pct { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg { padding: 22px; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; transition: .25s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 1400px) {
  .lesson-layout { grid-template-columns: minmax(0, 1fr) minmax(320px, 40%); grid-template-areas: "main notes" "side notes"; }
  .lesson-layout.no-notes { grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "main side"; }
}
@media (max-width: 960px) {
  .lesson-layout, .lesson-layout.no-notes { grid-template-columns: 1fr; grid-template-areas: "main" "notes" "side"; }
  .notes-pane { position: static; height: 70vh; }
}
@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .charts, .charts-2, .lesson-layout { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .hbar { grid-template-columns: 110px 1fr 44px; }
}

/* modo teatro */
body.theater main:has(.lesson-layout) { max-width: none; padding: 12px 24px; }
body.theater .lesson-layout { grid-template-columns: minmax(0, 1fr) minmax(320px, 32%); grid-template-areas: "main notes" "side notes"; }
body.theater .lesson-layout.no-notes { grid-template-columns: 1fr; grid-template-areas: "main" "side"; }
body.theater .notes-pane { top: 66px; height: calc(100vh - 78px); }
body.theater .video-wrap { aspect-ratio: auto; height: calc(100vh - 110px); border-radius: 8px; }
body.theater .video-wrap video { object-fit: contain; }
body.theater .lesson-layout > div > :not(.video-wrap), body.theater .side { max-width: 1232px; width: 100%; margin-left: auto; margin-right: auto; }
body.theater .side { grid-template-columns: 1fr 1fr; }
@media (max-width: 960px) { body.theater .side { grid-template-columns: 1fr; } body.theater .lesson-layout, body.theater .lesson-layout.no-notes { grid-template-columns: 1fr; grid-template-areas: "main" "notes" "side"; } }

/* editor de anotações */
.toolbar { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; padding: 6px; border: 1px solid var(--border); border-bottom: none; border-radius: 9px 9px 0 0; background: var(--surface-2); position: sticky; top: 57px; z-index: 5; }
.tbtn { min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; }
.tbtn:hover { background: var(--surface); border-color: var(--border); }
.tsep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); vertical-align: -3px; }
.editor { min-height: 320px; max-height: 70vh; overflow-y: auto; padding: 14px 16px; border: 1px solid var(--border); border-radius: 0 0 9px 9px; background: var(--surface); outline: none; line-height: 1.6; }
.editor:focus { border-color: var(--accent); }
.editor:empty::before { content: attr(data-ph); color: var(--muted); }
.editor h2, .notes-view h2 { font-size: 1.2rem; margin: .6em 0 .3em; }
.editor h3, .notes-view h3 { font-size: 1.05rem; margin: .5em 0 .25em; }
.editor p { margin: 0 0 .5em; }
.editor ul, .editor ol { margin: .2em 0 .6em; padding-left: 1.6em; }
.editor blockquote, .notes-view blockquote { margin: .5em 0; padding: 6px 12px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; }
.ts { display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: .85em; cursor: pointer; user-select: none; }
@media (prefers-color-scheme: dark) { .editor span[style*="background"], .notes-view span[style*="background"] { color: #111; } }

/* celular: barra do topo compacta */
@media (max-width: 600px) {
  .topbar { padding: 8px 12px; gap: 6px; }
  .brand small, .brand strong + small { display: none; }
  .brand strong { white-space: nowrap; font-size: .95rem; }
  .topnav { gap: 0; }
  .topnav a, .topnav .btn { padding: 6px 7px; font-size: .9rem; }
  #btnSettings { font-size: 0; } #btnSettings::before { content: "⚙"; font-size: 1.1rem; }
}

/* tela estreita: vídeo, depois anotações, depois o resto; o vídeo fica preso no topo */
@media (max-width: 960px) {
  .lesson-layout, .lesson-layout.no-notes, body.theater .lesson-layout { display: flex; flex-direction: column; gap: 14px; }
  .lesson-main { display: contents; }
  .lesson-main > .video-wrap { position: sticky; top: 56px; z-index: 6; }
  .notes-pane { order: 2; width: 100%; height: 60vh; }
  .lesson-main > .tabs, .lesson-main > #tabBody { order: 3; width: 100%; min-width: 0; }
  .lesson-layout > .side { order: 4; width: 100%; }
  .lesson-main > .crumbs, .lesson-main > .lesson-title, .lesson-main > .row { margin: 0; }
}
@media (max-width: 960px) { .lesson-layout:not(.no-notes) > .side { grid-template-columns: 1fr; } }

/* tradução do texto selecionado */
.tr-btn { position: absolute; z-index: 50; display: flex; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); box-shadow: 0 4px 14px rgba(0,0,0,.18); overflow: hidden; }
.tr-btn button { padding: 6px 11px; border: 0; background: none; color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.tr-btn button + button { border-left: 1px solid var(--border); }
.tr-btn button:hover { background: var(--surface-2); }
.tr-btn button[hidden] { display: none; }
mark.hl { background: #fff176; color: #111; border-radius: 2px; padding: 0 1px; cursor: pointer; }
.tr-box { position: absolute; z-index: 50; width: min(420px, calc(100vw - 16px)); max-height: 60vh; overflow: auto; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.tr-src { color: var(--muted); font-size: .8rem; margin-bottom: 6px; }
.tr-out { font-size: .98rem; line-height: 1.5; }
.tr-actions { display: flex; gap: 6px; margin-top: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* usuários */
body.logged-out .topnav { display: none; }
.login-wrap { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.login-card { width: min(400px, 100%); padding: 24px; }
.login-logo { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.login-tabs { margin: 12px 0 16px; }
#loginForm label { display: block; margin-bottom: 12px; font-weight: 600; font-size: .9rem; }
#loginForm input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; }
.login-err { color: var(--bad); min-height: 1.2em; margin: 0 0 10px; font-size: .9rem; }
#userBox { display: inline-flex; align-items: center; gap: 2px; margin-left: 4px; padding-left: 8px; border-left: 1px solid var(--border); }
#userBox[hidden] { display: none; }
.user-name { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.pw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pw-grid input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
.pw-banner { max-width: 1232px; margin: 14px auto 0; padding: 10px 16px; border-radius: 10px; background: #fff7cc; color: #5c4a00; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.users-card { padding: 0; overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.users th, table.users td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.users th { font-size: .8rem; color: var(--muted); font-weight: 600; }
table.users .actions { white-space: nowrap; text-align: right; }
.btn.danger { color: var(--bad); }
@media (max-width: 600px) { .pw-grid { grid-template-columns: 1fr; } .user-name { display: none; } .pw-banner { margin: 10px 12px 0; } }
.tr-btn[hidden], .tr-box[hidden], #loginForm label[hidden] { display: none; }
@media (max-width: 480px) { .brand > span:last-child { display: none; } #userBox { padding-left: 4px; margin-left: 0; } }
.new-user { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.new-user input { padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; }
@media (max-width: 600px) { .new-user { grid-template-columns: 1fr; } }
