:root {
  --verde: #0C291B;
  --crema: #F6F4EF;
  --regla: #CED4D1;
  --tinta: #1A1A1A;
  --gris: #6E6E6E;
  --cita: #E2EAE4;
  --papel: #FFFFFF;
  --acento: #0C291B;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --verde: #A9C7B3; --crema: #0F1512; --regla: #2C3631; --tinta: #E7E5DF; --gris: #9AA19D;
    --cita: #1C2A22; --papel: #141C18; --acento: #A9C7B3; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --verde: #A9C7B3; --crema: #0F1512; --regla: #2C3631; --tinta: #E7E5DF; --gris: #9AA19D;
  --cita: #1C2A22; --papel: #141C18; --acento: #A9C7B3; color-scheme: dark;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: calc(4.5rem + env(safe-area-inset-top, 0px)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--crema); color: var(--tinta);
  font-family: "Libre Baskerville", Baskerville, "Baskerville Old Face", Georgia, serif;
  font-weight: 400; font-size: 17px; line-height: 1.7;
}
b, strong, h1, h2, h3, th { font-weight: 400; }
a { color: var(--acento); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* barra */
.barra {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  padding: .7rem clamp(1rem, 4vw, 2.5rem);
  background: var(--verde); color: var(--crema);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .barra { background: #0A120E; color: var(--tinta); } }
.marca { color: inherit; text-decoration: none; letter-spacing: .14em; font-size: .95rem; }
.marca span { letter-spacing: .02em; font-style: italic; margin-left: .35em; opacity: .85; }
.controles { display: flex; gap: .6rem; margin-left: auto; flex-wrap: wrap; }
.campo select, .campo input {
  font: inherit; font-size: .85rem; color: var(--tinta); background: var(--papel);
  border: 1px solid var(--regla); border-radius: 2px; padding: 0 .55rem; height: 2.15rem; max-width: 70vw;
}
.ir input { width: 11.5rem; }

main { padding: 0 clamp(1rem, 4vw, 2.5rem) 6rem; }
.cargando, .vacio { color: var(--gris); padding: 3rem 0; }

/* portada */
.portada { max-width: 62rem; margin: 0 auto; padding-top: 3.5rem; }
.portada h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); line-height: 1.12; color: var(--verde); margin: 0 0 .6rem; letter-spacing: -.01em; }
.portada .bajada { color: var(--gris); max-width: 40rem; margin: 0 0 2.5rem; }
.grupo { margin: 2.5rem 0; }
.grupo h2 { font-size: 1.05rem; font-style: italic; color: var(--gris); border-bottom: 1px solid var(--regla); padding-bottom: .4rem; margin: 0 0 .6rem; }
.leyes { list-style: none; margin: 0; padding: 0; columns: 2 22rem; column-gap: 3rem; }
.leyes li { break-inside: avoid; padding: .32rem 0; display: grid; grid-template-columns: 6.2rem 1fr; gap: .8rem; align-items: baseline; }
.leyes .sig { color: var(--verde); font-size: .82rem; letter-spacing: .06em; }
.leyes .det { display: block; color: var(--gris); font-size: .78rem; }
.leyes.simple li { grid-template-columns: 1fr; }

/* constructor de enlaces */
.constructor { background: var(--papel); border: 1px solid var(--regla); padding: 1.4rem 1.5rem; margin: 0 0 1rem; }
.constructor h2 { font-size: 1.05rem; font-style: italic; color: var(--gris); margin: 0 0 1rem; }
.constructor .filas { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .8rem; }
.constructor label { display: flex; flex-direction: column; font-size: .78rem; color: var(--gris); gap: .25rem; }
.constructor input, .constructor select { font: inherit; font-size: .9rem; color: var(--tinta); background: var(--crema); border: 1px solid var(--regla); border-radius: 2px; padding: .4rem .5rem; }
.resultado { margin-top: 1rem; display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.resultado code { font-family: inherit; font-size: .9rem; background: var(--cita); padding: .3rem .55rem; overflow-wrap: anywhere; }
.boton { font: inherit; font-size: .85rem; color: var(--crema); background: var(--verde); border: 0; border-radius: 2px; padding: .45rem .9rem; cursor: pointer; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .boton { color: #0F1512; } }
.boton.sec { background: transparent; color: var(--acento); border: 1px solid var(--regla); }
a.boton { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.nw { white-space: nowrap; }
input[type=checkbox] { accent-color: var(--verde); }

/* ley */
.ley { display: grid; grid-template-columns: minmax(0, 16rem) minmax(0, 44rem); gap: 3rem; justify-content: center; padding-top: 2.2rem; }
.ley > aside { position: sticky; top: 5rem; align-self: start; max-height: calc(100vh - 6rem); overflow: auto; font-size: .8rem; line-height: 1.45; padding-right: .5rem; }
.ley > aside a { display: block; color: var(--gris); text-decoration: none; padding: .28rem 0; border-bottom: 1px solid transparent; }
.ley > aside a:hover { color: var(--acento); }
.ley > aside .tt { color: var(--verde); margin-top: .5rem; }
@media (max-width: 860px) { .ley { grid-template-columns: minmax(0, 1fr); gap: 0; } .ley > aside { display: none; } }

.encabezado h1 { font-size: clamp(1.6rem, 3.4vw, 2.3rem); line-height: 1.2; color: var(--verde); margin: 0 0 .5rem; }
.encabezado .meta { color: var(--gris); font-size: .86rem; margin: 0 0 .3rem; }
.encabezado .meta a { color: inherit; }
.estado { margin: 1.2rem 0 2rem; border-left: 3px solid var(--verde); padding: .2rem 0 .2rem 1rem; font-size: .88rem; }
.estado.historica { border-left-color: #8A6A1F; }
.estado.falta { border-left-color: #9B2C2C; }
.estado p { margin: .2rem 0; }

.citado { background: var(--papel); border: 1px solid var(--regla); padding: 1.1rem 1.25rem; margin: 0 0 2rem; }
.citado .ref { font-size: 1.15rem; color: var(--verde); margin: 0 0 .25rem; }
.citado .ver { color: var(--gris); font-size: .84rem; margin: 0 0 .8rem; }
.citado .acciones { display: flex; gap: .6rem; flex-wrap: wrap; }

.tit { text-align: center; color: var(--verde); font-size: .95rem; letter-spacing: .04em; margin: 3rem 0 1.5rem; line-height: 1.5; }
article.art { margin: 0 0 2.2rem; }
article.art > h2 { font-size: 1rem; color: var(--verde); margin: 0 0 .35rem; font-style: italic; }
article.art > h2 a { color: inherit; text-decoration: none; }
article.art.derogado { color: var(--gris); }
.p { margin: 0 0 .85rem; text-align: left; hyphens: manual; }
.u { position: relative; padding-left: 3.4rem; margin: 0 0 .5rem; }
.u.in, .u.si { padding-left: 2.3rem; }
.u.nu { padding-left: 2rem; }
.u > .p:first-of-type > .lbl { position: absolute; left: 0; width: 3rem; text-align: right; }
.u.in > .p:first-of-type > .lbl, .u.si > .p:first-of-type > .lbl { width: 1.9rem; }
.u.nu > .p:first-of-type > .lbl { width: 1.6rem; }
.lbl, .lbl-art { color: var(--verde); cursor: pointer; background: none; border: 0; padding: 0; font: inherit; line-height: inherit; user-select: none; -webkit-tap-highlight-color: transparent; }
.lbl-art { font-style: italic; }
.lbl:hover, .lbl-art:hover { text-decoration: underline; text-underline-offset: 3px; }
.extracto { margin: .2rem 0 1rem; padding-top: .8rem; border-top: 1px solid var(--regla); }
.extracto .lbl, .extracto .lbl-art { pointer-events: none; }
.extracto .cita { background: none; box-shadow: none; }
[hidden] { display: none !important; }
.nota { display: block; color: var(--gris); font-size: .72rem; font-style: italic; text-align: right; margin: -.4rem 0 .7rem; line-height: 1.4; }
.sin-notas .nota { display: none; }
.cita { background: var(--cita); box-shadow: -.6rem 0 0 var(--cita), .6rem 0 0 var(--cita); border-radius: 1px; }
.u.cita { box-shadow: -.6rem 0 0 var(--cita), .6rem 0 0 var(--cita); }
.ancla { color: var(--gris); text-decoration: none; margin-left: .4rem; font-size: .8rem; opacity: 0; }
article.art > h2:hover .ancla, .ancla:focus { opacity: 1; }
.trans .p { font-size: .9rem; }
.trans h3 { font-size: .9rem; color: var(--verde); margin: 2rem 0 .8rem; font-style: italic; }
.pie { margin-top: 4rem; color: var(--gris); font-size: .78rem; border-top: 1px solid var(--regla); padding-top: 1rem; }
.opciones { display: flex; gap: 1rem; font-size: .8rem; color: var(--gris); margin: 0 0 1.2rem; }
.opciones label { display: flex; gap: .35rem; align-items: center; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--verde); color: var(--crema); padding: .55rem 1rem; font-size: .85rem; border-radius: 2px; z-index: 10; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast { color: #0F1512; } }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
@media print { .barra, .ley > aside, .citado .acciones, .opciones { display: none !important; } body { background: #fff; } }

/* barra inferior y hoja (celular) */
.sigla { display: none; }
.barra-movil { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; grid-template-columns: repeat(3, 1fr); background: var(--verde); padding-bottom: env(safe-area-inset-bottom, 0px); }
.barra-movil button { font: inherit; font-size: .92rem; color: var(--crema); background: none; border: 0; min-height: 3.2rem; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.barra-movil button + button { border-left: 1px solid rgba(246, 244, 239, .18); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .barra-movil { background: #0A120E; } :root:not([data-theme="light"]) .barra-movil button { color: var(--tinta); } }
.hoja { border: 0; padding: 0; inset: auto 0 0 0; margin: 0; width: 100%; max-width: 100%; max-height: 82vh; background: var(--crema); color: var(--tinta); border-radius: 12px 12px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
.hoja::backdrop { background: rgba(12, 41, 27, .45); }
.hoja-cab { display: flex; justify-content: space-between; align-items: center; padding: .95rem 1.15rem .7rem; border-bottom: 1px solid var(--regla); }
.hoja-cab span { color: var(--verde); font-style: italic; }
.hoja-cab button { font: inherit; font-size: .88rem; background: none; border: 0; color: var(--acento); padding: .3rem 0 .3rem .8rem; cursor: pointer; }
#hojaCuerpo { padding: .8rem 1.15rem 1.3rem; overflow: auto; max-height: calc(82vh - 3.4rem); }
.lista-hoja { list-style: none; margin: 0; padding: 0; }
.lista-hoja a, .lista-hoja .opcion { display: block; width: 100%; text-align: left; padding: .72rem 0; border: 0; border-bottom: 1px solid var(--regla); color: var(--tinta); text-decoration: none; font: inherit; font-size: .9rem; line-height: 1.4; background: none; cursor: pointer; }
.lista-hoja .tt { color: var(--verde); }
.lista-hoja .opcion.actual { color: var(--verde); font-style: italic; }
.ir-hoja { display: flex; gap: .5rem; margin: 0 0 .7rem; }
.ir-hoja input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: .55rem .65rem; border: 1px solid var(--regla); background: var(--papel); color: var(--tinta); border-radius: 2px; }
.constructor summary { cursor: pointer; font-style: italic; color: var(--gris); font-size: 1.05rem; list-style: none; }
.constructor summary::-webkit-details-marker { display: none; }
.constructor summary::after { content: ' +'; color: var(--verde); }
.constructor[open] summary::after { content: ' \2212'; }
.constructor[open] summary { margin-bottom: 1rem; }

@media (max-width: 860px) {
  body { font-size: 16px; line-height: 1.62; }
  html { scroll-padding-top: calc(3.6rem + env(safe-area-inset-top, 0px)); }
  .barra { padding: .7rem 1.05rem; gap: .75rem; flex-wrap: nowrap; }
  .controles { display: none !important; }
  .sigla { display: block; margin-left: auto; font-size: .8rem; letter-spacing: .1em; opacity: .9; }
  main { padding: 0 1.05rem calc(5rem + env(safe-area-inset-bottom, 0px)); }
  .barra-movil { display: grid; }
  .ley { padding-top: 1.4rem; }
  .encabezado h1 { font-size: 1.4rem; line-height: 1.25; }
  .estado { margin: 1rem 0 1.4rem; font-size: .84rem; }
  .citado { padding: 1rem 1rem .9rem; margin-bottom: 1.6rem; }
  .citado .ref { font-size: 1.05rem; }
  .citado .acciones { display: grid; grid-template-columns: 1fr 1fr; }
  .citado .acciones .boton:first-child { grid-column: 1 / -1; padding: .65rem; }
  .u, .u.in, .u.nu, .u.si { padding-left: 0; }
  .u .u { padding-left: .8rem; border-left: 1px solid var(--regla); }
  .u > .p:first-of-type > .lbl, .u.fr > .p:first-of-type > .lbl, .u.in > .p:first-of-type > .lbl, .u.nu > .p:first-of-type > .lbl, .u.si > .p:first-of-type > .lbl, .u.ap > .p:first-of-type > .lbl { position: static; width: auto; text-align: left; margin-right: .15em; }
  .p { margin-bottom: .75rem; }
  .nota { text-align: left; margin: -.45rem 0 .75rem; }
  .cita, .u.cita { box-shadow: -.45rem 0 0 var(--cita), .45rem 0 0 var(--cita); }
  .tit { margin: 2.2rem 0 1.1rem; font-size: .88rem; }
  .opciones { margin-bottom: 1rem; }
  .portada { padding-top: 2rem; }
  .portada h1 { font-size: 2.1rem; }
  .portada .bajada { margin-bottom: 1.6rem; font-size: .95rem; }
  .constructor { padding: 1rem 1.05rem; }
  .constructor input, .constructor select { font-size: 16px; }
  .leyes { columns: 1; }
  .leyes li { grid-template-columns: 4.4rem 1fr; gap: .6rem; padding: .45rem 0; }
}
