:root {
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --text: #16233b;
  --text-muted: #5b6b85;
  --primary: #1e3a5f;
  --primary-light: #2f5583;
  --accent: #d9822b;
  --good: #2e8b57;
  --bad: #c0392b;
  --border: #e1e6ef;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(20, 30, 60, 0.08);
  --tabbar-h: 64px;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-elevated: #141e30;
    --text: #eef2fa;
    --text-muted: #9aa8c4;
    --primary: #3d6ea5;
    --primary-light: #4f82bb;
    --accent: #e69a4a;
    --good: #4caf78;
    --bad: #e05a4a;
    --border: #253048;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* El atributo hidden debería ocultar cualquier elemento por defecto, pero varios
   componentes (p. ej. .icon-btn) fijan su propio "display" con la misma prioridad que
   la regla nativa del navegador para [hidden] — y al ser ambas de origen "autor" según
   la cascada, ganaba la nuestra, dejando el elemento visible y clicable pese a hidden=true
   (así se quedaba pintado #btnBack en Home, ver commit del botón de atrás que se salía de
   la app). Forzamos que [hidden] gane siempre, sin depender de que cada componente se
   acuerde de excluir ese estado. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; font-weight: 800; }
h2 { font-size: 24px; }
h3 { font-size: 19px; }
h4 { font-size: 16px; }
p { margin: 0 0 10px; line-height: 1.5; }
button { font-family: inherit; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--primary); color: #fff; z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
}
.topbar-inner .page-title { flex: 1; font-size: 20px; font-weight: 800; line-height: 1.25; text-align: center; margin: 0; }
.icon-btn {
  background: transparent; border: none; color: #fff; font-size: 24px;
  width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:active { background: rgba(255,255,255,0.15); }
.icon-btn svg { width: 26px; height: 26px; }
#btnBack svg { width: 30px; height: 30px; }
.streak {
  font-size: 13px; background: rgba(255,255,255,0.15); padding: 4px 8px;
  border-radius: 20px; white-space: nowrap; cursor: pointer;
}

#app {
  padding: calc(var(--topbar-h) + env(safe-area-inset-top) + 14px) 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 640px; margin: 0 auto;
  min-height: 100vh;
}

/* En pantallas grandes (laptop/escritorio) usamos una columna más ancha en vez de
   dejar el contenido siempre encajonado en 640px con huecos enormes a los lados. */
@media (min-width: 760px) {
  #app { max-width: 820px; }
  .topbar-inner { max-width: 820px; margin: 0 auto; }
}
@media (min-width: 1100px) {
  #app { max-width: 980px; }
  .topbar-inner { max-width: 980px; margin: 0 auto; }
}

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--tabbar-h);
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  display: flex; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--text-muted); font-size: 11px;
}
.tab-item { position: relative; font-size: 12.5px; }
.tab-item.active { color: var(--primary-light); font-weight: 700; }
.tab-item.active::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary-light); }

.card {
  background: var(--bg-elevated); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
  border: 1px solid var(--border);
}
.card-tap { cursor: pointer; }
.card-tap:active { transform: scale(0.98); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%;
}
.btn:active { background: var(--primary-light); }
.btn.secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn.good { background: var(--good); }
.btn.bad { background: var(--bad); }
.btn.small { padding: 8px 12px; font-size: 13px; width: auto; }
.btn[disabled] { opacity: 0.5; }

