/* ==========================================================================
   Patrimonio Vivo — hoja de estilos única, sin dependencias externas.
   Estructura: tokens > base > layout > componentes > utilidades > impresión
   ========================================================================== */

:root {
  --ink: #241d18;
  --ink-soft: #5b4f45;
  --paper: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f0e9de;
  --line: #ddd2c2;
  --brand: #8c3b26;      /* terracota */
  --brand-soft: #f1e0d8;
  --accent: #2f5d50;     /* verde agua profundo */
  --accent-soft: #dfeae5;
  --gold: #b07d992;
  --gold: #a9812f;
  --shadow: 0 1px 2px rgba(36, 29, 24, .06), 0 8px 24px rgba(36, 29, 24, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
  --ink: #efe7dc;
  --ink-soft: #b6a999;
  --paper: #17130f;
  --surface: #201a15;
  --surface-2: #2a221b;
  --line: #3b3129;
  --brand: #d98466;
  --brand-soft: #3a241d;
  --accent: #7fbfa9;
  --accent-soft: #1f302b;
  --gold: #d9b467;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.22; margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -.01em; }
h2 { font-size: clamp(1.3rem, 2.6vw, 1.7rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1rem; }
a { color: var(--brand); }

/* ---------- layout ---------- */
.shell { max-width: 1120px; margin: 0 auto; padding: 0 1.1rem 4rem; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  max-width: 1240px; margin: 0 auto; padding: .6rem 1.1rem;
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: inherit; margin-right: auto; }
.brand__mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-family: var(--serif); font-size: 1.05rem;
}
html[data-theme="dark"] .brand__mark { color: #17130f; }
.brand__name { font-family: var(--serif); font-size: 1.08rem; font-weight: 600; }
.brand__sub { display: block; font-size: .7rem; color: var(--ink-soft); letter-spacing: .08em; text-transform: uppercase; }

.nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.nav a {
  text-decoration: none; color: var(--ink-soft); font-size: .88rem; font-weight: 500;
  padding: .35rem .55rem; border-radius: 999px;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }

.iconbtn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 1rem;
}
.iconbtn:hover { border-color: var(--brand); color: var(--brand); }

/* barra de progreso global */
.globalbar { height: 4px; background: var(--surface-2); }
.globalbar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--brand)); transition: width .4s ease; }

/* ---------- componentes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1rem; }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(272px, 1fr)); }
.grid--two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.hero { padding: 2.6rem 0 1.4rem; display: grid; gap: 1.4rem; grid-template-columns: 1.4fr 1fr; align-items: start; }
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } }
.hero p.lead { font-size: 1.06rem; color: var(--ink-soft); max-width: 60ch; }

.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: .72rem; color: var(--accent); font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; gap: .45rem; cursor: pointer;
  border-radius: 999px; padding: .55rem 1.05rem; font-size: .9rem; font-weight: 600;
  border: 1px solid var(--brand); background: var(--brand); color: #fff; text-decoration: none;
}
html[data-theme="dark"] .btn { color: #17130f; }
.btn:hover { filter: brightness(1.06); }
.btn--ghost { background: transparent; color: var(--brand); }
.btn--muted { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn--sm { padding: .35rem .7rem; font-size: .82rem; }
.btn--done { background: var(--accent); border-color: var(--accent); color: #fff; }
html[data-theme="dark"] .btn--done { color: #17130f; }

.chip {
  display: inline-block; padding: .12rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .05em;
  background: var(--accent-soft); color: var(--accent); border: 1px solid transparent;
}
.chip--A1 { background: #e7efe9; color: #2f6b46; }
.chip--A2 { background: #eaeaf5; color: #45489a; }
.chip--B1 { background: #f6ecdc; color: #8a6415; }
.chip--B2 { background: var(--brand-soft); color: var(--brand); }
html[data-theme="dark"] .chip--A1 { background: #1e2f25; color: #86c79c; }
html[data-theme="dark"] .chip--A2 { background: #22233a; color: #a3a6e8; }
html[data-theme="dark"] .chip--B1 { background: #322715; color: #e0b45e; }

.lesson-card { display: flex; flex-direction: column; gap: .55rem; text-decoration: none; color: inherit; position: relative; }
.lesson-card:hover { border-color: var(--brand); transform: translateY(-2px); transition: .18s; }
.lesson-card__num { font-family: var(--serif); font-size: .8rem; color: var(--ink-soft); }
.lesson-card__title { font-family: var(--serif); font-size: 1.12rem; }
.lesson-card__meta { font-size: .8rem; color: var(--ink-soft); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: auto; }
.lesson-card__row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.fav { border: none; background: transparent; cursor: pointer; font-size: 1.05rem; color: var(--ink-soft); padding: 0 .1rem; }
.fav[data-on="1"] { color: var(--gold); }
.done-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display: inline-block; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: 1.2rem 0; }
.search {
  flex: 1 1 240px; min-width: 200px; padding: .55rem .85rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: .92rem;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pill {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  border-radius: 999px; padding: .4rem .85rem; font-size: .84rem; cursor: pointer; font-weight: 600;
}
.pill[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* lección */
.lesson-head { border-bottom: 1px solid var(--line); padding: 1.6rem 0 1.1rem; margin-bottom: 1.4rem; }
.section { margin: 0 0 1.1rem; }
.section h3 { display: flex; align-items: center; gap: .5rem; color: var(--brand); font-size: 1rem; letter-spacing: .01em; }
.section h3::before { content: ""; width: 16px; height: 2px; background: var(--brand); display: inline-block; }
.prose { white-space: pre-line; font-family: var(--serif); font-size: 1.05rem; }
ul.clean { list-style: none; padding: 0; margin: 0; display: grid; gap: .45rem; }
ul.clean li { padding-left: 1.1rem; position: relative; }
ul.clean li::before { content: "—"; position: absolute; left: 0; color: var(--accent); }
.voc { display: grid; gap: .5rem; }
.voc div { background: var(--surface-2); border-radius: var(--radius-sm); padding: .5rem .7rem; font-size: .93rem; }
.voc b { font-family: var(--serif); }
details.sol { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: .6rem .8rem; background: var(--surface-2); }
details.sol summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.lesson-nav { display: flex; justify-content: space-between; gap: .6rem; margin-top: 1.8rem; flex-wrap: wrap; }

