/* Primero el móvil: una columna, acciones al alcance del pulgar y objetivos de al menos 48 px. */
:root {
  color-scheme: light dark;
  --bg: #f6f4ef; --surface: #fffdf8; --raised: #ece8df; --line: #d9d3c6;
  --ink: #1b1f24; --muted: #5d6268; --accent: #99600a; --accent-ink: #fffdf8; --accent-soft: #f4e5c8;
  --right: #1f7a4d; --wrong: #b3362b; --review: #8a6200;
  --bar: #99600a; --bar-2: #d9c79f;
  --right-soft: #e2f1e8; --wrong-soft: #f8e3e0; --review-soft: #f6ecd2;
  /* Áreas del temario: paleta categórica validada (orden fijo), siempre acompañada de texto */
  --area-1: #2a78d6; --area-2: #eb6834; --area-3: #1baf7a; --area-4: #eda100; --area-5: #e87ba4; --area-6: #6250d6;
  /* Mapa de calor: una sola tonalidad, de claro a oscuro */
  --heat-0: #ece8df; --heat-1: #f1d9ab; --heat-2: #dcab55; --heat-3: #b47c18; --heat-4: #7c5208;
  --serif: "Noto Serif", Georgia, "Times New Roman", serif;
  --mono: "Roboto Mono", "Droid Sans Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabs: 60px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --surface: #1a212a; --raised: #252e39; --line: #313b47;
    --ink: #eef0f2; --muted: #a0a9b4; --accent: #f2b04a; --accent-ink: #1b1305; --accent-soft: #3a2d15;
    --right: #5fc792; --wrong: #f0857a; --review: #e6bd5c;
    --bar: #f2b04a; --bar-2: #5c4a26;
    --right-soft: #16301f; --wrong-soft: #3a1d1a; --review-soft: #352b12;
    --area-1: #3987e5; --area-2: #d95926; --area-3: #199e70; --area-4: #c98500; --area-5: #d55181; --area-6: #9085e9;
    --heat-0: #252e39; --heat-1: #4a3b1d; --heat-2: #7d5d22; --heat-3: #b8862c; --heat-4: #f2b04a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); overscroll-behavior-y: none; }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--tabs) + 24px + env(safe-area-inset-bottom)); outline: none; }
body.focus main { padding-bottom: 110px; }
h1 { font-size: 22px; line-height: 1.25; margin: 4px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 13px; font-weight: 600; margin: 24px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

button, .btn { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
.btn { display: flex; align-items: center; justify-content: center; min-height: 52px; width: 100%; padding: 8px 16px; border-radius: 12px; font-weight: 600; background: var(--raised); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled), .row:active { filter: brightness(0.93); }
.link { color: var(--accent); font-weight: 600; min-height: 48px; padding: 0 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Barra inferior */
.tabs { position: fixed; inset: auto 0 0 0; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; height: var(--tabs); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted); text-decoration: none; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
body.focus .tabs { display: none; }

.update { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 16px; background: var(--accent-soft); font-size: 14px; }
.update[hidden] { display: none; }

/* Filas y listas */
.list { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-align: left; color: inherit; text-decoration: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; display: block; }
.row .sub { font-size: 14px; color: var(--muted); display: block; }
.row .count { font-family: var(--mono); font-size: 15px; color: var(--muted); white-space: nowrap; }
.row.hot { border-color: var(--accent); background: var(--accent-soft); }
.row.hot .count { color: var(--ink); font-weight: 600; }
.row:disabled { opacity: 0.5; }

/* Selector segmentado */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--raised); border-radius: 12px; }
.seg button { flex: 1; min-height: 44px; border-radius: 9px; font-size: 15px; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.15); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 22px; font-size: 15px; color: var(--muted); }
.chips button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }

