/* =========================================================
   Polilingo Kichwa — estilos
   Layout: camino de temas centrado; en escritorio barra lateral
   + panel de progreso a la derecha; en celular barra superior
   y pestañas abajo. Lección = pantalla completa.
   ========================================================= */
:root {
  --bg: #ffffff;
  --bg-soft: #f3f7ef;
  --surface: #ffffff;
  --line: #e1e8da;
  --line-strong: #cfd9c6;
  --ink: #25301e;
  --ink-soft: #5f6c59;
  --brand: #46a302;
  --brand-deep: #2f7800;
  --brand-tint: #e6f5d6;
  --sun: #ffb400;
  --sun-deep: #d18b00;
  --fire: #ff7a1a;
  --heart: #ff4b5c;
  --sky: #1b97e0;
  --sky-deep: #1279b6;
  --sky-tint: #ddf2ff;
  --ok: #4c9a00;
  --ok-bg: #d9f7bf;
  --bad: #d9363e;
  --bad-bg: #ffe1e2;
  --lock: #dfe4da;
  --lock-deep: #bcc5b5;
  --lock-ink: #8b9685;
  --shadow: 0 10px 30px rgba(37, 48, 30, .14);
  --font-display: "Fredoka", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1812;
    --bg-soft: #142019;
    --surface: #18261d;
    --line: #283a2d;
    --line-strong: #34493a;
    --ink: #e9f2e4;
    --ink-soft: #9fb19a;
    --brand: #5cbd12;
    --brand-deep: #3b8400;
    --brand-tint: #1d3612;
    --sky-tint: #0f2c3d;
    --ok: #79d13a;
    --ok-bg: #1c3510;
    --bad: #ff6b70;
    --bad-bg: #3f1a1c;
    --lock: #26352a;
    --lock-deep: #1b261e;
    --lock-ink: #6f8270;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1812;
  --bg-soft: #142019;
  --surface: #18261d;
  --line: #283a2d;
  --line-strong: #34493a;
  --ink: #e9f2e4;
  --ink-soft: #9fb19a;
  --brand: #5cbd12;
  --brand-deep: #3b8400;
  --brand-tint: #1d3612;
  --sky-tint: #0f2c3d;
  --ok: #79d13a;
  --ok-bg: #1c3510;
  --bad: #ff6b70;
  --bad-bg: #3f1a1c;
  --lock: #26352a;
  --lock-deep: #1b261e;
  --lock-ink: #6f8270;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
img, svg { max-width: 100%; }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; margin: 0; text-wrap: balance; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; border-radius: 10px; }

/* ---------- Franja tejida (faja andina) ---------- */
.weave {
  height: 12px;
  background-color: rgba(0, 0, 0, .16);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='12'%3E%3Cpath d='M0 6 6 0l6 6-6 6z' fill='%23fff' fill-opacity='.42'/%3E%3Cpath d='M12 6l6-6 6 6-6 6z' fill='%23000' fill-opacity='.14'/%3E%3Cpath d='M5 5h2v2H5zM17 5h2v2h-2z' fill='%23fff' fill-opacity='.9'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-size: 24px 12px;
}

/* ---------- Botones 3D ---------- */
.btn {
  --b: var(--surface);
  --bd: var(--line-strong);
  --c: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 20px;
  border: 2px solid var(--bd);
  border-bottom-width: 5px;
  border-radius: 14px;
  background: var(--b);
  color: var(--c);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: transform .06s, filter .15s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px); border-bottom-width: 2px; margin-top: 3px; }
