/* ==========================================================================
   Maqueta · Ilustre Municipalidad de Pica
   history.css — Nuestra Comuna · historias de Pica y Matilla: índice de
   capítulos fijo y línea de tiempo que se llena al avanzar la lectura.
   Encabezado, datos destacados y tarjeta final están en commune.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Cuerpo: índice + capítulos
   -------------------------------------------------------------------------- */
.history-body {
  padding: 3.5rem 0 4rem;
  background: linear-gradient(180deg, var(--pm-navy-900) 0%, var(--pm-navy-850) 100%);
}

.history-body__grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  align-items: start;
  gap: clamp(2rem, 5vw, 4rem);
}

.history-toc {
  position: sticky;
  top: calc(var(--commune-sticky-top) + 1.5rem);
}

.history-toc__title {
  margin-bottom: .75rem;
  color: var(--pm-gold-300);
  font-family: var(--pm-font-condensed);
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.history-toc__list {
  display: grid;
  gap: .15rem;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--commune-line);
  list-style: none;
}

.history-toc__list a {
  display: flex;
  gap: .65rem;
  margin-left: -2px;
  padding: .5rem .75rem;
  border-left: 2px solid transparent;
  color: var(--pm-text-soft);
  font-size: .9rem;
  line-height: 1.35;
  transition: color .2s ease, border-color .2s ease, background-color .2s ease;
}

.history-toc__list a:hover {
  color: var(--pm-text);
}

.history-toc__list a[aria-current="true"] {
  border-left-color: var(--pm-gold-500);
  background: rgba(247, 209, 56, .08);
  color: var(--pm-gold-400);
  font-weight: 600;
}

.history-toc__number {
  flex: none;
  color: var(--pm-blue-400);
  font-family: var(--pm-font-condensed);
  font-weight: 600;
}

/* Línea de tiempo: el trazo dorado avanza con la lectura (history.js) */
.history-chapters {
  position: relative;
  padding-left: 3rem;
}

.history-spine {
  position: absolute;
  top: .5rem;
  bottom: 0;
  left: .7rem;
  width: 2px;
  background: var(--commune-line);
}

.history-spine__progress {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--pm-gold-500), var(--pm-blue-400));
  transform: scaleY(var(--progress, 0));
  transform-origin: top;
}

/* Sin JavaScript el trazo se muestra completo */
html:not(.js) .history-spine__progress {
  transform: none;
}

.history-chapter {
  position: relative;
}

/* Más específico que "main section[id]" de main.css, que fija 72 px para todo el sitio */
.history-chapters .history-chapter {
  scroll-margin-top: calc(var(--commune-sticky-top) + 1.5rem);
}

.history-chapter + .history-chapter {
  margin-top: 3.25rem;
}

.history-chapter__marker {
  position: absolute;
  top: .15rem;
  left: calc(-3rem + .7rem - 8px);
  width: 18px;
  height: 18px;
  border: 3px solid var(--pm-gold-500);
  border-radius: 50%;
  background: var(--pm-navy-900);
  box-shadow: 0 0 0 5px var(--pm-navy-900);
}

.history-chapter__period {
  margin-bottom: .35rem;
  color: var(--pm-blue-300);
  font-family: var(--pm-font-condensed);
  font-size: .9rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.history-chapter__number {
  margin-right: .35rem;
  color: var(--pm-gold-400);
}

.history-chapter__title {
  margin-bottom: 1rem;
  color: var(--pm-gold-400);
  font-size: clamp(1.6rem, 2.6vw, 2.1rem);
  font-weight: 800;
  line-height: 1.15;
}

.history-chapter .commune-text {
  max-width: 72ch;
}

/* Hitos con año */
.history-events {
  display: grid;
  gap: .55rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}

.history-events li {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 1rem;
  align-items: baseline;
  padding: .75rem 1rem;
  border: 1px solid var(--commune-line);
  border-radius: 12px;
  background: rgba(13, 45, 84, .65);
}

.history-events__year {
  color: var(--pm-gold-400);
  font-family: var(--pm-font-condensed);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.history-events__text {
  color: var(--pm-text);
  font-size: .93rem;
  line-height: 1.55;
}

/* Recuadro destacado: personaje o patrimonio */
.history-feature {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-top: 1.5rem;
  padding: 1.2rem 1.3rem;
  border: 1px solid rgba(247, 209, 56, .4);
  border-left: 5px solid var(--pm-gold-500);
  border-radius: 14px;
  background: rgba(247, 209, 56, .07);
}

.history-feature__icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--pm-gold-500);
  color: var(--pm-navy-900);
  font-size: 1.3rem;
}

.history-feature__label {
  margin-bottom: .15rem;
  color: var(--pm-blue-300);
  font-family: var(--pm-font-condensed);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.history-feature__title {
  margin-bottom: .3rem;
  color: var(--pm-gold-400);
  font-size: 1.1rem;
  font-weight: 700;
}

.history-feature__text {
  margin: 0;
  color: var(--pm-text);
  font-size: .93rem;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Tablet y celular: el índice pasa a una franja de capítulos fija bajo el menú
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  .history-body {
    padding-top: 0;
  }

  /* minmax(0, 1fr): la franja de capítulos se desliza dentro de la pantalla en vez de ensancharla */
  .history-body__grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.75rem;
  }

  .history-toc {
    top: var(--commune-sticky-top);
    z-index: 3;
    margin-inline: calc(var(--bs-gutter-x, 1.5rem) * -.5);
    padding: .6rem calc(var(--bs-gutter-x, 1.5rem) * .5);
    border-bottom: 1px solid var(--commune-line);
    background: rgba(8, 33, 66, .95);
    backdrop-filter: blur(8px);
  }

  .history-toc__title {
    display: none;
  }

  .history-toc__list {
    display: flex;
    gap: .4rem;
    overflow-x: auto;
    border-left: 0;
    scrollbar-width: none;
  }

  .history-toc__list::-webkit-scrollbar {
    display: none;
  }

  .history-toc__list a {
    flex: none;
    margin-left: 0;
    padding: .4rem .8rem;
    border: 1px solid var(--commune-line);
    border-radius: 999px;
    white-space: nowrap;
  }

  .history-toc__list a[aria-current="true"] {
    border-color: var(--pm-gold-500);
  }

  /* Bajo el menú y la franja de capítulos */
  .history-chapters .history-chapter {
    scroll-margin-top: calc(var(--commune-sticky-top) + 4.5rem);
  }
}

@media (max-width: 575.98px) {
  .history-chapters {
    padding-left: 2.1rem;
  }

  .history-spine {
    left: .45rem;
  }

  .history-chapter__marker {
    left: calc(-2.1rem + .45rem - 8px);
  }

  .history-events li {
    grid-template-columns: 1fr;
    gap: .15rem;
  }
}

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