/*
 * /history: the story of Vijayanagara as one long timeline.
 *
 * Linked by that page alone (app/web/history.py). Every colour is a token
 * from tokens.css, so both themes come for free. The cards fade in with the
 * site's scroll-driven `.reveal` (site.css), which needs no script; the
 * script only marks which era is on screen.
 */

.history-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
}

/* A grid item is as wide as its content by default; the chip strip scrolls
   inside itself instead of widening the page. */
.history-page > *,
.history-era > * {
  min-width: 0;
}

/* The era chips, pinned under the site header while the timeline scrolls. */
.history-eras {
  position: sticky;
  top: calc(var(--header-height) + 4px);
  z-index: 20;
  margin-inline: calc(-1 * var(--space-2));
  padding: var(--space-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: var(--glass-solid);
  box-shadow: var(--shadow-sm);
}

.history-eras ul {
  display: flex;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: none;
}

.history-eras ul::-webkit-scrollbar {
  display: none;
}

.history-era-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  transition:
    background-color var(--duration) var(--ease),
    color var(--duration) var(--ease);
}

.history-era-chip:hover {
  background: var(--wash-hover);
  color: var(--ink);
}

.history-era-chip:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.history-era-chip[aria-current="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

/* --- An era ------------------------------------------------------------- */

.history-era {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  /* Clear of the pinned chips as well as the header when a chip is followed. */
  scroll-margin-top: 72px;
}

.history-era__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.history-era__head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  line-height: 1.15;
}

.history-era__years {
  margin: 2px 0 0;
  color: var(--accent-ink);
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-era__lede {
  max-width: 640px;
  margin: 0;
  color: var(--ink-2);
  font-size: var(--text-md);
  line-height: 1.6;
}

/* --- The line and its events ------------------------------------------- */

/* `ol.` outweighs base.css's reset of lists with role="list". */
ol.history-line {
  position: relative;
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0 0 0 28px;
  list-style: none;
}

/* The thread the events hang from. */
.history-line::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 8px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent-from), var(--accent));
  opacity: 0.45;
}

.history-event {
  position: relative;
  scroll-margin-top: 72px;
}

/* Each event's dot on the thread. */
.history-event::before {
  content: "";
  position: absolute;
  top: 22px;
  left: -26px;
  width: 14px;
  height: 14px;
  border: 3px solid var(--canvas);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.history-card {
  display: grid;
  gap: var(--space-2);
  max-width: 720px;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
}

.history-when {
  margin: 0;
  color: var(--accent-ink);
  font-size: var(--text-sm);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.history-card h3 {
  margin: 0;
  font-size: var(--text-lg);
  line-height: 1.3;
}

.history-card p {
  margin: 0;
  color: var(--ink-2);
  line-height: 1.65;
}

ul.history-mons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-1) 0 0;
  padding: 0;
  list-style: none;
}

.history-mon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-pill);
  background: var(--glass-strong);
  color: var(--accent-ink);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  transition:
    border-color var(--duration) var(--ease),
    background-color var(--duration) var(--ease);
}

.history-mon .icon {
  width: 15px;
  height: 15px;
}

.history-mon:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.history-mon:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* --- See it yourself ----------------------------------------------------- */

.history-end {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: var(--radius-xl);
}

.history-end h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
}

.history-end p {
  margin: 0;
}

@media (min-width: 720px) {
  .history-eras {
    margin-inline: 0;
    justify-self: start;
  }

  ol.history-line {
    padding-left: 40px;
  }

  .history-line::before {
    left: 13px;
  }

  .history-event::before {
    left: -33px;
  }

  .history-end {
    padding: var(--space-6);
  }
}
