:root {
  --bg: #fff8ef; --card: #ffffff; --ink: #2b2240; --soft: #6d6483; --line: #ece4d8;
  --mat: #4f6bed; --mat-l: #e8ecff; --eng: #ef5d60; --eng-l: #ffe9e9; --esp: #1fa67a; --esp-l: #e2f6ee;
  --sun: #ffc93c; --ok: #1fa67a; --ok-l: #e2f6ee; --bad: #e5484d; --bad-l: #ffeaea; --pur: #8b5cf6;
  --r: 18px; --sh: 0 6px 0 rgba(43, 34, 64, .08), 0 10px 24px rgba(43, 34, 64, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 Nunito, system-ui, sans-serif;
  background-image: radial-gradient(circle at 10% 0%, #ffe7c2 0, transparent 35%), radial-gradient(circle at 100% 30%, #e6e9ff 0, transparent 30%); background-attachment: fixed; }
h1, h2, h3, h4, .baloo { font-family: 'Baloo 2', Nunito, sans-serif; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: clamp(28px, 6vw, 44px); } h2 { font-size: 28px; } h3 { font-size: 22px; } h4 { font-size: 20px; margin-top: 1.1em; }
button { font: inherit; cursor: pointer; }
.wrap { max-width: 980px; margin: 0 auto; padding: 20px 16px 80px; }
.cargando { padding: 30vh 16px; text-align: center; font: 700 22px 'Baloo 2'; }
.peq { font-size: 14px; color: var(--soft); }

/* Botones */
.btn { border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 800; background: var(--ink); color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, .25); transition: transform .08s; display: inline-flex; gap: 8px; align-items: center; justify-content: center; text-decoration: none; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
.btn.sec { background: #fff; color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.sol { background: var(--sun); color: var(--ink); box-shadow: 0 4px 0 #d9a514; }
.btn.verde { background: var(--ok); box-shadow: 0 4px 0 #13805c; }
.btn.mat { background: var(--mat); box-shadow: 0 4px 0 #3348b8; } .btn.eng { background: var(--eng); box-shadow: 0 4px 0 #c2393c; } .btn.esp { background: var(--esp); box-shadow: 0 4px 0 #13805c; }
.btn.chico { padding: 7px 12px; font-size: 15px; border-radius: 11px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--soft); text-decoration: underline; padding: 4px; }

/* Login */
.portada { text-align: center; padding-top: 4vh; }
.portada .sub { color: var(--soft); font-weight: 700; margin-bottom: 26px; }
.usuarios { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; max-width: 640px; margin: 0 auto; }
.u-card { background: var(--card); border: 3px solid var(--line); border-radius: 26px; padding: 22px; box-shadow: var(--sh); text-align: center; transition: transform .15s; }
.u-card:hover { transform: translateY(-4px) rotate(-.5deg); }
.u-card .ava { font-size: 64px; line-height: 1; }
.u-card .nom { font: 800 34px 'Baloo 2'; }
.u-card .mini { display: flex; justify-content: center; gap: 16px; margin: 8px 0 14px; color: var(--soft); font-weight: 700; font-size: 15px; }
.u-card .mini b { display: block; font: 800 26px 'Baloo 2'; color: var(--ink); }
.pin { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.pin input { width: 150px; font: 800 26px 'Baloo 2'; text-align: center; letter-spacing: 10px; border: 3px solid var(--line); border-radius: 14px; padding: 6px; }
.err { color: var(--bad); font-weight: 800; min-height: 1.5em; }
.aviso { background: #fff3cd; border: 2px dashed #e0b84a; border-radius: 14px; padding: 10px 14px; margin: 18px auto; max-width: 640px; font-size: 15px; }

/* Encabezado */
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .yo { display: flex; align-items: center; gap: 10px; font: 800 26px 'Baloo 2'; }
.top .yo span:first-child { font-size: 40px; }
.top .esp { flex: 1; }

/* Tarjetas de estadísticas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--card); border-radius: var(--r); padding: 16px; box-shadow: var(--sh); display: flex; gap: 12px; align-items: center; }
.stat .v { font: 800 30px 'Baloo 2'; } .stat .l { color: var(--soft); font-weight: 700; font-size: 14px; line-height: 1.2; }
.anillo { --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: none; background: conic-gradient(var(--c, var(--pur)) calc(var(--p) * 1%), #eee8f7 0); display: grid; place-items: center; }
.anillo::after { content: attr(data-t); width: 48px; height: 48px; border-radius: 50%; background: #fff; display: grid; place-items: center; font: 800 15px 'Baloo 2'; }

.acciones { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 26px; }
.accion { border: 0; text-align: left; border-radius: 22px; padding: 18px; color: #fff; box-shadow: 0 6px 0 rgba(0, 0, 0, .18); }
.accion .t { font: 800 22px 'Baloo 2'; display: block; } .accion .d { opacity: .92; font-size: 15px; font-weight: 600; }
.accion.a1 { background: linear-gradient(135deg, #8b5cf6, #6d3df0); } .accion.a2 { background: linear-gradient(135deg, #ff8a3d, #f2603a); } .accion.a3 { background: linear-gradient(135deg, #22b4d6, #1f8fd0); }
.accion:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .18); }

/* Materias y temas */
.materia { background: var(--card); border-radius: 24px; box-shadow: var(--sh); padding: 18px; margin-bottom: 20px; border-top: 8px solid var(--c); }
.materia.mat { --c: var(--mat); --cl: var(--mat-l); } .materia.eng { --c: var(--eng); --cl: var(--eng-l); } .materia.esp { --c: var(--esp); --cl: var(--esp-l); }
.materia h3 { display: flex; align-items: center; gap: 8px; } .materia h3 .pct { margin-left: auto; font-size: 18px; color: var(--c); }
.tema { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 10px 6px; border-top: 1px dashed var(--line); }
.tema .em { font-size: 26px; text-align: center; }
.tema .nm { font-weight: 800; line-height: 1.25; } .tema .gd { font-size: 13px; color: var(--soft); font-weight: 700; }
.barra { height: 10px; background: var(--cl, #eee); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.barra > div { height: 100%; background: var(--c, var(--pur)); border-radius: 99px; transition: width .5s; }
.tema .bt { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tema .info { font-size: 13px; color: var(--soft); font-weight: 700; margin-top: 3px; }

/* Historial */
.hist { width: 100%; border-collapse: collapse; font-size: 15px; }
.hist th, .hist td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.hist tr.click { cursor: pointer; } .hist tr.click:hover { background: #faf6ff; }
.cal { font: 800 20px 'Baloo 2'; } .cal.a { color: var(--ok); } .cal.b { color: #d08a00; } .cal.c { color: var(--bad); }

/* Quiz */
.qtop { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.qtop .prog { flex: 1; height: 16px; background: #fff; border-radius: 99px; box-shadow: inset 0 0 0 2px var(--line); overflow: hidden; }
.qtop .prog > div { height: 100%; background: linear-gradient(90deg, var(--sun), #ff8a3d); border-radius: 99px; transition: width .3s; }
.qtop .num { font: 800 18px 'Baloo 2'; min-width: 64px; text-align: right; }
.qcard { background: var(--card); border-radius: 26px; box-shadow: var(--sh); padding: 22px; border-top: 8px solid var(--c, var(--pur)); }
.qcard.mat { --c: var(--mat); --cl: var(--mat-l); } .qcard.eng { --c: var(--eng); --cl: var(--eng-l); } .qcard.esp { --c: var(--esp); --cl: var(--esp-l); }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--cl, #eee); color: var(--c, var(--ink)); font-weight: 800; font-size: 14px; border-radius: 99px; padding: 4px 12px; margin-bottom: 12px; }
.chip.d2 { background: #fff1d6; color: #b46b00; }
.enun { font-size: 20px; font-weight: 700; margin-bottom: 16px; overflow-wrap: anywhere; }
.enun blockquote, .lect { background: #fbf8f2; border-left: 5px solid var(--sun); margin: 10px 0 14px; padding: 12px 16px; border-radius: 0 12px 12px 0; font-weight: 600; font-size: 17px; }
.lect p { margin: .4em 0 0; }
.opts { display: grid; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: center; text-align: left; background: #fff; border: 3px solid var(--line); border-radius: 16px; padding: 12px 14px; font-weight: 700; font-size: 18px; color: var(--ink); transition: border-color .1s, background .1s, transform .08s; }
.opt:hover:not(:disabled) { border-color: var(--c, var(--pur)); transform: translateX(3px); }
.opt .le { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--cl, #eee); color: var(--c, var(--ink)); font: 800 18px 'Baloo 2'; }
.opt.sel { border-color: var(--c, var(--pur)); background: var(--cl, #f4efff); }
.opt.ok { border-color: var(--ok); background: var(--ok-l); } .opt.ok .le { background: var(--ok); color: #fff; }
.opt.bad { border-color: var(--bad); background: var(--bad-l); } .opt.bad .le { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.fb { margin-top: 16px; border-radius: 18px; padding: 14px 16px; animation: aparece .25s ease; }
.fb.ok { background: var(--ok-l); border: 2px solid #a8e2cc; } .fb.bad { background: var(--bad-l); border: 2px solid #f5b5b7; }
.fb .ti { font: 800 22px 'Baloo 2'; margin-bottom: 4px; }
.fb .bts { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.qnav { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; flex-wrap: wrap; }
.rejilla { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.rejilla button { width: 36px; height: 36px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-weight: 800; font-size: 14px; }
.rejilla button.r { background: var(--ink); color: #fff; border-color: var(--ink); } .rejilla button.act { outline: 3px solid var(--sun); }
@keyframes aparece { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Resultado */
.res-top { text-align: center; background: var(--card); border-radius: 26px; box-shadow: var(--sh); padding: 26px 16px; margin-bottom: 18px; }
.res-top .big { font: 800 84px/1 'Baloo 2'; } .res-top .msg { font: 800 24px 'Baloo 2'; }
.res-mats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 16px 0 0; }
.res-mat { border-radius: 16px; padding: 12px; background: var(--cl); color: var(--ink); font-weight: 800; }
.res-mat.mat { --cl: var(--mat-l); } .res-mat.eng { --cl: var(--eng-l); } .res-mat.esp { --cl: var(--esp-l); }
.rev { background: var(--card); border-radius: 18px; box-shadow: var(--sh); padding: 14px 16px; margin-bottom: 12px; border-left: 8px solid var(--ok); }
.rev.bad { border-left-color: var(--bad); }
.rev .enun { font-size: 17px; margin-bottom: 6px; }
.rev .tu { font-weight: 700; } .rev .tu.bad { color: var(--bad); } .rev .tu.ok { color: var(--ok); }
.rev details { margin-top: 6px; } .rev summary { cursor: pointer; font-weight: 800; color: var(--pur); }
.filtro { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }

/* Lecciones */
.modal { position: fixed; inset: 0; background: rgba(43, 34, 64, .55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 20px 10px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-c { position: relative; background: #fff; border-radius: 26px; max-width: 760px; width: 100%; padding: 26px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: aparece .2s ease; }
.cerrar { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: #f2eefa; font-size: 18px; font-weight: 800; }
.lec-h { display: flex; gap: 12px; align-items: center; margin: 0 30px 10px 0; } .lec-h .em { font-size: 50px; }
.leccion p, .leccion li { font-size: 17px; }
.caja { border-radius: 16px; padding: 12px 14px; margin: 12px 0; }
.caja-t { font: 800 17px 'Baloo 2'; margin-bottom: 2px; }
.caja.truco { background: #fff6d6; border: 2px solid #ffe08a; } .caja.ojo { background: #ffecec; border: 2px solid #ffc0c0; } .caja.ej { background: #eef3ff; border: 2px solid #cfdaff; }
.reto { background: #f3edff; border-radius: 16px; padding: 12px 14px; margin-top: 14px; } .reto summary { font-weight: 800; cursor: pointer; } .reto div { margin-top: 8px; font-weight: 700; }
.suj { background: #dbe7ff; border-radius: 6px; padding: 0 4px; } .pred { background: #ffe1d6; border-radius: 6px; padding: 0 4px; }

/* Tablas, fracciones y figuras */
.tb { border-collapse: collapse; margin: 10px 0; font-size: 15px; width: auto; max-width: 100%; display: block; overflow-x: auto; }
.tb th, .tb td { border: 2px solid var(--line); padding: 5px 10px; text-align: center; }
.tb th { background: #f6f1ff; }
.fr { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .9em; line-height: 1.15; margin: 0 .12em; }
.fr > span:first-child { border-bottom: 2px solid currentColor; padding: 0 .2em; }
.fig { display: block; width: 100%; max-width: 520px; margin: 10px auto; }
.fig .ln { stroke: var(--ink); stroke-width: 2.5; fill: none; } .fig .dash { stroke-dasharray: 5 4; stroke-width: 2; }
.fig .pt { fill: var(--eng); } .fig .tx { font: 700 15px Nunito, sans-serif; fill: var(--ink); } .fig .tx.b { font-weight: 800; } .fig .tx.s { font-size: 12px; fill: var(--soft); }
.fig .grid { stroke: #e7e0f2; stroke-width: 1; } .fig .ax { stroke: var(--ink); stroke-width: 2; }
.fig .sh { fill: #e8ecff; stroke: var(--mat); stroke-width: 2.5; } .fig .sh2 { fill: #d4dcff; stroke: var(--mat); stroke-width: 2.5; } .fig .sh3 { fill: #bfcaff; stroke: var(--mat); stroke-width: 2.5; }

/* Confeti */
.confeti { position: fixed; top: -12px; width: 10px; height: 14px; z-index: 60; pointer-events: none; animation: cae linear forwards; }
@keyframes cae { to { transform: translateY(105vh) rotate(720deg); } }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 800; z-index: 70; font-size: 15px; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .tema { grid-template-columns: 30px 1fr; } .tema .bt { grid-column: 1 / -1; justify-content: stretch; } .tema .bt .btn { flex: 1; }
  .enun { font-size: 18px; } .opt { font-size: 16px; } .qcard { padding: 16px; } .res-top .big { font-size: 64px; }
}