/* Sesión */
.topbar { display: flex; align-items: center; gap: 8px; margin: -8px 0 8px; min-height: 48px; }
.topbar .close { width: 48px; height: 48px; margin-left: -12px; font-size: 24px; color: var(--muted); }
.track { flex: 1; height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }
.track i { display: block; height: 100%; background: var(--accent); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.question, .prose, .answer { font-variant-numeric: lining-nums; }
.question { font: 19px/1.5 var(--serif); }
.prose { font: 17px/1.55 var(--serif); }
.prose code, .question code { font: 0.86em var(--mono); background: var(--raised); padding: 1px 4px; border-radius: 4px; }
.prose pre { font: 13.5px/1.45 var(--mono); background: var(--raised); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 0 0 12px; }
.prose pre code { background: none; padding: 0; font: inherit; }
.answer { margin: 16px 0; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 8px 8px 0; font: 600 17px/1.4 var(--serif); overflow-wrap: anywhere; }
.answer p { margin: 0; }
.dock { position: fixed; inset: auto 0 0 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); z-index: 4; }
.dock > div { max-width: 608px; margin: 0 auto; display: grid; gap: 8px; }
.grades { grid-template-columns: 1fr 1fr 1fr; }
.grades .btn { font-size: 15px; padding: 8px 4px; }
.g-wrong { color: var(--wrong); }
.g-review { color: var(--review); }
.g-right { color: var(--right); }

/* Cifras */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.stat b { display: block; font: 600 24px/1.2 var(--mono); }
.stat span { font-size: 13px; color: var(--muted); }

