/* ============ Variables y temas ============ */
:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-var: #e9eee9;
  --outline: #d5dcd5;
  --text: #17201a;
  --muted: #5a675e;
  --primary: #1f4d36;
  --on-primary: #ffffff;
  --gold: #c9a24b;
  --gold-light: #e8d29a;
  --chip-bg: #f6e9c6;
  --chip-text: #4a3708;
  --ok: #2e7d4f;
  --ok-bg: #e1f2e7;
  --bad: #c0392b;
  --bad-bg: #fbe5e2;
  --head-a: #0f2a1d;
  --head-b: #2f7050;
  --tone-study: #2f7050; --tone-study-bg: #ddeee3;
  --tone-exam: #8a6a1e;  --tone-exam-bg: #f6e9c6;
  --tone-review: #b5472f; --tone-review-bg: #f9e0da;
  --tone-stats: #2f5f8f; --tone-stats-bg: #dce8f5;
  --shadow: 0 10px 30px rgba(15, 42, 29, .12);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e1310; --surface: #18201b; --surface-var: #222c25; --outline: #33413a;
  --text: #e4eae5; --muted: #a3b0a7; --primary: #7fc79e; --on-primary: #0b2418;
  --gold: #e0c070; --chip-bg: #4a3a12; --chip-text: #f6e9c6;
  --ok: #6fcf97; --ok-bg: #1b3a29; --bad: #ff8a7a; --bad-bg: #3a1d1a;
  --head-a: #08170f; --head-b: #1d4631;
  --tone-study: #7fc79e; --tone-study-bg: #1f3a2b;
  --tone-exam: #e0c070; --tone-exam-bg: #3f3412;
  --tone-review: #ff9c86; --tone-review-bg: #3f211b;
  --tone-stats: #8fb8e8; --tone-stats-bg: #1d2f44;
  --shadow: 0 10px 30px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1310; --surface: #18201b; --surface-var: #222c25; --outline: #33413a;
    --text: #e4eae5; --muted: #a3b0a7; --primary: #7fc79e; --on-primary: #0b2418;
    --gold: #e0c070; --chip-bg: #4a3a12; --chip-text: #f6e9c6;
    --ok: #6fcf97; --ok-bg: #1b3a29; --bad: #ff8a7a; --bad-bg: #3a1d1a;
    --head-a: #08170f; --head-b: #1d4631;
    --tone-study: #7fc79e; --tone-study-bg: #1f3a2b;
    --tone-exam: #e0c070; --tone-exam-bg: #3f3412;
    --tone-review: #ff9c86; --tone-review-bg: #3f211b;
    --tone-stats: #8fb8e8; --tone-stats-bg: #1d2f44;
    --shadow: 0 10px 30px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