.pill {
  display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: var(--border); color: var(--text-muted); font-weight: 600;
}
.pill.accent { background: var(--accent); color: #fff; }
.pill.good { background: var(--good); color: #fff; }
.pill.bad { background: var(--bad); color: #fff; }

.progress-bar {
  height: 8px; background: var(--border); border-radius: 6px; overflow: hidden; margin: 6px 0;
}
.progress-bar > div { height: 100%; background: var(--primary-light); border-radius: 6px; transition: width .3s; }

.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin: 22px 0 10px; font-weight: 700;
}
.section-title:first-child { margin-top: 0; }

.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 8px; text-decoration: none; color: var(--text);
}
.list-item:active { transform: scale(0.99); }
.list-item .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.chev { color: var(--text-muted); }

.flashcard {
  min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 28px 18px; cursor: pointer; user-select: none;
}
.flashcard .word { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.flashcard .hint { font-size: 13px; color: var(--text-muted); }
.flashcard .def { font-size: 16px; margin-bottom: 10px; }
.flashcard .example { font-style: italic; color: var(--text-muted); font-size: 14px; }
.flashcard .syn { margin-top: 10px; font-size: 13px; color: var(--text-muted); }

.review-actions { display: flex; gap: 10px; margin-top: 14px; }

.quiz-q { font-size: 16px; font-weight: 600; margin-bottom: 14px; }
.quiz-opt {
  display: block; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text); font-size: 15px; cursor: pointer;
}
.quiz-opt.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 15%, var(--bg-elevated)); }
.quiz-opt.incorrect { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 15%, var(--bg-elevated)); }
.quiz-explain { font-size: 14px; color: var(--text-muted); margin-top: 10px; padding: 10px; background: var(--bg); border-radius: 10px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

textarea.writing-area {
  width: 100%; min-height: 220px; border-radius: 10px; border: 1px solid var(--border);
  padding: 12px; font-size: 15px; font-family: inherit; resize: vertical; background: var(--bg-elevated); color: var(--text);
}
.wordcount { font-size: 13px; color: var(--text-muted); text-align: right; margin-top: 4px; }
.wordcount.ok { color: var(--good); }
.wordcount.warn { color: var(--accent); }

.checklist-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.checklist-item:last-child { border-bottom: none; }
.checklist-item input { margin-top: 3px; width: 18px; height: 18px; flex-shrink: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 5px 10px; font-size: 12.5px; color: var(--text-muted); }

.timer { font-variant-numeric: tabular-nums; font-weight: 700; }

.install-toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px);
  background: var(--primary); color: #fff; padding: 12px 14px; border-radius: 12px;
  display: flex; align-items: center; gap: 10px; z-index: 30; box-shadow: var(--shadow); font-size: 13px;
}
.install-toast[hidden] { display: none; }
.install-toast button.btn { width: auto; padding: 8px 12px; background: #fff; color: var(--primary); }
.install-toast .icon-btn { color: #fff; }

.stat-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.stat-num { font-size: 26px; font-weight: 800; color: var(--primary-light); }
.stat-label { font-size: 12px; color: var(--text-muted); }

.readtext { font-size: 15.5px; line-height: 1.65; white-space: pre-line; }

.tabbar { overflow-x: auto; justify-content: flex-start; }
.tabbar .tab-item { min-width: 70px; flex: 1 0 70px; }
.listening-player { display:flex; align-items:center; gap:10px; margin-top:12px; }
.listening-player .btn { width:auto; flex:1; }
.listening-count { font-size:13px; color:var(--text-muted); white-space:nowrap; }
.audio-pending { margin-top:10px; font-size:13px; color:var(--text-muted); }

.score-hero { text-align: center; padding: 20px 10px; }
.score-hero .big { font-size: 42px; font-weight: 800; color: var(--primary-light); }

a { color: var(--primary-light); }

.auth-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.auth-screen[hidden] { display: none; }
html.has-session #authScreen { display: none; }
.auth-card-wrap {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card-wrap[hidden] { display: none; }
.auth-card { width: 100%; max-width: 360px; }
.auth-logo { text-align: center; font-size: 30px; font-weight: 800; color: var(--primary-light); margin-bottom: 4px; }

/* ===================== Landing ===================== */
.landing-inner { max-width: 640px; margin: 0 auto; padding: 0 20px; }
@media (min-width: 760px) { .landing-inner { max-width: 780px; } }

.landing-hero { padding: 56px 0 40px; text-align: center; }
.landing-hero .auth-logo { font-size: 34px; margin-bottom: 10px; }
.landing-tagline {
  font-size: 18px; color: var(--text); max-width: 480px; margin: 0 auto 22px;
  line-height: 1.5; font-weight: 600;
}
.landing-cta-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.landing-cta-row .btn { width: auto; padding-left: 22px; padding-right: 22px; }
.landing-hero-note { margin-top: 14px; font-size: 13px; color: var(--text-muted); }

.landing-section { padding: 40px 0; }
.landing-section-alt { background: var(--bg-elevated); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.landing-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 22px; }
@media (max-width: 640px) { .landing-steps { grid-template-columns: 1fr; } }
.landing-step { text-align: center; }
.landing-step-num {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; margin: 0 auto 10px;
}
.landing-step h3 { font-size: 16px; margin-bottom: 4px; }
.landing-step p { color: var(--text-muted); font-size: 14px; margin: 0; }

.landing-features { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 22px; }
@media (min-width: 640px) { .landing-features { grid-template-columns: repeat(4, 1fr); } }
.landing-feature {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.landing-section-alt .landing-feature { background: var(--bg); }
.landing-feature-num {
  width: 28px; height: 28px; border-radius: 50%; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 700;
}
.landing-feature h3 { font-size: 14.5px; margin-bottom: 4px; }
.landing-feature p { color: var(--text-muted); font-size: 13px; margin: 0; line-height: 1.5; }

.landing-levels-table { text-align: center; }
.landing-levels-table th, .landing-levels-table td { text-align: center; }
.landing-levels-table thead th:first-child, .landing-levels-table tbody th { text-align: left; }

.landing-pricing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 22px; max-width: 480px; margin-left: auto; margin-right: auto; }
@media (max-width: 500px) { .landing-pricing-grid { grid-template-columns: 1fr; } }
.landing-price-card { text-align: center; }
.landing-price-featured { border-color: var(--primary-light); box-shadow: 0 0 0 2px var(--primary-light), var(--shadow); }
.landing-price { font-size: 30px; font-weight: 800; margin: 4px 0 8px; }
.landing-price span { font-size: 14px; font-weight: 400; color: var(--text-muted); }
.landing-price-card .btn { margin-top: 8px; }

.landing-faq { max-width: 560px; margin: 22px auto 0; }
.landing-faq details {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 10px;
  background: var(--bg-elevated);
}
.landing-faq summary { cursor: pointer; font-weight: 600; }
.landing-faq p { margin: 10px 0 0; color: var(--text-muted); font-size: 14px; }

.landing-final-cta { text-align: center; padding: 48px 0 56px; }
.landing-final-cta h2 { margin-bottom: 16px; }
.landing-footer {
  text-align: center; padding: 24px 20px 40px; color: var(--text-muted); font-size: 13px;
}
.landing-footer a { color: var(--text-muted); text-decoration: underline; }
.landing-footer .sep { margin: 0 8px; }

/* ===================== Páginas legales (privacidad, términos) ===================== */
.legal-page {
  max-width: 720px; margin: 0 auto; padding: 32px 20px 60px; line-height: 1.6;
}
.legal-page .back-link { display: inline-block; margin-bottom: 20px; color: var(--primary-light); font-weight: 600; text-decoration: none; }
.legal-page h1 { font-size: 26px; margin-bottom: 4px; }
.legal-page .updated { color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }
.legal-page h2 { font-size: 19px; margin: 32px 0 10px; color: var(--primary); }
.legal-page h2:first-of-type { margin-top: 0; }
.legal-page p, .legal-page li { color: var(--text); margin-bottom: 10px; }
.legal-page ul { padding-left: 20px; margin: 0 0 14px; }
.legal-page strong { color: var(--text); }
.legal-page a { color: var(--primary-light); }
.legal-page .fill-in { background: color-mix(in srgb, var(--accent) 18%, var(--bg-elevated)); padding: 1px 5px; border-radius: 4px; }
.auth-tagline { text-align: center; color: var(--text-muted); margin-bottom: 24px; }

.google-btn {
  background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.google-btn:active { background: var(--bg); }
.auth-divider {
  display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--text-muted); font-size: 12px;
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.link-btn {
  background: none; border: none; color: var(--primary-light); font-size: 13px; font-weight: 600;
  cursor: pointer; padding: 0; margin-top: 10px; display: block; width: 100%; text-align: center;
}

.auth-form input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 15px; margin-bottom: 10px;
}
.auth-error { color: var(--bad); font-size: 13px; margin: 8px 0 0; min-height: 16px; }
.auth-note { color: var(--good); font-size: 13px; margin: 8px 0 0; }

.field-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.field-input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 15px; margin-bottom: 12px;
  font-family: inherit;
}

.tense-table-wrap { overflow-x: auto; margin: -4px; padding: 4px; }
.tense-table { border-collapse: collapse; width: 100%; min-width: 420px; font-size: 14px; }
.tense-table th, .tense-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tense-table thead th { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.tense-table tbody th { color: var(--text-muted); font-weight: 600; white-space: nowrap; }

.conjugate-row { margin-bottom: 12px; }
.conjugate-row:last-child { margin-bottom: 0; }
.conjugate-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; text-transform: capitalize; }
.conjugate-row input, .cloze-input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 15px; font-family: inherit;
}
.cloze-input { margin-top: 10px; }
input.field-correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--bg-elevated)); }
input.field-incorrect { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--bg-elevated)); }
.field-hint { font-size: 12.5px; color: var(--good); margin: 4px 0 0; }