.btn[disabled] { --b: var(--lock); --bd: var(--lock-deep); --c: var(--lock-ink); cursor: not-allowed; filter: none; }
.btn[disabled]:active { transform: none; border-bottom-width: 5px; margin-top: 0; }
.btn-primary { --b: var(--brand); --bd: var(--brand-deep); --c: #fff; }
.btn-sky { --b: var(--sky); --bd: var(--sky-deep); --c: #fff; }
.btn-danger { --b: var(--bad); --bd: #a3242a; --c: #fff; }
.btn-light { --b: #fff; --bd: rgba(0, 0, 0, .18); --c: var(--lv, var(--brand)); }
.btn-ghost { --b: transparent; --bd: var(--line-strong); --c: var(--sky); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 6px 14px; font-size: .88rem; border-bottom-width: 4px; }

/* ---------- Estructura general ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar, .rail { display: none; }
.main {
  min-width: 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom, 0px));
}
.view { max-width: 600px; margin: 0 auto; }

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bg);
  border-bottom: 2px solid var(--line);
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 25;
  background: var(--bg);
}
.course-chip { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.course-chip svg { width: 34px; height: 34px; flex: none; }
.stats { display: flex; align-items: center; gap: 4px; }
.stat {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 8px; border: 0; border-radius: 12px; background: transparent;
  font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; cursor: pointer;
}
.stat:hover { background: var(--bg-soft); }
.stat-ico { font-size: 1.25rem; line-height: 1; }
.stat-fire .stat-num { color: var(--fire); }
.stat-xp .stat-num { color: var(--sun-deep); }
.stat-heart .stat-num { color: var(--heart); }
.stat.is-off { filter: grayscale(1); opacity: .6; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: var(--bg);
  border-top: 2px solid var(--line);
}
.tab-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-h); border: 0; background: transparent; cursor: pointer;
  font-size: .7rem; font-weight: 500; color: var(--ink-soft); letter-spacing: .02em;
}
.tab-btn .nav-ico { font-size: 1.5rem; line-height: 1; filter: grayscale(.6); opacity: .75; }
.tab-btn.is-active { color: var(--sky); }
.tab-btn.is-active .nav-ico { filter: none; opacity: 1; }

.brand { display: flex; align-items: center; gap: 10px; padding: 8px 12px 24px; text-decoration: none; color: var(--brand); }
.brand svg { width: 44px; height: 44px; flex: none; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; letter-spacing: -.01em; }
.brand-sub { display: block; font-family: var(--font-body); font-size: .72rem; font-weight: 500; color: var(--ink-soft); letter-spacing: .06em; text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-btn {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 14px; border: 2px solid transparent; border-radius: 14px;
  background: transparent; cursor: pointer; text-align: left;
  font-family: var(--font-display); font-weight: 600; font-size: .98rem; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-soft);
}
.nav-btn:hover { background: var(--bg-soft); }
.nav-btn .nav-ico { font-size: 1.7rem; line-height: 1; width: 34px; text-align: center; }
.nav-btn.is-active { color: var(--sky); background: var(--sky-tint); border-color: color-mix(in srgb, var(--sky) 45%, transparent); }

@media (min-width: 768px) {
  .app { grid-template-columns: 92px minmax(0, 1fr); }
  .tabbar { display: none; }
  .sidebar {
    display: block; position: sticky; top: 0; height: 100vh; height: 100dvh;
    padding: 20px 12px; border-right: 2px solid var(--line); overflow-y: auto;
  }
  .sidebar .brand-text, .sidebar .nav-label { display: none; }
  .sidebar .brand { justify-content: center; padding-inline: 0; }
  .sidebar .nav-btn { justify-content: center; padding-inline: 0; }
  .main { padding-block: 24px 64px; }
}
@media (min-width: 1160px) {
  .app { grid-template-columns: 250px minmax(0, 1fr) 360px; }
  .sidebar .brand-text, .sidebar .nav-label { display: inline; }
  .sidebar .brand-text { display: block; }
  .sidebar .brand { justify-content: flex-start; padding-inline: 12px; }
  .sidebar .nav-btn { justify-content: flex-start; padding-inline: 14px; }
  .topbar { display: none; }
  .rail {
    display: flex; flex-direction: column; gap: 18px;
    position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
    padding: 24px 24px 24px 8px;
  }
}

/* ---------- Panel derecho ---------- */
.rail-stats { display: flex; justify-content: space-between; }
.panel { border: 2px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 10px; background: var(--surface); }
.panel-title { font-size: 1.15rem; }
.panel-text { color: var(--ink-soft); font-size: .92rem; }
.goal-row { display: flex; align-items: center; gap: 12px; }
.goal-ico { font-size: 2rem; }
.bar { flex: 1; height: 16px; border-radius: 99px; background: var(--lock); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--sun); transition: width .5s ease; position: relative; }
.bar-fill::after { content: ""; position: absolute; left: 8px; right: 8px; top: 4px; height: 4px; border-radius: 9px; background: rgba(255, 255, 255, .45); }
.bar-label { font-size: .85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.tip-k { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; color: var(--brand); }

/* ---------- Camino (path) ---------- */
.unit { --lv: var(--brand); --lv-deep: color-mix(in srgb, var(--lv) 72%, #000); margin-bottom: 28px; }
.unit-banner {
  position: relative; overflow: hidden;
  border-radius: var(--radius);
  background: var(--lv); color: #fff;
  box-shadow: 0 5px 0 var(--lv-deep);
}
.unit-banner-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 14px; }
.unit-eyebrow { font-family: var(--font-display); font-weight: 600; font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; opacity: .9; }
.unit-title { font-size: 1.45rem; font-weight: 700; margin-top: 2px; }
.unit-desc { font-size: .9rem; opacity: .92; margin-top: 4px; }
.unit-guide-btn { flex: none; }
.unit.is-locked .unit-banner { background: var(--lock); color: var(--lock-ink); box-shadow: 0 5px 0 var(--lock-deep); }

.path { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 30px 0 8px; position: relative; }
.node-wrap { position: relative; transform: translateX(var(--x, 0px)); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.node {
  --nb: var(--lv); --nd: var(--lv-deep);
  position: relative;
  width: 74px; height: 68px;
  border: 0; border-radius: 50%;
  background: var(--nb);
  box-shadow: 0 7px 0 var(--nd);
  color: #fff; font-size: 1.9rem; line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform .06s, box-shadow .06s;
}
.node:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--nd); }
.node.is-locked { --nb: var(--lock); --nd: var(--lock-deep); color: var(--lock-ink); }
.node.is-done { --nb: var(--sun); --nd: var(--sun-deep); }
.node.is-review { border-radius: 22px; }
.node.is-current { box-shadow: 0 7px 0 var(--nd), 0 0 0 8px var(--bg), 0 0 0 13px color-mix(in srgb, var(--lv) 35%, transparent); }
.node-ico { pointer-events: none; }
.node.is-locked .node-ico { filter: grayscale(1); opacity: .5; }
.node-count { position: absolute; right: -6px; bottom: -4px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 99px; background: var(--surface); color: var(--sun-deep); border: 2px solid var(--sun); font-family: var(--font-display); font-weight: 700; font-size: .8rem; display: grid; place-items: center; }
.node-label { max-width: 140px; text-align: center; font-size: .82rem; font-weight: 500; color: var(--ink-soft); line-height: 1.25; }
.node-wrap.is-current .node-label { color: var(--ink); font-weight: 600; }
.node-bubble {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%);
  padding: 8px 14px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--lv); font-family: var(--font-display); font-weight: 700; letter-spacing: .06em; font-size: .9rem; white-space: nowrap;
  animation: bob 1.6s ease-in-out infinite;
}
.node-bubble::after { content: ""; position: absolute; left: 50%; top: 100%; width: 12px; height: 12px; background: var(--surface); border-right: 2px solid var(--line); border-bottom: 2px solid var(--line); transform: translate(-50%, -6px) rotate(45deg); }
@keyframes bob { 50% { transform: translate(-50%, -5px); } }
.path-mascot { position: absolute; width: 120px; pointer-events: none; opacity: .95; }
.path-mascot.left { left: 0; top: 150px; }
.path-mascot.right { right: 0; top: 640px; }
@media (max-width: 520px) { .path-mascot { width: 86px; } }

/* Popover del tema */
.pop {
  position: absolute; left: 50%; transform: translateX(-50%);
  z-index: 15; width: min(320px, 100%);
  padding: 16px; border-radius: var(--radius);
  background: var(--lv); color: #fff; box-shadow: var(--shadow);
  display: grid; gap: 12px; text-align: left;
}
.pop.is-locked { background: var(--surface); color: var(--ink); border: 2px solid var(--line); }
.pop::before { content: ""; position: absolute; left: calc(50% + var(--ax, 0px)); bottom: 100%; border: 10px solid transparent; border-bottom-color: var(--lv); transform: translateX(-50%); }
.pop .btn-sm.btn-light { --b: rgba(255, 255, 255, .16); --bd: rgba(0, 0, 0, .2); --c: #fff; }
.pop.is-locked::before { border-bottom-color: var(--line); }
.pop-title { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; }
.pop-sub { font-size: .9rem; opacity: .92; }
.pop-actions { display: grid; gap: 8px; }
.pop-words { display: flex; flex-wrap: wrap; gap: 6px; }
.pop-words span { padding: 2px 10px; border-radius: 99px; background: rgba(255, 255, 255, .22); font-size: .85rem; font-weight: 500; }
.pop.is-locked .pop-words span { background: var(--bg-soft); }

.course-end { text-align: center; padding: 24px 8px 8px; display: grid; gap: 10px; justify-items: center; color: var(--ink-soft); }
.course-end svg { width: 120px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(10, 16, 12, .55); }
.modal-card {
  width: min(640px, 100%); max-height: min(86vh, 860px); overflow: auto;
  border-radius: 22px; background: var(--bg); box-shadow: var(--shadow); border: 2px solid var(--line);
}
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; background: var(--bg); border-bottom: 2px solid var(--line); }
.modal-head h2 { font-size: 1.3rem; }
.modal-close { width: 40px; height: 40px; flex: none; border: 0; border-radius: 12px; background: var(--bg-soft); cursor: pointer; font-size: 1.3rem; color: var(--ink-soft); }
.modal-body { padding: 18px 20px 24px; display: grid; gap: 18px; }
.guide-sec { display: grid; gap: 8px; }
.guide-sec h3 { font-size: 1.1rem; color: var(--lv, var(--brand)); }
.guide-sec p { color: var(--ink); max-width: 65ch; }
.guide-ex { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.guide-ex li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 10px 12px; border-radius: 12px; background: var(--bg-soft); }
.ex-k { font-family: var(--font-display); font-weight: 600; font-size: 1.08rem; }
.ex-e { color: var(--ink-soft); font-size: .92rem; }
.confirm-text { color: var(--ink-soft); }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.confirm-actions .btn { flex: 1 1 160px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 80; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 500; box-shadow: var(--shadow);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
@media (min-width: 768px) { .toast { bottom: 28px; } }

/* ---------- Vistas generales ---------- */
.view-head { display: grid; gap: 6px; margin-bottom: 18px; }
.view-title { font-size: 1.7rem; }
.view-sub { color: var(--ink-soft); }
.search {
  width: 100%; min-height: 50px; padding: 10px 16px 10px 44px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--bg-soft) no-repeat 14px 50% / 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23889' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  font: inherit; color: var(--ink);
}
.search:focus { outline: none; border-color: var(--sky); }
.section-title { font-size: 1.15rem; margin: 22px 0 10px; display: flex; align-items: center; gap: 10px; }
.section-title .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--lv, var(--brand)); flex: none; }