/* quiz */
.q { border-bottom: 1px solid var(--line); padding: .8rem 0; }
.q:last-child { border-bottom: none; }
.q p { font-weight: 600; margin-bottom: .5rem; }
.q label { display: block; padding: .25rem 0; font-size: .95rem; cursor: pointer; }
.result { margin-top: .8rem; font-weight: 700; }

.footer { border-top: 1px solid var(--line); margin-top: 3rem; padding: 1.6rem 0; color: var(--ink-soft); font-size: .85rem; }
.muted { color: var(--ink-soft); }
.small { font-size: .84rem; }
.stack { display: grid; gap: .8rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.stat { font-family: var(--serif); font-size: 1.9rem; line-height: 1; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-soft); }

@media print {
  .topbar, .globalbar, .lesson-nav, .filters, .footer, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #999; }
  details.sol { display: block; }
  details.sol > *:not(summary) { display: block !important; }
}
.print-attr { margin-top: 1.4rem; border-top: 1px solid var(--line, #ccc); padding-top: .6rem; }
/* Legibilidad: tamaño de letra y espaciado ajustables */
html { font-size: calc(100% * var(--font-scale, 1)); }
html[data-spacing="wide"] body { line-height: 1.85; letter-spacing: .015em; word-spacing: .06em; }
html[data-spacing="wide"] p, html[data-spacing="wide"] li { margin-bottom: .8em; }
html[data-spacing="wide"] .card { padding: 1.5rem; }
html[data-theme="dark"] body { -webkit-font-smoothing: antialiased; }
#spacing[aria-pressed="true"] { outline: 2px solid currentColor; }
/* Certificados */
.cert-form { display: grid; gap: .7rem; max-width: 520px; }
.cert-form label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
.cert { border: 3px double var(--gold); border-radius: var(--radius-sm); padding: 1.6rem 1.2rem; text-align: center; background: var(--surface); }
.cert p { margin: .4rem 0; }
.cert__eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; color: var(--ink-soft); }
.cert__title { font-family: var(--serif); color: var(--brand); margin: .4rem 0 .8rem; }
.cert__name { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; color: var(--ink); border-bottom: 1px solid var(--line); display: inline-block; padding: 0 1rem .2rem; }
.cert__code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; word-break: break-all; }
.result.ok { color: var(--accent); }
.result.ko { color: var(--brand); }

.cert-grid { align-items: start; } .cert-grid > .card { align-content: start; }
.cert-status { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 0; }
.cert-status div { background: var(--surface-2); border-radius: var(--radius-sm); padding: .5rem .6rem; }
.cert-status dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.cert-status dd { margin: .15rem 0 0; font-weight: 700; }
.cert-status dd.ok { color: var(--accent); } .cert-status dd.ko { color: var(--brand); }
/* Páginas legales */
.legal h2 { font-size: 1.15rem; margin: 1rem 0 .2rem; }
.pending { background: var(--brand-soft); color: var(--brand); padding: 0 .3rem; border-radius: 4px; font-weight: 600; }
.footer-links { margin-top: .6rem; }
.footer-links a { color: inherit; }
.table-wrap { overflow-x: auto; }
.legal-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.legal-table th, .legal-table td { border: 1px solid var(--line); padding: .45rem .55rem; text-align: left; vertical-align: top; }
.legal-table th { background: var(--surface-2); }

