:root {
  --bg: #f6f3ee; --bg-2: #efebe4; --card: #ffffff;
  --text: #1d1c1a; --text-2: #6f6b64; --text-3: #a39e95;
  --line: rgba(60, 50, 35, .11); --fill: rgba(110, 100, 85, .1); --fill-2: rgba(110, 100, 85, .17);
  --bar: rgba(246, 243, 238, .82);
  --tint: #16927b; --tint-soft: rgba(22, 146, 123, .12);
  --accent: #f28a1f; --accent-soft: rgba(242, 138, 31, .14);
  --ok: #2f9a5d; --ok-soft: rgba(47, 154, 93, .12);
  --bad: #d9483b; --bad-soft: rgba(217, 72, 59, .1);
  --gold: #e0ac2e; --silver: #a3abb4; --bronze: #c98552;
  --shadow: 0 1px 2px rgba(60, 45, 20, .05), 0 6px 20px rgba(60, 45, 20, .05);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211; --bg-2: #1a1918; --card: #1f1e1c;
    --text: #f2efea; --text-2: #a9a49b; --text-3: #6f6b64;
    --line: rgba(255, 255, 255, .09); --fill: rgba(255, 255, 255, .07); --fill-2: rgba(255, 255, 255, .12);
    --bar: rgba(18, 18, 17, .8);
    --tint: #2fbf9f; --tint-soft: rgba(47, 191, 159, .16);
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.4 -apple-system, system-ui, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--tint); text-decoration: none; }
svg { display: block; }

/* ——— Barra de navegación ——— */
.nav {
  position: fixed; inset: 0 0 auto 0; z-index: 20; height: calc(48px + var(--safe-t)); padding-top: var(--safe-t);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid transparent; transition: border-color .2s;
}
.nav.scrolled, .nav.detail { border-bottom-color: var(--line); }
.nav-title { font-weight: 600; font-size: 17px; opacity: 0; transition: opacity .2s; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav.scrolled .nav-title, .nav.detail .nav-title { opacity: 1; }
.nav-back { justify-self: start; display: flex; align-items: center; gap: 2px; color: var(--tint); padding: 8px 12px 8px 6px; font-size: 17px; }
.nav-right { justify-self: end; padding-right: 12px; }

/* ——— Vista ——— */
.view { padding: calc(56px + var(--safe-t)) 16px calc(100px + var(--safe-b)); max-width: 720px; margin: 0 auto; min-height: 100vh; }
.view.detail { padding-top: calc(64px + var(--safe-t)); }
.large-title { font-size: 34px; font-weight: 700; letter-spacing: .3px; margin: 4px 4px 2px; }
.subtitle { color: var(--text-2); margin: 0 4px 18px; font-size: 15px; }
.h2 { font-size: 22px; font-weight: 700; margin: 0 4px 6px; }
.section-head { color: var(--text-2); font-size: 13px; text-transform: uppercase; letter-spacing: .4px; margin: 26px 16px 7px; }
.section-foot { color: var(--text-2); font-size: 13px; margin: 7px 16px 0; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

/* ——— Tarjetas y grupos ——— */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.group { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; min-height: 52px;
  padding: 10px 16px; position: relative; background: none;
}
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 60px; border-top: .5px solid var(--line); }
.group.plain .row + .row::before { left: 16px; }
button.row:active, a.row:active { background: var(--fill); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; color: var(--text); }
.row-sub { font-size: 13px; color: var(--text-2); margin-top: 1px; }
.row-value { color: var(--text-2); font-size: 15px; }
.chev { color: var(--text-3); width: 8px; flex: none; }
.icon-tile { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; }
.icon-tile svg { width: 19px; height: 19px; }

/* ——— Botones ——— */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 50px; border-radius: 14px;
  background: var(--tint); color: #fff; font-weight: 600; font-size: 17px; transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.98); opacity: .9; }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn.secondary { background: var(--fill); color: var(--tint); }
.btn.accent { background: var(--accent); }
.btn.small { height: 36px; width: auto; padding: 0 16px; font-size: 15px; border-radius: 18px; }
.btn-row { display: flex; gap: 10px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--fill); color: var(--tint); flex: none; }
.icon-btn svg { width: 18px; height: 18px; }
.link-btn { color: var(--tint); font-size: 15px; padding: 6px 4px; }

