/* India diaspora short read (Data Byte 003): a world map of grains on Deep
 * Basalt. The map bleeds to the panel's edges; the text above and the
 * readout and controls below keep the panel's padding. The shared figure
 * footer stays on Pearl, as on the other Data Bytes. Group colours must match
 * diasporaTheme in india-diaspora-renderer.js, which the Data Bytes check
 * verifies. */

/* ---------- figure panel ---------- */
/* No single-word last lines in this page's deck, story or figure source. */
.byte-page--diaspora :is(.byte-deck, .byte-story p, .byte-figure-footer__source) {
  text-wrap: pretty;
}
.diaspora {
  --diaspora-pad: 32px;
  --diaspora-gulf: #bb8833;
  --diaspora-west: #5596cf;
  --diaspora-neighbours: #c66991;
  --diaspora-elsewhere: #8f989b;
  padding: 28px var(--diaspora-pad) 0;
  color: var(--pearl);
  background: var(--basalt-deep);
  border-color: var(--basalt-deep);
}
.diaspora > .byte-figure-footer {
  margin: 0 calc(-1 * var(--diaspora-pad));
  color: var(--basalt);
  background: var(--pearl);
}
/* All figure text is sans and follows the shared chart type scale. */
.diaspora__header {
  margin-bottom: 16px;
}
.diaspora__header h2 {
  max-width: 48rem;
  font-size: var(--chart-title-size);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.012em;
  text-wrap: balance;
}
.diaspora__header p {
  max-width: 46rem;
  margin-top: 8px;
  color: var(--mist);
  font-size: var(--chart-subtitle-size);
  line-height: 1.5;
  text-wrap: pretty;
}
/* The key, as on the other Data Bytes: one row above the marks it explains,
 * with each round swatch in its grains' colour and the words in plain text. */
