/* ============================================================
   EN: Codices portal — visual language of parchment and ink:
       vellum background, gold leaf accent, lapis blue for links.
       Dark and light themes, RTL support for Arabic.
   ES: Portal de Codices — lenguaje visual de pergamino y tinta:
       fondo de vitela, oro de pan como acento, azul lapislazuli
       para los enlaces. Temas oscuro y claro, soporte RTL arabe.
   ============================================================ */

:root {
  --oro: #c8a35a;
  --oro-claro: #e3c98c;
  --lapis: #4a6fa5;
  --minio: #b0503c;          /* rojo minio de las capitulares / red lead of initials */
  --radio: 14px;
  --ancho: 1220px;
  --sombra: 0 18px 48px rgba(0, 0, 0, .38);
  --serif: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --sans: 'Inter', 'Noto Sans Arabic', 'Noto Sans SC', 'Noto Sans JP', system-ui, sans-serif;
}

/* Tema oscuro (por defecto) / dark theme (default) */
[data-theme="dark"] {
  --fondo: #14110d;
  --fondo-2: #1b1712;
  --tarjeta: #221d17;
  --borde: #352d23;
  --texto: #ece4d7;
  --texto-2: #a99a86;
  --sombra-tarjeta: 0 10px 28px rgba(0, 0, 0, .45);
}

/* Tema claro / light theme */
[data-theme="light"] {
  --fondo: #f6f1e6;
  --fondo-2: #efe7d7;
  --tarjeta: #fffdf8;
  --borde: #ded2ba;
  --texto: #2a2318;
  --texto-2: #6d6250;
  --sombra: 0 18px 44px rgba(90, 70, 40, .16);
  --sombra-tarjeta: 0 8px 22px rgba(90, 70, 40, .12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
img { max-width: 100%; display: block; }
a { color: var(--lapis); text-decoration: none; }
[data-theme="dark"] a:not(.brand):not(.btn) { color: #8fb0e0; }
a:hover { text-decoration: underline; }
.wrap { max-width: var(--ancho); margin: 0 auto; padding: 0 22px; }

/* ── Cabecera / header ── */
header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--fondo) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--borde);
}
.topbar { display: flex; align-items: center; gap: 18px; height: 66px; }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark svg { width: 30px; height: 30px; fill: none; stroke: var(--oro); stroke-width: 1.6; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand-txt b { font-family: var(--serif); font-size: 19px; letter-spacing: .3px; }
.brand-txt em { font-style: normal; font-size: 11px; color: var(--texto-2); }
#nav { display: flex; gap: 20px; margin-inline-start: auto; font-size: 14px; }
#nav a { color: var(--texto-2); }
#nav a:hover { color: var(--oro); text-decoration: none; }
.controls { display: flex; align-items: center; gap: 8px; }
.lang { position: relative; }
.lang-btn, .theme-btn, .burger {
  background: transparent; border: 1px solid var(--borde); color: var(--texto);
  border-radius: 9px; padding: 6px 10px; cursor: pointer; font: inherit; font-size: 13px;
}
.lang-btn:hover, .theme-btn:hover { border-color: var(--oro); }
.burger { display: none; }
.lang-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 8px);
  background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 12px;
  box-shadow: var(--sombra); padding: 6px; display: none; min-width: 170px; z-index: 50;
}
.lang-menu.open { display: block; }
.lang-menu button {
  display: block; width: 100%; text-align: start; background: transparent; border: 0;
  color: var(--texto); padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 14px;
}
.lang-menu button:hover { background: var(--fondo-2); }
.lang-menu button.active { color: var(--oro); font-weight: 600; }

/* ── Portada / hero ── */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--borde); }
.vellum {
  position: absolute; inset: 0;
  background:
    radial-gradient(1100px 420px at 78% -10%, color-mix(in srgb, var(--oro) 22%, transparent), transparent 65%),
    radial-gradient(760px 340px at 8% 108%, color-mix(in srgb, var(--lapis) 24%, transparent), transparent 62%);
  opacity: .55;
}
.hero-in { position: relative; padding: 74px 22px 58px; max-width: 900px; }
.kicker { color: var(--oro); font-size: 12px; letter-spacing: 2.4px; text-transform: uppercase; font-weight: 600; }
.hero h1 { font-family: var(--serif); font-size: clamp(34px, 5.6vw, 60px); line-height: 1.06; margin: 12px 0 16px; }
.lead { font-size: 18px; color: var(--texto-2); max-width: 68ch; }
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.btn {
  display: inline-block; padding: 11px 20px; border-radius: 11px; font-weight: 600;
  font-size: 15px; border: 1px solid transparent; cursor: pointer;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--oro); color: #17130c; }
