/* ============================================================
   Ty i Ja (1960s Polish magazine) look, "pomegranate" palette.
   Four inks only, everything else a screened tint of these on
   the paper stock, as on a 4-colour press run:
     paper #F1E8D0   ink #131010
     pomegranate #9E2B3C (lead)   turquoise-green #31806E (accent)
     saffron #DBA02E (the <5% micro accent: stamps, threads)
   Flat throughout: no gradients, no blurred shadows. Offsets are
   solid ink, like misregistered print or stacked cut paper.
   This :root block is the SINGLE source of truth for every color
   on the page; app.js reads tokens via getComputedStyle.
   ============================================================ */
:root {
  --bg: #f1e8d0;       /* paper */
  --ink: #131010;
  --pom: #9e2b3c;      /* pomegranate ink, the lead */
  --turq: #31806e;     /* turquoise-green ink, the accent */
  --saffron: #dba02e;  /* micro accent */

  /* screened tints (same inks, halftoned on paper) */
  --muted: #6e6250;
  --line: #dccfaf;
  --band: #e7dbbd;
  --soft-ink: #a5987f;
  --pom-screen: #e3bcb0;
  --turq-screen: #c2d6c9;
  --saffron-screen: #ecd9a8;

  --serif: "Lora", Georgia, serif;
  --display: "Shrikhand", "Cooper Black", serif;
  --caps: "Anton", "Arial Narrow", sans-serif;
  --nastaliq: "Gulzar", "Noto Nastaliq Urdu", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

/* paper grain over everything: texture, not shading */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 80;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.09 0 0 0 0 0.07 0 0 0 0 0.05 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- masthead: boxed cover table, slimmed ---------- */
.masthead {
  display: grid;
  grid-template-columns: 34px 190px 1fr;
  align-items: stretch;
  margin: 14px 24px 0;
  border: 2.5px solid var(--ink);
  background: var(--bg);
}
.mast-tab {
  border-right: 2.5px solid var(--ink);
  background: var(--pom);
  display: flex;
  align-items: center;
  justify-content: center;
}
.mast-tab span {
  font-family: var(--caps);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--bg);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 10px 0;
}
.mast-logo {
  border-right: 2.5px solid var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 10px;
}
.logo-en {
  font-family: var(--display);
  font-size: 42px;
  line-height: 1;
  color: var(--pom);
  text-shadow: 3px 3px 0 var(--turq-screen);
}
.logo-fa {
  font-family: var(--nastaliq);
  font-size: 18px;
  line-height: 2.1;
  color: var(--ink);
}
.mast-title { padding: 14px 20px 12px; }
.mast-title h1 {
  font-family: var(--caps);
  font-size: clamp(22px, 3.2vw, 36px);
  line-height: 1.04;
  text-transform: uppercase;
}
.mast-sub {
  margin-top: 7px;
  font-size: 14.5px;
  font-style: italic;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.stamp {
  font-family: var(--caps);
  font-size: 10px;
  font-style: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border: 2px solid var(--ink);
  padding: 2px 8px 1px;
  transform: rotate(-2deg);
  background: var(--bg);
  display: inline-block;
}
.stamp-pop { color: var(--pom); border-color: var(--pom); }

/* ---------- overview: every span at once ---------- */
.overview { margin: 20px auto 0; max-width: 1020px; padding: 0 24px; }
.overview-head { display: flex; align-items: baseline; gap: 14px; }
.overview-head h2 {
  font-family: var(--caps);
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.overview-head p { font-size: 13.5px; font-style: italic; color: var(--muted); }
#overview-chart { margin-top: 8px; border: 2px solid var(--ink); background: var(--bg); }
#overview-chart svg { display: block; width: 100%; height: auto; }
.ov-bar { cursor: pointer; }
.ov-bar:hover { fill: var(--pom); }

/* ---------- sticky controls ---------- */
.controls {
  position: sticky;
  top: 0;
  z-index: 40;
  margin-top: 18px;
  padding: 8px 24px;
  background: var(--bg);
  border-top: 2.5px solid var(--ink);
  border-bottom: 2.5px solid var(--ink);
}
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.control-row + .control-row { margin-top: 7px; }

.era-nav { display: flex; }
.era-nav a {
  font-family: var(--caps);
  font-size: 12.5px;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-decoration: none;
  border: 2px solid var(--ink);
  border-right-width: 0;
  padding: 3px 11px 2px;
  background: var(--bg);
}
.era-nav a:last-child { border-right-width: 2px; }
.era-nav a:hover { background: var(--band); }
.era-nav a.active { background: var(--ink); color: var(--bg); }

.chip {
  font-family: var(--caps);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
  padding: 4px 10px 3px;
  cursor: pointer;
}
.chip:hover { background: var(--band); }
.chip.active {
  background: var(--pom);
  border-color: var(--pom);
  color: var(--bg);
  box-shadow: 2px 2px 0 var(--ink);
}
.graph-open { border-color: var(--turq); color: var(--turq); }
.graph-open:hover { background: var(--turq-screen); }

.thread-label {
  font-family: var(--caps);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.thread-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.thread-btn {
  font-family: var(--caps);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 2px dashed var(--soft-ink);
  background: var(--bg);
  color: var(--ink);
  padding: 3px 9px 2px;
  cursor: pointer;
}
.thread-btn:hover { border-color: var(--ink); }
.thread-btn.active {
  border: 2px solid var(--ink);
  background: var(--saffron);
  box-shadow: 2px 2px 0 var(--ink);
}
.count-readout {
  margin-left: auto;
  font-family: var(--caps);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.thread-caption {
  margin-top: 7px;
  font-size: 13.5px;
  font-style: italic;
  color: var(--muted);
  max-width: 62em;
}

/* ---------- the timeline ---------- */
#timeline { max-width: 880px; margin: 0 auto; padding: 4px 24px 40px; }

.era-band {
  margin: 40px 0 6px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.era-band .era-num {
  font-family: var(--display);
  font-size: 44px;
  line-height: 1;
  color: var(--turq);
  text-shadow: 3px 3px 0 var(--pom-screen);
}
.era-band h2 {
  font-family: var(--caps);
  font-size: clamp(20px, 2.6vw, 28px);
  text-transform: uppercase;
  line-height: 1.05;
}
.era-band .era-span-label {
  font-family: var(--caps);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.era-rule {
  height: 8px;
  margin: 8px 0 4px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='8'%3E%3Cpath d='M0 7 L4 1 L8 7 L12 1 L16 7' fill='none' stroke='%239e2b3c' stroke-width='1.8'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
}

/* decade groups sit on a spine */
.decade { position: relative; padding-left: 108px; }
.decade::before {
  content: "";
  position: absolute;
  left: 88px;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--ink);
}
.decade[data-rendered="false"] .decade-figs { min-height: 30vh; }

.decade-label {
  position: sticky;
  top: 108px;
  float: left;
  margin-left: -108px;
  width: 80px;
  text-align: right;
  font-family: var(--caps);
  font-size: 20px;
  color: var(--pom);
  padding-top: 14px;
}

.decade-figs { display: flex; flex-direction: column; gap: 14px; padding: 14px 0 18px; }

/* ---------- figure rows ---------- */
.fig-row { position: relative; display: grid; grid-template-columns: 74px 1fr; gap: 14px; }
.fig-row::before {
  content: "";
  position: absolute;
  left: -24px;             /* dot on the spine (spine at -20px from grid start) */
  top: 14px;
  width: 11px;
  height: 11px;
  background: var(--bg);
  border: 3px solid var(--ink);
  border-radius: 0;        /* square dots: cut paper, not web */
  transform: rotate(45deg);
}
.fig-row.is-living::before { border-color: var(--turq); }
.fig-row.violent-end::before { background: var(--pom); border-color: var(--pom); }
/* influence weight = spine dot size */
.fig-row.w1::before, .fig-row.w2::before { width: 8px; height: 8px; left: -22px; }
.fig-row.w4::before { width: 14px; height: 14px; left: -26px; }
.fig-row.w5::before { width: 18px; height: 18px; left: -28px; top: 12px; }

.year-plate { text-align: right; padding-top: 6px; }
.year-plate .y-start {
  font-family: var(--caps);
  font-size: 24px;
  line-height: 1;
  display: block;
}
.year-plate .y-end {
  font-family: var(--caps);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}
.year-plate .y-death {
  font-family: var(--caps);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--pom);
  display: block;
  margin-top: 4px;
}
.year-plate .y-death.quiet { color: var(--muted); }
.year-plate .y-living {
  font-family: var(--caps);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--turq);
  display: block;
  margin-top: 4px;
}

/* the card: cut paper */
.fig-card {
  border: 2px solid var(--ink);
  background: var(--bg);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 11px 14px 12px;
}
.fig-card:target, .fig-card.flash { box-shadow: 4px 4px 0 var(--pom); border-color: var(--pom); }

.fig-names { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.fig-name {
  font-family: var(--caps);
  font-size: 20px;
  line-height: 1.08;
  text-transform: uppercase;
}
/* influence weight = headline size, like a magazine front page */
.fig-name.nw1 { font-size: 15px; color: #3d3630; }
.fig-name.nw2 { font-size: 17px; }
.fig-name.nw3 { font-size: 20px; }
.fig-name.nw4 { font-size: 26px; }
.fig-name.nw5 { font-size: 34px; color: var(--pom); }
.fig-fa {
  font-family: var(--nastaliq);
  font-size: 16px;
  line-height: 2;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.fig-meta { font-size: 12px; font-style: italic; color: var(--muted); margin-top: 1px; }
.fig-meta .fig-role-word {
  font-family: var(--caps);
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--turq);
  margin-right: 8px;
}
.pips { display: inline-flex; gap: 2px; margin-right: 8px; vertical-align: 1px; }
.pip {
  width: 6px;
  height: 6px;
  border: 1.2px solid var(--soft-ink);
  background: var(--bg);
  display: inline-block;
}
.pip.on { background: var(--ink); border-color: var(--ink); }
.inf-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.inf-chips .chip { display: inline-flex; align-items: center; gap: 6px; }
.inf-chips .pips { margin-right: 0; }
.chip.active .pip { border-color: var(--bg); }
.chip.active .pip.on { background: var(--bg); border-color: var(--bg); }
.fig-sig { font-size: 14.5px; line-height: 1.5; margin-top: 6px; }

/* the longer story for beginners */
.fig-story { margin-top: 7px; }
.fig-story summary {
  font-family: var(--caps);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pom);
  cursor: pointer;
  list-style: none;
}
.fig-story summary::before { content: "+ "; }
.fig-story[open] summary::before { content: "\2212  "; }
.fig-story summary::-webkit-details-marker { display: none; }
.fig-story p {
  margin-top: 6px;
  font-size: 14.5px;
  line-height: 1.55;
  border-left: 4px solid var(--saffron);
  background: var(--band);
  padding: 8px 10px;
}

/* connections */
.fig-conns { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }
.conn-chip {
  font-size: 12px;
  font-family: var(--serif);
  border: 1.5px solid var(--soft-ink);
  background: var(--bg);
  padding: 2px 8px;
  cursor: pointer;
  color: var(--ink);
}
.conn-chip b { font-family: var(--caps); font-weight: 400; letter-spacing: 0.04em; }
.conn-chip:hover { border-color: var(--ink); background: var(--band); }
.conn-chip .conn-kind { color: var(--muted); font-style: italic; }
.conn-chip.kind-killed .conn-kind, .conn-chip.kind-rival .conn-kind { color: var(--pom); }
.conn-chip.kind-family .conn-kind { color: var(--turq); }

/* thread mode */
body.thread-on .fig-row { opacity: 0.25; }
body.thread-on .fig-row.on-thread { opacity: 1; }
body.thread-on .fig-row.on-thread .fig-card { border-left: 8px solid var(--saffron); }

/* filtered out */
.fig-row.filtered-out { display: none; }
.decade.decade-empty { display: none; }
.era-band.era-band-empty { display: none; }

/* ---------- graph overlay ---------- */
.graph-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: var(--bg);
  overflow: auto;
  padding: 18px;
}
.graph-panel {
  max-width: 980px;
  margin: 0 auto;
  border: 2.5px solid var(--ink);
  background: var(--bg);
  box-shadow: 6px 6px 0 var(--ink);
  padding: 16px 18px 20px;
}
.graph-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.graph-head h2 {
  font-family: var(--caps);
  font-size: 22px;
  text-transform: uppercase;
}
.graph-hint { font-size: 13.5px; font-style: italic; color: var(--muted); }
.graph-head .chip { margin-left: auto; }
.graph-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.legend-chip {
  font-family: var(--caps);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 2px solid var(--soft-ink);
  background: var(--bg);
  padding: 3px 9px 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-chip .swatch { width: 14px; height: 3px; display: inline-block; }
.legend-chip.off { opacity: 0.35; }
#graph-svg-wrap { margin-top: 10px; }
#graph-svg-wrap svg { display: block; width: 100%; height: auto; }
.graph-detail {
  margin-top: 10px;
  border: 2px solid var(--ink);
  background: var(--band);
  padding: 10px 12px;
  font-size: 14px;
}
.graph-detail .g-name { font-family: var(--caps); font-size: 17px; text-transform: uppercase; }
.graph-detail .g-go {
  font-family: var(--caps);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  border: 2px solid var(--pom);
  color: var(--pom);
  background: var(--bg);
  padding: 2px 8px;
  cursor: pointer;
  margin-left: 10px;
}
.graph-detail ul { list-style: none; margin-top: 6px; }
.graph-detail li { margin-top: 2px; }
.graph-detail li i { color: var(--muted); }

/* ---------- colophon ---------- */
.colophon { border-top: 2.5px solid var(--ink); margin-top: 26px; background: var(--band); }
.colophon-inner { max-width: 880px; margin: 0 auto; padding: 24px 24px 38px; }
.colophon h2 {
  font-family: var(--caps);
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
.colophon p { font-size: 14.5px; line-height: 1.55; margin-bottom: 11px; max-width: 66em; }
.colophon-caution { border-left: 4px solid var(--pom); padding-left: 12px; }
.colophon-src { font-style: italic; color: var(--muted); }
.colophon a { color: var(--pom); }

@media (max-width: 680px) {
  .masthead { grid-template-columns: 26px 1fr; }
  .mast-logo { border-right: 0; }
  .mast-title { grid-column: 1 / -1; border-top: 2.5px solid var(--ink); }
  .decade { padding-left: 0; }
  .decade::before { left: 4px; }
  .decade-label {
    position: static;
    float: none;
    margin-left: 14px;
    width: auto;
    text-align: left;
    padding-top: 10px;
  }
  .fig-row { grid-template-columns: 1fr; gap: 4px; padding-left: 22px; }
  .fig-row::before { left: 0; }
  .year-plate { text-align: left; display: flex; gap: 10px; align-items: baseline; }
  .fig-names { flex-direction: column; gap: 2px; }
  .fig-fa { white-space: normal; }
  .count-readout { margin-left: 0; width: 100%; }
}
