/* Ratitos de cultura — hoja de estilos
   Concepto: una "ficha de estudio" por pregunta, columna única centrada,
   acciones en la zona del pulgar. Colores por categoría; neutros azulados. */
:root {
  /* Color */
  --bg: #eef0f5;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --ink: #171c2b;
  --muted: #5e6780;
  --line: #d9dee8;
  --primary: #171c2b;
  --on-primary: #ffffff;
  --ok: #17895a;
  --ok-soft: #dff4ea;
  --ko: #cf3b32;
  --ko-soft: #fbe4e2;
  --flame: #f29f05;
  --rule: rgba(30, 60, 120, 0.06);
  --shadow: 0 1px 2px rgba(23, 28, 43, 0.06), 0 8px 24px rgba(23, 28, 43, 0.07);
  /* Categorías */
  --c-geo: #1f74d6;
  --c-his: #b77a06;
  --c-art: #9a43c2;
  --c-sci: #148a5c;
  --c-ent: #d63a72;
  --c-dep: #db6114;
  /* Tipografía */
  --f-display: 'Bricolage Grotesque', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --f-body: 'Figtree', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius: 18px;
  --radius-s: 12px;
  --maxw: 34rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #11141b;
    --surface: #1a1e28;
    --surface-2: #222736;
    --ink: #e8ebf2;
    --muted: #9aa3b8;
    --line: #2d3344;
    --primary: #e8ebf2;
    --on-primary: #11141b;
    --ok: #3fc98b;
    --ok-soft: #173327;
    --ko: #ff6b61;
    --ko-soft: #3a1d1d;
    --flame: #ffb52e;
    --rule: rgba(160, 180, 230, 0.05);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --c-geo: #5ea3ff;
    --c-his: #eab04a;
    --c-art: #c98aeb;
    --c-sci: #45c893;
    --c-ent: #ff7aa6;
    --c-dep: #ff9a57;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #11141b;
  --surface: #1a1e28;
  --surface-2: #222736;
  --ink: #e8ebf2;
  --muted: #9aa3b8;
  --line: #2d3344;
  --primary: #e8ebf2;
  --on-primary: #11141b;
  --ok: #3fc98b;
  --ok-soft: #173327;
  --ko: #ff6b61;
  --ko-soft: #3a1d1d;
  --flame: #ffb52e;
  --rule: rgba(160, 180, 230, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --c-geo: #5ea3ff;
  --c-his: #eab04a;
  --c-art: #c98aeb;
  --c-sci: #45c893;
  --c-ent: #ff7aa6;
  --c-dep: #ff9a57;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--c-geo); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100%;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
}

/* Categorías: cada elemento con data-cat recibe su color */
[data-cat='geo'] { --cat: var(--c-geo); }
[data-cat='his'] { --cat: var(--c-his); }
[data-cat='art'] { --cat: var(--c-art); }
[data-cat='sci'] { --cat: var(--c-sci); }
[data-cat='ent'] { --cat: var(--c-ent); }
[data-cat='dep'] { --cat: var(--c-dep); }

/* ---------- Cabecera ---------- */
.top { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em; }
.brand svg { width: 34px; height: 34px; flex: none; }
.top .spacer { flex: 1; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.streak {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface);
  font-weight: 700; font-variant-numeric: tabular-nums; box-shadow: var(--shadow);
}
.streak svg { width: 18px; height: 18px; fill: var(--flame); }
.streak.off svg { fill: var(--line); }

/* ---------- Inicio ---------- */
.home { display: flex; flex-direction: column; gap: 18px; padding-top: 8px; flex: 1; }
.today {
  display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.ring { width: 76px; height: 76px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--surface-2); }
.ring .fill { stroke: var(--ok); stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.ring .num { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.today h2 { margin: 0 0 2px; font-family: var(--f-display); font-size: 1.15rem; letter-spacing: -0.01em; text-wrap: balance; }
.today p { margin: 0; color: var(--muted); font-size: 0.95rem; }

.cta {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; border: 0; border-radius: var(--radius);
  background: var(--primary); color: var(--on-primary); padding: 18px 20px; text-align: left; box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.cta:active { transform: scale(0.985); }
.cta .t { font-family: var(--f-display); font-weight: 800; font-size: 1.45rem; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; }
.cta .s { opacity: 0.75; font-size: 0.95rem; }
.btn-2 {
  width: 100%; border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px 18px; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700;
}
.btn-2 .badge { background: var(--ko); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 0.9rem; font-variant-numeric: tabular-nums; }

.section-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; margin: 4px 0 -6px; }
.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cat {
  position: relative; border: 2px solid transparent; border-radius: var(--radius-s); background: var(--surface); padding: 12px 12px 10px;
  text-align: left; display: flex; flex-direction: column; gap: 6px; min-width: 0; box-shadow: var(--shadow);
}
.cat[aria-pressed='true'] { border-color: var(--cat, var(--ink)); }
.cat .n { font-weight: 700; display: flex; align-items: center; gap: 8px; font-size: 0.98rem; }
.cat .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cat, var(--ink)); flex: none; }
.cat .bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.cat .bar i { display: block; height: 100%; background: var(--cat, var(--ink)); border-radius: 3px; min-width: 2px; }
.cat .m { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cat.all { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
.cat.all .rainbow { display: flex; gap: 4px; }
.cat.all .rainbow span { width: 8px; height: 8px; border-radius: 50%; }

.foot { margin-top: auto; padding-top: 8px; color: var(--muted); font-size: 0.85rem; text-align: center; }
.foot b { color: var(--ink); font-variant-numeric: tabular-nums; }

.intro {
  background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.intro h2 { margin: 0; font-family: var(--f-display); font-size: 1.2rem; letter-spacing: -0.01em; }
.intro ul { margin: 0; padding-left: 1.1em; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.intro button { align-self: flex-start; border: 0; background: transparent; color: var(--c-geo); font-weight: 700; padding: 6px 0; }

/* ---------- Pregunta ---------- */
.quiz { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.qbar { display: flex; align-items: center; gap: 10px; }
.progress { flex: 1; display: flex; gap: 4px; }
.progress span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.progress span.ok { background: var(--ok); }
.progress span.ko { background: var(--ko); }
.progress span.now { background: var(--ink); }
.counter { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; font-size: 0.95rem; min-width: 3.2em; text-align: right; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; position: relative;
  /* renglones de ficha */
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule) 31px 32px);
  background-position: 0 52px;
}
.card .band { height: 8px; background: var(--cat); }
.card .inner { padding: 14px 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.chip {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--cat);
}
.chip .tag { color: var(--muted); font-weight: 700; letter-spacing: 0.04em; }
.prompt { margin: 0; font-size: 1.05rem; color: var(--muted); text-wrap: balance; }
.subject { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: clamp(1.55rem, 6.4vw, 2.1rem); line-height: 1.12; letter-spacing: -0.02em; text-wrap: balance; overflow-wrap: anywhere; }
.subject.long { font-size: clamp(1.25rem, 5vw, 1.6rem); }
.prompt.solo { color: var(--ink); font-family: var(--f-display); font-weight: 800; font-size: clamp(1.35rem, 5.6vw, 1.8rem); line-height: 1.15; letter-spacing: -0.015em; }
.flag { font-size: 6rem; line-height: 1; text-align: center; padding: 6px 0; }
.qimg { display: block; width: 100%; max-height: 30vh; object-fit: contain; border-radius: var(--radius-s); background: var(--surface-2); }

.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  min-height: 58px; width: 100%; border: 2px solid var(--line); border-radius: var(--radius-s); background: var(--surface); padding: 12px 16px;
  text-align: left; font-weight: 700; font-size: 1.05rem; line-height: 1.25; display: flex; align-items: center; gap: 12px;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease; overflow-wrap: anywhere;
}
.opt .k {
  flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 0.85rem;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.opt:not(:disabled):active { transform: scale(0.98); }
@media (hover: hover) { .opt:not(:disabled):hover { border-color: var(--ink); } }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .k { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--ko); background: var(--ko-soft); }
.opt.wrong .k { background: var(--ko); color: #fff; }
.opt.dim { opacity: 0.55; }
.options.two .opt { min-height: 72px; font-size: 1.12rem; }
.vs { text-align: center; color: var(--muted); font-weight: 700; font-size: 0.8rem; letter-spacing: 0.1em; margin: -4px 0; }

@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.03); } 100% { transform: scale(1); } }
.opt.wrong.anim { animation: shake 0.3s ease; }
.opt.right.anim { animation: pop 0.3s ease; }

/* ---------- Dato (tras responder) ---------- */
.learn {
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
  border-left: 6px solid var(--ok);
}
.learn.bad { border-left-color: var(--ko); }
.learn .verdict { font-family: var(--f-display); font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.learn .verdict.good { color: var(--ok); }
.learn .verdict.bad { color: var(--ko); }
.learn .fact { margin: 0; font-size: 1.08rem; font-weight: 700; text-wrap: pretty; }
.ficha { display: flex; flex-direction: column; gap: 8px; border-top: 1px dashed var(--line); padding-top: 10px; }
.ficha .ft { display: flex; gap: 12px; align-items: flex-start; }
.ficha .fimg { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; flex: none; background: var(--surface-2); }
.ficha h3 { margin: 0; font-family: var(--f-display); font-size: 1.05rem; letter-spacing: -0.01em; }
.ficha .desc { margin: 2px 0 0; color: var(--muted); font-size: 0.95rem; }
.ficha dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 0.93rem; }
.ficha dt { color: var(--muted); }
.ficha dd { margin: 0; font-weight: 700; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.ficha .extract { margin: 0; font-size: 0.95rem; color: var(--ink); }
.links { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.links a, .links button { font-weight: 700; color: var(--c-geo); text-decoration: none; background: none; border: 0; padding: 4px 0; font-size: 0.95rem; }
.links a:hover, .links button:hover { text-decoration: underline; }

.report { border-top: 1px dashed var(--line); padding-top: 8px; }
.report button { background: none; border: 0; padding: 4px 0; color: var(--muted); font-size: 0.85rem; text-decoration: underline; text-underline-offset: 2px; }
.report button:disabled { text-decoration: none; cursor: default; }
.sources { margin: 0; padding-left: 1.1em; color: var(--muted); font-size: 0.9rem; display: flex; flex-direction: column; gap: 4px; }
.sources b { color: var(--ink); }
.next-wrap {
  position: sticky; bottom: 0; padding-top: 10px; padding-bottom: env(safe-area-inset-bottom, 0px); margin-top: auto;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.next {
  width: 100%; min-height: 58px; border: 0; border-radius: var(--radius); background: var(--primary); color: var(--on-primary);
  font-family: var(--f-display); font-weight: 800; font-size: 1.2rem; letter-spacing: -0.01em; display: flex; align-items: center; justify-content: center; gap: 8px;
}

/* ---------- Resumen ---------- */
.done { display: flex; flex-direction: column; gap: 16px; padding-top: 8px; flex: 1; }
.score {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 18px; text-align: center; display: flex; flex-direction: column; gap: 6px;
}
.score .big { font-family: var(--f-display); font-weight: 800; font-size: 3.2rem; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.score .big small { font-size: 1.4rem; color: var(--muted); }
.score h2 { margin: 0; font-family: var(--f-display); font-size: 1.35rem; letter-spacing: -0.01em; text-wrap: balance; }
.score p { margin: 0; color: var(--muted); }
.pills { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.pill { border-radius: 999px; background: var(--surface-2); padding: 5px 12px; font-size: 0.88rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.recap { display: flex; flex-direction: column; gap: 8px; }
.recap li {
  list-style: none; background: var(--surface); border-radius: var(--radius-s); padding: 12px 14px; display: grid; grid-template-columns: auto 1fr; gap: 10px;
  align-items: start; box-shadow: var(--shadow);
}
.recap ul { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recap .mk { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 0.8rem; font-weight: 800; }
.recap .mk.ok { background: var(--ok); }
.recap .mk.ko { background: var(--ko); }
.recap .tx { min-width: 0; overflow-wrap: anywhere; }
.recap .tx small { display: block; color: var(--muted); font-size: 0.82rem; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 .btn-2 { justify-content: center; text-align: center; }

/* ---------- Estadísticas y ajustes ---------- */
.page { display: flex; flex-direction: column; gap: 16px; padding-top: 4px; }
.page h1 { margin: 0; font-family: var(--f-display); font-size: 1.6rem; letter-spacing: -0.02em; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border-radius: var(--radius-s); padding: 14px; box-shadow: var(--shadow); }
.tile b { display: block; font-family: var(--f-display); font-size: 1.7rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile span { color: var(--muted); font-size: 0.88rem; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0; font-size: 1rem; font-family: var(--f-display); }
.catrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.catrow .bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: flex; }
.catrow .bar i { display: block; height: 100%; background: var(--cat); }
.catrow .bar i.l { opacity: 0.45; }
.catrow .nm { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.catrow .nm .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cat); }
.catrow .v { color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.days { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; align-items: end; height: 90px; }
.days div { background: var(--c-geo); border-radius: 4px 4px 2px 2px; min-height: 3px; opacity: 0.85; }
.days div.zero { background: var(--line); }
.days-l { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.78rem; }
.note { color: var(--muted); font-size: 0.9rem; margin: 0; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-weight: 700; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1 0 auto; min-width: 56px; min-height: 44px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; padding: 6px 10px; }
.seg button[aria-pressed='true'] { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.switch input { width: 48px; height: 28px; accent-color: var(--ok); }
textarea { width: 100%; min-height: 90px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface-2); padding: 10px; font-size: 0.85rem; resize: vertical; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-s { border: 2px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 14px; font-weight: 700; min-height: 44px; }
.btn-s.danger { border-color: var(--ko); color: var(--ko); }
.btn-s.solid-danger { background: var(--ko); border-color: var(--ko); color: #fff; }
.msg { font-size: 0.9rem; font-weight: 700; color: var(--ok); }
.msg.err { color: var(--ko); }

/* ---------- Carga ---------- */
.loading { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); }
.loading .brand { justify-content: center; color: var(--ink); font-size: 1.8rem; }
.loading .brand svg { width: 52px; height: 52px; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin 0.8s linear infinite; margin: 14px auto 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.fade-in { animation: fadeIn 0.22s ease both; }
@keyframes fadeIn { from { opacity: 0.001; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 640px) {
  body { font-size: 18px; }
  .app { padding-block: 24px 32px; }
}