.confetti-container { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti-piece {
  position: absolute; top: -12px; width: 8px; height: 14px; opacity: 0.9; border-radius: 2px;
  animation-name: confettiFall; animation-timing-function: ease-in; animation-fill-mode: forwards;
}
@keyframes confettiFall {
  from { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  to { transform: translateY(100vh) rotate(360deg); opacity: 0; }
}

.motivation-overlay {
  position: fixed; inset: 0; background: rgba(8, 12, 22, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 24px;
  animation: motivationFadeIn 0.2s ease;
}
.motivation-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 18px;
  padding: 28px 22px 22px; max-width: 400px; width: 100%; text-align: center;
  box-shadow: var(--shadow); animation: motivationPop 0.25s ease;
  /* Antes no tenía tope de alto: con contenido largo (p. ej. la ficha de repaso de
     tiempos verbales) se salía de la pantalla en vez de hacer scroll dentro de la
     tarjeta. Afecta a todos los popups que reutilizan esta clase (onboarding,
     recuperar contraseña, repaso de formas verbales). */
  max-height: calc(100vh - 48px); overflow-y: auto;
}
.motivation-card p { font-size: 16px; line-height: 1.55; margin-bottom: 18px; color: var(--text); }
@keyframes motivationFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes motivationPop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Landing: enlaces a guías del blog (enlazado interno para SEO) */
.landing-blog-list { list-style:none; margin:14px auto 0; padding:0; max-width:560px; }
.landing-blog-list li { padding:9px 0; border-bottom:1px solid var(--border, rgba(128,128,128,.25)); }
.landing-blog-list a { font-weight:600; }
