/* Tooling2000 Estudios — estilos (sin recursos externos) */
:root {
  --bg1: #f5f3ff; --bg2: #ecfeff; --surface: #ffffff; --text: #1f2937; --muted: #4b5563;
  --primary: #6d28d9; --primary-dark: #5b21b6; --on-primary: #ffffff; --accent: #0e7490;
  --ok: #047857; --ok-bg: #d1fae5; --bad: #b91c1c; --bad-bg: #fee2e2; --warn: #b45309; --warn-bg: #fef3c7;
  --border: #ddd6fe; --shadow: 0 6px 20px rgba(76, 29, 149, .12); --radius: 16px;
  --focus: #f59e0b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg1: #1e1b3a; --bg2: #0f2a33; --surface: #272446; --text: #f3f4f6; --muted: #cbd5e1;
    --primary: #a78bfa; --primary-dark: #c4b5fd; --on-primary: #1e1b3a; --accent: #67e8f9;
    --ok: #6ee7b7; --ok-bg: #064e3b; --bad: #fca5a5; --bad-bg: #7f1d1d; --warn: #fcd34d; --warn-bg: #78350f;
    --border: #4c4380; --shadow: 0 6px 20px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); font-size: 1.05rem; line-height: 1.6; color: var(--text);
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed; min-height: 100vh;
  display: flex; flex-direction: column;
}
main { flex: 1; padding-block: 1.25rem 2.5rem; }
img { max-width: 100%; height: auto; }
a { color: var(--primary-dark); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 1.2em 0 .5em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin-top: .3em; }
h2 { font-size: clamp(1.3rem, 3vw, 1.6rem); }
h3 { font-size: 1.2rem; }
p, ul, ol { margin: .6em 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: .5rem; top: -4rem; background: var(--primary); color: var(--on-primary); padding: .6rem 1rem; border-radius: 8px; z-index: 100; }
.skip:focus { top: .5rem; }

.container { width: min(100% - 2rem, 1000px); margin-inline: auto; }
.container.wide { width: min(100% - 2rem, 1280px); }
.center { text-align: center; }
.muted { color: var(--muted); }
.small, small { font-size: .875rem; }
.inline { display: inline; margin: 0; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

/* Barra superior y navegación */
.topbar { background: var(--surface); box-shadow: 0 2px 10px rgba(76, 29, 149, .12); position: sticky; top: 0; z-index: 50; }
.nav { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; padding-block: .6rem; position: relative; }
.brand { display: inline-flex; align-items: center; gap: .4rem; font-weight: 800; font-size: 1.2rem; color: var(--primary-dark); text-decoration: none; }
.brand small { font-weight: 600; color: var(--muted); }
.brand-logo { font-size: 1.6rem; }
.nav-toggle { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.nav-burger { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; font-size: 1.6rem; border-radius: 10px; border: 2px solid var(--border); cursor: pointer; user-select: none; }
.nav-toggle:focus-visible + .nav-burger { outline: 3px solid var(--focus); outline-offset: 2px; }
.nav-links { display: none; list-style: none; margin: 0; padding: .5rem 0; width: 100%; flex-direction: column; gap: .25rem; }
.nav-toggle:checked ~ .nav-links { display: flex; }
.nav-links a:not(.btn), .nav-links .btn-link { display: block; padding: .6rem .8rem; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.nav-links a:not(.btn):hover, .nav-links .btn-link:hover { background: var(--bg1); }
@media (min-width: 820px) {
  .nav-burger { display: none; }
  .nav-links, .nav-toggle:checked ~ .nav-links { display: flex; flex-direction: row; width: auto; align-items: center; gap: .25rem; padding: 0; }
}

/* Botones */
.btn, button.btn {
  display: inline-block; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--primary); color: var(--on-primary); border: 2px solid var(--primary); border-radius: 999px;
  padding: .65rem 1.3rem; min-height: 44px; line-height: 1.3; transition: transform .12s, background .15s, box-shadow .15s;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--on-primary); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn-sm { padding: .4rem .9rem; font-size: .92rem; min-height: 38px; }
.btn-lg { padding: .9rem 1.8rem; font-size: 1.15rem; }
.btn-ghost { background: transparent; color: var(--primary-dark); border-color: var(--primary); box-shadow: none; }
.btn-ghost:hover { background: var(--bg1); color: var(--primary-dark); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #7f1d1d; border-color: #7f1d1d; color: #fff; }
.btn:disabled, .btn.disabled, button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
span.btn.disabled { pointer-events: none; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary-dark); text-decoration: underline; cursor: pointer; }
.btn-link:hover { text-decoration-thickness: 2px; }

/* Layout / tarjetas */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); margin-block: 1rem;
}
.grid { display: grid; gap: 1rem; }
.cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.cards .card { margin: 0; }
a.card { color: inherit; text-decoration: none; transition: transform .15s, box-shadow .15s; }
a.card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(76, 29, 149, .2); }
a.card h2, a.card h3 { color: var(--primary-dark); margin-top: .3em; }
.subject .emoji { font-size: 2.6rem; display: block; }
.subject.soon { opacity: .65; cursor: default; }
.badge { display: inline-block; background: var(--warn-bg); color: var(--warn); font-weight: 700; font-size: .8rem; padding: .15rem .7rem; border-radius: 999px; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-block: .6rem; }
.actions { align-items: center; }
.crumbs { font-size: .92rem; color: var(--muted); margin-bottom: .5rem; }
.crumbs a { color: var(--primary-dark); }

