:root {
  --bg: #0e1120;
  --panel: #151a2e;
  --panel-2: #1b2139;
  --panel-3: #232a47;
  --line: #2a3150;
  --line-2: #363f63;
  --text: #e8eaf3;
  --text-2: #b4b9d0;
  --muted: #8189a8;
  --accent: #ffd23f;
  --accent-ink: #1a1400;
  --ok: #3ecf8e;
  --ok-bg: rgba(62, 207, 142, 0.12);
  --bad: #ff7a7a;
  --bad-bg: rgba(255, 122, 122, 0.1);
  --info: #7aa7ff;
  --info-bg: rgba(122, 167, 255, 0.1);
  --warn-bg: rgba(255, 210, 63, 0.09);
  --code-bg: #0b0e1b;
  --term-bg: #0a0c16;
  --radius: 10px;
  --side-w: 290px;
  --learn-w: 46%;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--info); }
button { font: inherit; color: inherit; }
input { font: inherit; }

/* Botones ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ffdc66; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { border: 0; background: transparent; color: var(--text-2); padding: 6px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Marca -------------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand-mark {
  font-family: var(--mono); font-weight: 700; font-size: 13px; color: var(--accent);
  background: #14182b; border: 1px solid var(--line-2); border-radius: 7px; padding: 3px 6px;
}
.brand-lg { font-size: 22px; justify-content: center; }
.brand-lg .brand-mark { font-size: 16px; padding: 4px 8px; }

/* Acceso ------------------------------------------------------------------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #1d2447 0, transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px; display: grid; gap: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-sub { color: var(--text-2); text-align: center; margin: 0 0 4px; font-size: 14px; }
.login label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.login input { background: var(--bg); border: 1px solid var(--line-2); color: var(--text); padding: 10px 12px; border-radius: 8px; }
.login input:focus { border-color: var(--accent); outline: none; }
.login-err { color: var(--bad); margin: 0; min-height: 1.2em; font-size: 14px; text-align: center; }

/* Estructura --------------------------------------------------------------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: 56px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topnav { display: flex; gap: 4px; margin-left: 12px; }
.topnav a { color: var(--text-2); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.topnav a:hover { background: var(--panel-2); color: var(--text); }
.topnav a.on { color: var(--accent-ink); background: var(--accent); }
.top-progress { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.bar { width: 140px; height: 8px; background: var(--panel-3); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), #6fe3b0); border-radius: 99px; transition: width .4s; }
.user { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; }

.body { flex: 1; display: flex; min-height: 0; }
.side {
  width: var(--side-w); flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; transition: margin-left .2s;
}
.side.closed { margin-left: calc(-1 * var(--side-w)); }
.side-search { padding: 12px; border-bottom: 1px solid var(--line); }
.side-search input { width: 100%; background: var(--bg); border: 1px solid var(--line-2); color: var(--text); padding: 8px 10px; border-radius: 8px; font-size: 14px; }
#side-nav { overflow: auto; padding: 8px 8px 24px; }
.sn-session { margin-bottom: 2px; }
.sn-head {
  width: 100%; display: flex; align-items: center; gap: 10px; background: none; border: 0; text-align: left;
  padding: 8px; border-radius: 8px; cursor: pointer; color: var(--text);
}
.sn-head:hover { background: var(--panel-2); }
.sn-num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--panel-3); color: var(--text-2); }
.sn-num.full { background: var(--ok); color: #03281a; }
.sn-title { flex: 1; font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.sn-pct { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sn-lessons { list-style: none; margin: 2px 0 8px 22px; padding: 0 0 0 12px; border-left: 1px solid var(--line); }
.sn-lessons a { display: flex; gap: 8px; align-items: baseline; padding: 5px 8px; border-radius: 6px; color: var(--text-2); text-decoration: none; font-size: 13.5px; line-height: 1.35; }
.sn-lessons a:hover { background: var(--panel-2); color: var(--text); }
.sn-lessons a.on { background: var(--panel-3); color: var(--text); font-weight: 600; }
.sn-lessons .chk { flex: none; width: 14px; color: var(--muted); font-size: 12px; }
.sn-lessons .chk.done { color: var(--ok); }

.main { flex: 1; display: flex; min-width: 0; position: relative; }
.learn { width: var(--learn-w); min-width: 320px; display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
.learn-scroll { flex: 1; overflow: auto; padding: 28px 32px 40px; scroll-behavior: smooth; }
.learn-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.learn-foot .count { color: var(--muted); font-size: 13px; }
.learn-foot:empty { display: none; }
.splitter { width: 6px; flex: none; cursor: col-resize; background: var(--line); transition: background .15s; }
.splitter:hover, .splitter.drag { background: var(--accent); }

.term { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--term-bg); }
.term-bar { height: 42px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 8px 0 14px; border-bottom: 1px solid #1a1f36; background: #0f1222; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.wait { background: var(--accent); }
.term-title { font-family: var(--mono); font-size: 13px; color: var(--text-2); }
.term-cwd { font-family: var(--mono); font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-actions { margin-left: auto; display: flex; gap: 4px; }
.term-wrap { flex: 1; min-height: 0; position: relative; padding: 8px 4px 4px 10px; }
#terminal { height: 100%; }
.term-overlay { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center; background: rgba(10, 12, 22, .85); color: var(--text-2); }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px; width: 300px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.menu-pop button small { color: var(--muted); display: block; font-size: 12px; }
.menu-pop button:hover { background: var(--panel-3); }
.menu-pop .danger { color: var(--bad); }

.mobile-tabs { display: none; }

/* Contenido de la lección --------------------------------------------------- */
.crumb { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.lesson-title { font-size: 28px; line-height: 1.2; margin: 0 0 18px; letter-spacing: -.02em; }
.jump { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 600; color: var(--accent); background: var(--warn-bg); border: 1px solid rgba(255,210,63,.25); padding: 4px 10px; border-radius: 99px; text-decoration: none; margin-bottom: 20px; cursor: pointer; }

.prose { color: var(--text); max-width: 76ch; }
.prose h2 { font-size: 21px; margin: 30px 0 10px; letter-spacing: -.01em; padding-top: 14px; border-top: 1px solid var(--line); }
.prose h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.prose h3 { font-size: 17px; margin: 22px 0 8px; color: var(--text); }
.prose p { margin: 10px 0; color: var(--text-2); }
.prose strong { color: var(--text); }
.prose ul, .prose ol { color: var(--text-2); padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose code { font-family: var(--mono); font-size: .88em; background: var(--panel-3); color: #ffe38a; padding: 1px 6px; border-radius: 5px; }
.prose pre { position: relative; background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; overflow: auto; margin: 14px 0; }
.prose pre code { background: none; color: #d6dcf5; padding: 0; font-size: 13.5px; line-height: 1.65; }
.prose table { border-collapse: collapse; margin: 14px 0; font-size: 14px; width: 100%; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--panel-2); color: var(--text); font-weight: 700; }
.prose td { color: var(--text-2); }
.prose blockquote { margin: 16px 0; padding: 10px 16px; border-left: 3px solid var(--info); background: var(--info-bg); border-radius: 0 8px 8px 0; }
.prose blockquote.ojo { border-left-color: var(--accent); background: var(--warn-bg); }
.prose blockquote p { margin: 4px 0; color: var(--text); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }

.cmdline { display: inline-block; min-width: 100%; position: relative; padding-right: 64px; }
.try {
  position: absolute; right: -6px; top: 0; font: 600 11px var(--sans); color: var(--accent);
  background: rgba(255, 210, 63, .1); border: 1px solid rgba(255, 210, 63, .3); border-radius: 6px;
  padding: 0 7px; line-height: 20px; cursor: pointer; opacity: 0; transition: opacity .15s;
}
.cmdline:hover .try, .try:focus { opacity: 1; }
@media (hover: none) { .try { opacity: .8; } }

/* Ejercicios --------------------------------------------------------------- */
.ex-head { display: flex; align-items: center; gap: 12px; margin: 34px 0 14px; padding-top: 22px; border-top: 2px solid var(--line); }
.ex-head h2 { margin: 0; font-size: 21px; }
.ex-head .n { color: var(--muted); font-size: 14px; font-weight: 600; }
.ex {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; margin: 10px 0;
  overflow: hidden; transition: border-color .2s, box-shadow .2s;
}
.ex.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 210, 63, .12); }
.ex.done { border-color: rgba(62, 207, 142, .45); }
.ex-top { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: none; border: 0; text-align: left; cursor: pointer; }
.ex-badge { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 800; border: 2px solid var(--line-2); color: var(--text-2); }
.ex.active .ex-badge { border-color: var(--accent); color: var(--accent); }
.ex.done .ex-badge { background: var(--ok); border-color: var(--ok); color: #03281a; }
.ex-title { flex: 1; font-weight: 700; font-size: 15px; }
.ex-kind { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ex-body { padding: 0 16px 16px 52px; }
.ex:not(.open) .ex-body { display: none; }
.ex-prompt p { margin: 6px 0; color: var(--text); }
.ex-prompt code { font-family: var(--mono); font-size: .88em; background: var(--panel-3); color: #ffe38a; padding: 1px 6px; border-radius: 5px; }
.ex-prompt pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow: auto; }
.ex-prompt pre code { background: none; padding: 0; color: #d6dcf5; }
.ex-dir { display: inline-flex; align-items: center; gap: 8px; margin: 10px 0 2px; font-size: 12.5px; color: var(--muted); }
.ex-dir code { font-family: var(--mono); color: var(--text-2); background: var(--panel-3); padding: 2px 7px; border-radius: 5px; }
.ex-dir button { background: none; border: 1px solid var(--line-2); color: var(--text-2); font-size: 12px; border-radius: 6px; padding: 1px 8px; cursor: pointer; }
.ex-dir button:hover { color: var(--accent); border-color: var(--accent); }
.ex-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ex-hints { margin-top: 12px; display: grid; gap: 6px; }
.ex-hint { font-size: 14px; background: var(--info-bg); border: 1px solid rgba(122, 167, 255, .25); color: var(--text); padding: 8px 12px; border-radius: 8px; }
.ex-hint code, .fb code, .quiz-opt code { font-family: var(--mono); font-size: .9em; background: var(--panel-3); padding: 1px 5px; border-radius: 4px; color: #ffe38a; }
.ex-sol { margin-top: 12px; }
.ex-sol pre { margin: 6px 0 0; background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: 13.5px/1.6 var(--mono); color: #d6dcf5; overflow: auto; white-space: pre; }
.ex-sol .lbl { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.fb { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 14px; border: 1px solid; }
.fb.ok { background: var(--ok-bg); border-color: rgba(62, 207, 142, .35); color: #b5f5d8; }
.fb.bad { background: var(--bad-bg); border-color: rgba(255, 122, 122, .35); color: #ffd0d0; }
.fb.soft { background: var(--panel-3); border-color: var(--line-2); color: var(--text-2); }
.fb.wait { background: var(--panel-3); border-color: var(--line-2); color: var(--text-2); }
.fb .cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.fb .cmp div { min-width: 0; }
.fb .cmp .lbl { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 3px; }
.fb .cmp pre { margin: 0; background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; font: 12.5px/1.5 var(--mono); color: var(--text); overflow: auto; max-height: 220px; white-space: pre; }
.fb .cmp pre .diff { background: rgba(255, 122, 122, .22); }

.quiz-opts { display: grid; gap: 8px; margin-top: 12px; }
.quiz-opt { display: flex; gap: 10px; align-items: flex-start; text-align: left; background: var(--panel); border: 1px solid var(--line-2); padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 14.5px; color: var(--text); }
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opt .l { flex: none; width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: var(--panel-3); color: var(--text-2); }
.quiz-opt.right { border-color: var(--ok); background: var(--ok-bg); }
.quiz-opt.right .l { background: var(--ok); color: #03281a; }
.quiz-opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.quiz-opt.wrong .l { background: var(--bad); color: #2b0000; }
.quiz-opt:disabled { cursor: default; }
.explain { margin-top: 10px; font-size: 14px; color: var(--text-2); }
.explain p { margin: 4px 0; }

.lesson-done { margin: 22px 0 0; padding: 16px; border-radius: 12px; background: var(--ok-bg); border: 1px solid rgba(62, 207, 142, .35); display: flex; align-items: center; gap: 14px; }
.lesson-done .big { font-size: 28px; }
.lesson-done p { margin: 0; color: var(--text); }

/* Inicio ------------------------------------------------------------------- */
.home h1 { font-size: 30px; margin: 0 0 4px; letter-spacing: -.02em; }
.home .sub { color: var(--text-2); margin: 0 0 22px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 22px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.cards { display: grid; gap: 10px; }
.scard { display: flex; gap: 14px; align-items: center; text-decoration: none; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); padding: 14px; border-radius: 12px; transition: border-color .15s, transform .15s; }
.scard:hover { border-color: var(--line-2); transform: translateY(-1px); }
.scard .num { flex: none; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; background: var(--panel-3); color: var(--text-2); }
.scard.full .num { background: var(--ok); color: #03281a; }
.scard .info { flex: 1; min-width: 0; }
.scard h3 { margin: 0; font-size: 15.5px; }
.scard p { margin: 2px 0 8px; font-size: 13px; color: var(--muted); line-height: 1.4; }
.scard .bar { width: 100%; height: 6px; }
.scard .pct { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 24px; }

/* Chuleta ------------------------------------------------------------------ */
.cheat-tools { display: flex; gap: 10px; margin: 0 0 16px; position: sticky; top: -28px; background: var(--panel); padding: 8px 0; z-index: 2; }
.cheat-tools input { flex: 1; background: var(--bg); border: 1px solid var(--line-2); color: var(--text); padding: 10px 12px; border-radius: 8px; }
.cheat-group h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cheat { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.cheat .c { font: 700 14px var(--mono); color: var(--accent); }
.cheat .syn { font: 13px var(--mono); color: var(--text-2); margin-left: 8px; }
.cheat .d { font-size: 14px; color: var(--text-2); margin: 4px 0; }
.cheat .d code { font-family: var(--mono); font-size: .9em; background: var(--panel-3); padding: 1px 5px; border-radius: 4px; color: #ffe38a; }
.cheat .eg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cheat .eg button { font: 12.5px var(--mono); background: var(--code-bg); border: 1px solid var(--line); color: #d6dcf5; border-radius: 6px; padding: 2px 8px; cursor: pointer; }
.cheat .eg button:hover { border-color: var(--accent); }

/* Examen ------------------------------------------------------------------- */
.exam-setup .field { margin: 16px 0; }
.exam-setup .field > label, .exam-setup .field > .lbl { display: block; font-weight: 700; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13.5px; font-weight: 600; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.exam-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.exam-bar .timer { margin-left: auto; font: 700 18px var(--mono); color: var(--accent); font-variant-numeric: tabular-nums; }
.exam-bar .timer.low { color: var(--bad); }
.exam-dots { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; }
.exam-dots span { width: 22px; height: 6px; border-radius: 3px; background: var(--panel-3); }
.exam-dots span.cur { background: var(--accent); }
.exam-dots span.ok { background: var(--ok); }
.exam-dots span.ko { background: var(--bad); }
.score { font-size: 56px; font-weight: 800; letter-spacing: -.03em; margin: 6px 0; }
.score small { font-size: 22px; color: var(--muted); }
.review { margin-top: 18px; display: grid; gap: 10px; }
.review .ex { margin: 0; }
.hist { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.hist td, .hist th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.hist th { color: var(--muted); font-weight: 600; font-size: 12.5px; }

/* Aviso -------------------------------------------------------------------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--panel-3); border: 1px solid var(--line-2); color: var(--text); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: opacity .2s, transform .2s; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: var(--ok); }

@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.ex.just-done .ex-badge { animation: pop .4s ease-out; }

/* Móvil -------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .topnav a { padding: 6px 8px; }
  .bar { width: 80px; }
  .side { position: absolute; z-index: 30; top: 56px; bottom: 0; box-shadow: 10px 0 40px rgba(0,0,0,.4); }
}
@media (max-width: 820px) {
  .topbar { gap: 8px; padding: 0 8px; }
  .brand-name, .user span, .top-progress .bar { display: none; }
  .topnav { margin-left: 0; }
  .topnav a { font-size: 13px; padding: 5px 7px; }
  .topnav a[data-nav="examen"] { font-size: 0; }
  .topnav a[data-nav="examen"]::after { content: 'Examen'; font-size: 13px; }
  .main { flex-direction: column; }
  .mobile-tabs { display: flex; flex: none; border-bottom: 1px solid var(--line); background: var(--panel); }
  .mobile-tabs button { flex: 1; background: none; border: 0; padding: 10px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; }
  .mobile-tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
  .learn { width: 100% !important; min-width: 0; flex: 1; }
  .splitter { display: none; }
  .term { flex: 1; }
  .main[data-pane="learn"] .term { display: none; }
  .main[data-pane="term"] .learn { display: none; }
  .learn-scroll { padding: 18px 16px 28px; }
  .ex-body { padding: 0 12px 14px 12px; }
  .fb .cmp { grid-template-columns: 1fr; }
  .lesson-title { font-size: 23px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* Acceso: extras ------------------------------------------------------------ */
.login-alt { margin: 0; text-align: center; font-size: 14px; color: var(--muted); }
.login-note { margin: -8px 0 0; font-size: 13px; min-height: 1em; color: var(--muted); }
.login-note.ok { color: var(--ok); }
.login-note.bad { color: var(--bad); }
.login input[readonly] { opacity: .7; }
.user-link { color: var(--text-2); text-decoration: none; font-weight: 600; padding: 4px 8px; border-radius: 8px; }
.user-link:hover { background: var(--panel-2); color: var(--text); }

/* Formularios y tablas (cuenta, administración) --------------------------------- */
.narrow { max-width: 560px; }
code.ic { font-family: var(--mono); font-size: .88em; background: var(--panel-3); color: #ffe38a; padding: 1px 6px; border-radius: 5px; }
.card-form { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 16px 0 24px; display: grid; gap: 12px; }
.card-form h2 { margin: 0; font-size: 18px; }
.card-form label, .inv-grid label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.card-form label small { font-weight: 500; color: var(--muted); }
.card-form input, .card-form select { background: var(--bg); border: 1px solid var(--line-2); color: var(--text); padding: 9px 11px; border-radius: 8px; font: inherit; font-size: 14px; }
.card-form input:focus, .card-form select:focus { border-color: var(--accent); outline: none; }
.card-form .btn { justify-self: start; }
.form-msg { margin: 0; font-size: 14px; min-height: 1.2em; }
.form-msg.ok { color: var(--ok); }
.form-msg.bad { color: var(--bad); }
.hint { color: var(--muted); font-size: 13.5px; margin: 0; }
.inv-grid { display: grid; grid-template-columns: minmax(180px, 1.4fr) minmax(180px, 1.4fr) minmax(120px, 1fr) minmax(120px, 1fr) auto; gap: 10px; align-items: end; }
.fresh { border: 1px dashed var(--accent); background: var(--warn-bg); border-radius: 10px; padding: 14px; display: grid; gap: 6px; }
.fresh-code { font: 800 24px var(--mono); letter-spacing: .06em; color: var(--accent); }
.fresh-link { font: 13px var(--mono); color: var(--text-2); word-break: break-all; }
.fresh-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.admin section { margin-bottom: 26px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.sec-head h2 { margin: 0; font-size: 18px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--panel-2); padding: 8px 10px; white-space: nowrap; }
.tbl td { padding: 9px 10px; border-top: 1px solid var(--line); vertical-align: top; color: var(--text); }
.tbl tr.off td { opacity: .55; }
.tbl .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tbl .acts { white-space: nowrap; text-align: right; }
.tbl .bar { height: 6px; margin-top: 6px; }
.btn.danger { color: var(--bad); }
.pill { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: var(--panel-3); color: var(--text-2); }
.pill.pendiente { background: rgba(255, 210, 63, .15); color: var(--accent); }
.pill.usada { background: var(--ok-bg); color: var(--ok); }
.pill.caducada, .pill.revocada { background: var(--bad-bg); color: var(--bad); }
.pill.admin { background: var(--info-bg); color: var(--info); }
@media (max-width: 1100px) { .inv-grid { grid-template-columns: 1fr 1fr; } .inv-grid .btn { grid-column: 1 / -1; justify-self: start; } }
@media (max-width: 820px) { .topnav a[data-nav="admin"] { font-size: 0; } .topnav a[data-nav="admin"]::after { content: 'Admin'; font-size: 13px; } .user-link { display: none; } }

.main.wide .learn { width: 100% !important; }
.main.wide .splitter, .main.wide .term, .main.wide .mobile-tabs { display: none !important; }
.main.wide .learn-scroll { padding-left: max(32px, calc((100% - 1200px) / 2)); padding-right: max(32px, calc((100% - 1200px) / 2)); }

.mini-input { background: var(--bg); border: 1px solid var(--line-2); color: var(--text); padding: 5px 9px; border-radius: 7px; font: inherit; font-size: 13px; min-width: 220px; }
.mini-input:focus { border-color: var(--accent); outline: none; }
.sent { font-size: 13.5px; color: var(--ok); }

/* Tutor IA ------------------------------------------------------------------ */
.learn { position: relative; }
.tutor-btn { background: linear-gradient(135deg, #3b2f7a, #25306b); border-color: #5b4fc0; color: #e9e4ff; }
.tutor-btn:hover { background: linear-gradient(135deg, #4a3c96, #2d3a82); }
.tutor-btn:disabled { opacity: .45; }
.tutor { position: absolute; top: 0; right: 0; bottom: 0; width: min(460px, 100%); z-index: 15; display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line-2); box-shadow: -18px 0 40px rgba(0,0,0,.35); }
.tutor-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.tutor-head b { font-size: 15px; }
.tutor-sub { font-size: 12px; color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tutor-msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.tutor-empty p { color: var(--text-2); margin: 0 0 8px; font-size: 14.5px; }
.tmsg { max-width: 92%; font-size: 14.5px; line-height: 1.55; border-radius: 12px; padding: 10px 13px; overflow-wrap: anywhere; }
.tmsg.user { align-self: flex-end; background: #2b3563; color: var(--text); border-bottom-right-radius: 4px; }
.tmsg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-2); border-bottom-left-radius: 4px; }
.tmsg.assistant p { margin: 6px 0; }
.tmsg.assistant p:first-child { margin-top: 0; }
.tmsg.assistant p:last-child { margin-bottom: 0; }
.tmsg.assistant strong { color: var(--text); }
.tmsg.assistant ul, .tmsg.assistant ol { padding-left: 20px; margin: 6px 0; }
.tmsg code { font-family: var(--mono); font-size: .88em; background: var(--panel-3); color: #ffe38a; padding: 1px 5px; border-radius: 4px; }
.tmsg pre { position: relative; background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow: auto; margin: 8px 0; }
.tmsg pre code { background: none; padding: 0; color: #d6dcf5; font-size: 13px; }
.tmsg pre.has-try { padding-right: 78px; }
.try-ai { opacity: 1 !important; top: 8px; right: 8px; }
.tmsg table { border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.tmsg th, .tmsg td { border: 1px solid var(--line); padding: 4px 8px; }
.tutor-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.tutor-chips .chip { font-size: 12.5px; padding: 4px 10px; }
.tutor-form { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.tutor-form textarea { flex: 1; resize: none; background: var(--bg); border: 1px solid var(--line-2); color: var(--text); padding: 9px 11px; border-radius: 10px; font: inherit; font-size: 14px; line-height: 1.4; }
.tutor-form textarea:focus { border-color: #7b6fe0; outline: none; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.fb .ask-ai { float: right; margin: -2px 0 6px 10px; background: linear-gradient(135deg, #3b2f7a, #25306b); border-color: #5b4fc0; color: #e9e4ff; }

/* Exámenes por niveles -------------------------------------------------------- */
.medals { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.medal { width: 17px; height: 17px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 800;
  border: 1px solid var(--line-2); color: var(--muted); background: var(--panel); }
.medal.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.medal.ko { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.medal.gold { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sn-lessons a.sn-exam { font-weight: 600; color: var(--text); }
.sn-lessons a.sn-exam .medals { margin-left: auto; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 18px; }
.level { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.level.gold { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 210, 63, .1); }
.level-top { display: flex; align-items: center; gap: 10px; }
.level-top h3 { margin: 0; font-size: 18px; flex: 1; }
.level-n { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; background: var(--panel-3); color: var(--text-2); }
.level-best { font: 800 18px var(--mono); }
.level-best.gold { color: var(--accent); }
.level-best.ok { color: var(--ok); }
.level-best.ko { color: var(--bad); }
.level p { margin: 0; color: var(--text-2); font-size: 14px; flex: 1; }
.level-meta { font-size: 12.5px; color: var(--muted); }
.level .btn { align-self: flex-start; }
@media (max-width: 820px) { .tutor-btn { padding: 5px 8px; font-size: 0; } .tutor-btn::after { content: '✨ IA'; font-size: 13px; } }

