/* Aula Offline — pizarra de estudio.
   Tinta azul sobre papel frío, un solo acento y una regla de tiempo como motivo. */

:root {
  --paper: #e8edf1;
  --surface: #ffffff;
  --soft: #f1f4f7;
  --ink: #0d1b26;
  --muted: #52667a;
  --line: #d0d9e1;
  --accent: #1f4fff;
  --accent-ink: #ffffff;
  --accent-soft: #e2e9ff;
  --mark: #ffd23f;
  --ok: #0e7c59;
  --ok-soft: #ddf3ea;
  --bad: #b8372b;
  --bad-soft: #fbe4e1;
  --hero: #0d1b26;
  --hero-ink: #eef3f7;
  --hero-muted: #9db0c1;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(13, 27, 38, .06), 0 10px 28px -16px rgba(13, 27, 38, .25);
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --side: 256px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0a131b;
    --surface: #111d28;
    --soft: #0e1822;
    --ink: #e8eef3;
    --muted: #8ea2b4;
    --line: #223342;
    --accent: #6f8fff;
    --accent-ink: #0a1220;
    --accent-soft: #16264d;
    --ok: #4cc79b;
    --ok-soft: #0f2c24;
    --bad: #ff8d80;
    --bad-soft: #35161a;
    --hero: #060d13;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -16px rgba(0, 0, 0, .7);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0; min-height: 100dvh; background: var(--paper); color: var(--ink);
  font: 400 1rem/1.55 var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
h1 { font-size: clamp(1.7rem, 1.25rem + 1.8vw, 2.3rem); line-height: 1.08; letter-spacing: -.025em; font-weight: 700; }
h2 { font-size: 1.15rem; line-height: 1.25; letter-spacing: -.01em; font-weight: 650; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.i {
  width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { border-color: var(--line); background: var(--surface); }
.btn-ghost:hover { background: var(--soft); border-color: var(--muted); }
.btn-danger { background: var(--bad); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-danger { color: #1d0907; } }
.btn-icon { width: 42px; padding: 0; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn-sm.btn-icon { width: 36px; padding: 0; }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: 1rem; }
.btn-block { width: 100%; }

/* ---------- Formularios ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; align-content: start; }
label { font-weight: 600; font-size: .92rem; }
.opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=search], input[type=number], textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.45; }
input:hover, textarea:hover, select:hover { border-color: var(--muted); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
::placeholder { color: var(--muted); opacity: .75; }
.hint { font-size: .85rem; color: var(--muted); }
.field-error { font-size: .9rem; color: var(--bad); font-weight: 600; }
.input-wrap { position: relative; display: flex; }
.input-wrap input { padding-right: 52px; }
.input-wrap .btn { position: absolute; right: 2px; top: 2px; width: 40px; min-height: 40px; border: 0; background: transparent; }
.input-suffix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.input-suffix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-suffix input { border: 0; box-shadow: none !important; background: transparent; }
.input-suffix span { padding-right: 12px; color: var(--muted); font-weight: 600; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: .93rem; font-weight: 500; margin-bottom: 16px; }
.alert .i { margin-top: 2px; }
.alert-error { background: var(--bad-soft); color: var(--bad); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- Marca ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; font-size: 1.1rem; text-decoration: none; }
.brand .i { width: 26px; height: 26px; color: var(--accent); }

/* ---------- Acceso ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero {
  background: var(--hero); color: var(--hero-ink); padding: 40px 48px; display: flex; flex-direction: column; gap: 40px;
  justify-content: space-between; overflow: hidden;
}
.brand-light .i { color: var(--mark); }
.auth-copy { max-width: 30rem; }
.auth-copy h1 { font-size: clamp(2.2rem, 1.4rem + 3vw, 3.8rem); line-height: 1.02; letter-spacing: -.035em; font-weight: 750; font-stretch: 85%; }
.auth-copy p { margin-top: 20px; color: var(--hero-muted); font-size: 1.05rem; max-width: 26rem; }
.ruler-art {
  position: relative; height: 56px; margin: 0 -48px; border-top: 1px solid rgba(255,255,255,.18);
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.55) 0 1px, transparent 1px 80px) 0 0 / 100% 22px no-repeat,
    repeating-linear-gradient(90deg, rgba(255,255,255,.28) 0 1px, transparent 1px 16px) 0 0 / 100% 12px no-repeat;
}
.playhead { position: absolute; top: -1px; left: 0; width: 2px; height: 56px; background: var(--mark); animation: sweep 2.6s cubic-bezier(.2, .7, .2, 1) .3s forwards; }
.playhead::before { content: ""; position: absolute; top: 0; left: -5px; width: 12px; height: 10px; background: var(--mark); clip-path: polygon(0 0, 100% 0, 50% 100%); }
@keyframes sweep { to { left: 64%; } }
.auth-panel { display: grid; place-items: center; padding: 32px 24px; }
.auth-card { width: min(100%, 400px); display: grid; gap: 4px; }
.auth-card h2 { font-size: 1.7rem; letter-spacing: -.02em; }
.auth-card > .muted { margin-bottom: 18px; }
.auth-card .btn-block { margin-top: 8px; }

/* ---------- Estructura de la app ---------- */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100dvh; }
.side { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 28px; padding: 24px 16px; border-right: 1px solid var(--line); background: var(--surface); }
.side .brand { padding: 0 8px; }
.nav { display: grid; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--radius);
  text-decoration: none; font-weight: 600; color: var(--muted); position: relative;
}
.nav a:hover { background: var(--soft); color: var(--ink); }
.nav a[aria-current] { color: var(--ink); background: var(--soft); }
.nav a[aria-current]::before { content: ""; position: absolute; left: -16px; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--mark); }
.side-foot { margin-top: auto; display: grid; gap: 14px; }
.meter-label { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.meter-bar { height: 6px; margin-top: 8px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.meter-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width .4s; }
.meter-bar.warn span { background: var(--bad); }
.logout-form { display: contents; }
.topbar { display: none; }
.nav-tabs { display: none; }

.main { padding: 40px clamp(20px, 4vw, 56px) 64px; max-width: 1040px; width: 100%; }
.page-head { margin-bottom: 28px; }
.page-head .sub { margin-top: 6px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow); }
.card > h2 { margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-actions { display: flex; gap: 12px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }

/* Guía */
.guide { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); }
.guide summary { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; list-style: none; border-radius: 6px; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary .chev { margin-left: auto; transition: transform .2s; }
.guide[open] summary .chev { transform: rotate(180deg); }
.guide ol { counter-reset: step; display: grid; gap: 12px; margin-top: 14px; }
.guide li { counter-increment: step; position: relative; padding-left: 36px; max-width: 68ch; color: var(--muted); }
.guide li::before {
  content: counter(step); position: absolute; left: 0; top: 1px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: .8rem; font-weight: 700; background: var(--accent-soft); color: var(--accent);
}
.guide strong { color: var(--ink); font-weight: 650; }
kbd { padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--soft); font: 600 .8rem var(--font); }

/* ---------- Cola de descargas ---------- */
.queue-sec { margin-top: 32px; }
.queue { display: grid; gap: 10px; }
.q-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px 16px; }
.q-head { display: flex; align-items: center; gap: 12px; }
.q-name { font-weight: 600; min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-state { font-size: .85rem; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.q-item.is-done .q-state { color: var(--ok); }
.q-item.is-error .q-state { color: var(--bad); }
.ruler {
  position: relative; height: 14px; margin: 12px 0 8px; border-radius: 4px; background: var(--soft); overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line);
}
.ruler-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); transition: width .5s ease; }
.is-done .ruler-fill { background: var(--ok); }
.is-error .ruler-fill { background: var(--bad); }
.ruler::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.65) 0 1px, transparent 1px 40px) 0 0 / 100% 100% no-repeat,
    repeating-linear-gradient(90deg, rgba(255,255,255,.4) 0 1px, transparent 1px 8px) 0 100% / 100% 45% no-repeat;
  mix-blend-mode: soft-light;
}
.is-busy .ruler-fill { background-image: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); background-size: 120px 100%; background-repeat: no-repeat; background-color: var(--accent); animation: scan 1.4s linear infinite; }
@keyframes scan { from { background-position: -120px 0; } to { background-position: calc(100% + 120px) 0; } }
.q-meta { font-size: .85rem; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.q-error { color: var(--bad); font-weight: 500; }

/* ---------- Biblioteca ---------- */
.lib { margin-top: 40px; }
.lib-tools { display: flex; gap: 10px; flex-wrap: wrap; }
.search { position: relative; }
.search .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 40px; min-width: 220px; }
.lib-tools select { width: auto; min-width: 170px; }
.course-group { margin-top: 22px; }
.course-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; font-size: 1rem; }
.course-title span { font-size: .85rem; font-weight: 500; color: var(--muted); }
.files { display: grid; gap: 8px; }
.file {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); transition: border-color .15s;
}
.file:hover { border-color: var(--muted); }
.file-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.file-ico.k-audio { background: var(--ok-soft); color: var(--ok); }
.file-ico.k-doc { background: var(--soft); color: var(--muted); }
.file-name { font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.file-meta { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.file-actions { display: flex; gap: 6px; align-items: center; }
.empty { text-align: center; padding: 44px 20px; border: 1px dashed var(--line); border-radius: var(--radius-lg); color: var(--muted); }
.empty .i { width: 32px; height: 32px; margin-bottom: 10px; color: var(--accent); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- Diálogos ---------- */
.dlg { width: min(92vw, 440px); padding: 22px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px -20px rgba(0,0,0,.5); }
.dlg::backdrop { background: rgba(6, 13, 19, .6); backdrop-filter: blur(2px); }
.dlg[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dlg-head h2 { overflow-wrap: anywhere; }
.dlg-text { color: var(--muted); margin-bottom: 20px; overflow-wrap: anywhere; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.dlg-player { width: min(96vw, 960px); padding: 16px; max-width: none; }
.dlg-player video { width: 100%; max-height: 72dvh; background: #000; border-radius: var(--radius); display: block; }
.player-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.speeds { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.speeds button { min-height: 36px; padding: 0 12px; border: 0; border-right: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: .85rem; cursor: pointer; }
.speeds button:last-child { border-right: 0; }
.speeds button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); }

/* ---------- Avisos ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; max-width: min(92vw, 380px); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: var(--ink); color: var(--paper); font-size: .92rem; font-weight: 500; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.out { opacity: 0; transition: opacity .25s; }
.toast-error { background: var(--bad); color: #fff; }
@media (prefers-color-scheme: dark) { .toast-error { color: #1d0907; } }
.toast-ok .i { color: var(--mark); }

/* ---------- Ajustes ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; }
.checks { display: grid; gap: 12px; }
.checks li { display: flex; gap: 10px; }
.checks .i { margin-top: 2px; }
.checks .is-ok .i { color: var(--ok); }
.checks .is-bad .i { color: var(--bad); }

/* ---------- Móvil ---------- */
@media (max-width: 880px) {
  .auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .auth-hero { padding: 24px 20px 0; gap: 20px; }
  .auth-copy h1 { font-size: 2rem; }
  .auth-copy p { margin-top: 10px; font-size: .98rem; }
  .ruler-art { margin: 0 -20px; height: 40px; }
  .playhead { height: 40px; }

  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px 8px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .nav-tabs {
    position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .nav-tabs a { flex-direction: column; justify-content: center; gap: 2px; min-height: 60px; border-radius: 0; font-size: .75rem; }
  .nav-tabs a[aria-current] { background: transparent; color: var(--accent); }
  .nav-tabs a[aria-current]::before { left: 25%; right: 25%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 4px 4px; background: var(--accent); }
  .main { padding: 24px 16px 96px; }
  .page-head { margin-bottom: 20px; }
  .card { padding: 18px; }
  .grid2, .settings-grid { grid-template-columns: 1fr; }
  .form-actions .btn { width: 100%; }
  .search input, .lib-tools select { min-width: 0; }
  .lib-tools { width: 100%; }
  .lib-tools .search { flex: 1 1 100%; }
  .lib-tools select { flex: 1 1 100%; width: 100%; }
  .file { grid-template-columns: auto minmax(0, 1fr); }
  .file-actions { grid-column: 1 / -1; justify-content: flex-end; border-top: 1px dashed var(--line); padding-top: 10px; }
  .toasts { left: 16px; right: 16px; bottom: 76px; max-width: none; }
  .dlg-player { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .playhead { left: 64%; }
}
