/* Alemán A1 — estilos (dark-friendly, sin CDN) */
:root {
  --bg: #0f1419;
  --bg-elevated: #1a2332;
  --bg-card: #1e2a3a;
  --bg-hover: #243447;
  --border: #2d3a4d;
  --text: #e8eef5;
  --text-muted: #8b9cb3;
  --accent: #3d9cf0;
  --accent-soft: rgba(61, 156, 240, 0.15);
  --success: #3dd68c;
  --success-soft: rgba(61, 214, 140, 0.15);
  --warning: #f5a623;
  --warning-soft: rgba(245, 166, 35, 0.15);
  --danger: #f07178;
  --danger-soft: rgba(240, 113, 120, 0.15);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(61, 156, 240, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(61, 214, 140, 0.08), transparent);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* —— Header —— */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  gap: 0.75rem;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header .tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--warning-soft);
  color: var(--warning);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

/* —— Screens —— */
.screen { display: none; padding: 0 1.25rem 1.5rem; flex: 1; }
.screen.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.screen-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  letter-spacing: -0.02em;
}

.screen-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

/* —— Progress overview —— */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.6rem;
  text-align: center;
}

.stat-card .value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-card .label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.15rem;
}

/* —— Module cards —— */
.module-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
}

.module-card:hover, .module-card:focus-visible {
  background: var(--bg-hover);
  border-color: var(--accent);
  outline: none;
}

.module-card:active { transform: scale(0.99); }

.module-card-top {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

.module-icon {
  font-size: 1.75rem;
  line-height: 1;
  flex-shrink: 0;
}

.module-card h3 {
  font-size: 1rem;
  font-weight: 650;
  margin-bottom: 0.15rem;
}

.module-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.85rem;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 999px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* —— Module hub —— */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 560;
  cursor: pointer;
  padding: 0.35rem 0;
  margin-bottom: 0.75rem;
}

.back-btn:hover, .back-btn:focus-visible { text-decoration: underline; outline: none; }

.activity-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.activity-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  cursor: pointer;
  color: inherit;
  font: inherit;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}

.activity-btn:hover, .activity-btn:focus-visible {
  background: var(--bg-hover);
  border-color: var(--accent);
  outline: none;
}

.activity-btn .act-icon { font-size: 1.6rem; display: block; margin-bottom: 0.4rem; }
.activity-btn .act-label { font-weight: 600; font-size: 0.9rem; }
.activity-btn .act-status {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.activity-btn .act-status.done { color: var(--success); }

.activity-btn.full-width { grid-column: 1 / -1; }

/* —— Flashcards —— */
.flash-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
  justify-content: space-between;
}

.flash-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 560;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  min-height: 44px;
}

.btn:hover, .btn:focus-visible {
  background: var(--bg-hover);
  border-color: var(--accent);
  outline: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #041018;
}

.btn-primary:hover, .btn-primary:focus-visible {
  background: #5aadf5;
  border-color: #5aadf5;
}

.btn-success {
  background: var(--success-soft);
  border-color: transparent;
  color: var(--success);
}

.btn-success:hover, .btn-success:focus-visible {
  background: rgba(61, 214, 140, 0.25);
  border-color: var(--success);
}

.btn-warning {
  background: var(--warning-soft);
  border-color: transparent;
  color: var(--warning);
}

