/* Mobile-first. Una cosa en pantalla a la vez, botones grandes para el pulgar. */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #ecebe6;
  --text: #1c1c1e;
  --muted: #66666c;
  --line: #e0ded8;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #e5ebfd;
  --good: #1b7442;
  --good-bg: #e1f2e7;
  --bad: #b13f16;
  --bad-bg: #fbe8df;
  --hl: #fff0b0;
  --hl-ink: #3b3000;
  --radius: 16px;
  --tap: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1c1c20;
    --surface-2: #29292f;
    --text: #f1f1f3;
    --muted: #a0a0a8;
    --line: #313137;
    --accent: #8ca8ff;
    --accent-ink: #0b1024;
    --accent-soft: #1f2748;
    --good: #72dc9d;
    --good-bg: #153321;
    --bad: #ff9c74;
    --bad-bg: #3b1f14;
    --hl: #4d4112;
    --hl-ink: #ffeaa6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h2 { font-size: 1.35rem; line-height: 1.25; margin: 0; }
h3 { font-size: 1.05rem; margin: 0; }
p, ul { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.center { text-align: center; }
.good { color: var(--good); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }

/* ---------- Estructura ---------- */

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px;
  background: var(--bg);
}
.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: -12px;
  border-radius: 12px;
  color: var(--text);
  font-size: 2.2rem;
  line-height: 1;
  text-decoration: none;
}
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  outline: none;
}
.view-inner, .stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.view-inner { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.loading { padding: 32px 0; text-align: center; color: var(--muted); }
.section-title { font-size: 1rem; font-weight: 600; color: var(--muted); margin: 8px 0 8px; }

/* ---------- Botones ---------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-good { background: var(--good-bg); color: var(--good); }
.btn-bad { background: var(--bad-bg); color: var(--bad); }
.btn-danger { background: transparent; color: var(--bad); border: 1.5px solid currentColor; }
.btn.is-recording { background: var(--bad-bg); color: var(--bad); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  margin-left: 8px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 1.1rem;
  vertical-align: middle;
  cursor: pointer;
}
:is(a, button, input, textarea, select, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Botones de acción pegados abajo */
.actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding: 16px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 16px);
}
.actions:empty { display: none; }

/* ---------- Inicio ---------- */

.home-top { display: flex; flex-direction: column; gap: 2px; padding-top: 4px; }
.streak { font-size: 1.5rem; font-weight: 700; }
.streak:not(.is-done) { opacity: 0.75; }
.start {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 132px;
  padding: 20px;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  text-align: center;
}
.start:active { transform: scale(0.99); }
.start-title { font-size: 1.6rem; font-weight: 700; }
.start-sub { font-size: 1rem; opacity: 0.9; }

.todo, .lessons, .verb-list, .boxes, .pairs { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.todo a {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
}
.todo a::after { content: '›'; margin-left: auto; padding-left: 12px; color: var(--muted); font-size: 1.4rem; }
.lesson-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}
.lesson-icon { font-size: 1.5rem; }
.lesson-body { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.lesson-name { font-weight: 600; }

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s; }

/* ---------- Lección ---------- */

.lesson-head { display: flex; flex-direction: column; gap: 6px; }
.modes { display: flex; flex-direction: column; gap: 10px; }
.mode {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 72px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}
.mode span { color: var(--muted); font-size: 0.92rem; }

.card {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.badge {
  align-self: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
}
.tip { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }

/* ---------- Ejercicios ---------- */

.run-progress { display: flex; align-items: center; gap: 10px; padding: 4px 0 0; }
.run-progress .bar { flex: 1; }
.run-count { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 0.85rem; color: var(--muted); }

.flashcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 20px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
}
.face-word { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; font-size: 2.2rem; font-weight: 700; line-height: 1.2; }
.face-word.is-es { font-size: 1.8rem; }
.hint, .pos { color: var(--muted); }
.pos { font-style: italic; }
.forms { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; font-size: 1.35rem; font-weight: 700; }
.forms .sep { color: var(--muted); font-weight: 400; }
.answer-main { font-size: 1.25rem; font-weight: 600; }
.example { font-style: italic; }