.btn-primary:hover { background: var(--oro-claro); }
.btn-ghost { border-color: var(--borde); color: var(--texto); }
.btn-ghost:hover { border-color: var(--oro); }
.stats { display: flex; gap: 34px; flex-wrap: wrap; margin-top: 38px; }
.stats div b { display: block; font-family: var(--serif); font-size: 30px; color: var(--oro); }
.stats div span { font-size: 12.5px; color: var(--texto-2); }

/* ── Secciones / sections ── */
.sec { padding: 62px 0; }
.sec.alt { background: var(--fondo-2); border-block: 1px solid var(--borde); }
.sec h2 { font-family: var(--serif); font-size: clamp(25px, 3.4vw, 35px); margin: 0 0 8px; }
.sec-lead { color: var(--texto-2); max-width: 74ch; margin: 0 0 26px; }

/* ── Linea de tiempo vertical / vertical timeline ── */
.tl { position: relative; margin-top: 26px; }
.tl-eje { position: relative; padding: 10px 0 20px; }
.tl-eje::before {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
  transform: translateX(-50%); opacity: .7;
  background: linear-gradient(var(--lapis), var(--oro) 55%, var(--minio));
}
.tsiglo { position: relative; text-align: center; padding: 18px 0 10px; }
.tsiglo span {
  display: inline-block; background: var(--fondo); border: 1px solid var(--borde);
  border-radius: 999px; padding: 3px 14px; font-size: 12px; color: var(--oro);
  font-family: var(--serif); letter-spacing: .6px;
}
.sec.alt .tsiglo span { background: var(--fondo-2); }
.tnodo {
  position: relative; display: flex; align-items: center; gap: 14px;
  width: 50%; padding: 9px 0; min-height: 78px; cursor: pointer;
}
.tnodo.izq { margin-inline-end: auto; flex-direction: row-reverse; text-align: end; padding-inline-end: 36px; }
.tnodo.der { margin-inline-start: 50%; padding-inline-start: 36px; }
.tnodo::after {
  content: ''; position: absolute; top: 50%; width: 24px; height: 1px; background: var(--borde);
}
.tnodo.izq::after { inset-inline-end: 10px; }
.tnodo.der::after { inset-inline-start: 10px; }
.tpunto {
  position: absolute; top: 50%; width: 11px; height: 11px; border-radius: 50%;
  margin-top: -5.5px; background: var(--fondo); border: 2.5px solid var(--oro); z-index: 2;
}
.tpunto.lleno { background: var(--minio); border-color: var(--minio); }
.tnodo.izq .tpunto { inset-inline-end: -6px; }
.tnodo.der .tpunto { inset-inline-start: -6px; }
.tminia {
  width: 52px; height: 68px; flex: none; border-radius: 7px; overflow: hidden;
  border: 1px solid var(--borde); background: var(--tarjeta); transition: transform .2s, border-color .2s;
}
.tminia img { width: 100%; height: 100%; object-fit: cover; }
.tnodo:hover .tminia { transform: scale(1.09); border-color: var(--oro); box-shadow: var(--sombra-tarjeta); }
.tetq { min-width: 0; }
.tetq b { display: block; font-family: var(--serif); font-size: 15.5px; line-height: 1.25; }
.tetq i { font-style: normal; font-size: 12px; color: var(--texto-2); }
.tetq em {
  display: inline-block; margin-top: 5px; font-style: normal; font-size: 10.5px;
  font-weight: 600; color: #fff; background: var(--minio); border-radius: 5px; padding: 2px 7px;
}
.tnodo:hover .tetq b { color: var(--oro); }

@media (max-width: 760px) {
  .tl-eje::before { left: 15px; }
  .tnodo, .tnodo.izq, .tnodo.der {
    width: 100%; margin: 0; flex-direction: row; text-align: start;
    padding: 8px 0 8px 44px; min-height: 0;
  }
  .tnodo::after { display: none; }
  .tnodo.izq .tpunto, .tnodo.der .tpunto { inset-inline-start: 10px; inset-inline-end: auto; }
  .tsiglo { text-align: start; padding-inline-start: 44px; }
}

