button {
  background-color: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}

/* --- Accessibility helpers --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -4rem;
  z-index: 10005;
  padding: 0.75rem 1.25rem;
  background: var(--color-link-hover);
  color: var(--color-bg);
  border-radius: 2em;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0.5rem;
}

:focus-visible {
  outline: 2px solid var(--color-link-hover);
  outline-offset: 3px;
}

/* El título hace de "volver al principio": quita el filtro, devuelve la
   densidad a su valor de salida y sube arriba. En reposo va en el gris del
   texto, y al pasar por encima sube al contraste máximo — blanco en el tema
   oscuro, negro en el claro. */
.frame__reset {
  font-size: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--color-text);
  padding: 0;
  transition: color 0.3s ease;
}

.frame__reset:hover,
.frame__reset:focus-visible {
  color: var(--color-link-hover);
}

/* --- Interruptor de tema ---
   Vive en la misma línea que el título. Raíl de un píxel y perilla que se
   desplaza: el mismo lenguaje que el slider de densidad. */
.frame__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.theme {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-dim);
  padding: 0.4rem 0;
  transition: color 0.3s ease;
}

.theme:hover,
.theme:focus-visible {
  color: var(--color-link-hover);
}

.theme__track {
  position: relative;
  width: 2.6rem;
  height: 1.4rem;
  flex: none;
  border: 1px solid var(--color-border);
  border-radius: 2em;
  transition: border-color 0.3s ease;
}

.theme:hover .theme__track {
  border-color: var(--color-border-hover);
}

.theme__knob {
  position: absolute;
  top: 50%;
  left: 0.25rem;
  width: 0.7rem;
  height: 0.7rem;
  margin-top: -0.35rem;
  border-radius: 50%;
  background: var(--color-link-hover);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.3s ease;
}

:root[data-theme='light'] .theme__knob {
  transform: translateX(1.1rem);
}

@media (prefers-reduced-motion: reduce) {
  .theme__knob {
    transition: none;
  }
}

/* --- Controls --- */
.options_grid_container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1.75rem;
  z-index: 1000;
}

@media screen and (max-width: 52.99em) {
  .options_grid_container {
    align-items: stretch;
  }
}

/* Density: one full-width slider, 50%-200%. Replaces the five fixed steps —
   the grid reads a column count straight off --cols. */
.density {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  margin-top: 1.5rem;
}

.density__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 1.1rem;
}

.density__label {
  color: var(--color-text);
  letter-spacing: 0.06em;
}

.density__value {
  color: var(--color-link-hover);
  font-variant-numeric: tabular-nums;
}

.density__input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: ew-resize;
}

.density__input::-webkit-slider-runnable-track {
  height: 1px;
  background: linear-gradient(
    to right,
    var(--color-link-hover) var(--fill, 16.6%),
    var(--color-track) var(--fill, 16.6%)
  );
}

.density__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 5px;
  height: 18px;
  margin-top: -8.5px;
  border: 0;
  border-radius: 0;
  background: var(--color-link-hover);
}

.density__input::-moz-range-track {
  height: 1px;
  background: var(--color-track);
}

.density__input::-moz-range-progress {
  height: 1px;
  background: var(--color-link-hover);
}

.density__input::-moz-range-thumb {
  width: 5px;
  height: 18px;
  border: 0;
  border-radius: 0;
  background: var(--color-link-hover);
}

.density__input:focus-visible {
  outline: 2px solid var(--color-link-hover);
  outline-offset: 8px;
}

.density__ticks {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  color: var(--color-dim);
  font-variant-numeric: tabular-nums;
}

.filter_tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

@media screen and (max-width: 52.99em) {
  .filter_tags {
    justify-content: flex-start;
  }
}

.filter-btn {
  font-size: inherit;
  color: var(--color-text);
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: 2em;
  transition: color 0.3s ease, border-color 0.3s ease, background-color 0.3s ease;
  text-transform: uppercase;
}

.filter-btn:hover {
  border-color: var(--color-border-hover);
  color: var(--color-link-hover);
}

.filter-btn.active {
  background-color: var(--color-active-bg);
  color: var(--color-link-hover);
  border-color: var(--color-link-hover);
}

/* --- Barra de metadatos ---
   La ficha técnica del archivo: cuántas piezas se están mirando, cuántas
   etiquetas y cuándo se publicó esta versión. Vive en la línea del título,
   pegada a About: una fila que se ordena de izquierda a derecha con un hueco
   fijo entre celdas, como un auto layout. */
.meta {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 2.4rem;
  /* Un hueco más ancho que el de dentro separa los datos de About */
  margin: 0 1.8rem 0 auto;
  padding: 0;
}

