/* =============================================================
   Punjabia — history.css · "The River of Time"
   Loaded by history.html only.
   -------------------------------------------------------------
   - body background      five faint grey river silhouettes
   - .river-filter/.chip  era filter chips (sticky under the nav)
   - .river               the meandering interactive timeline
   - .river-card          floating detail card on hover / focus
   HOW IT WORKS: events are plain HTML in history.html. JS
   (js/timeline-river.js) assigns alternating banks, sets each
   node's meander offset (--nx) and draws the SVG river through
   the nodes. With JS disabled the timeline falls back to a
   single readable column with every detail visible.
   ============================================================= */

/* ---------- Five-rivers background silhouette ----------
   Translucent light-grey meander lines behind the parchment page.
   The tile repeats seamlessly (paths enter and leave vertically
   at the same x). Kept extremely faint so text stays readable. */
body[data-theme="history"] {
  background-color: var(--bg);
  background-image:
    radial-gradient(90rem 50rem at 85% -10%, rgba(205,140,42,.07), transparent 60%),
    radial-gradient(70rem 45rem at -10% 30%, rgba(157,43,63,.05), transparent 55%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='760' height='1140' viewBox='0 0 760 1140'%3E%3Cg fill='none' stroke='%236C6048' stroke-width='1.4' stroke-opacity='.07'%3E%3Cpath d='M70 0 C70 95 132 170 122 300 C112 430 28 520 44 660 C60 800 122 880 106 985 C96 1050 70 1055 70 1140'/%3E%3Cpath d='M240 0 C240 110 176 200 190 330 C204 460 296 540 282 680 C270 800 208 880 222 990 C232 1065 240 1070 240 1140'/%3E%3Cpath d='M400 0 C400 90 462 190 450 320 C438 450 352 540 368 680 C384 820 452 890 438 1000 C428 1070 400 1070 400 1140'/%3E%3Cpath d='M560 0 C560 120 500 210 514 340 C528 470 612 550 598 690 C586 810 524 890 538 1000 C548 1070 560 1075 560 1140'/%3E%3Cpath d='M700 0 C700 100 748 190 738 320 C728 450 660 540 674 680 C688 820 744 890 730 1000 C722 1068 700 1070 700 1140'/%3E%3C/g%3E%3Cpath d='M400 0 C400 90 462 190 450 320 C438 450 352 540 368 680 C384 820 452 890 438 1000 C428 1070 400 1070 400 1140' fill='none' stroke='%236C6048' stroke-width='7' stroke-opacity='.025'/%3E%3C/svg%3E");
  background-repeat: no-repeat, no-repeat, repeat;
  background-size: auto, auto, 760px 1140px;
}

/* ---------- Section intro ---------- */
.river-lede {
  margin: .8rem 0 0;
  max-width: 62ch;
  font-family: var(--font-serif);
  font-size: .98rem;
  line-height: 1.6;
  color: var(--text-2);
}

/* ---------- Era filter chips ---------- */
.river-filter {
  position: sticky; top: 70px; z-index: 6;
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin: 1.4rem -.6rem 1.6rem;
  padding: .55rem .6rem;
  background: color-mix(in srgb, var(--khaddar-100) 84%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 14px;
}
.chip {
  display: inline-flex; align-items: center; gap: .5em;
  border: 1px solid var(--line); background: var(--khaddar-50);
  font-family: var(--font-sans); font-size: .85rem; font-weight: 600;
  color: var(--text-2);
  padding: .42rem .95rem; border-radius: 999px; cursor: pointer;
  transition: background .2s, color .2s, border-color .2s, transform .15s;
}
.chip::before {
  content: ""; width: .55em; height: .55em; border-radius: 50%;
  background: var(--era-c, var(--gold-500));
  box-shadow: 0 0 6px color-mix(in srgb, var(--era-c, var(--gold-500)) 55%, transparent);
}
.chip[data-era="all"]::before {
  background: conic-gradient(var(--gold-500), var(--madder-500), var(--indigo-600), var(--gold-500));
}
.chip:hover {
  border-color: color-mix(in srgb, var(--era-c, var(--gold-500)) 60%, transparent);
  transform: translateY(-1px);
}
.chip.is-active { background: var(--indigo-800); border-color: var(--indigo-600); color: var(--cream); }
.chip__count { font-weight: 500; font-size: .78em; opacity: .65; }

/* ---------- Era colours ----------
   One line per era key. To add an era: add a chip in history.html
   and one line here. Unknown keys fall back to gold. */
.river__event[data-era="ancient"],  .chip[data-era="ancient"]  { --era-c: var(--indigo-600); }
.river__event[data-era="faith"],    .chip[data-era="faith"]    { --era-c: var(--gold-600); }
.river__event[data-era="empire"],   .chip[data-era="empire"]   { --era-c: var(--madder-500); }
.river__event[data-era="colonial"], .chip[data-era="colonial"] { --era-c: var(--src-political); }
.river__event[data-era="modern"],   .chip[data-era="modern"]   { --era-c: var(--src-religious); }

/* ---------- River container & SVG ---------- */
.river { position: relative; margin-top: .4rem; }
.river__svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
  -webkit-mask-image: linear-gradient(transparent, #000 70px, #000 calc(100% - 70px), transparent);
  mask-image: linear-gradient(transparent, #000 70px, #000 calc(100% - 70px), transparent);
}
.river__bed  { fill: none; stroke-width: 16;  stroke-opacity: .10; stroke-linecap: round; transition: opacity .9s ease; }
.river__main { fill: none; stroke-width: 2.75; stroke-opacity: .9; stroke-linecap: round; }
.river__flow {
  fill: none; stroke-width: 6; stroke-opacity: .2; stroke-linecap: round;
  stroke-dasharray: 2 26;
  animation: river-flow 9s linear infinite;
  transition: opacity .9s ease;
}
@keyframes river-flow { to { stroke-dashoffset: -280; } } /* 10 × (2 + 26) */
.river__svg.is-drawing .river__bed,
.river__svg.is-drawing .river__flow { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .river__flow { animation: none; } }

/* ---------- The list ---------- */
.river__list { list-style: none; margin: 0; padding: 0; position: relative; z-index: 1; }

/* No-JS fallback: a single readable column with a plain line */
html:not(.js) .river__list {
  border-left: 2px solid color-mix(in srgb, var(--gold-500) 55%, transparent);
  padding-left: 1.6rem;
}
html:not(.js) .river__event { margin: 0 0 2.6rem; max-width: 620px; }
html:not(.js) .river__node { display: none; }
html:not(.js) .river__marker { justify-content: flex-start; margin: 0 0 1.6rem; }

/* JS layout: alternating banks around a central band the river
   meanders through. JS assigns .is-left/.is-right + grid rows. */
html.js .river__list {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(120px, 15vw, 190px) minmax(0, 1fr);
  row-gap: clamp(2.2rem, 4.5vw, 3.4rem);
}
html.js .river__event { grid-column: 1 / -1; max-width: 380px; }
html.js .river__event.is-left  { grid-column: 1; justify-self: end; text-align: right; }
html.js .river__event.is-right { grid-column: 3; justify-self: start; }
html.js .river__marker { grid-column: 1 / -1; }
html.js .river__detail { display: none; }
.river .is-hidden { display: none !important; }

/* ---------- Event (compact resting state) ---------- */
.river__event { position: relative; }
.river__link {
  display: block; position: relative;
  padding: .35rem .55rem;
  text-decoration: none; color: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .2s ease;
}
.river__event:hover .river__link,
.river__event.is-active .river__link { background: color-mix(in srgb, var(--accent-theme) 7%, transparent); }
.river__year {
  display: block;
  font-family: var(--font-display); font-weight: 600; font-style: italic;
  font-size: 1.45rem; line-height: 1.1; color: var(--gold-600);
}
.river__title {
  display: block; margin-top: .15rem;
  font-family: var(--font-display); font-size: 1.13rem; line-height: 1.3;
  color: var(--text);
  transition: color .2s;
}
.river__event:hover .river__title,
.river__event.is-active .river__title { color: var(--accent-theme-2); }
.river__event--soon .river__title { color: var(--text-2); }

/* ---------- The node (point on the river) ---------- */
.river__node {
  position: absolute; top: 1.15rem;
  width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--era-c, var(--gold-500));
  border: 3px solid var(--khaddar-100);
  box-shadow:
    0 0 0 1.5px var(--era-c, var(--gold-500)),
    0 0 12px color-mix(in srgb, var(--era-c, var(--gold-500)) 40%, transparent);
  transition: transform .2s, box-shadow .2s;
}
html.js .is-left  .river__node { left: calc(100% + var(--nx, 44px)); }
html.js .is-right .river__node { left: calc(0px - var(--nx, 44px)); }
.river__event:hover .river__node,
.river__event.is-active .river__node,
.river__link:focus-visible .river__node {
  transform: scale(1.3);
  box-shadow:
    0 0 0 1.5px var(--era-c, var(--gold-500)),
    0 0 18px color-mix(in srgb, var(--era-c, var(--gold-500)) 65%, transparent),
    0 0 0 7px color-mix(in srgb, var(--era-c, var(--gold-500)) 12%, transparent);
}

/* ---------- Era markers along the banks ---------- */
.river__marker { display: flex; justify-content: center; padding: .4rem 0; }
.river__marker span {
  font-family: var(--font-sans); font-size: .72rem; font-weight: 600;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-3);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; padding: .4em 1.1em;
}

/* ---------- Detail block (inline on touch / no-JS) ---------- */
.river__detail { margin-top: .7rem; }
.river__meta {
  display: flex; flex-wrap: wrap; gap: .35rem .9rem;
  margin: 0 0 .45rem;
  font-family: var(--font-sans); font-size: .82rem;
}
.river__dates { color: var(--accent-theme); font-weight: 600; letter-spacing: .04em; }
.river__people { color: var(--text-3); font-weight: 500; }
.river__hook {
  margin: 0 0 .7rem;
  font-family: var(--font-serif); font-size: .95rem; line-height: 1.6;
  color: var(--text-2);
}
.river__art { margin: 0 0 .6rem; }
.river__art img, .river__art svg {
  width: 100%; height: auto; display: block;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--indigo-900);
}
.river__art svg { border: 0; }
.river__art figcaption {
  font-family: var(--font-serif); font-style: italic; font-size: .83rem;
  color: var(--text-3); margin-top: .45rem;
}
.river__go {
  font-family: var(--font-sans); font-weight: 600; font-size: .88rem;
  color: var(--accent-theme); text-decoration: none;
}
a.river__go:hover { color: var(--accent-theme-2); }
.river__go--soon { color: var(--text-3); }

