:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --fill: #ececf0;
  --blue: #0071e3;
  --blue-soft: #e8f2fd;
  --green: #248a3d;
  --green-soft: #e3f5e8;
  --orange: #b25000;
  --orange-soft: #fff1e0;
  --red: #d70015;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .04);
  --radius: 20px;
  color-scheme: light;
}
/* Oscuro: automático según el dispositivo, salvo que se elija «Claro»; o forzado con «Oscuro» */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #000000; --card: #1c1c1e; --text: #f5f5f7; --muted: #98989f; --line: #2f2f33; --fill: #2a2a2e;
    --blue: #2997ff; --blue-soft: #0f2b47; --green: #30d158; --green-soft: #11321c; --orange: #ff9f0a; --orange-soft: #3a2a0c;
    --red: #ff453a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme=dark] {
    --bg: #000000; --card: #1c1c1e; --text: #f5f5f7; --muted: #98989f; --line: #2f2f33; --fill: #2a2a2e;
    --blue: #2997ff; --blue-soft: #0f2b47; --green: #30d158; --green-soft: #11321c; --orange: #ff9f0a; --orange-soft: #3a2a0c;
    --red: #ff453a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.47 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--blue); text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); outline-offset: 2px; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.topbar-in { max-width: 720px; margin: 0 auto; padding: 0 20px; height: 52px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; color: var(--text); font-size: 17px; }
.brand img { width: 26px; height: 26px; }
.link { color: var(--blue); font-size: 16px; padding: 10px 0 10px 10px; }
.page { max-width: 720px; margin: 0 auto; padding: 14px 20px 80px; }
.back { display: inline-flex; align-items: center; gap: 2px; font-size: 17px; padding: 8px 8px 8px 0; margin-left: -4px; }
.back svg { width: 22px; height: 22px; }

.eyebrow { color: var(--muted); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-top: 10px; }
h1 { font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -0.025em; margin-top: 6px; text-wrap: balance; }
h1.small { font-size: 27px; line-height: 1.18; }
.lead { color: var(--muted); font-size: 19px; line-height: 1.4; margin-top: 10px; text-wrap: pretty; }
h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; margin: 34px 4px 12px; }
h2 small { display: block; color: var(--muted); font-weight: 400; font-size: 15px; letter-spacing: 0; margin-top: 1px; }
.note { color: var(--muted); font-size: 14px; line-height: 1.45; margin: 12px 4px 0; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 22px; }
.stack { display: grid; gap: 14px; margin-top: 24px; }