.hero { display: grid; gap: 1.5rem; align-items: center; padding: 1.5rem 0; }
.hero p.lead { font-size: 1.2rem; }
.hl { background: linear-gradient(transparent 60%, #fde68a 60%); padding-inline: .15em; }
@media (prefers-color-scheme: dark) { .hl { background: linear-gradient(transparent 60%, #78350f 60%); } }
.hero-actions { display: flex; flex-wrap: wrap; gap: .8rem; margin-block: 1rem; }
.hero-art { font-size: clamp(3rem, 10vw, 5rem); text-align: center; letter-spacing: .2em; }
@media (min-width: 820px) { .hero { grid-template-columns: 1.4fr 1fr; } }
.lead { font-size: 1.12rem; color: var(--muted); }

.how .steps { counter-reset: s; list-style: none; padding: 0; display: grid; gap: .7rem; }
.how .steps li { counter-increment: s; padding-left: 2.8rem; position: relative; }
.how .steps li::before { content: counter(s); position: absolute; left: 0; top: -.1rem; width: 2.1rem; height: 2.1rem; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 800; }

.tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin-block: .8rem; }
.tabs a { padding: .4rem 1rem; border-radius: 999px; background: var(--surface); border: 2px solid var(--border); text-decoration: none; font-weight: 700; }
.tabs a:hover { background: var(--bg1); }

.cta { text-align: center; background: linear-gradient(135deg, var(--surface), var(--bg1)); }
.notice { background: var(--warn-bg); color: var(--text); border-left: 6px solid var(--warn); border-radius: 12px; padding: .8rem 1rem; margin-block: 1rem; }
.book-hero { border-left: 8px solid var(--primary); }

/* Guía */
.guide h3 { color: var(--accent); }
.concepts { background: var(--bg1); border-radius: 12px; padding: .5rem 1rem; }
.tip { background: var(--warn-bg); border-left: 6px solid var(--warn); border-radius: 12px; padding: .5rem 1rem; margin-block: 1rem; }
.example { border: 2px solid var(--border); border-radius: 12px; padding: .6rem 1rem; margin-block: .8rem; }
.example summary { cursor: pointer; }
.steps-list { padding-left: 1.4rem; }
.steps-list li { margin-block: .3rem; }
.answer-box { background: var(--ok-bg); color: var(--ok); border-radius: 10px; padding: .5rem .9rem; font-weight: 600; }
sup { font-size: .7em; line-height: 0; }

/* Formularios */
label { font-weight: 600; display: block; margin-top: .8rem; }
input[type=text], input[type=email], input[type=number], input:not([type]), select, textarea, input.answer {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 2px solid var(--border); border-radius: 12px; padding: .65rem .8rem; min-height: 44px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--primary); }
input[name=pin], #pin { letter-spacing: .4em; font-size: 1.4rem; text-align: center; max-width: 14rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; margin-block: 1rem; }
.check input { width: 1.2rem; height: 1.2rem; margin-top: .25rem; flex: none; accent-color: var(--primary); }
form .btn { margin-top: 1rem; }
.auth { max-width: 520px; margin-inline: auto; }
.msg { margin: .8rem 0 0; min-height: 1.4em; font-weight: 600; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--bad); }
.danger-zone { margin-top: 1.5rem; border: 2px dashed var(--bad); border-radius: 12px; padding: .6rem 1rem; }
.danger-zone summary { cursor: pointer; color: var(--bad); font-weight: 700; }

/* Práctica */
.practice-list { display: grid; gap: 1rem; }
.practice-item { border: 2px solid var(--border); border-radius: var(--radius); padding: 1rem; background: var(--surface); transition: border-color .2s, background .2s; }
.practice-item.is-correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok-bg) 45%, var(--surface)); animation: pop .5s ease; }
.practice-item.is-wrong { border-color: var(--bad); animation: shake .45s ease; }
.q-prompt { font-weight: 600; margin-top: 0; }
.q-num { color: var(--primary-dark); font-weight: 800; margin-right: .2rem; }
.choices { display: grid; gap: .5rem; margin-block: .6rem; }
.choice { display: flex; align-items: center; gap: .7rem; margin: 0; font-weight: 500; padding: .6rem .8rem; min-height: 48px; border: 2px solid var(--border); border-radius: 12px; cursor: pointer; background: var(--surface); position: relative; transition: background .15s, border-color .15s, transform .1s; }
.choice:hover { background: var(--bg1); }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.choice .letter { flex: none; width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--bg1); color: var(--primary-dark); border: 2px solid var(--border); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--bg1); box-shadow: 0 0 0 2px var(--primary) inset; }
.choice:has(input:checked) .letter { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); box-shadow: none; }
.choice.right { border-color: var(--ok); background: var(--ok-bg); box-shadow: none; }
.choice:has(input:disabled) { cursor: default; }
.answer { max-width: 28rem; }
.hints { margin-block: .5rem; }
.hint { background: var(--warn-bg); border-radius: 10px; padding: .5rem .8rem; margin: .4rem 0; }
.feedback { min-height: 1.4em; margin-top: .6rem; font-weight: 600; }
.is-correct .feedback { color: var(--ok); }
.is-wrong .feedback { color: var(--bad); }
.steps-reveal { margin-top: .8rem; background: var(--bg1); border-radius: 12px; padding: .5rem 1rem 1rem; }
.steps-reveal h4 { margin-top: .5rem; }
.steps-out { padding-left: 1.4rem; }
.steps-out li { margin-block: .4rem; animation: fadeIn .4s ease both; }
.why { background: var(--bad-bg); color: var(--text); border-left: 5px solid var(--bad); border-radius: 10px; padding: .5rem .8rem; }
.explain { background: var(--bg1); border-radius: 10px; padding: .5rem .8rem; }