/* Inline expansion (touch screens / narrow windows).
   JS toggles .is-open on the event; a "+ / −" hint marks it. */
html.js .river--inline .river__event.is-open .river__detail {
  display: block;
  animation: river-detail-in .25s ease;
}
@keyframes river-detail-in { from { opacity: 0; transform: translateY(6px); } }
.river--inline .river__year::after {
  content: " +"; font-style: normal; font-size: .72em;
  color: var(--text-3);
}
.river--inline .river__event.is-open .river__year::after { content: " −"; }

/* ---------- Floating detail card (hover / focus) ---------- */
.river-card {
  position: absolute; z-index: 9995;
  width: min(360px, calc(100vw - 2rem));
  background: var(--indigo-900); color: var(--cream);
  border: 1px solid var(--indigo-600); border-radius: 16px;
  box-shadow: 0 0 0 1px rgba(52,58,114,.4), 0 18px 48px rgba(20,22,47,.45);
  padding: 1.05rem 1.15rem 1.15rem;
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.river-card.is-open { opacity: 1; transform: none; pointer-events: auto; }
@media (prefers-reduced-motion: reduce) { .river-card { transition: none; } }

.river-card__kicker {
  margin: 0 0 .3rem;
  font-family: var(--font-sans); font-size: .7rem; font-weight: 600;
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--gold-300);
}
.river-card__title {
  margin: 0 0 .35rem;
  font-family: var(--font-display); font-size: 1.22rem; line-height: 1.25;
  color: var(--cream);
}
.river-card__meta {
  display: flex; flex-wrap: wrap; gap: .3rem .8rem;
  margin: 0 0 .55rem;
  font-family: var(--font-sans); font-size: .8rem;
}
.river-card__meta .river__dates { color: var(--gold-400); }
.river-card__meta .river__people { color: var(--cream-muted); }
.river-card__hook {
  margin: 0 0 .7rem;
  font-family: var(--font-serif); font-size: .93rem; line-height: 1.55;
  color: var(--cream-muted);
}
.river-card .river__art { margin: 0 0 .7rem; }
.river-card .river__art img {
  width: 100%; height: 180px; object-fit: cover; display: block;
  border-radius: 10px; border: 1px solid var(--indigo-600);
  background: var(--indigo-800);
}
.river-card .river__art svg { width: 100%; height: auto; display: block; border-radius: 10px; }
.river-card .river__art figcaption {
  font-family: var(--font-serif); font-style: italic; font-size: .78rem;
  color: var(--cream-muted); margin-top: .4rem;
}
.river-card .river__go { color: var(--gold-400); font-size: .9rem; }
.river-card a.river__go:hover { color: var(--gold-300); }
.river-card .river__go--soon { color: var(--cream-muted); }

/* ---------- Narrow screens: river runs down the left ---------- */
@media (max-width: 859px) {
  html.js .river__list {
    grid-template-columns: clamp(56px, 15vw, 88px) minmax(0, 1fr);
    row-gap: 2rem;
  }
  html.js .river__event,
  html.js .river__event.is-left,
  html.js .river__event.is-right {
    grid-column: 2; justify-self: start; text-align: left; max-width: none;
  }
  html.js .river__marker { grid-column: 1 / -1; justify-content: flex-start; }
  .river-filter { top: 66px; }
}
