:root {
  --primary: #7C3AED;
  --primary-light: #EDE9FE;
  --success: #10B981;
  --error: #EF4444;
  --bg: #F5F3FF;
  --card: #FFFFFF;
  --text: #1E1B4B;
  --muted: #6B7280;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(124,58,237,0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  /* evita que el scroll rebote en iOS */
  overscroll-behavior: none;
}

/* ── Screens ── */
.screen {
  display: none;
  padding: 20px 16px;
  /* safe-area para iPhone con muesca/barra home */
  padding-bottom: max(32px, env(safe-area-inset-bottom, 32px));
  max-width: 600px;
  margin: 0 auto;
}
.screen.active { display: block; }

/* ── Home ── */
.home-header {
  text-align: center;
  padding: 28px 0 20px;
}
.logo { font-size: 52px; margin-bottom: 8px; }
.home-header h1 { font-size: 1.9rem; color: var(--primary); font-weight: 800; }
.subtitle { color: var(--muted); margin-top: 4px; font-size: 0.9rem; }

.stats-bar {
  display: flex;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}
.stat { text-align: center; flex: 1; }
.stat-value { display: block; font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}

.topic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.topic-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 2px solid transparent;
  text-align: center;
  /* feedback táctil más rápido */
  transition: transform 0.12s, border-color 0.12s;
  touch-action: manipulation;
  user-select: none;
}
.topic-card:active { transform: scale(0.97); border-color: var(--primary); }

.topic-icon { font-size: 2rem; margin-bottom: 8px; display: block; }
.topic-name { font-weight: 700; font-size: 0.9rem; color: var(--text); }
.topic-meta { font-size: 0.75rem; color: var(--muted); margin-top: 3px; }
.topic-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 12px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary);
}

/* ── Exercise header ── */
.ex-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.btn-back {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
  /* área táctil amplia */
  padding: 10px 4px;
  flex-shrink: 0;
  touch-action: manipulation;
}
.ex-topic-label { font-weight: 700; font-size: 0.9rem; color: var(--text); flex: 1; text-align: center; }
.ex-progress { font-size: 0.8rem; color: var(--muted); flex-shrink: 0; }

.progress-track {
  height: 6px;
  background: #E5E7EB;
  border-radius: 99px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.4s;
  width: 0%;
}

/* ── Exercise card ── */
.ex-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 18px;
  box-shadow: var(--shadow);
}
.ex-question {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.55;
  margin-bottom: 22px;
}

/* Multiple choice */
.ex-options { display: flex; flex-direction: column; gap: 10px; }
.ex-options.hidden { display: none; }

.opt-btn {
  background: var(--primary-light);
  border: 2px solid transparent;
  border-radius: 12px;
  /* mínimo 48px para dedo */
  min-height: 52px;
  padding: 13px 16px;
  text-align: left;
  /* 16px mínimo para no hacer zoom en iOS */
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
  touch-action: manipulation;
  user-select: none;
}
.opt-btn:active:not(:disabled) { background: #DDD6FE; border-color: var(--primary); }
.opt-btn.correct { background: #D1FAE5; border-color: var(--success); color: #065F46; }
.opt-btn.wrong   { background: #FEE2E2; border-color: var(--error);   color: #991B1B; }
.opt-btn:disabled { cursor: default; }

/* Input — apilado verticalmente en móvil */
.ex-input-wrap { display: flex; flex-direction: column; gap: 10px; }
.ex-input-wrap.hidden { display: none; }

.ex-input {
  width: 100%;
  border: 2px solid #E5E7EB;
  border-radius: 12px;
  padding: 14px 16px;
  /* 16px = no-zoom en iOS */
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
  background: #fff;
}
.ex-input:focus { border-color: var(--primary); }
.ex-input.correct { border-color: var(--success); background: #D1FAE5; }
.ex-input.wrong   { border-color: var(--error);   background: #FEE2E2; }

.btn-check {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  min-height: 52px;
  padding: 14px 20px;
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
  touch-action: manipulation;
  user-select: none;
  transition: opacity 0.12s;
}
.btn-check:active { opacity: 0.8; }

/* True/False */
.ex-tf-wrap { display: flex; gap: 12px; }
.ex-tf-wrap.hidden { display: none; }
.btn-tf {
  flex: 1;
  border: 2px solid #E5E7EB;
  border-radius: 12px;
  min-height: 56px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
}
.btn-tf:active:not(:disabled) { background: var(--primary-light); border-color: var(--primary); }
.btn-tf.correct { background: #D1FAE5; border-color: var(--success); color: #065F46; }
.btn-tf.wrong   { background: #FEE2E2; border-color: var(--error);   color: #991B1B; }
.btn-tf:disabled { cursor: default; }

/* ── Feedback ── */
.feedback {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.45;
  animation: pop 0.18s ease;
}
.feedback.hidden { display: none; }
.feedback.ok  { background: #D1FAE5; color: #065F46; }
.feedback.err { background: #FEE2E2; color: #991B1B; }
#feedback-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 1px; }

@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Steps button ── */
.btn-steps {
  margin-top: 12px;
  width: 100%;
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  min-height: 48px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: background 0.12s;
}
.btn-steps:active { background: var(--primary-light); }
.btn-steps.open   { background: var(--primary-light); }
.btn-steps.hidden { display: none; }

/* ── Steps panel ── */
.steps-panel {
  margin-top: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
  animation: pop 0.2s ease;
}
.steps-panel.hidden { display: none; }

.steps-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}

.steps-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
}

.steps-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.step-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.step-text {
  flex: 1;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
}

/* ── Next button ── */
.btn-next {
  margin-top: 16px;
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  min-height: 56px;
  padding: 16px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: opacity 0.12s;
}
.btn-next:active { opacity: 0.8; }
.btn-next.hidden { display: none; }

/* ── Result screen ── */
#screen-result {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
}
.result-card {
  background: var(--card);
  border-radius: 24px;
  padding: 36px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  width: 100%;
}
.result-emoji { font-size: 5rem; margin-bottom: 12px; }
.result-card h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; }
#result-subtitle { color: var(--muted); margin-bottom: 20px; }
.result-score { margin: 16px 0; }
.result-score span:first-child { font-size: 2.8rem; font-weight: 900; color: var(--primary); }
.result-score-label { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.result-detail { font-size: 0.9rem; color: var(--muted); margin-bottom: 24px; }
.result-actions { display: flex; gap: 12px; }

.btn-primary {
  flex: 1;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  min-height: 52px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.12s;
}
.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  flex: 1;
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  border-radius: 12px;
  min-height: 52px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.12s;
}
.btn-secondary:active { opacity: 0.7; }

/* ── Desktop adjustments ── */
@media (min-width: 480px) {
  .screen { padding: 28px 24px 48px; }
  .ex-card { padding: 28px 24px; }
  .ex-input-wrap { flex-direction: row; align-items: center; }
  .ex-input { font-size: 1rem; }
  .topic-card:hover { transform: translateY(-3px); border-color: var(--primary); }
  .opt-btn:hover:not(:disabled) { border-color: var(--primary); background: #DDD6FE; }
  .btn-tf:hover:not(:disabled) { background: var(--primary-light); border-color: var(--primary); }
}