/* ---------- Botones y campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 26px; border-radius: 14px;
  background: var(--blue); color: #fff; font-weight: 600; font-size: 17px; width: 100%;
  transition: opacity .15s, transform .1s;
}
.btn:hover { opacity: .9; }
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.secondary { background: var(--fill); color: var(--text); }
.btn.quiet { background: none; color: var(--blue); font-weight: 500; }
.btn.danger { background: none; color: var(--red); font-weight: 500; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 26px; }

label.field { display: block; font-size: 15px; font-weight: 600; margin-bottom: 16px; }
label.field span { display: block; margin: 0 2px 7px; }
input[type=email], input[type=password], input[type=search], textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 13px;
  padding: 14px 15px; font-size: 17px; font-weight: 400; outline: none; transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue) 18%, transparent); }
textarea { min-height: 150px; resize: vertical; line-height: 1.5; display: block; }
.card input, .card textarea { background: var(--bg); }
input[type=search] { background: var(--fill); border-color: transparent; }
.error { color: var(--red); font-size: 15px; margin: -4px 2px 14px; min-height: 0; }

/* ---------- Acceso ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 20px; }
.login-box { width: 100%; max-width: 400px; }
.login-box .logo { width: 68px; height: 68px; display: block; margin: 0 auto 20px; border-radius: 17px; box-shadow: 0 10px 28px rgba(0, 113, 227, .28); }
.login-box h1 { text-align: center; font-size: 30px; margin: 0; }
.login-box .lead { text-align: center; font-size: 17px; margin-bottom: 30px; }
.login-box form { padding: 24px 22px 22px; }

/* ---------- Tarjetas grandes de inicio ---------- */
.big { display: flex; align-items: center; gap: 18px; padding: 22px; color: var(--text); text-align: left; width: 100%; transition: transform .15s; }
.big:hover { transform: translateY(-1px); }
.big:active { transform: scale(.99); }
.big .txt { flex: 1; min-width: 0; }
.big h3 { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.big p { color: var(--muted); font-size: 15px; line-height: 1.4; margin-top: 5px; }
.big .meta { color: var(--blue); font-size: 15px; font-weight: 600; margin-top: 10px; }
.chev { width: 20px; height: 20px; color: color-mix(in srgb, var(--muted) 55%, transparent); flex: none; }

.ring { position: relative; width: 68px; height: 68px; flex: none; }
.ring svg { width: 68px; height: 68px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; }
.ring .track { stroke: var(--fill); }
.ring .val { stroke: var(--blue); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; font-weight: 700; }

/* ---------- Listas ---------- */
.list { overflow: hidden; }
.item { display: flex; align-items: center; gap: 14px; padding: 15px 18px; width: 100%; text-align: left; color: var(--text); position: relative; min-height: 62px; }
.item + .item::before { content: ""; position: absolute; top: 0; right: 0; left: 66px; border-top: 1px solid var(--line); }
.list.plain .item + .item::before { left: 18px; }
a.item:hover, button.item:hover { background: color-mix(in srgb, var(--fill) 45%, transparent); }
.item .txt { flex: 1; min-width: 0; }
.item .t { font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .s { display: block; color: var(--muted); font-size: 14px; line-height: 1.35; margin-top: 2px; }
.num { width: 34px; height: 34px; border-radius: 50%; background: var(--fill); display: grid; place-items: center; font-size: 14px; font-weight: 600; flex: none; color: var(--muted); }
.num.estudiando { background: var(--orange-soft); color: var(--orange); }
.num.dominado { background: var(--green-soft); color: var(--green); }
.ico { width: 34px; height: 34px; border-radius: 10px; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; flex: none; }
.ico svg { width: 19px; height: 19px; }

.pill { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 99px; white-space: nowrap; flex: none; }
.pill.estudiando { background: var(--orange-soft); color: var(--orange); }
.pill.dominado { background: var(--green-soft); color: var(--green); }

/* ---------- Resumen y progreso ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 18px 8px; }
.stats div + div { border-left: 1px solid var(--line); }
.stats b { display: block; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stats span { color: var(--muted); font-size: 13px; }
.stats .dominado b { color: var(--green); }
.stats .estudiando b { color: var(--orange); }
.bar { height: 8px; border-radius: 99px; background: var(--fill); overflow: hidden; margin-top: 14px; }
.bar i { display: block; height: 100%; background: var(--blue); border-radius: 99px; transition: width .4s ease; }
.bar-label { display: flex; justify-content: space-between; font-size: 15px; font-weight: 600; }
.bar-label span { color: var(--muted); font-weight: 400; }

/* ---------- Selector segmentado ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--fill); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { min-height: 38px; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--text); padding: 0 6px; }
.seg button[aria-pressed=true] { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; }
.seg.big-seg { padding: 4px; border-radius: 15px; }
.seg.big-seg button { min-height: 54px; font-size: 16px; border-radius: 12px; }
.seg.big-seg button[aria-pressed=true][data-estado=estudiando] { color: var(--orange); }
.seg.big-seg button[aria-pressed=true][data-estado=dominado] { color: var(--green); }
.tools { display: grid; gap: 10px; margin-top: 18px; }

/* ---------- Tema ---------- */
.official { font-size: 17px; line-height: 1.6; }
.saved { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 8px; }

/* ---------- Tareas ---------- */
.task { padding: 16px 18px; position: relative; }
.task + .task::before { content: ""; position: absolute; top: 0; right: 0; left: 62px; border-top: 1px solid var(--line); }
.task-main { display: flex; gap: 14px; align-items: flex-start; width: 100%; text-align: left; color: var(--text); }
.check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--muted) 50%, transparent); flex: none; display: grid; place-items: center; transition: background .15s, border-color .15s; }
.check svg { width: 16px; height: 16px; color: #fff; opacity: 0; }
.task.done .check { background: var(--blue); border-color: var(--blue); }
.task.done .check svg { opacity: 1; }
.task .t { font-weight: 500; line-height: 1.35; padding-top: 3px; }
.task.done .t { color: var(--muted); }
.task .s { color: var(--muted); font-size: 14px; line-height: 1.4; margin-top: 3px; }
.task-note { margin: 10px 0 0 44px; }
.task-note textarea { min-height: 90px; font-size: 16px; }
.mini { color: var(--blue); font-size: 14px; font-weight: 500; margin: 6px 0 0 44px; padding: 6px 0; }

/* ---------- Sorteo ---------- */
.prob { text-align: center; padding: 28px 22px; }
.prob b { font-size: 56px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; display: block; }
.prob p { color: var(--muted); font-size: 16px; margin-top: 10px; text-wrap: balance; }
.verdict { text-align: center; font-size: 19px; font-weight: 600; margin: 26px 8px 14px; text-wrap: balance; }

/* ---------- Especialidades ---------- */
.spec { display: flex; align-items: center; gap: 16px; padding: 20px 22px; width: 100%; text-align: left; color: var(--text); border: 2px solid transparent; }
.spec.on { border-color: var(--blue); }
.spec .code { font-size: 15px; font-weight: 700; color: var(--blue); background: var(--blue-soft); border-radius: 10px; padding: 8px 10px; flex: none; }
.spec .t { font-weight: 600; font-size: 18px; line-height: 1.25; }
.spec .s { color: var(--muted); font-size: 14px; margin-top: 2px; }
.spec .check { margin-left: auto; }
.spec.on .check { background: var(--blue); border-color: var(--blue); }
.spec.on .check svg { opacity: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chip { padding: 8px 14px; border-radius: 99px; background: var(--fill); font-size: 15px; font-weight: 500; color: var(--text); }
.chip[aria-pressed=true] { background: var(--text); color: var(--bg); }

.foot { display: grid; gap: 2px; margin-top: 40px; }
.empty { text-align: center; color: var(--muted); padding: 36px 20px; }

/* ---------- Cuenta, instalación y avisos ---------- */
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.row p { color: var(--muted); font-size: 15px; line-height: 1.4; }
.row b { display: block; color: var(--text); font-size: 17px; font-weight: 600; }
.row .btn { width: auto; min-height: 42px; padding: 0 18px; font-size: 15px; flex: none; }
.pad > p > b { display: block; }
.row-app > p { color: var(--muted); font-size: 15px; line-height: 1.4; }
.row-app > p > b { color: var(--text); font-size: 17px; }
.pasos { margin: 12px 0 0; padding-left: 22px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.banner { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-top: 22px; }
.banner img { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.banner .txt { flex: 1; min-width: 0; font-size: 15px; line-height: 1.35; }
.banner .txt b { display: block; }
.banner .txt span { color: var(--muted); }
.banner .x { color: var(--muted); font-size: 22px; padding: 6px 4px 6px 8px; line-height: 1; }
body { padding-bottom: env(safe-area-inset-bottom); }
.topbar { padding-top: env(safe-area-inset-top); }

/* ---------- Práctica ---------- */
.topbar nav { display: flex; gap: 6px; }
.aviso { background: var(--orange-soft); color: var(--orange); border-radius: 14px; padding: 12px 16px; font-size: 15px; line-height: 1.4; margin-top: 16px; }
.wait { text-align: center; padding: 44px 24px; }
.wait h3 { font-size: 20px; margin-top: 18px; }
.wait p { color: var(--muted); margin-top: 6px; text-wrap: balance; }
.spin { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--fill); border-top-color: var(--blue); margin: 0 auto; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pill.mal { background: color-mix(in srgb, var(--red) 13%, transparent); color: var(--red); }
.pill.borrador { background: var(--fill); color: var(--muted); }
.item .t.full { display: block; -webkit-line-clamp: unset; overflow: visible; }
.item .s.ok { color: var(--green); }
.item .s.mal { color: var(--red); }
.item .frag { font-style: italic; font-weight: 400; }
div.item { align-items: flex-start; }
.enun summary { padding: 16px 20px; font-weight: 600; cursor: pointer; color: var(--blue); list-style: none; }
.enun summary::-webkit-details-marker { display: none; }
.enun[open] summary { border-bottom: 1px solid var(--line); }
.enun-in { padding: 16px 20px 20px; line-height: 1.6; }
.enun-in ol { margin: 12px 0 0; padding-left: 22px; }
.enun-in li { margin-top: 6px; }
.enun-in.pre { white-space: pre-wrap; }
.editor-bar { position: sticky; top: 53px; z-index: 5; display: flex; justify-content: space-between; gap: 12px; background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); padding: 12px 4px; margin-top: 12px; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.editor-bar b { color: var(--text); font-weight: 600; }
.editor-bar b.over { color: var(--red); }
textarea.editor { min-height: 60vh; font-size: 18px; line-height: 1.65; padding: 20px; border-radius: var(--radius); }
.nota { text-align: center; padding: 30px 22px 24px; }
.nota b { display: block; font-size: 64px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.nota b.dominado { color: var(--green); } .nota b.estudiando { color: var(--orange); } .nota b.mal { color: var(--red); }
.nota span { color: var(--muted); font-size: 15px; }
.nota p { margin-top: 14px; text-align: left; line-height: 1.5; }
.nota small { display: block; color: var(--muted); font-size: 13px; margin-top: 12px; }
.crit + .crit { margin-top: 22px; }
.crit p { color: var(--muted); font-size: 15px; line-height: 1.45; margin-top: 10px; }
.bul { margin: 0; padding-left: 22px; line-height: 1.5; }
.bul li + li { margin-top: 8px; }
.preg { margin-top: 22px; }
.opts { display: grid; gap: 10px; margin-top: 22px; }
.opt { display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px; text-align: left; color: var(--text); width: 100%; border: 2px solid transparent; line-height: 1.4; }
.opt:not([disabled]):hover { border-color: color-mix(in srgb, var(--blue) 40%, transparent); }
.opt .letra { width: 30px; height: 30px; border-radius: 50%; background: var(--fill); display: grid; place-items: center; font-size: 14px; font-weight: 700; flex: none; color: var(--muted); }
.opt.bien { border-color: var(--green); background: var(--green-soft); }
.opt.bien .letra { background: var(--green); color: #fff; }
.opt.mal { border-color: var(--red); }
.opt.mal .letra { background: var(--red); color: #fff; }
.opt.off { opacity: .55; }
.expl { margin-top: 14px; }
.expl p { color: var(--muted); margin-top: 6px; line-height: 1.5; }
.chart { display: flex; align-items: flex-end; gap: 8px; height: 150px; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; }
.chart i { width: 100%; max-width: 34px; border-radius: 7px 7px 3px 3px; background: var(--blue); }
.chart i.dominado { background: var(--green); } .chart i.estudiando { background: var(--orange); } .chart i.mal { background: var(--red); }
.chart span { font-size: 12px; font-weight: 600; }
.chart small { font-size: 10px; color: var(--muted); white-space: nowrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg); font-size: 15px; font-weight: 500;
  padding: 10px 18px; border-radius: 99px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  h1 { font-size: 30px; }
  h1.small { font-size: 24px; }
  .lead { font-size: 17px; }
  .page { padding-left: 16px; padding-right: 16px; }
  .big { padding: 20px 18px; gap: 14px; }
  .seg.big-seg button { font-size: 15px; }
  .seg button { font-size: 13px; }
  .item .pill.estudiando:not(.show), .item .pill.dominado:not(.show) { display: none; }
  .link { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
