:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --line: #e3e6ee;
  --text: #161a26;
  --muted: #646b7d;
  --primary: #1e3a8a;
  --primary-ink: #ffffff;
  --ok: #047857;   --ok-bg: #e7f6ef;
  --warn: #b45309; --warn-bg: #fdf3e2;
  --bad: #b91c1c;  --bad-bg: #fdecec;
  --info: #1d4ed8; --info-bg: #e8effd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f121a;
    --surface: #171b26;
    --surface-2: #1f2432;
    --line: #2a3040;
    --text: #e8eaf0;
    --muted: #9aa2b5;
    --primary: #8fb0ff;
    --primary-ink: #0f121a;
    --ok: #4ade80;   --ok-bg: rgba(74, 222, 128, .12);
    --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .12);
    --bad: #f87171;  --bad-bg: rgba(248, 113, 113, .13);
    --info: #93b4ff; --info-bg: rgba(147, 180, 255, .13);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

/* ---------- Barra superior ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-in { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); font-weight: 800; }
.nav-top { display: none; gap: 4px; margin-left: 8px; }
.nav-top a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav-top a:hover { background: var(--surface-2); color: var(--text); }
.nav-top a[aria-current] { background: var(--surface-2); color: var(--text); }
.sync { margin-left: auto; min-width: 0; font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.sync-txt { overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 760px) and (max-width: 900px) { .sync-txt { display: none; } }
@media (max-width: 380px) { .brand span:last-child { display: none; } }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.sync-dot.old { background: var(--warn); }

.nav-bottom {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-bottom a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; font-size: .72rem; color: var(--muted); text-decoration: none; }
.nav-bottom svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-bottom a[aria-current] { color: var(--primary); font-weight: 600; }

@media (min-width: 760px) {
  .nav-top { display: flex; }
  .nav-bottom { display: none; }
  body { padding-bottom: 40px; }
}

/* ---------- Encabezado de página ---------- */
.main { padding-top: 20px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: .85rem; font-weight: 500; }
.eyebrow a { text-decoration: none; }
.hero-actions { display: flex; gap: 6px; }
.course-title { border-left: 5px solid var(--c); padding-left: 10px; }
.intro { margin: -6px 0 16px; max-width: 60ch; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); min-width: 40px; }
.btn-ghost:hover { background: var(--surface-2); }
.link { background: none; border: 0; padding: 4px 0; color: var(--primary); font: inherit; font-size: .8rem; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }
.switch-inline { margin: 0 0 12px; }

