:root {
  --ink: #17343a; --muted: #5a7076; --deep: #103f45; --teal: #176b65; --mint: #dff1e9; --bg: #f2f5f3; --line: #dbe5e1;
  --white: #fff; --ok: #157347; --ok-bg: #e3f5ea; --warn: #9a5b00; --warn-bg: #fff3dc; --bad: #b42318; --bad-bg: #fde8e6;
  --who: #1d4ed8; --who-bg: #dbe7ff; --aux: #c2410c; --aux-bg: #ffe8d6; --verb: #15803d; --verb-bg: #dcf5e3;
  --rest: #475569; --rest-bg: #edf1f6; --neg: #b91c1c; --neg-bg: #fde2e2; --qw: #7e22ce; --qw-bg: #f1e5ff;
  --shadow: 0 8px 24px #143b3414; --radius: 16px; --tabs: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 17px;
  padding-bottom: calc(var(--tabs) + env(safe-area-inset-bottom) + 12px);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid #54a99d; outline-offset: 2px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 27px; line-height: 1.15; letter-spacing: -.5px; margin-bottom: 8px; }
h2 { font-size: 21px; line-height: 1.2; margin-bottom: 10px; }
h3 { font-size: 17px; margin-bottom: 6px; }
p { margin-bottom: 12px; }
a { color: var(--teal); }
.small { font-size: 14px; color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Cabecera */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--deep); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px;
}
.brand { font-weight: 800; font-size: 19px; letter-spacing: -.4px; flex: 1; }
.brand span { color: #9fdfc7; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: #ffffff22; white-space: nowrap; }
.badge.off { background: #f5b04233; }
.icon-btn { border: 0; background: #ffffff1a; color: #fff; width: 40px; height: 40px; border-radius: 12px; font-size: 19px; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
main:focus { outline: none; }

/* Barra inferior */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0; background: none; height: var(--tabs); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 11.5px; color: var(--muted); font-weight: 600;
}
.tabs button .ic { font-size: 21px; line-height: 1; }
.tabs button.active { color: var(--deep); }
.tabs button.active .ic { transform: scale(1.12); }

/* Tarjetas */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.tight { padding: 14px; }
.hero { background: linear-gradient(140deg, #103f45, #176b65); color: #fff; border-radius: 20px; padding: 20px; margin-bottom: 16px; }
.hero p { color: #d9eee8; }
.hero .eyebrow { color: #a9dfcb; }
.eyebrow { font-size: 12px; letter-spacing: 1.2px; text-transform: uppercase; font-weight: 800; color: var(--teal); margin-bottom: 4px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* Botones */
.btn {
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 700; background: var(--deep); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; text-decoration: none;
}
.btn.block { width: 100%; }
.btn.big { font-size: 19px; min-height: 58px; border-radius: 16px; }
.btn.light { background: var(--mint); color: var(--deep); }
.btn.ghost { background: transparent; color: var(--deep); border: 1.5px solid var(--line); }
.btn.white { background: #fff; color: var(--deep); }
.btn.warn { background: var(--warn-bg); color: var(--warn); }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.sm { min-height: 38px; padding: 7px 12px; font-size: 15px; border-radius: 11px; }
.btn.rec { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px #b4231822; } }

.listen { display: flex; gap: 8px; flex-wrap: wrap; }
.listen .btn { flex: 1; min-width: 92px; }
.speaking { animation: glow 1s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px #176b6533; } }

/* Lista de opciones */
.list-btn {
  width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 14px;
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.list-btn .ic { font-size: 26px; width: 40px; text-align: center; flex-shrink: 0; }
.list-btn .t { font-weight: 700; }
.list-btn .d { font-size: 14px; color: var(--muted); }
.list-btn .go { color: var(--muted); font-size: 20px; }

/* Progreso */
.bar { height: 8px; background: #e2ebe7; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--teal); border-radius: 99px; transition: width .3s; }
.timer { height: 6px; background: #e2ebe7; border-radius: 99px; overflow: hidden; margin: 8px 0; }
.timer > i { display: block; height: 100%; background: var(--aux); width: 100%; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat strong { display: block; font-size: 24px; color: var(--deep); }
.stat span { font-size: 13px; color: var(--muted); }

/* Ejercicio */
.ex-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ex-head .bar { flex: 1; }
.chip { display: inline-block; font-size: 12.5px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: var(--mint); color: var(--deep); }
.prompt { font-size: 20px; font-weight: 700; line-height: 1.35; margin-bottom: 12px; }
.from { background: var(--rest-bg); border-radius: 12px; padding: 10px 12px; font-size: 18px; margin-bottom: 12px; }
.speaker { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.bubble-text { background: #f4f8f6; border: 1px dashed #c8d9d2; border-radius: 12px; padding: 10px 12px; font-size: 18px; }
.passage { background: #f7faf9; border-left: 4px solid var(--teal); padding: 10px 12px; border-radius: 8px; font-size: 18px; margin-bottom: 12px; }
.opts { display: grid; gap: 10px; }
.opt { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 13px 14px; text-align: left; font-size: 18px; font-weight: 600; min-height: 54px; }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
textarea.answer {
  width: 100%; min-height: 84px; border: 2px solid var(--line); border-radius: 14px; padding: 12px; font-size: 19px;
  resize: vertical; background: #fff;
}
textarea.answer:focus { border-color: var(--teal); outline: none; }
.tools { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.tools .btn { flex: 1; }
.notice { font-size: 14.5px; background: var(--warn-bg); color: #6b4300; border-radius: 12px; padding: 9px 12px; margin: 8px 0; }

/* Construir frase */
.line { min-height: 62px; border: 2px dashed #b9cec6; border-radius: 14px; padding: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: #fff; margin-bottom: 12px; }
.line:empty::before { content: 'Toca los bloques en orden…'; color: var(--muted); font-size: 15px; padding-left: 6px; }
.pool { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.tile { border: 2px solid #c9d8d2; background: #fff; border-radius: 12px; padding: 9px 13px; font-size: 18px; font-weight: 650; box-shadow: 0 2px 0 #c9d8d2; }
.tile.used { visibility: hidden; }
.tile.bad { border-color: var(--bad); background: var(--bad-bg); }

/* Ranuras de estructura (colores) */
.slot { display: inline-block; border-radius: 9px; padding: 3px 8px; font-weight: 700; margin: 2px 1px; }
.s-who { background: var(--who-bg); color: var(--who); }
.s-aux { background: var(--aux-bg); color: var(--aux); }
.s-verb { background: var(--verb-bg); color: var(--verb); }
.s-rest { background: var(--rest-bg); color: var(--rest); }
.s-neg { background: var(--neg-bg); color: var(--neg); }
.s-q { background: var(--qw-bg); color: var(--qw); }
table.slots { width: 100%; border-collapse: separate; border-spacing: 0 6px; font-size: 16px; }
table.slots th { font-size: 11.5px; letter-spacing: .8px; text-align: left; padding: 0 6px; }
table.slots td { padding: 0 2px; vertical-align: middle; }
table.slots td.play { width: 46px; text-align: right; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.explain p { margin-bottom: 8px; }
.explain strong { color: var(--deep); }

/* Retroalimentación */
.fb { border-radius: 16px; padding: 14px; margin-top: 14px; border: 2px solid; }
.fb.ok { background: var(--ok-bg); border-color: #9fd8b5; }
.fb.close { background: var(--warn-bg); border-color: #f0cf8f; }
.fb.bad { background: var(--bad-bg); border-color: #f3b7b0; }
.fb h3 { font-size: 19px; margin-bottom: 6px; }
.fb .model { font-size: 19px; font-weight: 700; margin: 6px 0 10px; }
.diff { font-size: 18px; line-height: 1.9; margin: 6px 0; }
.diff .same { color: var(--ok); }
.diff .missing { background: #c8f0d6; color: #0b5132; border-radius: 6px; padding: 1px 5px; font-weight: 700; }
.diff .extra { color: var(--bad); text-decoration: line-through; }
.why { font-size: 15.5px; color: #33494e; }
.coach { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-top: 10px; }

/* Diálogos */
.dlg-line { display: flex; gap: 10px; margin-bottom: 10px; align-items: flex-start; }
.dlg-line .txt { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 9px 12px; flex: 1; }
.dlg-line.you { flex-direction: row-reverse; }
.dlg-line.you .txt { background: var(--mint); border-color: #bfe3d3; }
.dlg-line.now .txt { border-color: var(--teal); box-shadow: 0 0 0 3px #176b6533; }
.dlg-line .es { font-size: 14px; color: var(--muted); margin-top: 3px; }
.dlg-line .who { font-size: 12px; font-weight: 700; color: var(--muted); }
.mini { border: 0; background: var(--mint); color: var(--deep); border-radius: 10px; padding: 6px 9px; font-size: 15px; font-weight: 700; margin-top: 6px; margin-right: 4px; }
.steps { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 4px; }
.steps button { flex-shrink: 0; border: 1.5px solid var(--line); background: #fff; border-radius: 99px; padding: 7px 13px; font-weight: 700; font-size: 14.5px; }
.steps button.active { background: var(--deep); color: #fff; border-color: var(--deep); }

/* Avatares */
.avatar { display: inline-flex; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: #e4eee8; }
.avatar.sm { width: 36px; height: 36px; }
.avatar.lg { width: 84px; height: 84px; }
.avatar svg { width: 100%; height: 100%; }
.you-av { display: inline-flex; width: 36px; height: 36px; border-radius: 50%; background: var(--deep); color: #fff; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0; }

/* Chat / llamada */
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.msg { max-width: 86%; padding: 10px 13px; border-radius: 16px; font-size: 17px; }
.msg.emma { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--deep); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.tip { background: var(--warn-bg); color: #6b4300; align-self: stretch; max-width: 100%; font-size: 15.5px; }
.msg .partial { opacity: .6; }
.call-orb { width: 120px; height: 120px; border-radius: 50%; margin: 10px auto 16px; background: radial-gradient(circle at 35% 30%, #4fb39f, #103f45); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 40px; transition: transform .15s; }
.call-orb.talking { animation: orb 0.9s ease-in-out infinite; }
@keyframes orb { 50% { transform: scale(1.07); } }

/* Fluidez */
.clock { font-size: 64px; font-weight: 800; text-align: center; color: var(--deep); font-variant-numeric: tabular-nums; }

/* Puedo… */
.cando { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cando:last-child { border-bottom: 0; }
.tri { display: flex; gap: 4px; flex-shrink: 0; }
.tri button { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 5px 8px; font-size: 13px; font-weight: 700; }
.tri button.on0 { background: #eef2f1; }
.tri button.on1 { background: var(--warn-bg); border-color: #f0cf8f; }
.tri button.on2 { background: var(--ok-bg); border-color: #9fd8b5; }

/* Aviso */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%) translateY(20px);
  background: #17343a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: 92vw; z-index: 30; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
select, input[type=text], input[type=password] { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fff; font-size: 17px; }
input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--teal); }

@media (min-width: 760px) {
  body { font-size: 17.5px; }
  .tabs { max-width: 720px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
