:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #273449;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --brand: #6366f1;
  --brand2: #818cf8;
  --ok: #22c55e;
  --close: #eab308;
  --bad: #ef4444;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #1e293b, var(--bg));
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Barra superior ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; position: sticky; top: 0; z-index: 5;
  background: rgba(15, 23, 42, .8); backdrop-filter: blur(8px);
}
.brand { font-size: 22px; font-weight: 800; letter-spacing: .5px; }
.brand span { background: linear-gradient(90deg, var(--brand2), #f0abfc); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tools { display: flex; gap: 8px; }
.pill {
  border: 0; border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600;
  background: var(--panel2); color: var(--text); cursor: pointer;
}
.pill:active { transform: scale(.96); }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 8px; padding: 10px 12px; overflow-x: auto; }
.tab {
  flex: 1; min-width: max-content; border: 0; cursor: pointer;
  padding: 12px 14px; border-radius: 12px; font-size: 15px; font-weight: 700;
  background: var(--panel); color: var(--muted);
}
.tab.active { background: linear-gradient(180deg, var(--brand), #4f46e5); color: #fff; box-shadow: 0 6px 20px -8px var(--brand); }

/* ---- Vista ---- */
.view { max-width: 760px; margin: 0 auto; padding: 8px 16px 40px; }
h2 { font-size: 22px; margin: 10px 0 4px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.back { background: none; border: 0; color: var(--brand2); font-weight: 700; font-size: 15px; cursor: pointer; padding: 8px 0; }

/* ---- Grid de lecciones ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  border: 0; cursor: pointer; text-align: left; color: var(--text);
  background: var(--panel); border-radius: var(--radius); padding: 16px;
  transition: transform .08s, box-shadow .2s; box-shadow: 0 4px 18px -14px #000;
}
.tile:hover { transform: translateY(-2px); box-shadow: 0 10px 26px -16px #000; }
.tile:active { transform: scale(.98); }
.tile-emoji { font-size: 34px; }
.tile-title { font-weight: 800; font-size: 17px; margin-top: 6px; }
.tile-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---- Tarjeta de práctica ---- */
.card {
  background: var(--panel); border-radius: var(--radius); padding: 16px; margin: 14px 0;
  box-shadow: 0 4px 18px -14px #000;
}
.p-en { font-size: 26px; font-weight: 800; }
.p-es { color: var(--muted); font-size: 16px; margin-top: 2px; }
.p-hint { margin-top: 6px; font-size: 14px; color: #cbd5e1; }
.p-hint b { color: var(--brand2); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.btn {
  border: 0; cursor: pointer; border-radius: 12px; padding: 12px 16px;
  font-size: 15px; font-weight: 700; color: #fff;
  background: linear-gradient(180deg, var(--brand2), var(--brand));
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--panel2); color: var(--text); }
.btn.mic { background: linear-gradient(180deg, #34d399, #10b981); }
.btn.mic.rec { background: linear-gradient(180deg, #f87171, #ef4444); animation: pulse 1s infinite; }
.btn.big { font-size: 18px; padding: 16px 22px; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn:disabled { opacity: .7; cursor: default; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); } 50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); } }

.best { color: var(--muted); font-size: 13px; margin-top: 8px; min-height: 8px; }

/* ---- Resultado ---- */
.result { margin-top: 8px; }
.score-row { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.score { font-size: 30px; font-weight: 900; padding: 6px 12px; border-radius: 12px; background: var(--panel2); }
.score.s0, .score.s1 { color: var(--bad); }
.score.s2 { color: var(--close); }
.score.s3, .score.s4 { color: var(--ok); }
.fb { display: flex; align-items: center; gap: 8px; color: var(--text); }
.fb-emoji { font-size: 24px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { padding: 5px 10px; border-radius: 999px; font-weight: 700; font-size: 14px; background: var(--panel2); }
.chip.ok { background: rgba(34,197,94,.18); color: #86efac; }
.chip.close { background: rgba(234,179,8,.18); color: #fde047; }
.chip.bad, .chip.missing { background: rgba(239,68,68,.18); color: #fca5a5; }
.heard { color: var(--muted); font-size: 14px; }
.heard i { color: var(--text); }
.pass { color: var(--ok); font-weight: 700; margin-top: 8px; }
.retry { color: var(--close); margin-top: 8px; }

.warnbox { background: rgba(234,179,8,.12); border: 1px solid rgba(234,179,8,.35); color: #fde68a; padding: 12px 14px; border-radius: 12px; margin-top: 10px; font-size: 14px; }

/* ---- Coach secuencial ---- */
.progress-txt { color: var(--muted); font-weight: 700; margin: 6px 0; }
.run-nav { display: flex; justify-content: space-between; margin-top: 16px; }

/* ---- Conversación ---- */
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; padding: 6px; margin: 10px 0; }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 16px; }
.bubble .b-top { font-weight: 700; }
.bubble .b-bot { font-size: 13px; color: var(--muted); margin-top: 2px; }
.bubble.app { align-self: flex-start; background: var(--panel2); border-bottom-left-radius: 4px; }
.bubble.you { align-self: flex-end; background: linear-gradient(180deg, #4f46e5, #4338ca); border-bottom-right-radius: 4px; }
.bubble.you .b-bot { color: #c7d2fe; }
.your-turn { color: var(--brand2); font-weight: 800; margin: 6px 0; }
.done { font-size: 22px; font-weight: 800; margin: 10px 0; }

/* ---- Banner del modelo ---- */
.model-banner { max-width: 760px; margin: 8px auto 0; padding: 12px 16px; background: var(--panel); border-radius: 12px; }
.mb-text { font-weight: 700; }
.mb-bar { height: 8px; background: var(--panel2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.mb-bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand2), var(--brand)); transition: width .2s; }
.mb-note { color: var(--muted); font-size: 12px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

/* ---- Modo niño (letras grandes) ---- */
body.kid .p-en { font-size: 34px; }
body.kid .p-es { font-size: 19px; }
body.kid .btn { font-size: 18px; padding: 16px 20px; }
body.kid .tile-title { font-size: 20px; }
body.kid .tile-emoji { font-size: 42px; }

/* ==================== Camino (currículo por niveles) ==================== */
.overall { margin: 4px 0 18px; }
.overall .bar { height: 12px; border-radius: 999px; background: var(--panel2); overflow: hidden; }
.overall .bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--brand2)); transition: width .5s ease; }
.overall-txt { margin-top: 6px; font-size: 13px; color: var(--muted); text-align: right; }

.level-head { display: flex; gap: 12px; align-items: center; margin: 20px 0 10px; }
.level-head.locked { opacity: .55; }
.level-emoji { font-size: 30px; width: 46px; height: 46px; display: grid; place-items: center; background: var(--panel2); border-radius: 14px; flex: 0 0 auto; }
.level-title { font-weight: 800; font-size: 17px; }
.level-goal { font-size: 13px; color: var(--muted); }

.lesson-list { display: flex; flex-direction: column; gap: 8px; }
.lesson-row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  border: 0; width: 100%; padding: 12px 14px; border-radius: 14px;
  background: var(--panel); color: var(--text); cursor: pointer;
  border-left: 4px solid transparent; transition: transform .08s;
}
.lesson-row:active { transform: scale(.99); }
.lesson-row.done { border-left-color: var(--ok); }
.lesson-row.locked { opacity: .5; cursor: not-allowed; }
.lr-emoji { font-size: 26px; width: 40px; text-align: center; flex: 0 0 auto; }
.lr-main { flex: 1 1 auto; min-width: 0; }
.lr-title { font-weight: 700; }
.lr-sub { font-size: 12px; color: var(--muted); }
.lr-badge { font-weight: 800; font-size: 14px; color: var(--brand2); flex: 0 0 auto; min-width: 40px; text-align: right; }
.lesson-row.done .lr-badge { color: var(--ok); }

/* ==================== Tutor (Owly) ==================== */
.tutor { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; }
.tutor-face { font-size: 34px; flex: 0 0 auto; line-height: 1.1; }
.tutor-bubble {
  background: var(--panel2); padding: 12px 14px; border-radius: 4px 16px 16px 16px;
  font-size: 15px; line-height: 1.35; max-width: 90%;
}
.tutor.pass .tutor-bubble { background: rgba(34,197,94,.18); border: 1px solid rgba(34,197,94,.5); }

/* Puntos de progreso de la lección */
.lesson-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 4px; }
.lesson-title { font-weight: 800; font-size: 18px; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 999px; background: var(--panel2); }
.dot.past { background: var(--ok); }
.dot.on { background: var(--brand2); transform: scale(1.3); }

/* Tarjeta de práctica GRANDE (modo tutor) */
.card.practice.big .p-en { font-size: 34px; }
.card.practice.big .p-es { font-size: 18px; }
.card.practice.big .mic { font-size: 17px; padding: 14px 20px; }

/* Resumen al terminar la lección */
.lesson-summary { text-align: center; margin: 14px 0; color: var(--muted); }
.lesson-summary .ls-big { font-size: 40px; font-weight: 800; color: var(--text); }
.run-nav.center { justify-content: center; flex-wrap: wrap; gap: 10px; }

/* Letras aún más grandes en modo niño para el camino */
body.kid .level-title { font-size: 20px; }
body.kid .lr-title { font-size: 18px; }
body.kid .tutor-bubble { font-size: 18px; }
body.kid .card.practice.big .p-en { font-size: 42px; }

/* ==================== Ejercicios de comprensión (táctiles) ==================== */
.exercise { margin: 8px 0 4px; }
.ex-instr { font-size: 15px; color: var(--muted); margin: 6px 0 10px; }
.ex-stim { font-size: 26px; font-weight: 800; text-align: center; margin: 8px 0 14px; }
.ex-stim.big-emoji { font-size: 64px; }
.audio-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.opts { display: grid; grid-template-columns: 1fr; gap: 10px; }
.opts.emoji { grid-template-columns: repeat(3, 1fr); }
.opts.chips, .opts.chips.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  border: 2px solid var(--panel2); background: var(--panel); color: var(--text);
  border-radius: 14px; padding: 16px 14px; font-size: 18px; font-weight: 600;
  cursor: pointer; text-align: center; transition: transform .08s, border-color .15s;
}
.opt:active { transform: scale(.98); }
.opt.big-emoji { font-size: 46px; padding: 12px; }
.opt.correct { border-color: var(--ok); background: rgba(34,197,94,.18); }
.opt.wrong { border-color: var(--bad); background: rgba(239,68,68,.18); }
.opt:disabled { cursor: default; opacity: .95; }

/* Ordenar palabras */
.build-line { min-height: 52px; display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; border: 2px dashed var(--panel2); border-radius: 12px; margin-bottom: 12px; }
.build-line.ok { border-color: var(--ok); }
.build-line.bad { border-color: var(--bad); }
.chip { border: 0; background: var(--brand); color: #fff; border-radius: 10px; padding: 10px 14px; font-size: 16px; font-weight: 700; cursor: pointer; }
.chip.pick { background: var(--panel2); }
.ex-correct { width: 100%; color: var(--ok); font-weight: 700; margin-top: 6px; }

/* ==================== Sesión "Hoy" ==================== */
.session-top { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; }
.tutor-face.small { font-size: 24px; }
.sbar { flex: 1 1 auto; height: 10px; border-radius: 999px; background: var(--panel2); overflow: hidden; }
.sbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), var(--brand2)); transition: width .3s; }
.sbar-txt { font-size: 13px; color: var(--muted); min-width: 42px; text-align: right; }
.today-done { text-align: center; padding: 20px 0; }
.today-done .big-emoji { font-size: 60px; }
.done-stats { display: flex; flex-direction: column; gap: 8px; align-items: center; margin: 12px 0 18px; }
.done-stats .ds { font-size: 16px; color: var(--muted); }
.done-stats .ds b { color: var(--text); font-size: 20px; }
.ds.streak { color: #f59e0b; }

/* Confeti */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.confetti > i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall 2.2s linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .2; } }

/* ==================== Barras duales (Entiendo / Puedo decir) ==================== */
.overall .ov-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
.overall .bar { height: 12px; border-radius: 999px; background: var(--panel2); overflow: hidden; }
.overall .bar > i { display: block; height: 100%; width: 0; transition: width .5s ease; }
.overall .bar > i.u { background: linear-gradient(90deg, var(--ok), var(--brand2)); }
.overall .bar > i.p { background: linear-gradient(90deg, var(--close), #f59e0b); }

/* Emoji grande en tarjetas/meet */
.p-emoji { font-size: 60px; text-align: center; margin-bottom: 4px; }
.card.practice.big.meet .p-en { font-size: 34px; }
h3.section { margin: 22px 0 8px; font-size: 16px; }
.tile.wide { width: 100%; }

/* ==================== Historias ==================== */
.story { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 14px; }
.st-line { display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 12px; padding: 8px 10px; }
.st-text { flex: 1 1 auto; }
.st-en { font-weight: 700; }
.st-en.hidden { filter: blur(6px); }
.st-es { color: var(--muted); font-size: 14px; }
.story-q { margin-top: 10px; }
.b-bot.hidden { filter: blur(5px); }

/* Modo niño: controles más grandes */
body.kid .opt { font-size: 22px; padding: 20px; }
body.kid .opts.emoji { grid-template-columns: repeat(2, 1fr); }
body.kid .opt.big-emoji { font-size: 60px; }

/* ==================== Charla libre (LLM en el navegador) ==================== */
.llm-progress { margin: 10px 0; }
.llm-status { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.chat-tools { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.model-tag { font-size: 12px; color: var(--muted); }
.thread.chat { max-height: 52vh; overflow-y: auto; padding: 6px; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.chat-input { display: flex; gap: 8px; align-items: center; position: sticky; bottom: 0; padding: 8px 0; background: linear-gradient(180deg, transparent, var(--bg) 30%); }
.chat-in {
  flex: 1 1 auto; min-width: 0; border: 2px solid var(--panel2); background: var(--panel);
  color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 16px;
}
.chat-in:focus { outline: none; border-color: var(--brand2); }
.chat-input .mic { padding: 12px 14px; }
body.kid .chat-in { font-size: 18px; }

/* El atributo hidden debe ganar SIEMPRE (si no, display:flex de .chat-input lo anula). */
[hidden] { display: none !important; }
