* {
  box-sizing: border-box;
}

:root {
  --bg: #f7f7ff;
  --surface: #ffffff;
  --surface-2: #f0efff;
  --text: #20243a;
  --muted: #667085;
  --primary: #6d5dfc;
  --primary-dark: #5042d8;
  --success: #17a673;
  --danger: #e24b5a;
  --warning: #ffb703;
  --shadow: 0 18px 55px rgba(32, 36, 58, 0.14);
  --radius: 24px;
}

html {
  min-height: 100%;
  background: radial-gradient(circle at top left, #e5f6ff 0, transparent 32rem),
              radial-gradient(circle at top right, #ffe9f2 0, transparent 28rem),
              var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: transparent;
}

button, input, select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 18px 14px 38px;
}

.hero {
  color: white;
  padding: 24px 20px;
  border-radius: 30px;
  background:
    linear-gradient(135deg, rgba(109, 93, 252, 0.97), rgba(34, 173, 178, 0.9)),
    radial-gradient(circle at 85% 0%, rgba(255,255,255,.35), transparent 16rem);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.hero::after {
  content: "★";
  position: absolute;
  right: 20px;
  bottom: 8px;
  font-size: 96px;
  opacity: 0.13;
  transform: rotate(-12deg);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.logo {
  width: 58px;
  height: 58px;
  border-radius: 19px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 22px;
  color: var(--primary-dark);
  background: rgba(255,255,255,0.95);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.08);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  letter-spacing: .04em;
  text-transform: uppercase;
  opacity: 0.9;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 7vw, 44px);
  line-height: 1.02;
}

.hero-copy {
  position: relative;
  z-index: 1;
  margin: 16px 0 0;
  max-width: 640px;
  font-size: 16px;
  line-height: 1.45;
  opacity: 0.95;
}

.panel {
  margin-top: 16px;
  padding: 18px;
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(109, 93, 252, 0.12);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(32, 36, 58, 0.08);
  backdrop-filter: blur(10px);
}

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

@media (min-width: 720px) {
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.mode-card {
  border: 0;
  text-align: left;
  padding: 18px;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff, #f6f6ff);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(32, 36, 58, 0.09);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}

.mode-card:hover,
.mode-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 16px 36px rgba(32, 36, 58, 0.14);
  outline: 3px solid rgba(109, 93, 252, 0.24);
}

.mode-icon {
  width: 44px;
  height: 44px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  background: var(--surface-2);
  font-size: 24px;
}

.label {
  display: block;
  margin-bottom: 7px;
  font-weight: 800;
}

.input, .select {
  width: 100%;
  min-height: 48px;
  border: 2px solid #e4e7ec;
  border-radius: 16px;
  padding: 0 14px;
  background: white;
  color: var(--text);
  outline: none;
}

.input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(109, 93, 252, 0.14);
}

.form-row {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

@media (min-width: 720px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

.timer-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  border-radius: 20px;
  background: #fff8e7;
  border: 1px solid rgba(255,183,3,0.35);
}

@media (min-width: 720px) {
  .timer-card {
    grid-template-columns: 1fr auto;
    align-items: center;
  }
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}

.toggle input {
  width: 20px;
  height: 20px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  border: 0;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 16px;
  color: white;
  background: var(--primary);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(109, 93, 252, 0.24);
  transition: transform .15s ease, filter .15s ease;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.02);
  outline: 3px solid rgba(109, 93, 252, 0.22);
}

.btn.secondary {
  background: #edf0ff;
  color: var(--primary-dark);
  box-shadow: none;
}

.btn.danger {
  background: var(--danger);
}

.btn.success {
  background: var(--success);
}

.btn.full {
  width: 100%;
}

.status-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 16px;
}

@media (min-width: 720px) {
  .status-bar {
    grid-template-columns: 1.2fr 0.8fr;
    align-items: center;
  }
}

.progress-wrap {
  width: 100%;
  height: 13px;
  border-radius: 99px;
  background: #e8e9f8;
  overflow: hidden;
}

.progress {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #22adb2);
  transition: width .25s ease;
}