.meta__cell {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  white-space: nowrap;
}

.meta__key {
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-dim);
}

.meta__val {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

/* Hasta que no cabe en la línea del título, baja a una propia debajo */
@media screen and (max-width: 1099px) {
  .frame__top {
    flex-wrap: wrap;
  }

  .meta {
    order: 3;
    flex: 1 0 100%;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin: 0.4rem 0 0;
  }
}

/* --- Léxico ---
   El párrafo que define las etiquetas, antes de la retícula: un filete de pelo
   de lado a lado, dos rótulos pequeños en las esquinas y el texto debajo.

   EL TAMAÑO DEL TEXTO SE CAMBIA AQUÍ, en --intro-size, y en ningún sitio más.
   Este valor manda en todas las pantallas; el bloque de móvil del final de
   esta sección lo vuelve a declarar solo para el teléfono. 1rem = 11px. */
.intro {
  --intro-size: 2.5rem;
  padding: 4rem 2rem 2rem;
}

.intro__rule {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--color-rule);
}

.intro__label {
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-faint);
}

/* A sangre: el párrafo ocupa el mismo ancho que el filete y que la retícula,
   de margen a margen. Lo único que decide su tamaño es --intro-size. */
.intro__text {
  margin: 2.5rem 0 0;
  max-width: none;
  font-size: var(--intro-size);
  line-height: 1.16;
  letter-spacing: 0.005em;
  color: var(--color-text);
  text-wrap: pretty;
}

/* El término es lo único en blanco: la definición queda un paso por detrás. */
.intro__tag {
  font-size: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  /* Los controles de formulario no heredan el text-transform del body */
  text-transform: inherit;
  color: var(--color-link-hover);
  padding: 0;
  transition: opacity 0.3s ease;
}

.intro__tag sup {
  font-size: max(9px, 0.3em);
  vertical-align: super;
  letter-spacing: 0.08em;
  color: var(--color-dim);
  margin-left: 0.15em;
}