/* ——— Control segmentado ——— */
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.seg button { flex: 1; padding: 6px 8px; border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--text); }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg button.on { background: #3a3936; } }

/* ——— Interruptor ——— */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--fill-2); border-radius: 31px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); transition: transform .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ——— Inicio ——— */
.hero { display: flex; gap: 14px; align-items: center; }
.hero img { width: 76px; height: 76px; flex: none; }
.hero-text b { display: block; font-size: 17px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat { background: var(--fill); border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.stat svg { width: 22px; height: 22px; flex: none; }
.stat-num { font-size: 20px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-2); }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--fill-2); flex: none; display: grid; place-items: center; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.check svg { width: 14px; height: 14px; }
.week { display: flex; justify-content: space-between; align-items: flex-end; height: 86px; gap: 6px; margin-top: 4px; }
.week-day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week-bar { width: 100%; max-width: 28px; border-radius: 6px; background: var(--tint); min-height: 4px; }
.week-bar.zero { background: var(--fill-2); }
.week-label { font-size: 11px; color: var(--text-2); }
.week-day.today .week-label { color: var(--text); font-weight: 600; }
.banner { display: flex; gap: 12px; align-items: center; border-radius: var(--radius); padding: 14px 16px; background: var(--accent-soft); margin-bottom: 12px; }
.banner svg { width: 26px; height: 26px; color: var(--accent); flex: none; }
.bar { height: 6px; background: var(--fill); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ——— Rejilla de práctica ——— */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { color: var(--text); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 22px; min-height: 120px; }
.tile:active { transform: scale(.98); }
.tile-title { font-weight: 600; font-size: 17px; }
.tile-sub { font-size: 13px; color: var(--text-2); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--fill); color: var(--text-2); }
.badge.tint { background: var(--tint-soft); color: var(--tint); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.medal { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 2px dashed var(--fill-2); }
.medal.m1 { background: var(--bronze); border: 0; } .medal.m2 { background: var(--silver); border: 0; } .medal.m3 { background: var(--gold); border: 0; }

/* ——— Lecciones y ejercicios ——— */
.explain h3 { font-size: 15px; margin: 0 0 4px; color: var(--tint); }
.explain p { margin: 0; }
.explain .item + .item { margin-top: 14px; padding-top: 14px; border-top: .5px solid var(--line); }
.progress { height: 8px; background: var(--fill); border-radius: 4px; overflow: hidden; margin: 4px 0 22px; }
.progress > i { display: block; height: 100%; background: var(--tint); border-radius: 4px; transition: width .3s; }
.q-label { font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.q { font-size: 24px; font-weight: 600; line-height: 1.3; margin-bottom: 4px; }
.q-es { color: var(--text-2); margin-bottom: 18px; }
.opts { display: grid; gap: 10px; margin-top: 18px; }
.opt { background: var(--card); box-shadow: var(--shadow); border-radius: 14px; padding: 15px 16px; text-align: left; font-size: 17px; border: 2px solid transparent; }
.opt.sel { border-color: var(--tint); background: var(--tint-soft); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.field { width: 100%; height: 52px; border-radius: 14px; border: 0; background: var(--card); box-shadow: var(--shadow); padding: 0 16px; font-size: 19px; outline: 2px solid transparent; margin-top: 18px; }
.field:focus { outline-color: var(--tint); }
.field.right { outline-color: var(--ok); } .field.wrong { outline-color: var(--bad); }
.answer-zone { min-height: 58px; border-bottom: 2px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0; margin-top: 10px; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.chip { background: var(--card); box-shadow: var(--shadow); border-radius: 10px; padding: 9px 13px; font-size: 17px; border: .5px solid var(--line); }
.chip.used { opacity: .25; pointer-events: none; }
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 14px 16px calc(14px + var(--safe-b)); background: var(--bar); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border-top: .5px solid var(--line); }
.dock-inner { max-width: 688px; margin: 0 auto; }
.feedback { border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; font-size: 15px; }
.feedback b { display: block; font-size: 17px; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.ko { background: var(--bad-soft); color: var(--bad); }
.feedback .fx { color: var(--text); margin-top: 4px; }
body.has-dock .tabbar { display: none; }
.result { text-align: center; padding-top: 30px; }
.result img { width: 140px; height: 140px; margin: 0 auto 8px; }
.result .big { font-size: 48px; font-weight: 800; }

/* ——— Historias ——— */
.story-line { font-size: 20px; line-height: 1.6; margin: 0; padding: 10px 6px; border-radius: 10px; transition: background .2s; }
.story-line.speaking { background: var(--accent-soft); }
.story-line + .story-line { border-top: .5px solid var(--line); }
.w { border-radius: 4px; cursor: pointer; }
.w:active, .w.hl { background: var(--tint-soft); }
.tr { display: block; font-size: 15px; color: var(--text-2); line-height: 1.4; margin-top: 2px; }
.story-tools { display: flex; gap: 8px; margin: 0 0 14px; }

/* ——— Tarjetas ——— */
.flash { perspective: 1200px; height: 280px; margin: 8px 0 18px; }
.flash-inner { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.flash-face.back { transform: rotateY(180deg); }
.flash-word { font-size: 32px; font-weight: 700; }
.flash-hint { color: var(--text-3); font-size: 13px; position: absolute; bottom: 16px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grades button { border-radius: 12px; padding: 10px 4px; background: var(--fill); font-size: 14px; font-weight: 600; line-height: 1.2; }
.grades button small { display: block; font-weight: 400; font-size: 11px; color: var(--text-2); margin-top: 2px; }
.grades .g0 { color: var(--bad); } .grades .g1 { color: var(--accent); } .grades .g2 { color: var(--ok); } .grades .g3 { color: var(--tint); }

/* ——— Emparejar y rápido ——— */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .opt { text-align: center; padding: 14px 8px; font-size: 16px; min-height: 58px; }
.match .opt.done { opacity: .3; pointer-events: none; border-color: var(--ok); }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-2); }
.speed-card { text-align: center; padding: 34px 16px; }
.speed-en { font-size: 30px; font-weight: 700; }
.speed-es { font-size: 20px; color: var(--text-2); margin-top: 8px; }
.yn { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.yn .btn.no { background: var(--bad); }
.yn .btn.yes { background: var(--ok); }

/* ——— Barra de pestañas ——— */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + var(--safe-b)); background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); border-top: .5px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 500; color: var(--text-3); padding: 2px 12px; min-width: 64px; }
.tab svg { width: 26px; height: 26px; }
.tab.on { color: var(--tint); }

/* ——— Hoja inferior y aviso ——— */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .3); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 14px 14px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); animation: up .28s cubic-bezier(.2, .8, .2, 1); max-height: 90vh; overflow: auto; }
.sheet-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); margin: 0 auto 14px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translate(-50%, -200%); visibility: hidden; z-index: 60; background: var(--card); color: var(--text); box-shadow: 0 8px 30px rgba(0, 0, 0, .15); border-radius: 22px; padding: 10px 18px; font-size: 15px; font-weight: 600; transition: transform .35s cubic-bezier(.2, .8, .2, 1); white-space: nowrap; }
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.empty { text-align: center; padding: 40px 20px 10px; }
.empty img { width: 120px; height: 120px; margin: 0 auto 10px; }
.input-label { font-size: 13px; color: var(--text-2); margin: 14px 4px 6px; display: block; }
.sheet .field { margin-top: 0; }
.verb-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.verb-table th { text-align: left; font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; padding: 10px 8px; }
.verb-table td { padding: 10px 8px; border-top: .5px solid var(--line); }
.verb-table td:last-child { color: var(--text-2); }
input[type=range] { width: 100%; accent-color: var(--tint); }

/* ——— Shadowing ——— */
.shadow-card { text-align: center; padding: 28px 18px 18px; }
.shadow-line { font-size: 26px; font-weight: 600; line-height: 1.5; }
.sw { border-radius: 6px; padding: 0 2px; transition: color .2s, background .2s; }
.sw.now { background: var(--accent-soft); }
.sw.ok { color: var(--ok); }
.sw.miss { color: var(--text-3); }
.heard { font-size: 15px; margin-top: 14px; min-height: 21px; font-style: italic; }
.shadow-ctrls { display: flex; justify-content: center; align-items: center; gap: 28px; margin: 26px 0 10px; }
.mic { width: 78px; height: 78px; border-radius: 50%; background: var(--tint); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 18px rgba(22, 146, 123, .35); transition: transform .15s, background .2s; }
.mic svg { width: 32px; height: 32px; }
.mic:active { transform: scale(.94); }
.mic.rec { background: var(--bad); box-shadow: 0 0 0 0 rgba(217, 72, 59, .5); animation: pulse 1.4s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 18px rgba(217, 72, 59, 0); } 100% { box-shadow: 0 0 0 0 rgba(217, 72, 59, 0); } }
#result .btn-row { margin-top: 4px; }