/* Logos: siempre proporcionados */
.brand-logos { display: inline-flex; align-items: center; gap: .5rem; }
.brand-logos img { height: 38px; width: auto; max-width: 120px; object-fit: contain; }
.cert__logos { display: flex; justify-content: center; align-items: center; gap: 1.2rem; flex-wrap: wrap; margin-bottom: .6rem; }
.cert__logos img { height: 56px; width: auto; max-width: 180px; object-fit: contain; }

/* Certificado en A4 apaisado */
#print-root { display: none; }
@media print {
  body.print-cert > *:not(#print-root) { display: none !important; }
  body.print-cert { background: #fff !important; margin: 0; }
  body.print-cert #print-root { display: block; }
  .cert--sheet {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    box-sizing: border-box; width: 297mm; height: 209mm; margin: 0; overflow: hidden;
    padding: 16mm 22mm; border: 0; border-radius: 0; background: #fffdf9 !important; color: #241d18 !important;
    display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
    outline: 2.5mm double #a9812f; outline-offset: -9mm;
    break-inside: avoid; page-break-inside: avoid; font-size: 12pt;
  }
  .cert--sheet * { color: inherit !important; }
  .cert--sheet .cert__logos { margin-bottom: 6mm; gap: 12mm; }
  .cert--sheet .cert__logos img { height: 22mm; width: auto; max-width: 70mm; object-fit: contain; }
  .cert--sheet .cert__eyebrow { font-size: 9pt; color: #5b4f45 !important; }
  .cert--sheet .cert__title { font-size: 30pt; color: #8c3b26 !important; margin: 3mm 0 6mm; }
  .cert--sheet .cert__name { font-size: 28pt; padding: 0 12mm 2mm; border-bottom: .4mm solid #a9812f; margin: 2mm 0 5mm; }
  .cert--sheet p { margin: 1.5mm 0; max-width: 220mm; }
  .cert--sheet .cert__code { font-size: 11pt; margin-top: 5mm; }
  .cert--sheet .small { font-size: 9pt; }
}
@media (max-width: 720px) { .brand-logos { display: none; } }
/* Logos sobre fondo claro para que se lean también en modo oscuro */
.brand-logos { background: #fff; border-radius: 8px; padding: 3px 8px; margin-left: .4rem; }
.brand-logos img { height: 34px; }
html[data-theme="dark"] .cert { background: #fffdf9; color: #241d18; }
html[data-theme="dark"] .cert .cert__name { color: #241d18; }
html[data-theme="dark"] .cert { --ink: #241d18; --ink-soft: #5b4f45; --brand: #8c3b26; --line: #ddd2c2; --surface: #fffdf9; }
/* Con logos, el logo del Club sustituye a la marca «PV» y se compacta la cabecera */
.brand:has(.brand-logos) .brand__mark { display: none; }
.brand-logos { order: -1; margin: 0 .2rem 0 0; padding: 2px 6px; gap: .35rem; }
.brand-logos img { height: 30px; max-width: 90px; }
@media (max-width: 1240px) { .brand-logos img + img { display: none; } }
@media (max-width: 720px) { .brand-logos { display: inline-flex; } .brand-logos img { height: 28px; } }
.legal code, #view code { font-size: .85em; background: var(--surface-2); padding: .1rem .3rem; border-radius: 4px; word-break: break-all; }

/* ---- Glosario general ---- */
.gl-tools .search { flex: 1 1 260px; }
.gl-letters { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 .8rem; }
.gl-letters .btn { min-width: 2.3rem; justify-content: center; }
.gl-legend { margin: 0 0 1rem; }
.gl-group { margin-top: 1.4rem; scroll-margin-top: 5.5rem; }
.gl-letter { font-size: 1.6rem; color: var(--brand); border-bottom: 1px solid var(--line); padding-bottom: .2rem; }
.gl-list { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); margin: .8rem 0 0; }
.gl-item { padding: .9rem 1rem; }
.gl-item dt { font-family: var(--serif); font-weight: 600; font-size: 1.12rem; }
.gl-item dd { margin: .25rem 0 0; }
.gl-def { margin: 0 0 .45rem; }
.gl-refs { margin: .3rem 0 0; display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.gl-link { display: inline-flex; align-items: center; gap: .25rem; font-weight: 700; text-decoration: none; padding: .1rem .45rem .1rem .2rem; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; background: var(--surface); }
.gl-link:hover, .gl-link:focus-visible { border-color: var(--brand); }
.gl-refs--also .gl-link { font-weight: 400; color: var(--ink-soft); }
.gl-lv { font-size: .68rem; padding: 0 .3rem; border-radius: 999px; background: var(--surface-2); color: var(--ink-soft); font-weight: 700; }
[hidden] { display: none !important; }
@media print { .gl-tools, .gl-letters { display: none; } }
