:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f4;
  --ink: #12222b;
  --muted: #5b6f7a;
  --line: #d8e1e5;
  --brand: #0f766e;
  --brand-ink: #0b5a54;
  --brand-soft: #d9f2ee;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn: #a16207;
  --warn-soft: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 34, 43, 0.06), 0 4px 14px rgba(16, 34, 43, 0.05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d161c;
    --surface: #15222b;
    --surface-2: #1c2c37;
    --ink: #e6eef2;
    --muted: #94a8b4;
    --line: #2a3d49;
    --brand: #2dd4bf;
    --brand-ink: #5eead4;
    --brand-soft: #123c3a;
    --ok: #4ade80;
    --ok-soft: #12351f;
    --bad: #f87171;
    --bad-soft: #3d1717;
    --warn: #fbbf24;
    --warn-soft: #3a2c0a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; text-wrap: balance; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 0.9em; }
a { color: var(--brand-ink); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
[hidden] { display: none !important; }

/* ---------- estructura */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--brand); text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand span { color: var(--ink); }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav a, .nav button { padding: 7px 11px; border-radius: 8px; color: var(--ink); text-decoration: none; font: inherit; font-size: 0.925rem; background: none; border: 0; cursor: pointer; }
.nav a:hover, .nav button:hover { background: var(--surface-2); }
.nav .who { color: var(--muted); font-size: 0.875rem; padding: 0 8px; }
.main { max-width: 1120px; margin: 0 auto; padding: 28px 20px 72px; }
.main.wide { max-width: 1360px; }

.crumbs { font-size: 0.875rem; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
a.card { display: block; color: inherit; text-decoration: none; transition: border-color 0.15s, transform 0.15s; }
a.card:hover { border-color: var(--brand); transform: translateY(-1px); }
.card h3 { margin-bottom: 4px; }
.card .meta { color: var(--muted); font-size: 0.875rem; }
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }
section + section { margin-top: 34px; }

/* ---------- controles */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.925rem; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn-danger { color: var(--bad); }
.btn-small { min-height: 30px; padding: 3px 9px; font-size: 0.85rem; }
.btn-icon { min-width: 38px; padding: 0; font-size: 1.1rem; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06201d; } }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

label.field { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 12px; }
label.field > span { display: block; margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.95rem;
}
textarea { resize: vertical; min-height: 84px; }
input:disabled, textarea:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; letter-spacing: 0.12em; font-weight: 700; }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: inherit; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 10px;
  background: #12222b; color: #fff; font-size: 0.925rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #991b1b; }

/* ---------- acceso */
.auth { max-width: 420px; margin: 5vh auto 0; }
.auth h1 { margin-bottom: 4px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; margin: 18px 0; }
.tabs button { flex: 1; padding: 7px; border: 0; border-radius: 7px; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- lección */
.player { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 28px; align-items: start; }
.pages { position: sticky; top: 76px; list-style: none; margin: 0; padding: 0; counter-reset: page; }
.pages button {
  display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--ink);
  font: inherit; font-size: 0.925rem; cursor: pointer;
}
.pages button::before { counter-increment: page; content: counter(page); color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.pages button:hover { background: var(--surface-2); }
.pages button[aria-current="page"] { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.pages .done::after { content: "✓"; margin-left: auto; color: var(--ok); }
.lesson-body { min-width: 0; }
.lesson-body > * + * { margin-top: 20px; }
.lesson-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }

.prose { max-width: 74ch; }
.prose h3 { font-size: 1.3rem; margin-top: 0.2em; }
.prose h4 { margin-top: 1.3em; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 0.9em; }
.prose li + li { margin-top: 0.3em; }
.prose code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }
.prose blockquote { margin: 1em 0; padding: 10px 14px; border-left: 3px solid var(--brand); background: var(--brand-soft); border-radius: 0 8px 8px 0; }
.prose blockquote p { margin: 0; }
figure { margin: 0; }
figure img, figure video, figure iframe { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line); }
figure iframe { width: 100%; aspect-ratio: 16 / 9; }
figcaption { color: var(--muted); font-size: 0.875rem; margin-top: 6px; }