@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.025); box-shadow: 0 0 0 6px rgba(16, 185, 129, .3); } 100% { transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Evaluación */
.eval-meta { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; list-style: none; padding: 0; margin: .5rem 0 1rem; justify-content: space-between; align-items: center; }
ul.eval-meta li { background: var(--bg1); border-radius: 999px; padding: .2rem .8rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.3rem; background: var(--bg1); padding: .2rem .9rem; border-radius: 999px; }
.timer.warn { background: var(--bad-bg); color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.progress { height: 12px; background: var(--bg1); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progress > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .3s; }
.eval-question { min-height: 8rem; }
.eval-actions { justify-content: space-between; margin-top: 1rem; }
.qnav { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1rem; }
.qnav button { width: 42px; height: 42px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.qnav button.answered { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.qnav button.current { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary); }
.score-card { background: linear-gradient(135deg, var(--bg1), var(--surface)); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.score-big { font-size: clamp(2rem, 8vw, 3.2rem); font-weight: 900; margin: .2em 0; }
.score-grade { font-size: 1.5rem; }
.score-grade strong { font-size: 2rem; }
.review { padding-left: 1.4rem; }
.review > li { margin-block: 1rem; padding: .8rem 1rem; background: var(--surface); border: 2px solid var(--border); border-left-width: 8px; border-radius: 12px; }
.review > li.ok { border-left-color: var(--ok); color: var(--text); }
.review > li.bad { border-left-color: var(--bad); color: var(--text); }

/* Panel, tablas, stats */
.stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-block: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; box-shadow: var(--shadow); }
.stat span { display: block; font-size: 2rem; font-weight: 900; color: var(--primary-dark); }
.stat.ok span { color: var(--ok); }
.stat.bad span { color: var(--bad); }
.kpi { font-size: 2rem; font-weight: 900; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table, .table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); }
th { background: var(--bg1); white-space: nowrap; }
td.ok, td.bad { font-weight: 700; }
tr.me td { background: var(--warn-bg); font-weight: 700; }
.progress-row { display: grid; gap: .25rem; margin-block: .9rem; }
.bar { height: 14px; background: var(--bg1); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); }

/* Lector */
.reader { display: grid; gap: 1rem; grid-template-columns: 1fr; }
.reader-toc { display: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; align-self: start; position: sticky; top: 5rem; max-height: calc(100vh - 6rem); overflow: auto; }
.reader-toc h2 { margin-top: 0; font-size: 1.1rem; }
.reader-toc ol { padding-left: 1.2rem; }
.reader-toc li.current a { font-weight: 800; background: var(--warn-bg); border-radius: 6px; padding: 0 .3rem; }
@media (min-width: 900px) { .reader { grid-template-columns: 260px 1fr; } .reader-toc { display: block; } }
.reader-main { min-width: 0; }
.reader-bar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.jump { display: flex; align-items: center; gap: .4rem; }
.jump label { margin: 0; }
.jump input { width: 5rem; min-height: 38px; padding: .3rem .5rem; }
.reader-bar .btn { margin: 0; }
.reader-view { display: grid; gap: 1rem; justify-items: center; }
.page-img { margin: 0; background: #fffdf7; padding: .5rem; border-radius: 6px; box-shadow: 0 8px 26px rgba(0, 0, 0, .25); max-width: 100%; }
.page-img img { display: block; margin-inline: auto; }
.page-text { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .6rem 1rem; }
.page-text summary { cursor: pointer; font-weight: 700; }
.page-text .text { font-size: 1.2rem; line-height: 1.8; max-width: 70ch; }
.chapter-list { padding-left: 1.4rem; }
.chapter-list li { margin-block: .6rem; }

/* Tutor */
.tutor-log { max-height: 55vh; min-height: 12rem; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; padding: .8rem; background: var(--bg1); border-radius: 12px; border: 1px solid var(--border); }
.bubble { max-width: 85%; padding: .6rem .9rem; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; animation: fadeIn .25s ease; }
.bubble.user { align-self: flex-end; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.err { align-self: flex-start; background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad); }
.bubble.typing:empty::after { content: "● ● ●"; letter-spacing: .15em; color: var(--muted); animation: pulse 1s infinite; }
.tutor-form { display: flex; gap: .6rem; align-items: flex-end; margin-top: .8rem; flex-wrap: wrap; }
.tutor-form textarea { flex: 1 1 14rem; resize: vertical; }
.tutor-form .btn { margin: 0; }

/* Publicidad y cookies */
.ad-slot { min-height: 100px; margin-block: 1.2rem; padding: .3rem; text-align: center; background: color-mix(in srgb, var(--surface) 60%, transparent); border: 1px dashed var(--border); border-radius: 12px; position: relative; }
.ad-slot::before { content: "Publicidad"; display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.cookie-banner { position: fixed; inset: auto 0 0 0; z-index: 200; background: var(--surface); border-top: 3px solid var(--primary); box-shadow: 0 -6px 24px rgba(0, 0, 0, .2); padding: .8rem 1rem; display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; align-items: center; justify-content: center; }
.cookie-banner p { margin: 0; flex: 1 1 18rem; max-width: 60ch; font-size: .95rem; }
.cookie-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.cookie-actions .btn { margin: 0; }

/* Pie y legales */
.footer { background: var(--surface); border-top: 1px solid var(--border); padding-block: 1.2rem; font-size: .92rem; color: var(--muted); }
.footer-grid { display: grid; gap: .8rem; }
@media (min-width: 700px) { .footer-grid { grid-template-columns: 1fr auto; align-items: center; } }
.legal { max-width: 800px; margin-inline: auto; }
.legal h2 { font-size: 1.2rem; }

/* Administración */
.admin-nav { display: flex; flex-wrap: wrap; gap: .5rem; margin-block: .8rem; }
.admin-nav a { padding: .3rem .9rem; border-radius: 999px; border: 2px solid var(--border); background: var(--surface); text-decoration: none; font-weight: 600; }
.admin-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-block: .8rem; }
.filters label { margin: 0; }
.filters input, .filters select { width: auto; min-width: 8rem; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print { .topbar, .footer, .cookie-banner, .ad-slot { display: none !important; } body { background: #fff; } }