.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 13px;
}

.pill.warn {
  background: #fff1bf;
  color: #8a5b00;
}

.pill.good {
  background: #daf8ec;
  color: #087c54;
}

.question-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  border-radius: 26px;
  background: white;
  box-shadow: var(--shadow);
  animation: enter .28s ease both;
}

@keyframes enter {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.area-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  background: #eff4ff;
  color: #2b54a7;
  font-weight: 900;
  font-size: 13px;
}

.passage {
  margin: 14px 0;
  padding: 14px;
  border-left: 5px solid var(--primary);
  border-radius: 16px;
  background: #f7f7ff;
  line-height: 1.52;
}

.question-text {
  margin: 14px 0 12px;
  font-size: clamp(20px, 5.4vw, 28px);
  line-height: 1.18;
  font-weight: 900;
}

.options {
  display: grid;
  gap: 10px;
}

.option-btn {
  width: 100%;
  border: 2px solid #e4e7ec;
  min-height: 54px;
  padding: 12px 14px;
  border-radius: 18px;
  background: #fff;
  color: var(--text);
  text-align: left;
  font-weight: 800;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}

.option-btn:hover,
.option-btn:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(109, 93, 252, 0.55);
  outline: none;
}

.option-btn.selected {
  border-color: var(--primary);
  background: #f0efff;
}

.option-btn.correct {
  border-color: var(--success);
  background: #e2fbf0;
  animation: pop .38s ease both;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: #ffe8eb;
  animation: shake .42s ease both;
}

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.035); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.feedback {
  margin-top: 14px;
  padding: 14px;
  border-radius: 18px;
  background: #f7f7ff;
  border: 1px solid #e4e7ec;
  line-height: 1.45;
}

.feedback.good {
  background: #e5fbf2;
  border-color: #b9f0d9;
}

.feedback.bad {
  background: #fff0f2;
  border-color: #ffcbd2;
}

.sparkle {
  pointer-events: none;
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 76px;
  animation: sparkle .72s ease both;
}

.question-card.celebrate .sparkle {
  display: flex;
}

@keyframes sparkle {
  0% { opacity: 0; transform: scale(.4) rotate(-14deg); }
  45% { opacity: 1; transform: scale(1.1) rotate(8deg); }
  100% { opacity: 0; transform: scale(1.45) rotate(20deg); }
}

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

@media (min-width: 720px) {
  .results-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.result-card {
  padding: 16px;
  border-radius: 22px;
  background: #f8f9ff;
  border: 1px solid #e4e7ec;
  text-align: center;
}

.big-score {
  font-size: clamp(52px, 18vw, 88px);
  line-height: 1;
  margin: 12px 0;
  font-weight: 1000;
  letter-spacing: -0.06em;
  color: var(--primary-dark);
}

.review-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.review-item {
  padding: 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #e4e7ec;
  line-height: 1.4;
}

.review-item.ok {
  border-left: 6px solid var(--success);
}

.review-item.no {
  border-left: 6px solid var(--danger);
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 16px;
  z-index: 20;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(32, 36, 58, 0.94);
  color: white;
  box-shadow: var(--shadow);
  transform: translateY(140%);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  text-align: center;
  font-weight: 800;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.small {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.confetti {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 16px;
  border-radius: 4px;
  animation: fall 1.4s linear forwards;
  z-index: 50;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0.8;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* Mejoras v2: configuración avanzada y modo relato */
.settings-switches {
  align-items: start;
}

.toggle-stack {
  display: grid;
  gap: 12px;
}

.reader-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 14px;
}

.small-btn {
  min-height: 42px;
  padding: 0 12px;
  font-size: 14px;
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(109, 93, 252, 0.18);
}

.voice-btn {
  background: linear-gradient(135deg, var(--primary), #22adb2);
}

.pill.voice {
  background: #edf7ff;
  color: #0b67a3;
  border-color: rgba(11,103,163,0.18);
}

@media (max-width: 520px) {
  .reader-tools .btn {
    flex: 1 1 100%;
  }
}