/* Gráficos */
.meter { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.meter:last-child { border-bottom: 0; }
.meter .val { font-family: var(--mono); font-size: 14px; color: var(--muted); }
.meter .bar { grid-column: 1 / -1; height: 6px; background: var(--raised); border-radius: 3px; overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--bar); border-radius: 3px; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; }
.bars button { flex: 1; height: 100%; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; padding: 0; }
.bars i { display: block; background: var(--bar); border-radius: 0; }
.bars i.rest { background: var(--bar-2); border-radius: 3px 3px 0 0; }
.bars i.top { border-radius: 3px 3px 0 0; }
.bars button[aria-pressed="true"] i { outline: 1px solid var(--ink); }
.axis { display: flex; justify-content: space-between; font: 12px var(--mono); color: var(--muted); margin-top: 4px; border-top: 1px solid var(--line); padding-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.readout { min-height: 22px; font-size: 14px; margin: 8px 0 0; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-size: 13px; font-weight: 500; color: var(--muted); }
th, td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
td.r, th.r { text-align: right; font-family: var(--mono); }

/* Cálculo mental: todo cabe en pantalla, sin desplazamiento */
body.drill main { padding: 8px 16px 0; height: 100dvh; display: flex; flex-direction: column; }
.drill-head { display: flex; align-items: center; justify-content: space-between; min-height: 48px; font: 600 17px var(--mono); }
.drill-head .close { width: 48px; height: 48px; margin-left: -12px; font-size: 24px; color: var(--muted); }
.prompt { flex: 1 1 auto; min-height: 90px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.prompt .expr { font: 600 clamp(30px, 10vw, 44px)/1.2 var(--mono); }
.prompt .typed { font: 500 32px/1.3 var(--mono); min-height: 44px; color: var(--accent); }
.prompt .flash { font-size: 14px; min-height: 22px; color: var(--wrong); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.keypad button { min-height: clamp(50px, 9dvh, 68px); border-radius: 12px; background: var(--raised); font: 500 24px var(--mono); touch-action: manipulation; }
.keypad button:active { filter: brightness(0.85); }
.keypad .act { font: 600 16px var(--sans); }
.keypad .ok { background: var(--accent); color: var(--accent-ink); }

label.field { display: block; margin-bottom: 12px; }
label.field input[type=date] { display: block; width: 100%; min-height: 48px; margin-top: 8px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: inherit; font: inherit; }
textarea { width: 100%; min-height: 120px; font: 14px/1.4 var(--mono); padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: inherit; }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--raised); font-size: 14px; margin: 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.notice.bad { color: var(--wrong); }
.stack { display: grid; gap: 8px; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

/* Tipo test: opciones largas, alineadas a la izquierda; al responder se marcan correcta y elegida */
.options { margin-top: 16px; }
.btn.opt { justify-content: flex-start; text-align: left; font-weight: 500; line-height: 1.35; padding: 12px 14px; }
.btn.opt.g-right { outline: 2px solid var(--right); opacity: 1; }
.btn.opt.g-wrong { outline: 2px solid var(--wrong); opacity: 1; }
.notice a { color: inherit; }

/* Bloques de tema: lista de ideas clave para autocorregirse; toda la fila es pulsable */
.ideas { margin: 12px 0 16px; }
.idea { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; line-height: 1.4; cursor: pointer; overflow-wrap: anywhere; }
.idea input { flex: none; width: 22px; height: 22px; margin: 1px 0 0; }
.idea p { margin: 0; }
.dock .stack p { margin: 0; text-align: center; }
.mastered { color: var(--right); font-weight: 600; }

/* ---------- Identidad por área del temario ---------- */
.area-1 { --area: var(--area-1); } .area-2 { --area: var(--area-2); } .area-3 { --area: var(--area-3); }
.area-4 { --area: var(--area-4); } .area-5 { --area: var(--area-5); } .area-6 { --area: var(--area-6); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 2px 10px 2px 8px; border-radius: 13px; background: var(--raised); color: var(--ink); font-size: 13px; font-weight: 500; white-space: nowrap; }
.chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--area, var(--muted)); flex: none; }
.chip.deck { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.meta { align-items: center; }
/* La tarjeta de la sesión lleva una franja del color de su área */
.question.area-1, .question.area-2, .question.area-3, .question.area-4, .question.area-5, .question.area-6 { border-left: 4px solid var(--area); padding-left: 12px; }

/* ---------- Respuesta: color, icono y un pequeño rebote ---------- */
.btn.opt.g-right { background: var(--right-soft); color: var(--ink); }
.btn.opt.g-wrong { background: var(--wrong-soft); color: var(--ink); }
.btn.opt.g-right::before, .btn.opt.g-wrong::before { flex: none; width: 22px; font-weight: 700; margin-right: 8px; }
.btn.opt.g-right::before { content: "✓"; color: var(--right); }
.btn.opt.g-wrong::before { content: "✕"; color: var(--wrong); }
.btn.opt:disabled:not(.g-right):not(.g-wrong) { opacity: 0.55; }
.verdict { display: flex; align-items: center; gap: 10px; margin: 16px 0 8px; padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.verdict.right { background: var(--right-soft); color: var(--right); }
.verdict.wrong { background: var(--wrong-soft); color: var(--wrong); }
.verdict.review { background: var(--review-soft); color: var(--review); }
.verdict b { font-size: 20px; line-height: 1; }
.verdict .vtext span { color: var(--ink); font-weight: 500; }
.grades .btn.g-wrong { background: var(--wrong-soft); }
.grades .btn.g-review { background: var(--review-soft); }
.grades .btn.g-right { background: var(--right-soft); }
@keyframes pop { 0% { transform: scale(0.97); } 60% { transform: scale(1.015); } 100% { transform: scale(1); } }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.btn.opt.g-right.picked, .verdict.right { animation: pop 0.28s ease-out; }
.btn.opt.g-wrong.picked { animation: nudge 0.25s ease-in-out; }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* Barra de la sesión: un segmento por tarjeta, coloreado según cómo fue */
.strip { flex: 1; display: flex; gap: 2px; height: 6px; }
.strip i { flex: 1; min-width: 2px; border-radius: 3px; background: var(--raised); }
.strip i.right { background: var(--right); } .strip i.wrong { background: var(--wrong); } .strip i.review { background: var(--review); }
.strip i.now { background: var(--muted); }

/* Lista de ideas de un bloque: al marcar se tiñe de «acierto» */
.idea:has(input:checked) { border-color: var(--right); background: var(--right-soft); }
.idea input { accent-color: var(--right); }
.tally { display: flex; align-items: center; gap: 10px; justify-content: center; }
.tally .meterline { flex: 0 0 120px; height: 6px; border-radius: 3px; background: var(--raised); overflow: hidden; }
.tally .meterline i { display: block; height: 100%; border-radius: 3px; background: var(--wrong); transition: width 0.2s, background 0.2s; }
.tally .meterline i.mid { background: var(--review); } .tally .meterline i.ok { background: var(--right); }

/* ---------- Inicio ---------- */
.hello { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 4px 0 14px; }
.hello h1 { margin: 0; }
.hello .when { font-size: 14px; color: var(--muted); text-align: right; }
.hero { display: flex; align-items: center; gap: 16px; padding: 16px; border-radius: 16px; background: var(--accent-soft); border: 1px solid var(--accent); width: 100%; text-align: left; color: inherit; }
.hero:disabled { opacity: 1; background: var(--surface); border-color: var(--line); cursor: default; }
.hero .grow { flex: 1; min-width: 0; }
.hero .title { display: block; font-size: 19px; font-weight: 700; }
.hero .sub { display: block; font-size: 14px; color: var(--muted); }
.hero .go { font-size: 30px; line-height: 1; font-weight: 300; color: var(--accent); }
.ring { --p: 0; --c: var(--accent); flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1turn), var(--raised) 0); position: relative; }
.ring::before { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--bg); }
.hero .ring::before { background: var(--accent-soft); }
.hero:disabled .ring::before { background: var(--surface); }
.ring b { position: relative; font: 600 15px var(--mono); }
.ring.big { width: 112px; height: 112px; } .ring.big::before { inset: 11px; } .ring.big b { font-size: 26px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.pill b { font-family: var(--mono); }

/* ---------- Resumen de sesión ---------- */
.summary-head { display: flex; align-items: center; gap: 18px; margin: 8px 0 16px; }
.summary-head p { margin: 0; }
.summary-head .msg { font: 600 18px/1.35 var(--serif); }
.summary-strip { display: flex; flex-wrap: wrap; gap: 3px; margin: 4px 0 16px; }
.summary-strip i { width: 14px; height: 14px; border-radius: 4px; background: var(--raised); }
.summary-strip i.right { background: var(--right); } .summary-strip i.wrong { background: var(--wrong); } .summary-strip i.review { background: var(--review); }

/* ---------- Estadísticas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.card + .card { margin-top: 8px; }
.stat small { display: block; font-size: 12px; margin-top: 2px; color: var(--muted); }
.up { color: var(--right) !important; } .down { color: var(--wrong) !important; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 15px; align-items: center; }
.hbar:last-child { border-bottom: 0; }
.hbar .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .name i { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--area, var(--bar)); }
.hbar .val { font: 600 15px var(--mono); white-space: nowrap; }
.hbar .detail { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.hbar .track2 { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--raised); overflow: hidden; }
.hbar .track2 i { display: block; height: 100%; border-radius: 4px; background: var(--area, var(--bar)); }
.note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 3px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--heat-0); }
.heat i.h1 { background: var(--heat-1); } .heat i.h2 { background: var(--heat-2); } .heat i.h3 { background: var(--heat-3); } .heat i.h4 { background: var(--heat-4); }
.heat i.future { background: transparent; }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: 12px; color: var(--muted); margin-top: 6px; }
.heat-legend i { width: 12px; height: 12px; border-radius: 3px; }
.weak { display: grid; gap: 8px; }
.weak .card p { margin: 0 0 6px; font: 15px/1.4 var(--serif); }
.weak .card .small { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }

/* ---------- Prueba común: ejercicios de Matemáticas con teclado propio ---------- */
.exercise { font: 600 20px/1.45 var(--serif); margin: 12px 0 6px; overflow-wrap: anywhere; }
.typed-box { display: flex; align-items: baseline; justify-content: center; gap: 8px; min-height: 64px; margin: 14px 0; padding: 10px 14px; border: 2px solid var(--accent); border-radius: 14px; background: var(--surface); }
.typed-box #typed { font: 600 30px/1.2 var(--mono); letter-spacing: 0.02em; }
.typed-box .muted { font-size: 18px; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.keys .key { min-height: clamp(48px, 7.5dvh, 60px); border-radius: 12px; background: var(--raised); font: 500 22px var(--mono); touch-action: manipulation; }
.keys .key:active { filter: brightness(0.88); }
.keys .zero { grid-column: span 2; }
.keys .ok { grid-column: span 2; background: var(--accent); color: var(--accent-ink); font: 700 18px var(--sans); }
body.focus main:has(.keys) { padding-bottom: 300px; }
.steps { margin: 10px 0 12px; }
.steps ol { margin: 6px 0 0; padding-left: 22px; font: 16px/1.5 var(--serif); }
.steps li + li { margin-top: 4px; }