.prompt { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  min-height: var(--tap);
  padding: 12px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.option:disabled { cursor: default; }
.option.is-correct, .cloze-input.is-correct { border-color: var(--good); background: var(--good-bg); color: var(--good); font-weight: 600; }
.option.is-wrong, .cloze-input.is-wrong { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.option:disabled:not(.is-correct):not(.is-wrong) { opacity: 0.55; }
.feedback { display: flex; flex-direction: column; gap: 8px; }
.feedback:empty { display: none; }
.feedback ul { padding-left: 20px; }

.cloze-sentence { font-size: 1.3rem; line-height: 2.2; }
.cloze-input {
  width: 7.5em;
  line-height: 1.3;
  margin: 0 4px;
  padding: 6px 10px;
  border: 0;
  border-bottom: 2px solid var(--accent);
  border-radius: 8px 8px 0 0;
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.answer-box, .select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.answer-box { resize: vertical; }
.select { min-height: 48px; }

/* ---------- Trabalenguas ---------- */

.tt-text { font-size: 1.35rem; line-height: 1.6; }
.tt-phrase { border-radius: 6px; padding: 1px 0; cursor: pointer; transition: background 0.2s; }
.tt-phrase.is-current { background: var(--hl); color: var(--hl-ink); }
.phrase { font-size: 1.8rem; font-weight: 700; line-height: 1.3; text-align: center; padding: 24px 8px; }
.ipa { text-align: center; color: var(--muted); font-family: "Charis SIL", "Doulos SIL", "Lucida Sans Unicode", serif; }
.pairs li { display: flex; align-items: center; justify-content: space-between; }
.tips { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
details { padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
summary { cursor: pointer; font-weight: 600; }
details p { margin-top: 8px; }

.rate { display: flex; flex-direction: column; gap: 6px; }
.rate input { width: 100%; accent-color: var(--accent); height: 32px; }
.rate-value { font-weight: 700; font-variant-numeric: tabular-nums; }

.mic { display: flex; flex-direction: column; gap: 10px; }
.speech-result { display: flex; flex-direction: column; gap: 8px; }
.speech-result:empty { display: none; }
.score { font-size: 1.2rem; font-weight: 700; }
.diff { font-size: 1.25rem; line-height: 1.7; }
.w-ok { color: var(--good); }
.w-miss { color: var(--bad); text-decoration: underline wavy; text-underline-offset: 4px; font-weight: 600; }

/* ---------- Lectura ---------- */

.reading { display: flex; flex-direction: column; gap: 14px; font-size: 1.15rem; line-height: 1.7; }
.vocab {
  padding: 0 3px;
  border: 0;
  border-radius: 5px;
  background: var(--hl);
  color: var(--hl-ink);
  font: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 4px;
}
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 0.35); }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  animation: sheet-in 0.18s ease-out;
}
.sheet-word { display: flex; align-items: center; font-size: 1.8rem; font-weight: 700; }
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } }

/* ---------- Fin / vacío ---------- */

.finish { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 40px; text-align: center; }
.finish-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--good-bg);
  color: var(--good);
  font-size: 2.2rem;
  font-weight: 700;
}
.finish-score { font-size: 1.15rem; }
.finish-streak { font-size: 1.3rem; font-weight: 700; }
.empty { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-top: 40px; text-align: center; }

/* ---------- Progreso ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 6px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
}
.stat strong { font-size: 1.8rem; line-height: 1.1; }
.stat span { font-size: 0.82rem; color: var(--muted); }
.boxes li { display: grid; grid-template-columns: 7.5em 1fr 2.5em; align-items: center; gap: 10px; }
.box-label { display: flex; flex-direction: column; font-weight: 600; line-height: 1.2; }
.box-label small { color: var(--muted); font-weight: 400; }
.box-bar { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.box-bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.box-count { text-align: right; font-variant-numeric: tabular-nums; }
.verb-list li { padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.verb-row { display: flex; align-items: center; justify-content: space-between; }

/* ---------- Ajustes ---------- */

.settings .btn { min-height: 52px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.segment {
  min-height: 48px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.segment[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / 0.15); }
.field { display: flex; flex-direction: column; gap: 6px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.import-choice { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }

/* ---------- Avisos ---------- */

.toast, .update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  z-index: 30;
  max-width: 528px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); text-align: center; }
.update-banner { top: calc(8px + env(safe-area-inset-top)); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.update-banner button { padding: 8px 14px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Idiomas ---------- */

.lang-switch, .lang-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.badges .badge { align-self: auto; }
ruby { ruby-position: over; }
rt { font-size: 0.5em; font-weight: 400; color: var(--muted); }
.prompt > span { flex: 1; }
code { padding: 1px 6px; border-radius: 6px; background: var(--surface-2); font-size: 0.95em; }

/* ---------- Subir material ---------- */

.upload-block { display: flex; flex-direction: column; gap: 8px; }
.upload-block .section-title { margin: 0; }
.file-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list:empty { display: none; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps { padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