.question { border-left: 3px solid var(--brand); }
.question .q-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 10px; }
.question .q-prompt { font-weight: 600; white-space: pre-wrap; }
.question .points { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.options { display: grid; gap: 6px; margin-bottom: 12px; }
.options label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.options label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.options label.right { border-color: var(--ok); }
.options input { margin-top: 5px; accent-color: var(--brand); }
.numeric { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.numeric input { max-width: 160px; }
.q-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.saved { color: var(--muted); font-size: 0.85rem; }
.feedback { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 0.925rem; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback.note { background: var(--surface-2); color: var(--ink); }
.feedback p { margin: 4px 0 0; color: var(--ink); }

.table-wrap { overflow-x: auto; margin-bottom: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 0.925rem; }
table.data th, table.data td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.data thead th { background: var(--surface-2); font-weight: 600; }
table.data tbody th { font-weight: 600; white-space: nowrap; background: var(--surface-2); }
table.data td input { border: 0; padding: 4px; border-radius: 4px; min-width: 90px; background: transparent; }
table.data td:has(input) { padding: 2px; }
.just-filled { animation: filled 0.7s; }
@keyframes filled { from { background: var(--brand-soft); } }

/* ---------- visor de registros */
.lab { padding: 0; overflow: hidden; }
.lab-head { padding: 14px 18px 10px; }
.lab-head h4 { margin: 0 0 2px; }
.lab-head p { margin: 0; }
.scope { background: #111d28; color: #dbe6ee; padding: 14px; }
.scope-controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end; margin-bottom: 12px; }
.scope .ctl { display: grid; gap: 3px; font-size: 0.8rem; color: #a9bccb; min-width: 150px; }
.scope .ctl output { color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
.scope .ctl-check { display: flex; align-items: center; gap: 7px; min-width: 0; padding-bottom: 6px; }
.scope select, .scope input[type="text"] { background: #1b2b39; border-color: #33495b; color: #fff; padding: 6px 8px; font-size: 0.875rem; }
.scope input[type="range"] { width: 100%; accent-color: #5eead4; }
.scope .btn { background: #1b2b39; border-color: #33495b; color: #fff; min-height: 34px; }
.scope .btn:hover { border-color: #6b8599; }
.scope .btn-primary { background: #0d9488; border-color: #0d9488; min-width: 104px; }
.scope .btn-primary.is-recording { background: #dc2626; border-color: #dc2626; color: #fff; }
.scope-canvas { display: block; width: 100%; height: 400px; border-radius: 8px; cursor: crosshair; touch-action: manipulation; }
.scope-canvas.scope-tall { height: 560px; }
.pages button small { display: block; color: var(--muted); font-weight: 400; font-size: 0.75rem; }
.scope-scroll { display: block; margin: 8px 0 0; }
.scope-scroll:disabled { opacity: 0.25; }
.scope-tools { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 10px; }
.scope-zoom { display: inline-flex; gap: 4px; }
.scope-auto { font-size: 0.85rem; color: #a9bccb; display: inline-flex; align-items: center; gap: 4px; }
.scope-commentbox { display: inline-flex; gap: 6px; margin-left: auto; }
.scope-comment { width: 150px !important; }
.scope-readout { margin-top: 12px; overflow-x: auto; }
.scope-readout table { border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.scope-readout th, .scope-readout td { padding: 3px 14px 3px 0; text-align: left; font-weight: 500; color: #a9bccb; white-space: nowrap; }
.scope-readout .cur-a { color: #fb923c; }
.scope-readout .cur-b { color: #60a5fa; }
.scope-readout .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.scope .val { background: #1b2b39; border: 1px solid #33495b; color: #fff; border-radius: 6px; padding: 2px 8px; font: inherit; font-variant-numeric: tabular-nums; cursor: pointer; }
.scope .val:hover { border-color: #5eead4; }
.scope .val-empty { color: #5d7386; }
.scope-hint { margin: 8px 0 0; font-size: 0.82rem; color: #8fa3b5; }

/* ---------- docente */
.gradebook { overflow-x: auto; }
.gradebook table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.gradebook th, .gradebook td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.gradebook thead th { font-weight: 600; color: var(--muted); font-size: 0.8rem; vertical-align: bottom; white-space: normal; min-width: 110px; }
.gradebook td.num { font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 180px; }
.list .grow strong { display: block; }

.grading { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; align-items: start; }
.students { list-style: none; margin: 0; padding: 0; position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow-y: auto; }
.students button { display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-size: 0.925rem; cursor: pointer; }
.students button:hover { background: var(--surface-2); }
.students button[aria-current="true"] { background: var(--brand-soft); }
.students small { display: block; color: var(--muted); }
.grade-row { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.grade-row input[type="number"] { width: 90px; }
.grade-row textarea { flex: 1; min-width: 200px; min-height: 40px; }

.editor-page { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 18px; }
.editor-page > header { display: flex; gap: 8px; align-items: center; padding: 10px 14px; background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.editor-page > header input { font-weight: 600; }
.editor-blocks { padding: 14px; }
.editor-block { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.editor-block > header { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.editor-block .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.add-block { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; justify-content: flex-end; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }

/* ---------- informe */
.report-head { border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 22px; }
.report h2 { margin-top: 30px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }

@media (max-width: 860px) {
  .player, .grading { grid-template-columns: 1fr; gap: 16px; }
  .pages { position: static; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
  .pages button { white-space: nowrap; }
  .students { position: static; max-height: 240px; }
  .scope-canvas { height: 320px; }
  .scope-canvas.scope-tall { height: 460px; }
  .scope-commentbox { margin-left: 0; }
  .main { padding: 20px 16px 56px; }
}

@media print {
  .topbar, .no-print, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .main { max-width: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- revisión de guías */
.reviewed { margin: 28px 0 0; font-size: 0.78rem; color: var(--muted); text-align: right; }
.review-panel { margin-bottom: 18px; }
.review-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.review-list li { border-left: 3px solid var(--warn); padding: 4px 0 4px 12px; }
.review-list li.done { border-left-color: var(--ok); opacity: 0.75; }
.review-list p { margin: 4px 0 6px; }
.review-quote { all: unset; cursor: pointer; font-style: italic; color: var(--muted); display: block; }
.review-quote:hover, .review-quote:focus-visible { text-decoration: underline; }
.review-hit { background: var(--warn-soft); box-shadow: 0 0 0 4px var(--warn-soft); border-radius: 3px; }
.review-bubble { position: absolute; z-index: 30; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22); }
.review-dialog { border: 1px solid var(--line, #d5dde3); border-radius: 12px; padding: 20px; width: min(520px, calc(100vw - 32px)); background: var(--surface, #fff); color: inherit; }
.review-dialog::backdrop { background: rgba(15, 23, 32, 0.45); }
.review-dialog blockquote { margin: 0; font-style: italic; color: var(--muted); max-height: 7.5em; overflow: auto; }
.review-dialog textarea { width: 100%; }