/* ── Mapa de talleres / workshop map ── */
.mapa {
  position: relative; width: 100%; aspect-ratio: 2 / 1; border-radius: var(--radio);
  border: 1px solid var(--borde); overflow: hidden;
  background: var(--tarjeta);
}
.mapa-marca {
  position: absolute; width: 11px; height: 11px; border-radius: 50%;
  background: var(--oro); border: 2px solid color-mix(in srgb, var(--fondo) 70%, transparent);
  transform: translate(-50%, -50%); cursor: pointer;
}
.mapa-marca:hover { background: var(--minio); z-index: 3; }
.mapa-marca::after {
  content: attr(data-nombre); position: absolute; left: 50%; bottom: 150%;
  transform: translateX(-50%); background: var(--tarjeta); color: var(--texto);
  border: 1px solid var(--borde); border-radius: 7px; padding: 3px 8px;
  font-size: 11.5px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s;
}
.mapa-marca:hover::after { opacity: 1; }

/* ── Catalogo / catalogue ── */
.filtros { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-bottom: 22px; }
#q {
  flex: 1 1 260px; background: var(--tarjeta); border: 1px solid var(--borde);
  color: var(--texto); border-radius: 11px; padding: 10px 14px; font: inherit; font-size: 14.5px;
}
#q:focus { outline: none; border-color: var(--oro); }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  background: transparent; border: 1px solid var(--borde); color: var(--texto-2);
  border-radius: 999px; padding: 5px 13px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.chip:hover { border-color: var(--oro); }
.chip.on { background: var(--oro); border-color: var(--oro); color: #17130c; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); gap: 20px; }
.carta {
  background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio);
  overflow: hidden; cursor: pointer; box-shadow: var(--sombra-tarjeta);
  transition: transform .16s, border-color .16s;
}
.carta:hover { transform: translateY(-3px); border-color: var(--oro); }
.carta-img { aspect-ratio: 3 / 4; background: var(--fondo-2); overflow: hidden; }
.carta-img img { width: 100%; height: 100%; object-fit: cover; }
.carta-txt { padding: 13px 15px 16px; }
.carta-txt h3 { font-family: var(--serif); font-size: 17px; margin: 0 0 5px; }
.carta-meta { font-size: 12px; color: var(--texto-2); display: flex; gap: 8px; flex-wrap: wrap; }
.carta-sub { font-size: 13px; color: var(--texto-2); margin-top: 8px; }
.marca-completo {
  display: inline-block; background: var(--minio); color: #fff; font-size: 10.5px;
  font-weight: 600; border-radius: 5px; padding: 2px 7px; margin-top: 9px;
}
.vacio { color: var(--texto-2); text-align: center; padding: 36px 0; }

/* ── Copias completas / complete copies ── */
.completos { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: 20px; }
.completo {
  display: flex; gap: 14px; background: var(--tarjeta); border: 1px solid var(--borde);
  border-radius: var(--radio); padding: 15px; cursor: pointer; box-shadow: var(--sombra-tarjeta);
}
.completo:hover { border-color: var(--minio); }
.completo img { width: 74px; height: 96px; object-fit: cover; border-radius: 6px; }
.completo b { font-family: var(--serif); font-size: 16.5px; display: block; }
.completo span { font-size: 12.5px; color: var(--texto-2); }
.completo .cuenta { color: var(--minio); font-weight: 600; }

/* ── Fuentes / sources ── */
.fuentes { max-width: 78ch; color: var(--texto-2); }
.fuentes .nota { font-size: 13.5px; opacity: .85; }

/* ── Pie / footer ── */
footer { border-top: 1px solid var(--borde); padding: 26px 0; }
.foot { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--texto-2); }