/* Cartas: mazos */
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.deck {
  --lv: var(--brand);
  display: grid; gap: 4px; align-content: start; text-align: left;
  min-height: 118px; padding: 14px; cursor: pointer;
  border: 2px solid var(--line); border-bottom-width: 5px; border-radius: var(--radius); background: var(--surface);
}
.deck:hover { border-color: color-mix(in srgb, var(--lv) 55%, var(--line)); }
.deck-emoji { font-size: 1.8rem; line-height: 1; }
.deck-name { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; line-height: 1.2; }
.deck-count { font-size: .8rem; color: var(--ink-soft); }
.deck.is-locked { opacity: .55; cursor: not-allowed; }
.deck.is-done .deck-count { color: var(--sun-deep); font-weight: 600; }

/* Visor de cartas */
.viewer { display: grid; gap: 16px; justify-items: center; }
.viewer-nav { display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%; }
.viewer-count { font-family: var(--font-display); font-weight: 600; color: var(--ink-soft); min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.round-btn { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--line-strong); border-bottom-width: 5px; background: var(--surface); cursor: pointer; font-size: 1.3rem; display: grid; place-items: center; }
.round-btn:active { transform: translateY(3px); border-bottom-width: 2px; }
.mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; width: 100%; }
.mini { display: grid; gap: 2px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); text-align: left; cursor: pointer; }
.mini.is-active { border-color: var(--sky); background: var(--sky-tint); }
.mini-k { font-family: var(--font-display); font-weight: 600; font-size: 1rem; line-height: 1.2; overflow-wrap: anywhere; }
.mini-e { font-size: .82rem; color: var(--ink-soft); line-height: 1.25; }
.results { display: grid; gap: 8px; margin-top: 12px; }
.result { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); }
.result-emoji { font-size: 1.6rem; flex: none; }
.result-body { min-width: 0; flex: 1; }
.result-where { font-size: .76rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
.empty { padding: 28px 12px; text-align: center; color: var(--ink-soft); display: grid; gap: 10px; justify-items: center; }
.empty svg { width: 110px; }

/* ---------- Carta volteable ---------- */
.flip { --lv-deep: color-mix(in srgb, var(--lv, #46a302) 72%, #000); width: min(360px, 100%); aspect-ratio: 4 / 5; max-width: 100%; perspective: 1200px; cursor: pointer; border: 0; padding: 0; background: none; }
.flip-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3, .7, .3, 1.15); }
.flip.is-flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 22px; border-radius: 24px; text-align: center; overflow: hidden;
  border: 2px solid var(--line); border-bottom-width: 7px; background: var(--surface);
}
.flip-front .weave { position: absolute; left: 0; right: 0; top: 0; }
.flip-back { transform: rotateY(180deg); background: var(--lv, var(--brand)); border-color: var(--lv-deep, var(--brand-deep)); color: #fff; }
.flip-emoji { font-size: clamp(3.2rem, 14vw, 4.6rem); line-height: 1.1; }
.flip-word { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.6rem, 7vw, 2.3rem); line-height: 1.1; overflow-wrap: anywhere; }
.flip-mean { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.3rem, 5.5vw, 1.8rem); line-height: 1.15; }
.flip-note { font-size: .92rem; opacity: .95; max-width: 32ch; }
.flip-ex { margin-top: 4px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, .18); font-size: .92rem; width: 100%; }
.flip-ex b { display: block; font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.flip-hint { position: absolute; bottom: 14px; left: 0; right: 0; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.flip-back .flip-hint { color: rgba(255, 255, 255, .85); }

.speak-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 48px; height: 48px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--sky); color: #fff; box-shadow: 0 4px 0 var(--sky-deep); font-size: 1.25rem;
}
.speak-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--sky-deep); }
.speak-btn.is-big { width: 96px; height: 96px; border-radius: 24px; font-size: 2.4rem; box-shadow: 0 6px 0 var(--sky-deep); }
.speak-btn.is-sm { width: 36px; height: 36px; border-radius: 10px; font-size: .95rem; box-shadow: 0 3px 0 var(--sky-deep); margin-left: auto; }
.speak-btn.is-slow { background: var(--surface); color: var(--sky); border: 2px solid var(--line-strong); box-shadow: 0 4px 0 var(--line-strong); }