.diaspora__key {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 0 0 12px;
  padding: 0;
  color: var(--limestone);
  font-size: var(--chart-label-size);
  line-height: 1.4;
  list-style: none;
}
.diaspora__key li {
  position: relative;
  padding-left: 18px;
}
.diaspora__swatch {
  position: absolute;
  top: calc((1.4em - 10px) / 2);
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.diaspora__swatch--gulf {
  background: var(--diaspora-gulf);
}
.diaspora__swatch--west {
  background: var(--diaspora-west);
}
.diaspora__swatch--neighbours {
  background: var(--diaspora-neighbours);
}
.diaspora__swatch--elsewhere {
  background: var(--diaspora-elsewhere);
}

/* ---------- year readout ---------- */
/* The year in view is the map's caption, one line between the map and the
 * controls that move it, at the chart label size. */
.diaspora__readout {
  padding-top: 16px;
  font-size: var(--chart-label-size);
  line-height: 1.5;
}
.diaspora__year {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.diaspora__total {
  margin-left: 8px;
  color: var(--limestone);
  font-weight: 400;
}
/* The page's copy of the total is for screen readers while the visible one
 * counts; it stays out of a copied selection. */
.diaspora__readout .visually-hidden {
  user-select: none;
}

/* ---------- the map ---------- */
/* The canvas keeps the world map's proportions on every screen and bleeds to
 * the panel's edges. */
.diaspora__stage {
  position: relative;
  margin-inline: calc(-1 * var(--diaspora-pad));
}
.diaspora__canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 1200 / 560;
}
.diaspora__layer {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.diaspora__layer--grains {
  touch-action: pan-y;
}
.diaspora__layer--grains[data-pointing="true"] {
  cursor: pointer;
}
/* The house tooltip, on ink: the place at 16px bold, its numbers at the chart
 * label size, details at 13px, then its line from 1990 to 2024. */
.diaspora__tip {
  position: absolute;
  z-index: 2;
  padding: 12px 14px;
  color: var(--pearl);
  background: var(--ink);
  border: 1px solid var(--graphite);
  font-size: 13px;
  line-height: 1.4;
  pointer-events: none;
}
.diaspora__tip strong,
.diaspora__tip b,
.diaspora__tip > span {
  display: block;
}
.diaspora__tip strong {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
}
.diaspora__tip b {
  margin-top: 6px;
  font-size: var(--chart-label-size);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.diaspora__tip > span {
  color: var(--mist);
}
.diaspora__trend {
  margin-top: 10px;
}
.diaspora__trend svg {
  display: block;
  overflow: visible;
}
.diaspora__trend-zero {
  stroke: var(--graphite);
  stroke-width: 1;
}
.diaspora__trend-now {
  stroke: var(--ink);
  stroke-width: 2;
}
.diaspora__trend-years {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  color: var(--mist);
  font-variant-numeric: tabular-nums;
}

/* ---------- play and year controls ---------- */
.diaspora__controls {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 0 20px;
}
/* The house button, on Deep Basalt. */
.diaspora__play {
  flex: none;
  min-width: 96px;
  min-height: 44px;
  padding: 8px 14px;
  color: var(--pearl);
  background: transparent;
  border: 1px solid var(--graphite);
  border-radius: 2px;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 160ms;
}
.diaspora__play:hover {
  border-color: var(--mist);
}
/* One button per snapshot on a hairline; the year shown is underlined. */
.diaspora__years {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  min-width: 0;
}
/* Each button carries its share of the hairline, so a wrapped row keeps it. */
.diaspora__years button {
  height: 44px;
  box-shadow: inset 0 -1px 0 var(--graphite);
  padding: 0;
  color: var(--mist);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.diaspora__years button:hover {
  color: var(--pearl);
}
.diaspora__years button[aria-pressed="true"] {
  color: var(--pearl);
  border-bottom-color: var(--pearl);
  font-weight: 600;
}
.diaspora__play:focus-visible,
.diaspora__years button:focus-visible {
  outline: 2px solid var(--pearl);
  outline-offset: -2px;
}

/* ---------- below the figure ---------- */
/* Destination and group are text; every year column is a right-aligned count. */
.diaspora-data td:first-of-type {
  text-align: left;
}
.diaspora-data thead th:nth-child(n + 3) {
  text-align: right;
}
.diaspora-data tfoot :is(th, td) {
  border-top: 2px solid var(--basalt);
  font-weight: 700;
}
/* On narrow screens the years scroll sideways; the destination stays put. */
.diaspora-data :is(tbody, tfoot) th,
.diaspora-data thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--white);
  /* A rule on its edge shows that the years pass beneath it. */
  box-shadow: inset -1px 0 0 var(--limestone);
}
.diaspora-data th,
.diaspora-data td {
  white-space: nowrap;
}
/* The caption wraps at the visible width and stays put as the years scroll. */
.diaspora-data caption {
  position: sticky;
  left: 0;
  max-width: calc(100vw - 2 * var(--gutter) - 52px);
  text-wrap: pretty;
}
@media (max-width: 760px) {
  .diaspora {
    --diaspora-pad: 16px;
    padding-top: 20px;
  }
}
@media (max-width: 559px) {
  /* Phones give the world map the whole screen width: the panel runs edge to
   * edge, and its text keeps the page's gutter. */
  .diaspora {
    --diaspora-pad: var(--gutter);
    margin-inline: calc(-1 * var(--gutter));
    border-inline: 0;
    /* The map is only about 175px tall here, so the figure's text steps down
     * with it: the key and the year's figures at the house small size, like
     * the map's names. */
    --chart-title-size: 1.1875rem;
    --chart-subtitle-size: 0.875rem;
    --chart-label-size: 0.8125rem;
  }
  .diaspora__key {
    column-gap: 16px;
  }
  .diaspora__controls {
    flex-wrap: wrap;
    gap: 8px;
  }
  /* Phones: a full-width button, then the years on their own full row, at
   * the house small size like the map's names. */
  .diaspora__play,
  .diaspora__years {
    flex-basis: 100%;
  }
  .diaspora__years button {
    font-size: 13px;
  }
}
/* The smallest phones fold the years into two rows of four. */
@media (max-width: 359px) {
  .diaspora__years {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
@media print {
  .diaspora__controls {
    display: none;
  }
}