html[data-text="1"] { font-size: 115%; }
html[data-text="2"] { font-size: 130%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--primary); }
svg { display: block; width: 1.5rem; height: 1.5rem; fill: currentColor; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

#app { min-height: 100vh; }

/* ============ Botones ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 3.25rem; padding: .6rem 1.4rem;
  border: 2px solid var(--primary); border-radius: 1rem;
  background: var(--primary); color: var(--on-primary);
  font-weight: 700; text-decoration: none; transition: transform .12s ease, opacity .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn svg { width: 1.25rem; height: 1.25rem; }
.btn--outline { background: transparent; color: var(--primary); border-color: var(--outline); }
.btn--text { background: transparent; border-color: transparent; color: var(--primary); min-height: 2.75rem; padding: .4rem 1rem; border-radius: .75rem; }
.btn--strong { font-weight: 800; }
.btn--danger { color: var(--bad); }
.btn--block { display: flex; width: 100%; }

.icon-btn {
  display: grid; place-items: center; width: 3rem; height: 3rem;
  border: 0; border-radius: 50%; background: transparent; color: #fff; text-decoration: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, .14); }
.icon-btn.is-fav { color: var(--gold); }

/* ============ Cabecera de pantallas interiores ============ */
.topbar {
  background: linear-gradient(135deg, var(--head-a), var(--head-b));
  color: #fff;
  border-radius: 0 0 1.75rem 1.75rem;
  padding: env(safe-area-inset-top, 0) 0 .75rem;
  position: sticky; top: 0; z-index: 5;
}
.topbar__in { display: flex; align-items: center; gap: .25rem; max-width: 1100px; margin: 0 auto; padding: .5rem .75rem; min-height: 4rem; }
.topbar__title { flex: 1; font-size: 1.35rem; font-weight: 800; padding-left: .25rem; }
.topbar__actions { display: flex; align-items: center; gap: .25rem; }
.topbar__stats { max-width: 720px; margin: 0 auto; padding: 0 1rem; }
.topbar__best { text-align: center; color: #cfe0d5; margin-top: .6rem; font-size: .95rem; }

.timer {
  display: inline-flex; align-items: center; gap: .4rem; margin-right: .5rem;
  padding: .35rem .8rem; border-radius: 999px;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .2);
  font-variant-numeric: tabular-nums; font-weight: 800;
}
.timer svg { width: 1.2rem; height: 1.2rem; color: var(--gold); }
.timer.is-warning { color: #ffb4a8; }

.progress { height: .5rem; margin: .25rem 1.25rem 0; border-radius: .25rem; background: rgba(255, 255, 255, .2); overflow: hidden; max-width: 1060px; }
@media (min-width: 1100px) { .progress { margin-inline: auto; } }
.progress i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: .25rem; transition: width .35s ease; }

/* ============ Inicio ============ */
.home { max-width: 1100px; margin: 0 auto; }

.hero {
  position: relative; overflow: hidden; color: #fff; text-align: center;
  background: linear-gradient(135deg, var(--head-a), var(--head-b));
  border-radius: 0 0 2rem 2rem;
  padding: calc(env(safe-area-inset-top, 0) + .5rem) 1.25rem 1.75rem;
}
.hero__rings {
  position: absolute; right: -9rem; top: -8rem; width: 22rem; height: 22rem; border-radius: 50%;
  background: radial-gradient(circle, transparent 0 28%, rgba(255,255,255,.08) 28% 29%, transparent 29% 52%, rgba(255,255,255,.08) 52% 53%, transparent 53% 76%, rgba(255,255,255,.08) 76% 77%, transparent 77%);
  pointer-events: none;
}
.hero__tools { position: relative; display: flex; justify-content: space-between; }
.hero__content { position: relative; display: grid; justify-items: center; gap: .15rem; padding-top: .25rem; }
.hero__logo svg { width: 4.5rem; height: 4.5rem; }
.hero h1 { font-size: 2.2rem; font-weight: 800; margin-top: .5rem; line-height: 1.1; }
.hero__gold { color: var(--gold); font-weight: 800; letter-spacing: .45em; font-size: .9rem; margin-right: -.45em; }
.hero__sub { color: #cfe0d5; margin-top: .6rem; }

.statpill {
  display: flex; list-style: none; margin: 1.3rem 0 0; padding: .75rem 0; width: 100%; max-width: 30rem;
  border-radius: 999px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .18);
}
.statpill li { flex: 1; display: grid; justify-items: center; line-height: 1.25; }
.statpill li + li { border-left: 1px solid rgba(255, 255, 255, .22); }
.statpill strong { color: var(--gold-light); font-size: 1.35rem; }
.statpill span { color: #cfe0d5; font-size: .78rem; }

.home__cards { padding: 1.5rem 1rem 2rem; display: grid; gap: .8rem; max-width: 40rem; margin: 0 auto; }
.home__cards h2 { font-size: 1.25rem; font-weight: 800; margin: .2rem .25rem .2rem; }
.home__link { text-align: center; margin-top: .75rem; font-size: .9rem; }

.mode {
  display: flex; align-items: center; gap: 1rem; width: 100%; text-align: left;
  padding: 1rem; border: 1px solid var(--outline); border-radius: 1.25rem;
  background: var(--surface); color: var(--text); text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease;
  animation: rise .45s ease both;
}
.mode:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.mode.is-disabled { opacity: .5; pointer-events: none; }
.mode__icon { display: grid; place-items: center; flex: none; width: 3.4rem; height: 3.4rem; border-radius: 50%; }
.mode__icon svg { width: 1.8rem; height: 1.8rem; }
.mode__icon--study { background: var(--tone-study-bg); color: var(--tone-study); }
.mode__icon--exam { background: var(--tone-exam-bg); color: var(--tone-exam); }
.mode__icon--review { background: var(--tone-review-bg); color: var(--tone-review); }
.mode__icon--stats { background: var(--tone-stats-bg); color: var(--tone-stats); }
.mode__body { flex: 1; display: grid; gap: .1rem; }
.mode__body strong { font-size: 1.15rem; }
.mode__body span { color: var(--muted); font-size: .92rem; line-height: 1.4; }
.mode__chev { color: var(--muted); }

@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

@media (min-width: 900px) {
  .home { display: grid; grid-template-columns: 4fr 6fr; min-height: 100vh; max-width: none; background: linear-gradient(135deg, var(--head-a), var(--head-b)); padding: .75rem; gap: .75rem; }
  .hero { border-radius: 0; background: none; display: grid; align-content: center; padding-bottom: 1rem; }
  .hero__tools { position: absolute; inset: 0 0 auto 0; padding: .25rem; }
  .hero__logo svg { width: 7rem; height: 7rem; }
  .hero h1 { font-size: 3rem; }
  .home__cards { max-width: none; width: 100%; margin: 0; background: var(--bg); border-radius: 1.75rem; align-content: center; padding: 2rem 2.5rem; }
}

/* ============ Preguntas ============ */
.qpage { max-width: 1100px; margin: 0 auto; padding: 1rem 1rem 9rem; }
.qpage__cols { display: grid; gap: 1rem; }
.qpage__cols.fade { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.qcard { padding: 1.25rem; background: var(--surface); border: 1px solid var(--outline); border-radius: 1.25rem; }
.chip { display: inline-block; padding: .25rem .8rem; border-radius: 999px; background: var(--chip-bg); color: var(--chip-text); font-weight: 800; font-size: .85rem; }
.qcard__text { margin-top: 1rem; font-size: 1.15rem; font-weight: 800; line-height: 1.4; }

.answers { display: grid; gap: .75rem; align-content: start; }
.answer {
  display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left;
  min-height: 4.25rem; padding: .75rem .9rem;
  border: 1px solid var(--outline); border-radius: 1.25rem; background: var(--surface); color: var(--text);
  transition: transform .12s ease, border-color .12s ease;
}
.answer:hover { border-color: var(--primary); }
.answer__letter { display: grid; place-items: center; flex: none; width: 2.3rem; height: 2.3rem; border-radius: 50%; background: var(--surface-var); color: var(--muted); font-weight: 800; }
.answer__text { flex: 1; font-size: 1.02rem; }
.answer__status svg { width: 1.7rem; height: 1.7rem; }
.answer--ok { border: 2px solid var(--ok); background: var(--ok-bg); }
.answer--ok .answer__letter { background: var(--ok); color: #fff; }
.answer--ok .answer__status { color: var(--ok); }
.answer--bad { border: 2px solid var(--bad); background: var(--bad-bg); }
.answer--bad .answer__letter { background: var(--bad); color: #fff; }
.answer--bad .answer__status { color: var(--bad); }
.answer.shake { animation: shake .38s ease; }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

.pills { display: flex; gap: .75rem; margin-bottom: 1rem; }
.pill { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 2.75rem; padding: .4rem .8rem; border: 1px solid var(--outline); border-radius: 999px; background: var(--surface); font-size: .92rem; }
.pill svg { width: 1.25rem; height: 1.25rem; }
.pill--ok svg { color: var(--ok); }
.pill--bad svg { color: var(--bad); }

.bottombar { position: fixed; inset: auto 0 0 0; z-index: 4; background: var(--surface); border-top: 1px solid var(--outline); box-shadow: 0 -6px 20px rgba(0, 0, 0, .08); padding-bottom: env(safe-area-inset-bottom, 0); }
.bottombar__in { max-width: 1100px; margin: 0 auto; padding: .6rem 1rem .8rem; display: grid; gap: .5rem; }
.bottombar__row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.slider { width: 100%; accent-color: var(--primary); height: 2rem; }

@media (min-width: 820px) {
  .qpage__cols { grid-template-columns: 1fr 1fr; align-items: start; }
  .pills { margin-bottom: 1rem; }
  .qcard__text { font-size: 1.4rem; }
  .answer__text { font-size: 1.15rem; }
}

/* ============ Resultado ============ */
.result { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; background: linear-gradient(135deg, var(--head-a), var(--head-b)); }
.result__card { width: min(100%, 28rem); padding: 2rem 1.5rem 1.5rem; text-align: center; background: var(--surface); border-radius: 2rem; box-shadow: var(--shadow); display: grid; gap: 1rem; justify-items: center; animation: rise .45s ease both; }
.result__icon { display: grid; place-items: center; width: 5rem; height: 5rem; border-radius: 50%; }
.result__icon svg { width: 2.6rem; height: 2.6rem; }
.result__icon.is-ok, .result__score.is-ok { background: var(--ok-bg); color: var(--ok); }
.result__icon.is-bad, .result__score.is-bad { background: var(--bad-bg); color: var(--bad); }
.result__score { background: none !important; font-size: 3.2rem; font-weight: 800; line-height: 1; }
.result__title { font-size: 1.45rem; font-weight: 800; }
.result .pills { width: 100%; margin: 0; }
.result__actions { display: grid; gap: .5rem; width: 100%; margin-top: .5rem; }

/* ============ Estadísticas ============ */
.stats, .settings { max-width: 720px; margin: 0 auto; padding: 1.25rem 1rem 3rem; display: grid; gap: 1rem; }
.card { padding: 1.1rem; background: var(--surface); border: 1px solid var(--outline); border-radius: 1.25rem; display: grid; gap: .5rem; }
.card h2 { font-size: 1.05rem; }
.stats__h { font-size: 1.2rem; font-weight: 800; margin: .75rem .25rem 0; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }

.chart { width: 100%; height: auto; }
.bar--ok { fill: var(--ok); }
.bar--bad { fill: var(--bad); }
.chart__pass { stroke: var(--gold); stroke-width: 2.5; stroke-dasharray: 10 8; }
.chart__label { fill: var(--muted); font-size: 15px; font-weight: 700; }

.hist__list { display: grid; gap: .6rem; }
.hist { display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left; padding: .85rem; background: var(--surface); border: 1px solid var(--outline); border-radius: 1.25rem; }
.hist__score { display: grid; place-items: center; flex: none; width: 3.1rem; height: 3.1rem; border-radius: 50%; font-weight: 800; font-size: 1.1rem; }
.hist.is-ok .hist__score { background: var(--ok-bg); color: var(--ok); }
.hist.is-bad .hist__score { background: var(--bad-bg); color: var(--bad); }
.hist__body { flex: 1; display: grid; line-height: 1.35; }
.hist__body span { color: var(--muted); font-size: .85rem; }
.hist__fails { color: var(--muted); font-size: .85rem; }

/* ============ Ajustes ============ */
.settings__h { font-size: .95rem; font-weight: 800; color: var(--primary); letter-spacing: .03em; margin: .5rem .25rem -.5rem; }
.row__title { display: block; margin-top: .5rem; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--outline); border-radius: 999px; overflow: hidden; }
.seg__btn { min-height: 2.8rem; padding: .4rem; border: 0; background: transparent; font-weight: 600; }
.seg__btn + .seg__btn { border-left: 1px solid var(--outline); }
.seg__btn.is-on { background: var(--chip-bg); color: var(--chip-text); font-weight: 800; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.5rem; }
.row__text { display: grid; }
.row__text span { color: var(--muted); font-size: .85rem; }
.switch { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 3.2rem; height: 1.9rem; border-radius: 999px; background: var(--surface-var); border: 2px solid var(--outline); transition: background .15s ease; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 50%; left: .2rem; width: 1.2rem; height: 1.2rem; margin-top: -.6rem; border-radius: 50%; background: var(--muted); transition: transform .15s ease, background .15s ease; }
.switch:checked { background: var(--primary); border-color: var(--primary); }
.switch:checked::after { transform: translateX(1.25rem); background: var(--on-primary); }
.settings__btns { display: flex; flex-wrap: wrap; gap: .6rem; }

/* ============ Diálogos ============ */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modal__scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); animation: fadein .2s ease; }
.modal__panel { position: relative; width: min(100%, 26rem); max-height: 90vh; overflow: auto; padding: 1.5rem; background: var(--surface); border-radius: 1.75rem; box-shadow: var(--shadow); animation: rise .25s ease; }
.modal--sheet { place-items: end center; padding: 0; }
.modal--sheet .modal__panel { width: min(100%, 36rem); border-radius: 1.75rem 1.75rem 0 0; padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0)); animation: slideup .25s ease; }
.modal__title { font-size: 1.3rem; font-weight: 800; margin-bottom: .75rem; }
.modal__text { color: var(--muted); }
.modal__actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.sheet__list { display: grid; gap: .6rem; }
.sheet__list .mode { animation: none; }
.blocks { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.blockbtn { display: grid; place-items: center; min-height: 3.2rem; border-radius: 999px; background: var(--chip-bg); color: var(--chip-text); font-weight: 800; font-size: .95rem; text-decoration: none; }
.blockbtn:hover { filter: brightness(.96); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: 7rem; z-index: 60; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: .75rem 1.25rem; border-radius: 999px; background: #222c25; color: #fff; font-size: .95rem; transition: opacity .2s ease, transform .2s ease; max-width: 90vw; text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