/* ---------- Lección ---------- */
.lesson {
  position: fixed; inset: 0; z-index: 50;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--bg);
  padding-top: env(safe-area-inset-top, 0px);
}
.lesson-head {
  display: flex; align-items: center; gap: 14px;
  width: min(1000px, 100%); margin: 0 auto;
  padding-block: 16px 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.lesson-close { width: 40px; height: 40px; flex: none; border: 0; background: transparent; cursor: pointer; color: var(--lock-ink); font-size: 1.6rem; border-radius: 12px; }
.lesson-close:hover { background: var(--bg-soft); }
.progress { flex: 1; height: 18px; border-radius: 99px; background: var(--lock); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 99px; background: var(--brand); transition: width .4s ease; position: relative; }
.progress-fill::after { content: ""; position: absolute; left: 10px; right: 10px; top: 4px; height: 5px; border-radius: 9px; background: rgba(255, 255, 255, .35); }
.hearts { display: inline-flex; align-items: center; gap: 4px; font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--heart); }
.hearts.is-hit { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.lesson-body {
  overflow-y: auto;
  padding-block: 12px 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.ex { width: min(600px, 100%); margin: 0 auto; display: grid; gap: 18px; animation: ex-in .3s ease; }
@keyframes ex-in { from { opacity: 0; transform: translateX(18px); } }
.ex-kicker { justify-self: start; display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 99px; background: var(--brand-tint); color: var(--brand-deep); font-family: var(--font-display); font-weight: 700; font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; }
:root[data-theme="dark"] .ex-kicker { color: var(--ok); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ex-kicker { color: var(--ok); } }
.ex-kicker.is-review { background: var(--bad-bg); color: var(--bad); }
.ex-title { font-size: clamp(1.35rem, 4.6vw, 1.8rem); font-weight: 700; }
.ex-prompt { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.prompt-word { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.5rem, 6vw, 2rem); overflow-wrap: anywhere; }
.prompt-sub { color: var(--ink-soft); }
.bubble-row { display: flex; align-items: flex-end; gap: 10px; }
.bubble-row svg { width: 96px; flex: none; }
.speech { position: relative; flex: 1; min-width: 0; padding: 14px 16px; border: 2px solid var(--line); border-radius: 18px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.speech::before { content: ""; position: absolute; left: -9px; bottom: 22px; width: 14px; height: 14px; background: var(--bg); border-left: 2px solid var(--line); border-bottom: 2px solid var(--line); transform: rotate(45deg); }
.speech-text { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; min-width: 0; overflow-wrap: anywhere; }
.speech-sub { flex-basis: 100%; color: var(--ink-soft); font-size: .9rem; }

.opts { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 10px 14px;
  border: 2px solid var(--line); border-bottom-width: 5px; border-radius: 16px; background: var(--surface);
  cursor: pointer; text-align: left; font-size: 1.05rem;
}
.opt:hover { background: var(--bg-soft); }
.opt-key { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border: 2px solid var(--line); border-radius: 9px; color: var(--ink-soft); font-size: .85rem; font-weight: 600; }
.opt-text { min-width: 0; overflow-wrap: anywhere; }
.opt-text.is-k { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; }
.opt.is-selected { border-color: var(--sky); background: var(--sky-tint); color: var(--sky-deep); }
:root[data-theme="dark"] .opt.is-selected { color: #8fd3ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .opt.is-selected { color: #8fd3ff; } }
.opt.is-selected .opt-key { border-color: var(--sky); color: var(--sky); }
.opt.is-right { border-color: var(--ok); background: var(--ok-bg); }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.pics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.pic { flex-direction: column; justify-content: center; text-align: center; min-height: 150px; gap: 6px; }
.pic .opt-key { position: absolute; top: 10px; left: 10px; }
.pic { position: relative; }
.pic-emoji { font-size: 3rem; line-height: 1.1; }
.pic .opt-text { font-weight: 500; }

.match { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.match-col { display: grid; gap: 10px; align-content: start; }
.mbtn {
  min-height: 58px; padding: 8px 10px; border: 2px solid var(--line); border-bottom-width: 5px; border-radius: 14px;
  background: var(--surface); cursor: pointer; font-size: 1rem; overflow-wrap: anywhere; line-height: 1.2;
}
.mbtn.is-k { font-family: var(--font-display); font-weight: 600; font-size: 1.08rem; }
.mbtn.is-selected { border-color: var(--sky); background: var(--sky-tint); }
.mbtn.is-matched { border-color: var(--line); background: var(--bg-soft); color: var(--lock-ink); opacity: .55; cursor: default; border-bottom-width: 2px; margin-top: 3px; }
.mbtn.is-wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .35s; }
.mbtn.is-good { border-color: var(--ok); background: var(--ok-bg); }

.answer-zone {
  min-height: 116px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; padding: 8px 0;
  background-image: linear-gradient(var(--line) 2px, transparent 2px);
  background-size: 100% 58px; background-position: 0 55px;
}
.bank { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding-top: 8px; }
.tile {
  min-height: 46px; padding: 8px 14px; border: 2px solid var(--line); border-bottom-width: 5px; border-radius: 13px;
  background: var(--surface); cursor: pointer; font-size: 1.05rem; line-height: 1.2;
}
.tile.is-k { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; }
.tile.is-used { color: transparent; background: var(--lock); border-color: var(--lock); cursor: default; }
.tile:not(.is-used):active { transform: translateY(3px); border-bottom-width: 2px; }

.type-wrap { display: grid; gap: 10px; }
.type-input {
  width: 100%; min-height: 130px; resize: none; padding: 14px 16px;
  border: 2px solid var(--line); border-radius: 16px; background: var(--bg-soft); color: var(--ink);
  font: 600 1.2rem var(--font-display);
}
.type-input:focus { outline: none; border-color: var(--sky); background: var(--surface); }
.char-row { display: flex; gap: 8px; }
.char-btn { min-width: 46px; height: 42px; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 11px; background: var(--surface); cursor: pointer; font: 600 1.1rem var(--font-display); }

.fill-sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; }
.blank { min-width: 90px; min-height: 44px; padding: 4px 12px; border-bottom: 3px solid var(--ink-soft); display: inline-flex; align-items: center; justify-content: center; color: var(--sky); }
.fill-mean { color: var(--ink-soft); }
.listen-row { display: flex; justify-content: center; gap: 16px; align-items: flex-end; padding: 6px 0; }

.lesson-foot { border-top: 2px solid var(--line); background: var(--bg); padding-bottom: env(safe-area-inset-bottom, 0px); }
.lesson-foot.is-ok { background: var(--ok-bg); border-color: transparent; }
.lesson-foot.is-bad { background: var(--bad-bg); border-color: transparent; }
.foot-inner {
  width: min(1000px, 100%); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding-block: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.foot-inner .btn { min-width: 170px; }
.fb { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 260px; }
.fb-ico { flex: none; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 1.8rem; background: var(--surface); }
.fb-title { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; }
.fb-text { font-size: .98rem; overflow-wrap: anywhere; }
.is-ok .fb-title, .is-ok .fb-text { color: var(--ok); }
.is-bad .fb-title, .is-bad .fb-text { color: var(--bad); }
.fb-text b { font-family: var(--font-display); }
@media (max-width: 640px) {
  .foot-inner .btn { flex: 1 1 100%; }
  .fb-ico { width: 44px; height: 44px; font-size: 1.4rem; }
}

/* Final de lección */
.finish { width: min(520px, 100%); margin: 0 auto; display: grid; gap: 20px; justify-items: center; text-align: center; padding-top: 12px; }
.finish svg.mascot { width: 160px; }
.finish-title { font-size: clamp(1.7rem, 6vw, 2.2rem); color: var(--sun-deep); }
.finish-title.is-bad { color: var(--bad); }
.finish-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; }
.fstat { --c: var(--sun); border: 2px solid var(--c); border-radius: 16px; overflow: hidden; background: var(--c); }
.fstat-label { padding: 4px 6px; color: #fff; font-family: var(--font-display); font-weight: 700; font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; }
.fstat-val { padding: 12px 4px; background: var(--bg); border-radius: 13px; font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; color: var(--c); font-variant-numeric: tabular-nums; }
.fstat-acc { --c: var(--brand); }
.fstat-time { --c: var(--sky); }
.streak-up { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 99px; background: color-mix(in srgb, var(--fire) 16%, transparent); color: var(--fire); font-family: var(--font-display); font-weight: 700; }

/* ---------- Practicar ---------- */
.practice-grid { display: grid; gap: 12px; }
.pcard {
  display: flex; align-items: center; gap: 16px; padding: 18px; text-align: left; cursor: pointer;
  border: 2px solid var(--line); border-bottom-width: 5px; border-radius: 18px; background: var(--surface);
}
.pcard:hover { background: var(--bg-soft); }
.pcard[disabled] { opacity: .5; cursor: not-allowed; }
.pcard-ico { flex: none; width: 60px; height: 60px; border-radius: 16px; display: grid; place-items: center; font-size: 2rem; background: var(--bg-soft); }
.pcard-title { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; }
.pcard-text { color: var(--ink-soft); font-size: .9rem; }

/* ---------- Perfil ---------- */
.profile-head { display: flex; align-items: center; gap: 16px; padding-bottom: 18px; border-bottom: 2px solid var(--line); margin-bottom: 8px; }
.profile-head svg { width: 92px; flex: none; }
.profile-name { font-size: 1.6rem; }
.profile-meta { color: var(--ink-soft); font-size: .92rem; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile-stat { display: flex; align-items: center; gap: 12px; padding: 14px; border: 2px solid var(--line); border-radius: 16px; }
.tile-stat-ico { font-size: 1.7rem; flex: none; }
.tile-stat-val { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-stat-label { font-size: .82rem; color: var(--ink-soft); }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; text-align: center; }
.day { display: grid; gap: 4px; justify-items: center; font-size: .78rem; color: var(--ink-soft); font-weight: 600; }
.day i { width: 34px; height: 34px; border-radius: 50%; background: var(--lock); display: grid; place-items: center; font-style: normal; font-size: 1rem; }
.day.is-on i { background: var(--fire); color: #fff; }
.day.is-today { color: var(--ink); }
.day.is-today i { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--fire); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.badge { display: grid; gap: 4px; justify-items: center; text-align: center; padding: 14px 10px; border: 2px solid var(--line); border-radius: 16px; filter: grayscale(1); opacity: .5; }
.badge.is-earned { filter: none; opacity: 1; border-color: color-mix(in srgb, var(--sun) 60%, var(--line)); }
.badge-ico { font-size: 2rem; line-height: 1; }
.badge-name { font-family: var(--font-display); font-weight: 600; font-size: .95rem; line-height: 1.2; }
.badge-text { font-size: .76rem; color: var(--ink-soft); line-height: 1.3; }
.settings { display: grid; border: 2px solid var(--line); border-radius: 16px; overflow: hidden; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border-top: 2px solid var(--line); }
.set-row:first-child { border-top: 0; }
.set-label { display: grid; min-width: 0; }
.set-label b { font-weight: 600; }
.set-label span { font-size: .84rem; color: var(--ink-soft); }
.switch { appearance: none; -webkit-appearance: none; flex: none; width: 52px; height: 30px; border-radius: 99px; background: var(--lock-deep); position: relative; cursor: pointer; transition: background .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(22px); }
.select { flex: none; min-height: 40px; padding: 6px 10px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; }
.sources { display: grid; gap: 8px; font-size: .9rem; color: var(--ink-soft); }
.sources a { color: var(--sky); }
.sources ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.guide-ex li .ex-e { flex: 1 1 auto; }

/* ---------- Mascota ---------- */
.mascot { display: block; }
.mascot .blink { animation: blink 4.5s infinite; transform-origin: center; transform-box: fill-box; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }

/* ---------- Carga ---------- */
.loading { min-height: 60vh; display: grid; place-items: center; text-align: center; gap: 12px; color: var(--ink-soft); padding: 24px; }
.loading svg { width: 120px; }
.error-box { max-width: 520px; padding: 18px; border: 2px solid var(--bad); border-radius: 16px; background: var(--bad-bg); color: var(--ink); text-align: left; display: grid; gap: 8px; }
.error-box code { font-size: .88rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