.intro__tag:hover,
.intro__tag:focus-visible {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* Máscaras del reparto por palabras: cada una se levanta desde su propia
   línea. El relleno deja sitio al superíndice y a las colas de las letras
   para que el recorte no las coma. */
.intro__text.is-split .w {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  padding: 0.18em 0 0.1em;
  margin: -0.18em 0 -0.1em;
}

.intro__text.is-split .w__i {
  display: inline-block;
  will-change: transform;
}

@media screen and (max-width: 767px) {
  .intro {
    /* Mismo mando, valor para el teléfono */
    --intro-size: 2.2rem;
    padding: 2rem 1rem 0;
  }

  .intro__text {
    margin-top: 1.5rem;
    line-height: 1.2;
  }
}

/* --- Grid --- */
.grid_gallery_item.hidden {
  display: none;
}

.grid_gallery_container {
  position: relative;
  display: grid;
  gap: 1.5rem;
  padding: 2rem;
  width: 100%;
  margin: 0;
  grid-template-columns: repeat(var(--cols, 10), 1fr);
}

.grid_gallery_item {
  margin: 0;
  display: flex;
  flex-direction: column;
  container-type: inline-size;
}

.grid_gallery_item.expanded {
  grid-column: span 2;
  grid-row: span 2;
}

.grid_gallery_item figcaption {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  font-size: 1.15rem;
  text-align: left;
  margin-top: 0.5rem;
  letter-spacing: 0.04em;
  min-width: 0;
}

.cap__n {
  flex: none;
}

.cap__t {
  color: var(--color-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A title needs room. Below it the number carries the cell on its own. */
@container (max-width: 150px) {
  .cap__t {
    display: none;
  }
}


.grid_empty {
  padding: 0 2rem 2rem;
  font-size: 1rem;
}

/* The image is now a real button wrapping a real <img> */
.image {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  aspect-ratio: var(--aspect-ratio, 1 / 1);
  /* Algunes peces son tires (una columna de talonari, una tira de rifes): a
     3,5 cops l'amplada de columna trencaven la reticula. La cel·la no passa
     de --max-ratio cops la seva amplada; la tira s'hi encaixa sencera. */
  max-height: calc(100cqw * var(--max-ratio, 2));
  overflow: hidden;
  cursor: pointer;
}

.image img {
  display: block;
  width: 100%;
  height: 100%;
  /* contain, no cover: quan la cel·la queda topada, es veu la peca sencera
     mes petita en comptes de retallada. Per a la resta, com que
     --aspect-ratio es la proporcio real de l'escaneig, no hi ha diferencia. */
  object-fit: contain;
  filter: brightness(var(--image-dim));
  transition: filter 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.image:hover img,
.image:focus-visible img {
  filter: brightness(var(--image-lit));
}

@media (prefers-reduced-motion: reduce) {
  .image img {
    transition: none;
  }
}

@media screen and (max-width: 767px) {
  .grid_gallery_container {
    gap: 1rem;
    padding: 1rem;
  }
}

/* --- Pie ---
   Filete a sangre, una nota corta, tres columnas de enlaces pequeños y la
   línea legal al fondo. Mismo inset de 2rem que la retícula y el léxico. */
.footer {
  margin-top: 6rem;
  padding: 2rem 2rem 2.5rem;
  border-top: 1px solid var(--color-rule);
}

.footer__note {
  margin: 0 0 4rem;
  max-width: 62ch;
  font-size: 1.6rem;
  line-height: 1.45;
  letter-spacing: 0.04em;
  color: var(--color-text);
  text-wrap: pretty;
}

/* Tres columnas fijas, no auto-fit: la retícula del pie no debe recolocarse
   sola al cambiar el ancho, solo apilarse en el teléfono. */
.footer__cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2rem;
  max-width: 1100px;
}

.footer__col {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
}

.footer__col a {
  width: fit-content;
  color: var(--color-text);
  text-decoration: none;
  transition: color 0.3s ease;
}

.footer__col a:hover,
.footer__col a:focus-visible {
  color: var(--color-link-hover);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

/* La tercera columna son datos del archivo, no enlaces: un paso por detrás. */
.footer__col--meta {
  color: var(--color-dim);
}

.footer__legal {
  margin: 5rem 0 0;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-dim);
}

/* Crédito del código de partida: misma voz que la línea legal, justo debajo */
.footer__credit {
  margin: 0.6rem 0 0;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-dim);
}

.footer__credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 0.3s ease;
}

.footer__credit a:hover,
.footer__credit a:focus-visible {
  color: var(--color-link-hover);
}

@media screen and (max-width: 767px) {
  .footer {
    margin-top: 3rem;
    padding: 1.5rem 1rem 2rem;
  }

  .footer__note {
    margin-bottom: 2.5rem;
    max-width: none;
    font-size: 1.3rem;
  }

  .footer__cols {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .footer__legal {
    margin-top: 3rem;
  }
}

/* --- Paneles laterales (About y Rights) ---
   Entran desde la derecha por encima de la galería, que se queda visible
   detrás del velo. Mismo gesto que el visor, pero sin ocupar toda la pantalla. */
.panel {
  position: fixed;
  inset: 0;
  z-index: 10003;
}

.panel[hidden] {
  display: none;
}

.panel__overlay {
  position: absolute;
  inset: 0;
  background: var(--color-scrim);
  opacity: 0;
  transition: opacity 0.35s ease;
  cursor: pointer;
}

.panel__sheet {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(58rem, 96vw);
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  padding: 2rem;
  overflow-y: auto;
  background: var(--color-bg);
  border-left: 1px solid var(--color-rule);
  transform: translateX(100%);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.panel.is-open .panel__overlay {
  opacity: 1;
}

.panel.is-open .panel__sheet {
  transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {
  .panel__overlay,
  .panel__sheet {
    transition: none;
  }
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--color-rule);
}

/* Mismo tratamiento que el título de la web: el panel se encabeza con el
   nombre del archivo, no repitiendo el rótulo que acabas de pulsar. */
.panel__title {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-link-hover);
}

.panel__close {
  display: grid;
  place-items: center;
  padding: 0.3rem;
  color: var(--color-dim);
  transition: color 0.3s ease;
}

.panel__close:hover,
.panel__close:focus-visible {
  color: var(--color-link-hover);
}

.panel__close svg {
  display: block;
  width: 18px;
  height: 18px;
}

/* El cuerpo del panel es el único sitio de la web que no va en caja alta: son
   párrafos para leer, no rótulos.

   EL TAMAÑO DEL TEXTO DE LOS PANELES SE CAMBIA AQUÍ, en --panel-size. */
.panel__body {
  --panel-size: 2.9rem;
  text-transform: none;
  font-size: var(--panel-size);
  line-height: 1.32;
  letter-spacing: 0.005em;
  color: var(--color-text);
}

.panel__body p {
  margin: 0 0 1.2em;
  text-wrap: pretty;
}

.panel__body strong {
  font-weight: inherit;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-link-hover);
}

/* Contacto y fecha viven al fondo de la hoja, no pegados al texto: el
   margen automático los empuja hasta abajo por alto que sea el panel. */
.panel__foot {
  margin-top: auto;
  padding-top: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--color-rule);
}

.panel__contact,
.panel__stamp {
  margin: 0;
  text-transform: uppercase;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-dim);
  font-variant-numeric: tabular-nums;
}

