:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #1c2030;
  --muted: #6b7185;
  --border: #dde1ec;
  --accent: #4f6bed;
  --accent-ink: #ffffff;
  --accent-soft: #e3e8ff;
  --ok: #1f9d55;
  --ok-soft: #dcf5e6;
  --bad: #d64545;
  --bad-soft: #fde2e2;
  --warn: #c98a00;
  --locked: #b8bdcc;
  --shadow: 0 2px 10px rgba(20, 30, 60, .07);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1b1e29;
    --surface-2: #252937;
    --text: #e8eaf2;
    --muted: #9aa0b4;
    --border: #2f3445;
    --accent: #7b91ff;
    --accent-ink: #0f1220;
    --accent-soft: #273058;
    --ok: #3ccf7c;
    --ok-soft: #173826;
    --bad: #ff6b6b;
    --bad-soft: #3d1c1f;
    --warn: #f0b429;
    --locked: #4a5063;
    --shadow: 0 2px 10px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: 76px;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
a { color: var(--accent); }

/* ---------- top & tab bars ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; flex: 1; }
.lang-btn {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: 6px 12px; font-weight: 600;
}
.top-stats { display: flex; gap: 12px; font-weight: 600; font-size: .95rem; }
.top-stats span { white-space: nowrap; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; max-width: 120px; background: none; border: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .75rem; color: var(--muted); padding: 4px; border-radius: 10px;
}
.tabbar button .ico { font-size: 1.3rem; }
.tabbar button.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

body.in-session .topbar, body.in-session .tabbar { display: none; }
body.in-session { padding-bottom: 0; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

/* ---------- generic ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink);
}
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.block { width: 100%; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; width: 40px; height: 40px; font-size: 1.1rem;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn.big { width: 64px; height: 64px; font-size: 1.8rem; }
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .8rem;
}
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.bar.ok > div { background: var(--ok); }

/* ---------- home ---------- */
.today { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.ring { width: 84px; height: 84px; }
.ring circle { fill: none; stroke-width: 9; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--ok); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .5s; }
.ring text { fill: var(--text); font-weight: 700; font-size: 15px; text-anchor: middle; dominant-baseline: central; }

.level { margin: 22px 0 8px; display: flex; align-items: baseline; gap: 10px; }
.level h2 { margin: 0; font-size: 1.15rem; }
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.unit {
  text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; min-height: 104px;
}
.unit .uico { font-size: 1.6rem; }
.unit .utitle { font-weight: 600; font-size: .95rem; }
.unit.done { border-color: var(--ok); }
.unit.done .ustat { color: var(--ok); }
.unit.next { border: 2px solid var(--accent); }
.unit.locked { opacity: .55; }
.ustat { font-size: .78rem; color: var(--muted); font-weight: 600; }

/* ---------- unit page ---------- */
.grammar { font-size: .97rem; }
.grammar table { border-collapse: collapse; margin: 8px 0; }
.grammar td, .grammar th { border: 1px solid var(--border); padding: 4px 10px; text-align: left; }
.grammar code, .grammar b { color: var(--accent); }
.grammar code { font-family: inherit; font-weight: 600; }
.wordlist { list-style: none; padding: 0; margin: 0; }
.wordlist li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.wordlist li:last-child { border-bottom: 0; }
.wordlist .t { font-weight: 600; }
.rom { color: var(--muted); font-size: .85em; font-style: italic; }