/* ---------- Resumen ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 24px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 1.7rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat-warn strong { color: var(--warn); }
.stat-bad strong { color: var(--bad); }

.block { margin-bottom: 28px; }
.block > h2, .block summary h2 { margin-bottom: 12px; }
.empty, .empty-inline { color: var(--muted); }
.empty { text-align: center; padding: 60px 0; }

/* ---------- Días y tarjetas ---------- */
.day { margin-bottom: 18px; }
.day-title { display: flex; align-items: center; gap: 10px; font-size: .95rem; font-weight: 600; margin-bottom: 8px; }
.day-num { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.day-rel { margin-left: auto; font-size: .8rem; color: var(--muted); font-weight: 500; }
.day-rel.is-soon { color: var(--bad); font-weight: 700; }

.tasks { display: grid; gap: 8px; }
.task {
  display: flex; gap: 12px; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.task.is-urgent { border-color: var(--bad); border-left-color: var(--c); box-shadow: 0 0 0 1px var(--bad) inset; }
.task-main { min-width: 0; }
.task-course { display: inline-block; font-size: .78rem; font-weight: 700; color: var(--c); text-decoration: none; text-transform: uppercase; letter-spacing: .03em; }
.task-title { font-size: 1rem; font-weight: 600; margin: 2px 0 6px; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag-pts { color: var(--text); font-weight: 600; }
.task-dates { margin: 0; font-size: .85rem; color: var(--muted); }
.task-dates strong { color: var(--text); font-weight: 600; }
.rel { margin-left: 6px; font-weight: 600; color: var(--text); }
.task-note { margin: 6px 0 0; font-size: .85rem; }
.task-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; text-align: right; }
.mark { margin: 0; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--surface-2); color: var(--muted); }

.score { font-variant-numeric: tabular-nums; }
.score strong { font-size: 1.35rem; }
.score span { color: var(--muted); font-size: .85rem; margin-left: 2px; }
.score-ok strong { color: var(--ok); }
.score-warn strong { color: var(--warn); }
.score-bad strong { color: var(--bad); }
.score-muted strong { color: var(--muted); }

@media (max-width: 520px) {
  .task { flex-direction: column; gap: 8px; }
  .task-side { flex-direction: row; align-items: center; justify-content: space-between; text-align: left; }
}

/* Diagnósticos (valen 0): ocultos salvo que se pidan */
body:not(.show-diag) .is-diag { display: none !important; }
.task.is-diag { opacity: .8; }

/* ---------- Novedades ---------- */
.news { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.news li { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.news-course { display: block; font-size: .75rem; font-weight: 700; color: var(--c); text-transform: uppercase; }
.news time { margin-left: 6px; font-size: .8rem; }

details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
details > summary h2 { margin: 0 !important; }
.lost > summary { margin-bottom: 10px; }

/* ---------- Calendario ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 12px; font-size: .8rem; }
.legend a { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.legend a::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-bottom: 20px; }
.cal-head { text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal-cell {
  min-height: 64px; padding: 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: stretch; gap: 3px; text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.cal-cell.is-out { background: transparent; border-color: transparent; cursor: default; }
.cal-cell.is-past { background: var(--surface-2); }
.cal-cell.is-past .chip { opacity: .65; }
.cal-cell.is-today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.cal-cell.is-selected { outline: 3px solid var(--primary); outline-offset: -1px; }
.cal-day { font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-cell.is-today .cal-day { color: var(--primary); }
.chip { display: block; border-radius: 5px; background: var(--c); color: #fff; font-size: .68rem; font-weight: 600; padding: 1px 5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip.estado-calificada, .chip.estado-cerrada { background: color-mix(in srgb, var(--c) 25%, var(--surface)); color: var(--text); }
.chip.estado-vencida, .chip.estado-cero { background: var(--bad-bg); color: var(--bad); box-shadow: inset 3px 0 0 var(--c); }
.chip.is-diag { background: transparent; color: var(--muted); border: 1px dashed var(--c); }
@media (max-width: 640px) {
  .cal-cell { min-height: 52px; padding: 3px; flex-direction: row; flex-wrap: wrap; align-content: flex-start; gap: 2px; }
  .cal-day { width: 100%; }
  .chip { width: 8px; height: 8px; padding: 0; border-radius: 50%; }
  .chip.is-diag { border-width: 1px; }
  .chip-txt { display: none; }
}

/* ---------- Calificaciones ---------- */
.grades { display: grid; gap: 12px; }
@media (min-width: 760px) { .grades { grid-template-columns: 1fr 1fr; } }
.grade-card { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.grade-card header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.grade-card h2 a { color: var(--text); text-decoration: none; }
.grade-card h2 a:hover { text-decoration: underline; }
.grade-card p { margin: 2px 0 0; }
.grade-pct { text-align: right; flex-shrink: 0; }
.grade-pct strong { display: block; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.grade-pct span { font-size: .8rem; color: var(--muted); }
.nivel-ok .grade-pct strong, .grade-pct.nivel-ok strong { color: var(--ok); }
.nivel-warn .grade-pct strong, .grade-pct.nivel-warn strong { color: var(--warn); }
.nivel-bad .grade-pct strong, .grade-pct.nivel-bad strong { color: var(--bad); }
.bar { display: flex; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 12px 0 4px; }
.bar-got { background: var(--ok); }
.bar-lost { background: var(--bad); opacity: .75; }
.bar-legend { margin: 0 0 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.k { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-left: 6px; }
.k:first-child { margin-left: 0; }
.k-got { background: var(--ok); } .k-lost { background: var(--bad); opacity: .75; } .k-rest { background: var(--surface-2); border: 1px solid var(--line); }
.mini { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.mini li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .85rem; }
.mini li:last-child { border-bottom: 0; }
.mini-name { min-width: 0; overflow-wrap: anywhere; color: var(--text); text-decoration: none; }
.mini-name:hover { color: var(--primary); text-decoration: underline; }
.mini-val { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.due { display: inline-flex; flex-direction: column; align-items: flex-end; font-weight: 600; line-height: 1.2; text-align: right; }
.due small { font-weight: 500; font-size: .75rem; color: var(--muted); }
.due.is-soon, .due.is-soon small { color: var(--bad); }

/* ---------- Actualizar ---------- */
.steps ol { padding-left: 20px; display: grid; gap: 14px; }
.steps li p { margin: 8px 0; }
.bookmarklet { cursor: grab; }
.import-form { display: grid; gap: 10px; max-width: 560px; }
.import-form label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.import-form textarea { font: 12px/1.4 ui-monospace, monospace; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.import-form .btn { justify-self: start; }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: .9rem; }
.history li { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* ---------- Pantalla de sincronización ---------- */
.recibir-box { max-width: 420px; margin: 12vh auto 0; padding: 32px 24px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.recibir-box h1 { font-size: 1.3rem; margin: 12px 0 6px; }
.recibir-box p { margin: 0 0 20px; }
.recibir-icon { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto; border-radius: 50%; font-size: 1.6rem; font-weight: 800; }
.is-ok .recibir-icon { background: var(--ok-bg); color: var(--ok); }
.is-error .recibir-icon { background: var(--bad-bg); color: var(--bad); }

/* ---------- Tarjeta clicable ---------- */
.task { position: relative; }
.task-title a { color: inherit; text-decoration: none; }
.task-title a.stretched::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.task:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }
.task-course, .task-side form, .task-side a { position: relative; z-index: 1; }
.tag-done { background: var(--ok-bg); color: var(--ok); }

/* ---------- Detalle de actividad ---------- */
.back { margin-bottom: 8px; }
.act-head { border-left: 5px solid var(--c); padding-left: 12px; margin-bottom: 16px; }
.act-head h1 { margin: 2px 0 8px; font-size: 1.45rem; overflow-wrap: anywhere; }
.act-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 24px; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; }
.fact span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.fact strong { font-size: .95rem; }
.fact em { font-style: normal; font-size: .8rem; color: var(--muted); }
.fact-bad { border-color: var(--bad); }
.fact-bad em { color: var(--bad); font-weight: 700; }
.sub { font-size: .95rem; margin: 18px 0 6px; }
.prose { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; overflow-wrap: anywhere; overflow-x: auto; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose img { max-width: 100%; height: auto; }
.prose table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.prose td, .prose th { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.prose pre { white-space: pre-wrap; font: inherit; margin: 0; }
.retro { margin: 0 0 8px; background: var(--info-bg); border-left: 4px solid var(--info); border-radius: 10px; padding: 10px 14px; }
.retro p { margin: 0 0 4px; }
.files { margin: 0; padding-left: 20px; }
.rubric { display: grid; gap: 6px; }
.rubric-row { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.rubric-row summary { justify-content: space-between; font-weight: 600; font-size: .9rem; }
.rubric-row summary span:first-of-type { flex: 1; }
.rubric-row ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; font-size: .85rem; }
.rubric-row li { display: grid; gap: 2px; padding-left: 10px; border-left: 3px solid var(--line); }
.rubric-row li:first-child { border-left-color: var(--ok); }
.rubric-row li.is-sel { border-left-color: var(--primary); background: var(--info-bg); border-radius: 0 6px 6px 0; padding: 6px 8px 6px 10px; }
.rubric-row.is-lost { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.rubric-row.is-lost .tag-pts { background: var(--bad-bg); color: var(--bad); }
/* ---------- Cuenta / login ---------- */
.avatar { display: grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font-weight: 700; text-decoration: none; }
.avatar[aria-current] { border-color: var(--primary); color: var(--primary); }
.login-box { text-align: left; }
.login-box h1, .login-box > p { text-align: center; }
.brand-mark.big { width: 52px; height: 52px; margin: 0 auto; font-size: 1.5rem; border-radius: 14px; }
.login-form { display: grid; gap: 12px; }
.login-form.narrow { max-width: 360px; }
.login-form label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 500; }
.login-form input { min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 1rem; }
.login-form .btn { margin-top: 4px; }
.form-error, .form-ok { padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.form-error { background: var(--bad-bg); color: var(--bad); }
.form-ok { background: var(--ok-bg); color: var(--ok); }

.ics-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.ics-box ul { padding-left: 18px; display: grid; gap: 8px; }
.copy-url { display: block; margin: 4px 0; padding: 6px 8px; border-radius: 6px; background: var(--surface-2); font-size: .78rem; overflow-wrap: anywhere; }
.more { margin-top: 10px; }
.more .sub { margin: 0; }
.more .prose { margin-top: 8px; }

.checklist { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.checklist form { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 0; }
.check { width: 26px; height: 26px; flex-shrink: 0; border-radius: 7px; border: 2px solid var(--line); background: var(--surface); color: #fff; font-weight: 800; cursor: pointer; display: grid; place-items: center; }
.is-done .check { background: var(--ok); border-color: var(--ok); }
.is-done .check-txt { text-decoration: line-through; color: var(--muted); }
.check-txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.del { color: var(--muted); text-decoration: none; font-size: .9rem; padding: 4px 6px; }
.add-step { display: flex; gap: 8px; margin: 0; }
.from-rubric { margin-top: 10px; }
.add-step input[type=text] { flex: 1; min-width: 0; min-height: 40px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; }

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