.btn-warning:hover, .btn-warning:focus-visible {
  background: rgba(245, 166, 35, 0.25);
  border-color: var(--warning);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-listen {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.btn-listen:hover, .btn-listen:focus-visible {
  background: rgba(61, 156, 240, 0.25);
  border-color: var(--accent);
}

.btn-block { width: 100%; }

.flashcard {
  perspective: 1000px;
  min-height: 240px;
  margin-bottom: 1.25rem;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 240px;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.flashcard-face.back { transform: rotateY(180deg); background: var(--bg-elevated); }

.flash-lang-tag {
  position: absolute;
  top: 0.85rem;
  left: 1rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
}

.flash-word {
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.flash-example {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
  max-width: 90%;
}

.flash-hint {
  position: absolute;
  bottom: 0.85rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.flash-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.flash-nav {
  display: flex;
  justify-content: space-between;
  gap: 0.65rem;
}

.empty-state, .done-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state .emoji, .done-state .emoji { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state h3, .done-state h3 { margin-bottom: 0.35rem; }
.empty-state p, .done-state p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.25rem; }

/* —— Quiz —— */
.quiz-progress {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.quiz-q {
  font-size: 1.15rem;
  font-weight: 650;
  margin-bottom: 1.25rem;
  line-height: 1.4;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.quiz-option {
  text-align: left;
  padding: 0.95rem 1.1rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: inherit;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 48px;
}

.quiz-option:hover:not(:disabled), .quiz-option:focus-visible:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--accent);
  outline: none;
}

.quiz-option.correct {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.quiz-option.wrong {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.quiz-option:disabled { cursor: default; }

.quiz-feedback {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: none;
}

.quiz-feedback.show { display: block; }
.quiz-feedback.ok { background: var(--success-soft); color: var(--success); }
.quiz-feedback.bad { background: var(--danger-soft); color: var(--danger); }

.quiz-score {
  text-align: center;
  padding: 2rem 1rem;
}

.quiz-score .big {
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin: 0.5rem 0;
}

/* —— Dialogue —— */
.dialogue-scene {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 1.25rem;
}

.dialogue-thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.bubble {
  max-width: 90%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  font-size: 0.95rem;
}

.bubble.them {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.me {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-bottom-right-radius: 4px;
}

.bubble .who {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.bubble .es {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.dialogue-prompt {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.dialogue-prompt h4 {
  font-size: 0.9rem;
  margin-bottom: 0.85rem;
  color: var(--text-muted);
  font-weight: 560;
}

.fill-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.fill-input {
  flex: 1;
  min-width: 140px;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  min-height: 44px;
}

.fill-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.fill-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* —— Bottom nav —— */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 0.4rem 0.5rem calc(0.4rem + var(--safe-bottom));
  display: flex;
  justify-content: center;
}

.bottom-nav-inner {
  display: flex;
  width: 100%;
  max-width: 720px;
  justify-content: space-around;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.25rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.65rem;
  font-weight: 560;
  cursor: pointer;
  border-radius: 10px;
  min-height: 48px;
  transition: color 0.15s, background 0.15s;
}

.nav-item .nav-ico { font-size: 1.25rem; line-height: 1; }

.nav-item.active { color: var(--accent); }
.nav-item:hover, .nav-item:focus-visible {
  color: var(--text);
  background: var(--bg-hover);
  outline: none;
}

.nav-item.active:hover, .nav-item.active:focus-visible { color: var(--accent); }

/* —— Progress screen —— */
.xp-ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 1rem 0 1.75rem;
}

.xp-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--pct, 0%), var(--border) 0);
  display: grid;
  place-items: center;
}

.xp-ring-inner {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.xp-ring-inner .pct { font-size: 1.5rem; font-weight: 700; }
.xp-ring-inner .lbl { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; }

.module-progress-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.mp-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
}

.mp-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 560;
}

.mp-item-top span:last-child {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.reset-zone {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.reset-zone p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.btn-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

.btn-danger:hover, .btn-danger:focus-visible {
  background: rgba(240, 113, 120, 0.25);
  border-color: var(--danger);
}

/* —— Toast —— */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 560;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.xp { border-color: var(--accent); color: var(--accent); }

/* —— Misc —— */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden { display: none !important; }

@media (min-width: 600px) {
  .activity-grid { grid-template-columns: repeat(2, 1fr); }
  .flashcard, .flashcard-inner { min-height: 280px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .flashcard-inner { transition: none; }
}