/* ── Ficha ampliada / record panel ── */
.panel { position: fixed; inset: 0; z-index: 60; display: flex; }
.panel-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .62); backdrop-filter: blur(3px); }
.panel-in {
  position: relative; margin: auto; width: min(1000px, 94vw); max-height: 92vh; overflow: auto;
  background: var(--fondo); border: 1px solid var(--borde); border-radius: 18px;
  box-shadow: var(--sombra); padding: 30px 32px 36px;
}
.panel-x {
  position: absolute; inset-inline-end: 16px; top: 14px; background: transparent;
  border: 1px solid var(--borde); color: var(--texto); border-radius: 9px;
  width: 34px; height: 34px; cursor: pointer; font-size: 15px;
}
.panel-x:hover { border-color: var(--oro); }
.panel-in h2 { font-family: var(--serif); font-size: 30px; margin: 0 0 4px; padding-inline-end: 46px; }
.panel-sub { color: var(--texto-2); margin-bottom: 18px; }
.panel-datos { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.dato {
  background: var(--fondo-2); border: 1px solid var(--borde); border-radius: 9px;
  padding: 7px 12px; font-size: 12.5px;
}
.dato b { color: var(--oro); font-weight: 600; }
.panel-desc { color: var(--texto); margin-bottom: 8px; }
.panel-origen { font-size: 12px; color: var(--texto-2); margin-bottom: 22px; font-style: italic; }
.panel-h3 { font-family: var(--serif); font-size: 18px; margin: 26px 0 12px; }
.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 9px; }
.galeria img {
  width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 7px;
  border: 1px solid var(--borde); cursor: zoom-in; background: var(--fondo-2);
}
.galeria img:hover { border-color: var(--oro); }
.panel-mapa { height: 190px; }
.enlaces { display: flex; flex-direction: column; gap: 7px; font-size: 14px; }
.mas-folios {
  margin-top: 13px; background: transparent; border: 1px solid var(--borde); color: var(--texto);
  border-radius: 10px; padding: 9px 16px; cursor: pointer; font: inherit; font-size: 14px;
}
.mas-folios:hover { border-color: var(--minio); color: var(--minio); }

/* ── Visor con lupa / viewer with loupe ── */
.visor { position: fixed; inset: 0; z-index: 80; background: rgba(8, 6, 4, .96); display: flex; flex-direction: column; }
.visor-lienzo { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.visor-lienzo img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center center; cursor: grab; }
.visor-lienzo img.arrastrando { cursor: grabbing; }
.visor-x, .visor-nav {
  position: absolute; z-index: 3; background: rgba(255, 255, 255, .09); border: 1px solid rgba(255, 255, 255, .2);
  color: #fff; border-radius: 10px; cursor: pointer; font-size: 20px; line-height: 1;
}
.visor-x { top: 16px; inset-inline-end: 18px; width: 40px; height: 40px; }
.visor-nav { top: 50%; transform: translateY(-50%); width: 44px; height: 66px; font-size: 30px; }
.visor-nav.prev { inset-inline-start: 16px; }
.visor-nav.next { inset-inline-end: 16px; }
.visor-x:hover, .visor-nav:hover { background: rgba(255, 255, 255, .2); }
.lupa {
  position: absolute; width: 210px; height: 210px; border-radius: 50%; pointer-events: none;
  border: 2px solid var(--oro); box-shadow: 0 0 0 1px rgba(0, 0, 0, .6), 0 12px 34px rgba(0, 0, 0, .6);
  background-repeat: no-repeat; z-index: 4;
}
.visor-pie {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 11px 20px; color: #d8cdba; font-size: 12.5px; border-top: 1px solid rgba(255, 255, 255, .1);
}
.visor-ayuda { opacity: .6; }
.tira { display: flex; gap: 7px; overflow-x: auto; padding: 9px 14px 14px; background: rgba(0, 0, 0, .35); }
.tira img {
  height: 62px; width: 46px; object-fit: cover; border-radius: 4px; cursor: pointer;
  opacity: .5; border: 2px solid transparent; flex: 0 0 auto; background: #241f19;
}
.tira img.on, .tira img:hover { opacity: 1; border-color: var(--oro); }

/* ── RTL (arabe) / RTL (Arabic) ── */
[dir="rtl"] .tl-etq { transform: translateX(-50%) rotate(32deg); }
[dir="rtl"] .brand-txt { text-align: right; }

/* ── Movil / mobile ── */
@media (max-width: 900px) {
  #nav {
    display: none; position: absolute; top: 66px; inset-inline: 0;
    background: var(--fondo); border-bottom: 1px solid var(--borde);
    flex-direction: column; gap: 0; padding: 8px 22px 16px;
  }
  #nav.open { display: flex; }
  #nav a { padding: 10px 0; border-bottom: 1px solid var(--borde); }
  .burger { display: block; }
  .panel-in { padding: 24px 20px 30px; width: 96vw; }
  .stats { gap: 24px; }
  .lupa { width: 150px; height: 150px; }
}
