:root {
  --bg: #f6f4ff;
  --surface: #ffffff;
  --surface-2: #f1eefc;
  --ink: #1f1a3d;
  --ink-2: #5b5680;
  --line: #e3dff5;
  --primary: #6c4cf1;
  --primary-ink: #ffffff;
  --primary-soft: #ebe6ff;
  --coral: #ff6b6b;
  --green: #22a06b;
  --green-soft: #e3f6ec;
  --red: #e5484d;
  --red-soft: #fde8e8;
  --gold: #f5b100;
  --gold-soft: #fff4d1;
  --blue: #2f7cf6;
  --orange: #f2780c;
  --purple: #8b3fd9;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(48, 30, 120, 0.08);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 12px 22px; min-height: 48px;
  background: var(--primary); color: var(--primary-ink); font-weight: 800;
  cursor: pointer; transition: transform .1s ease, filter .15s ease, background .15s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus { outline: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary-soft), 0 0 0 6px var(--primary); }
.btn.secondary { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.danger { background: var(--red); }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: 15px; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; font-size: 15px; color: var(--ink-2); }
.input, select.input, textarea.input {
  border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff;
  min-height: 48px; width: 100%;
}
.input:focus { outline: none; border-color: var(--primary); }
.error-text { color: var(--red); font-weight: 700; min-height: 1.4em; }
.muted { color: var(--ink-2); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; background: var(--surface); box-shadow: var(--shadow);
  font-weight: 800;
}
.pill.coins { background: var(--gold-soft); color: #7a5600; }
.pill.streak { background: #ffe9e3; color: #a33a12; }

/* ── Portada / perfiles ─────────────────────────────────────────────── */
.home { max-width: 920px; margin: 0 auto; padding: 32px 16px 48px; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 30px; font-weight: 900; }
.brand .logo {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(135deg, #8b6cff, #6c4cf1); color: #fff; font-size: 28px;
}
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; margin-top: 28px; }
.profile {
  background: var(--surface); border-radius: 24px; padding: 26px 18px; text-align: center;
  box-shadow: var(--shadow); cursor: pointer; border: 3px solid transparent;
  transition: transform .15s, border-color .15s;
}
.profile:hover { transform: translateY(-3px); border-color: var(--primary); }
.profile .avatar { font-size: 64px; line-height: 1.1; }
.profile .name { font-size: 22px; font-weight: 900; margin-top: 8px; }
.profile .stats { display: flex; justify-content: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.login-box { max-width: 400px; margin: 40px auto 0; }

/* ── Pantalla de estudio ────────────────────────────────────────────── */
.study { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .who { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 19px; }
.topbar .who .avatar { font-size: 30px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--surface-2);
  cursor: pointer; font-size: 20px; display: grid; place-items: center;
}

.workspace {
  display: grid; grid-template-columns: 1fr 380px; gap: 14px; padding: 14px; min-height: 0;
}
.stage { display: grid; grid-template-rows: 1fr auto; gap: 10px; min-height: 0; min-width: 0; }
.stage-main {
  position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: auto; min-height: 0;
}
.stage-item { padding: 18px; min-height: 100%; }
.stage-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 8px 14px; background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line); cursor: pointer; font-weight: 700; font-size: 14px;
  max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.active { background: var(--primary); color: #fff; box-shadow: none; }
.chip.attention { animation: pulse 1.2s infinite; }

.chat {
  display: grid; grid-template-rows: auto 1fr auto; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); min-height: 0;
}
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.mica-orb {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 22px;
  background: radial-gradient(circle at 30% 30%, #a996ff, #6c4cf1); color: #fff; flex: none;
}
.mica-orb.speaking { animation: speak 0.9s ease-in-out infinite; }
.chat-head .status { font-size: 14px; color: var(--ink-2); }
.messages { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.tutor { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.alumno { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.alumno.voice { background: #8a72f5; }
.bubble img { max-width: 100%; border-radius: 10px; display: block; }
.sys { align-self: center; font-size: 14px; font-weight: 700; color: var(--ink-2); background: var(--bg);
  padding: 4px 12px; border-radius: 999px; text-align: center; }
.sys.coins { background: var(--gold-soft); color: #7a5600; }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; min-height: 48px; max-height: 120px; }

.controls {
  display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface);
  border-top: 1px solid var(--line);
}
.ctrl {
  display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: var(--surface-2);
  border-radius: 16px; padding: 8px 14px; min-width: 76px; min-height: 60px; cursor: pointer;
  font-size: 13px; font-weight: 800; color: var(--ink-2);
}
.ctrl .ic { font-size: 22px; }
.ctrl.on { background: var(--primary-soft); color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.ctrl.attention { animation: pulse 1.2s infinite; box-shadow: inset 0 0 0 3px var(--orange); }
.ctrl.mic { min-width: 96px; background: var(--primary); color: #fff; }
.ctrl.mic.muted { background: var(--red-soft); color: var(--red); }
.ctrl.end { background: var(--red-soft); color: var(--red); }

/* Vista previa de cámara / pantalla */
.preview {
  position: fixed; left: 16px; bottom: 96px; width: 280px; z-index: 30; background: #000;
  border-radius: 16px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.preview video { width: 100%; display: block; max-height: 220px; object-fit: contain; background: #000; }
.preview .bar { display: flex; gap: 6px; padding: 8px; background: rgba(20,16,50,.92); }
.preview .bar .btn { flex: 1; min-height: 40px; padding: 6px 10px; font-size: 14px; }
.preview .bar .icon-btn { width: 40px; height: 40px; background: rgba(255,255,255,.15); color: #fff; }

/* Pizarra */
.board-wrap { position: relative; width: 100%; aspect-ratio: 1000 / 600; max-height: 100%; }
.board-svg { width: 100%; height: 100%; display: block; background:
  linear-gradient(var(--surface-2) 1px, transparent 1px) 0 0 / 100% 40px, #fffef9; border-radius: 12px; }
.board-svg .el { animation: appear .45s ease both; }
.board-title { font-weight: 900; font-size: 20px; margin: 0 0 10px; }
.draw-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.draw-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 10px;
  padding: 8px; background: var(--surface-2); border-radius: 14px; position: sticky; top: 0; z-index: 5; }
.tool-group { display: flex; gap: 4px; align-items: center; padding-right: 8px; border-right: 2px solid var(--line); }
.tool { display: flex; flex-direction: column; align-items: center; gap: 0; border: 0; background: #fff;
  border-radius: 10px; min-width: 52px; min-height: 48px; padding: 4px 6px; cursor: pointer; font-size: 18px;
  box-shadow: inset 0 0 0 2px var(--line); }
.tool span { font-size: 11px; font-weight: 800; color: var(--ink-2); }
.tool.active { background: var(--primary-soft); box-shadow: inset 0 0 0 3px var(--primary); }
.tool:disabled { opacity: .4; cursor: default; }
.draw-tools .btn { margin-left: auto; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.swatch.active { box-shadow: 0 0 0 3px var(--ink); }
.formula-fo div { font-size: 28px; color: var(--ink); }

/* Widgets */
.widget h3 { margin: 0 0 12px; font-size: 21px; font-weight: 900; }
.widget .explain { margin-top: 12px; color: var(--ink-2); }
.frac-row { display: flex; flex-wrap: wrap; gap: 26px; align-items: flex-end; }
.frac-item { text-align: center; }
.frac-item .lbl { margin-top: 6px; font-size: 24px; }
.steps { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.step { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; animation: appear .4s both; }
.step b { color: var(--primary); }
.syntax { overflow-x: auto; padding-bottom: 8px; }
.syntax-grid { display: grid; gap: 6px 4px; align-items: stretch; width: max-content; min-width: 100%; }
.syntax-word { font-size: 22px; font-weight: 800; text-align: center; padding: 4px 6px; }
.syntax-box {
  border-radius: 10px; padding: 6px 8px; text-align: center; font-weight: 800; font-size: 14px;
  border: 2px solid; min-height: 36px; display: grid; place-items: center; cursor: default;
}
.syntax-box.hidden-fn { cursor: pointer; background: repeating-linear-gradient(45deg, #fff, #fff 6px, var(--surface-2) 6px, var(--surface-2) 12px) !important; color: var(--ink-2) !important; }
.wtable { border-collapse: collapse; width: 100%; font-size: 18px; }
.wtable th, .wtable td { border: 2px solid var(--line); padding: 8px 12px; text-align: center; }
.wtable th { background: var(--primary-soft); }
.tarjeta { border-left: 6px solid var(--primary); }
.tarjeta ul { padding-left: 22px; margin: 8px 0; }
.tarjeta li { margin: 6px 0; font-size: 19px; }
.tarjeta .ejemplo { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; margin-top: 10px; }
.tarjeta .truco { background: var(--gold-soft); border-radius: 12px; padding: 10px 14px; margin-top: 10px; }
.tag { display: inline-block; font-size: 13px; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }

/* Reto */
.quiz h3 { display: flex; align-items: center; gap: 8px; }
.q { background: var(--surface-2); border-radius: 14px; padding: 14px; margin-bottom: 12px; border: 3px solid transparent; }
.q.ok { border-color: var(--green); background: var(--green-soft); }
.q.ko { border-color: var(--red); background: var(--red-soft); }
.q .enun { font-weight: 800; margin-bottom: 10px; font-size: 19px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { border: 0; border-radius: 12px; padding: 10px 16px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); cursor: pointer; font-weight: 700; min-height: 46px; }
.opt.sel { box-shadow: inset 0 0 0 3px var(--primary); background: var(--primary-soft); }
.q .fb { margin-top: 10px; font-weight: 700; }
.quiz-score { font-size: 22px; font-weight: 900; text-align: center; margin: 8px 0 14px; }

/* Monedas: notificación */
.toast {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--gold-soft); color: #7a5600; padding: 12px 20px; border-radius: 999px;
  font-weight: 900; box-shadow: 0 10px 30px rgba(120, 80, 0, .2); animation: toast 2.8s ease both;
}
.burst { position: fixed; z-index: 49; font-size: 26px; pointer-events: none; animation: burst 1.2s ease-out forwards; }

/* Panel lateral (cuaderno / mapa) */
.drawer-bg { position: fixed; inset: 0; background: rgba(20,16,50,.35); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--bg); z-index: 61;
  overflow-y: auto; padding: 18px 16px; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
.progress { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.topic-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* Pantalla de inicio de sesión de estudio */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(246,244,255,.96); display: grid; place-items: center; padding: 16px; }
.overlay .card { max-width: 440px; width: 100%; text-align: center; }
.overlay .big-orb { width: 96px; height: 96px; font-size: 48px; margin: 0 auto 12px; }

/* Ventana de confirmación */
.modal-bg { position: fixed; inset: 0; z-index: 100; background: rgba(31, 26, 61, .45); display: grid;
  place-items: center; padding: 16px; animation: fadeIn .16s ease both; backdrop-filter: blur(3px); }
.modal-bg.closing { animation: fadeOut .16s ease both; }
.modal { background: var(--surface); border-radius: 24px; padding: 26px 22px 20px; width: min(400px, 100%);
  text-align: center; box-shadow: 0 20px 60px rgba(31, 26, 61, .3); animation: pop .22s cubic-bezier(.2,1.4,.4,1) both; }
.modal-icon { font-size: 52px; line-height: 1; margin-bottom: 6px; }
.modal h2 { margin: 6px 0 6px; font-size: 22px; }
.modal p { margin: 0 0 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.9) translateY(10px); } to { opacity: 1; transform: none; } }

/* Reiniciar (zona de padres) */
.reset-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.reset-opt { display: flex; gap: 12px; align-items: flex-start; background: var(--surface-2); border-radius: 14px;
  padding: 10px 12px; cursor: pointer; font-size: 15px; line-height: 1.35; }
.reset-opt input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--red); flex: none; }
.reset-opt:has(input:checked) { background: var(--red-soft); }

/* Elegir voz */
.overlay .card { max-height: calc(100dvh - 32px); overflow-y: auto; }
.voice-current { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border-radius: 14px; padding: 8px 8px 8px 14px; margin: 12px 0 4px; text-align: left; }
.voice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; text-align: left; }
.voice-card { display: flex; align-items: center; gap: 8px; border: 0; border-radius: 14px; padding: 8px;
  background: var(--surface-2); box-shadow: inset 0 0 0 2px transparent; cursor: pointer; min-height: 56px; }
.voice-card.sel { background: var(--primary-soft); box-shadow: inset 0 0 0 3px var(--primary); }
.voice-card .play { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--primary);
  color: #fff; font-size: 16px; cursor: pointer; }
.voice-card .play.playing { background: var(--orange); }
.voice-card .vn { font-weight: 900; }
.voice-card .vd { font-size: 13px; color: var(--ink-2); line-height: 1.2; }
@media (max-width: 420px) { .voice-grid { grid-template-columns: 1fr; } }

/* Zona de padres */
.parents { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.tabs { display: flex; gap: 8px; margin: 18px 0; flex-wrap: wrap; }
.tab { border: 0; background: var(--surface); padding: 10px 18px; border-radius: 999px; font-weight: 800; cursor: pointer; box-shadow: var(--shadow); }
.tab.active { background: var(--primary); color: #fff; }
.session-card { cursor: pointer; margin-bottom: 12px; transition: transform .1s; }
.session-card:hover { transform: translateY(-2px); }
.session-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 14px; color: var(--ink-2); font-weight: 700; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 14px 0; }
.summary-grid .card h4 { margin: 0 0 8px; }
.summary-grid ul { margin: 0; padding-left: 20px; }
.transcript { display: flex; flex-direction: column; gap: 8px; }
.transcript .bubble { max-width: 80%; }
.transcript .time { font-size: 12px; opacity: .7; display: block; }
.alert { background: var(--red-soft); color: #8a1c20; border-radius: 12px; padding: 10px 14px; font-weight: 700; }
.badge { background: var(--red); color: #fff; border-radius: 999px; padding: 2px 9px; font-size: 13px; font-weight: 800; }
.status-tag { font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 999px; }
.st-dominado { background: var(--green-soft); color: var(--green); }
.st-aprendiendo { background: var(--primary-soft); color: var(--primary); }
.st-repasar { background: #ffe9d6; color: var(--orange); }
.avatar-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.avatar-pick button { font-size: 28px; border: 0; background: var(--surface-2); border-radius: 12px; width: 50px; height: 50px; cursor: pointer; }
.avatar-pick button.sel { box-shadow: inset 0 0 0 3px var(--primary); background: var(--primary-soft); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

@keyframes appear { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes speak { 0%, 100% { box-shadow: 0 0 0 0 rgba(108,76,241,.5); } 50% { box-shadow: 0 0 0 10px rgba(108,76,241,0); } }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -10px); } 12%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -10px); } }
@keyframes burst { from { opacity: 1; transform: translate(0, 0) scale(1); } to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.4); } }

/* Tablet en vertical y pantallas estrechas */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr); padding: 10px; gap: 10px; }
  .ctrl { min-width: 64px; padding: 6px 10px; }
  .preview { width: 200px; bottom: 100px; }
}
@media (max-width: 520px) {
  body { font-size: 16px; }
  .topbar .who span.nm { display: none; }
  .ctrl { min-width: 56px; font-size: 11px; }
  .ctrl .ic { font-size: 20px; }
}