.panel__contact a {
  color: var(--color-link-hover);
}

/* Los disparadores: cabecera y pie */
.frame__tools {
  display: flex;
  align-items: center;
  gap: 1.6rem;
}

.panel-links {
  display: flex;
  gap: 1rem;
}

.panel-link {
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--color-dim);
  padding: 0.4rem 0;
  transition: color 0.3s ease;
}

.panel-link:hover,
.panel-link:focus-visible {
  color: var(--color-link-hover);
}

.footer__link {
  width: fit-content;
  font-size: inherit;
  letter-spacing: inherit;
  color: var(--color-text);
  padding: 0;
  text-align: left;
  transition: color 0.3s ease;
}

.footer__link:hover,
.footer__link:focus-visible {
  color: var(--color-link-hover);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

@media screen and (max-width: 767px) {
  .panel__sheet {
    width: 100%;
    padding: 1.5rem 1rem 2rem;
    border-left: 0;
  }

  .panel__body {
    --panel-size: 2.2rem;
  }

  .frame__tools {
    gap: 1rem;
  }

  .panel-links {
    gap: 0.8rem;
  }
}

/* --- Lightbox --- */
body.is-locked {
  overflow: hidden;
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
}

.lightbox.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__overlay {
  position: absolute;
  inset: 0;
  background: var(--color-overlay);
  cursor: pointer;
}

.lightbox__container {
  position: relative;
  z-index: 10001;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.lightbox__image {
  max-width: min(90vw, calc(100vw - 9rem));
  max-height: calc(100dvh - 9rem);
  object-fit: contain;
  transform-origin: center center;
  touch-action: none;
  cursor: zoom-in;
}

.lightbox__image.is-fixed {
  cursor: default;
}

.lightbox__image.is-zoomed {
  cursor: grab;
}

.lightbox__image.is-panning {
  cursor: grabbing;
}

.lightbox__image.is-gliding {
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  .lightbox__image.is-gliding {
    transition: none;
  }
}

.lightbox__image.is-entering {
  animation: fadeIn 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {
  .lightbox__image.is-entering {
    animation: none;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Hairline icons: 1px strokes instead of typographic glyphs, whose weight
   depended on whatever font happened to load. Generous padding keeps the
   touch target usable while the mark itself stays thin. */
.lightbox__close,
.lightbox__prev,
.lightbox__next {
  position: fixed;
  display: grid;
  place-items: center;
  padding: 0.9rem;
  color: var(--color-text);
  transition: color 0.3s ease;
  z-index: 10002;
}

.lightbox__close svg,
.lightbox__prev svg,
.lightbox__next svg {
  display: block;
  width: 24px;
  height: 24px;
  filter: var(--halo-icon);
}

.lightbox__close:hover,
.lightbox__prev:hover,
.lightbox__next:hover,
.lightbox__close:focus-visible,
.lightbox__prev:focus-visible,
.lightbox__next:focus-visible {
  color: var(--color-link-hover);
}

.lightbox__close {
  top: 1.4rem;
  right: 1.4rem;
}

.lightbox__prev,
.lightbox__next {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox__prev {
  left: 1rem;
}

.lightbox__next {
  right: 1rem;
}

.lightbox__meta {
  position: fixed;
  bottom: 2rem;
  left: 2rem;
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  z-index: 10002;
  max-width: calc(100vw - 12rem);
}

/* The image now fills the stage, so the chrome sits on top of it — and a scan
   of pink paper is a very bright backdrop. A shadow keeps the type readable
   without putting a box around it. */
.lightbox__counter,
.lightbox__caption,
.lightbox__zoom {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: var(--halo-text);
}

.lightbox__counter {
  color: var(--color-dim);
  flex: none;
}

.lightbox__caption {
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Percentage of the scan's own resolution — at 100% you are looking at the
   actual scanned pixels. */
.lightbox__zoom {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  color: var(--color-dim);
  z-index: 10002;
}

/* On phones the arrows sit below the image instead of over it */
@media screen and (max-width: 767px) {
  .lightbox__image {
    max-width: calc(100vw - 2rem);
    max-height: calc(100dvh - 12rem);
  }

  .lightbox__prev,
  .lightbox__next {
    top: auto;
    bottom: 1.25rem;
    transform: none;
  }

  .lightbox__prev {
    left: 25%;
  }

  .lightbox__next {
    right: 25%;
  }

  .lightbox__close {
    top: 0.5rem;
    right: 0.5rem;
  }

  .lightbox__meta {
    bottom: 4.5rem;
    left: 1rem;
    right: 1rem;
    max-width: none;
  }

  .lightbox__zoom {
    bottom: 4.5rem;
    right: 1rem;
  }
}