/* ---------- session ---------- */
.session { max-width: 680px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.s-top { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.s-top .bar { flex: 1; }
.s-body { flex: 1; padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.s-kind { font-size: .85rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.prompt { font-size: 1.6rem; font-weight: 700; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.prompt.es { font-size: 1.35rem; }
.learn-card { text-align: center; padding: 28px 16px; }
.learn-card .t { font-size: 2rem; font-weight: 700; margin: 6px 0; }
.learn-card .es { font-size: 1.15rem; color: var(--muted); }
.options { display: grid; gap: 10px; }
.opt {
  text-align: left; background: var(--surface); border: 2px solid var(--border);
  border-radius: 12px; padding: 14px 16px; font-size: 1.05rem; display: flex; gap: 12px; align-items: center;
}
.opt .k { color: var(--muted); font-size: .8rem; border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { opacity: 1; cursor: default; }
.answer-input {
  width: 100%; font-size: 1.2rem; padding: 14px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
}
.answer-input:focus { outline: none; border-color: var(--accent); }
.tiles { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; }
.tiles.target { border-bottom: 2px dashed var(--border); padding-bottom: 10px; }
.tile {
  border: 2px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 8px 12px; font-size: 1.05rem; box-shadow: 0 2px 0 var(--border);
}
.tile.used { visibility: hidden; }
.s-foot {
  position: sticky; bottom: 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; gap: 12px; align-items: center;
}
.s-foot.ok { background: var(--ok-soft); }
.s-foot.bad { background: var(--bad-soft); }
.s-foot .fb { flex: 1; }
.s-foot .fb b { display: block; font-size: 1.05rem; }
.s-foot.ok .fb b { color: var(--ok); }
.s-foot.bad .fb b { color: var(--bad); }
.mic-state { min-height: 1.5em; }
.reading p { margin: 0; }
.sentence { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.sentence:last-child { border-bottom: 0; }
.sentence .tr { color: var(--muted); font-size: .92rem; }
.summary { text-align: center; padding-top: 40px; }
.summary .big { font-size: 3rem; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden { display: none; }
.modal .card { width: 100%; max-width: 420px; }
.lang-choice { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; margin-bottom: 8px; padding: 12px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); }
.lang-choice.active { border-color: var(--accent); }
.lang-choice .flag { font-size: 1.8rem; }

/* ---------- settings ---------- */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.setting:last-child { border-bottom: 0; }
select, input[type=range] { font: inherit; }
select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.notice { border-left: 4px solid var(--warn); }
.method h3 { margin-top: 1em; }
.method li { margin-bottom: 6px; }

@media (max-width: 480px) {
  .prompt { font-size: 1.35rem; }
  .learn-card .t { font-size: 1.6rem; }
  .top-stats { gap: 8px; font-size: .85rem; }
  .brand { font-size: 1rem; }
}

/* ---------- Hablar (chat con IA) ---------- */
.chat-head { gap: 8px; }
.chat { display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }
.msg { display: flex; flex-direction: column; max-width: 85%; gap: 4px; }
.msg.ai { align-self: flex-start; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 16px; font-size: 1.05rem; }
.msg.ai .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.me .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.bubble .tr { color: var(--muted); font-size: .92rem; margin-top: 6px; }
.bubble.typing { letter-spacing: 3px; color: var(--muted); }
.msg-tools { gap: 6px; margin-top: 6px; }
.icon-btn.sm { width: 30px; height: 30px; font-size: .9rem; }
.corr { font-size: .92rem; padding: 6px 10px; border-radius: 10px; max-width: 100%; }
.corr.bad { background: var(--bad-soft); }
.corr.bad b { color: var(--bad); }
.corr.ok { background: var(--ok-soft); color: var(--ok); }
.corr.ok b { color: var(--text); }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: .88rem; }
.chat-input {
  position: sticky; bottom: 70px; display: flex; gap: 8px; align-items: center;
  background: var(--bg); padding: 10px 0;
}
.chat-input textarea {
  flex: 1; resize: none; font: inherit; font-size: 1rem; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
}
.chat-input textarea:focus { outline: none; border-color: var(--accent); }
.chat-input .icon-btn.big { width: 52px; height: 52px; font-size: 1.4rem; }

/* ---------- introducción ---------- */
.modal .card.intro { max-width: 520px; max-height: 92vh; overflow-y: auto; }
.intro-hero { font-size: 3rem; text-align: center; }
.intro-list { padding-left: 1.2em; }
.intro-list li { margin-bottom: 8px; }
ul.intro-list { list-style: none; padding-left: 0; }
.dots { display: flex; justify-content: center; gap: 6px; margin: 14px 0; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.dots span.on { background: var(--accent); width: 22px; border-radius: 999px; }

/* ---------- práctica del día ---------- */
.card.daily { border: 2px solid var(--accent); }
.mission summary { cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: .85rem; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.chip.done { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.msg.sys { align-self: center; max-width: 100%; text-align: center; background: var(--ok-soft); color: var(--ok); padding: 8px 14px; border-radius: 12px; font-weight: 600; }

/* ---------- móvil / app instalada ---------- */
.topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
.session .s-top { padding-top: calc(14px + env(safe-area-inset-top)); }
.chat-input { bottom: calc(66px + env(safe-area-inset-bottom)); }
button, .tile, .opt { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
@media (max-width: 480px) {
  main { padding: 12px; }
  .tabbar button { font-size: .68rem; padding: 4px 2px; }
  .tabbar button .ico { font-size: 1.2rem; }
  .units { grid-template-columns: repeat(2, 1fr); }
  .chat-head .small.muted { display: none; }
  .msg { max-width: 92%; }
}

/* ---------- práctica de pronunciación ---------- */
.pron { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.mic-state { max-width: 520px; }
.mic-state.ok { color: var(--ok); font-weight: 700; font-size: 1.1rem; }
.mic-state.bad { color: var(--text); background: var(--bad-soft); padding: 8px 12px; border-radius: 10px; }
.pron-words { font-size: 1.35rem; font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.w-ok { color: var(--ok); }
.w-bad { color: var(--bad); background: var(--bad-soft); border: 0; border-radius: 6px; padding: 0 6px; font: inherit; text-decoration: underline dotted; }
.icon-btn.listening { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(214, 69, 69, .5); } 50% { box-shadow: 0 0 0 12px rgba(214, 69, 69, 0); } }

/* ---------- historias, escritura, exámenes, logros ---------- */
.st .w { cursor: pointer; border-radius: 4px; }
.st .w:hover { background: var(--accent-soft); }
button.chip { cursor: pointer; color: var(--text); }
button.chip:hover { border-color: var(--accent); }
.sheet {
  position: fixed; left: 50%; bottom: 76px; transform: translate(-50%, 140%); z-index: 40;
  width: min(520px, calc(100% - 24px)); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 16px; box-shadow: 0 8px 30px rgba(0,0,0,.25); transition: transform .25s;
}
.sheet.open { transform: translate(-50%, 0); }
body.in-session .sheet { bottom: 90px; }
.quiz-q { margin-bottom: 14px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.unit.exam { border-style: dashed; }
.unit.exam.next { border: 2px dashed var(--accent); }
.cert { text-align: center; border: 2px solid var(--ok); }
.why { margin-top: 6px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.badge { text-align: center; padding: 10px 6px; border-radius: 12px; border: 1px solid var(--border); opacity: .4; filter: grayscale(1); display: flex; flex-direction: column; gap: 2px; }
.badge.on { opacity: 1; filter: none; border-color: var(--ok); background: var(--ok-soft); }
.badge span { font-size: 1.6rem; }
.badge small { color: var(--muted); font-size: .72rem; }
.toast {
  position: fixed; top: 12px; left: 50%; transform: translate(-50%, -150%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  max-width: calc(100% - 24px); transition: transform .3s; box-shadow: var(--shadow);
}
.toast.show { transform: translate(-50%, 0); }

.icon-btn.listening-on { background: var(--accent); color: var(--accent-ink); }

.bar.meter { height: 18px; margin: 10px 0; }
.bar.meter > div { background: var(--ok); transition: width .05s; }
