/* Shuls Elections — styles.css
   Palette and type scale first; everything else follows from them. */

:root {
  /* grounds and inks */
  --ground: #f3f4f5;
  --ground-2: #e6e8ea;
  --ink: #0c0c0c;
  --ink-2: #555a60;
  --ink-3: #666b71;
  --rule: #b3b8bd;
  --rule-faint: #d2d5d8;
  --blue: #1a4d9e;
  --red: #a9221c;

  /* type */
  --font: "Alegreya", Georgia, serif;
  --t-masthead: 34px;
  --t-section: 24px;
  --t-box: 18px;
  --t-race: 17px;
  --t-agate: 15px;
  --t-small: 13px;
  --lh: 1.35;

  /* furniture */
  --measure: 1080px;
  --gutter: 16px;
  --sq: 11px;
  --col-votes: 5.8em;
  --col-margin: 4.4em;
  --gap: 6px;

  /* motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 280ms;
}

@media (min-width: 1024px) {
  :root {
    --t-masthead: 48px;
    --t-section: 28px;
    --t-box: 20px;
    --t-race: 18px;
    --t-agate: 16px;
    --t-small: 14px;
    --gutter: 24px;
  }
}

/* ---------- base and browser surfaces ---------- */

html {
  color-scheme: light;
  background: var(--ground);
  scrollbar-color: var(--rule) var(--ground);
  accent-color: var(--ink);
  caret-color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--t-agate);
  line-height: var(--lh);
  color: var(--ink);
  background: var(--ground);
  font-variant-numeric: lining-nums tabular-nums;
  font-kerning: normal;
}

::selection {
  background: var(--ink);
  color: var(--ground);
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  border-radius: 0;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 700;
  text-wrap: balance;
}

p, dl, dd {
  margin: 0;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.ink-d { color: var(--blue); }
.ink-r { color: var(--red); }
.ink-i { color: var(--ink); }

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter) 48px;
}

/* ---------- masthead ---------- */

.masthead {
  border-top: 1px solid var(--ink);
  padding-top: 10px;
  text-align: center;
}

.masthead h1 {
  font-size: var(--t-masthead);
  line-height: 1.05;
  letter-spacing: -0.005em;
  margin: 8px 0 10px;
}

.double-rule {
  height: 2px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.edition {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 8px;
  text-align: left;
}

.edition-text {
  flex: 1 1 auto;
  font-style: italic;
}

/* Each separator is bound to the item it precedes, so a wrap never strands a middle dot. */
.ed-item {
  white-space: nowrap;
}

.extra {
  flex: 0 0 auto;
  font-size: var(--t-small);
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--ink);
  color: var(--ground);
  padding: 2px 6px 1px 7px;
  visibility: hidden;
}

.extra.on {
  visibility: visible;
  animation: extra-in 240ms var(--ease-out) both;
}

@keyframes extra-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: none; }
}

.honesty {
  margin-top: 3px;
  font-size: var(--t-small);
  color: var(--ink-2);
  text-align: left;
}

/* ---------- How They Stand ---------- */

.standing {
  margin-top: 22px;
  border: 1px solid var(--ink);
  padding: 10px 14px 12px;
}

.standing h2 {
  font-size: var(--t-box);
  line-height: 1.2;
  text-align: center;
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.chamber {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name counts"
    "strip strip"
    "flips flips";
  column-gap: 12px;
  padding: 7px 0 8px;
  border-top: 1px solid var(--rule);
}

.chamber:first-child {
  border-top: 0;
}

.chamber-name {
  grid-area: name;
  font-size: var(--t-race);
  font-weight: 500;
  line-height: 1.3;
}

.chamber-counts {
  grid-area: counts;
  text-align: right;
  align-self: baseline;
}

.strip {
  grid-area: strip;
  position: relative;
  height: 7px;
  margin-top: 5px;
  border: 1px solid var(--rule);
  background: var(--ground-2);
}

.strip-d,
.strip-r {
  position: absolute;
  top: 0;
  bottom: 0;
}

.strip-d { left: 0; background: var(--blue); }
.strip-r { right: 0; background: var(--red); }

.strip-tick {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 1px;
  margin-left: -1px;
  background: var(--ink);
}

.chamber-flips {
  grid-area: flips;
  margin-top: 4px;
  font-size: var(--t-small);
  color: var(--ink-2);
}

/* ---------- sections ---------- */

.section {
  margin-top: 30px;
}

.section-head {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "title switch"
    "standing standing";
  align-items: baseline;
  column-gap: 12px;
  border-top: 1px solid var(--ink);
  padding-top: 7px;
  padding-bottom: 6px;
}

.section-head h2 {
  grid-area: title;
  font-size: var(--t-section);
  line-height: 1.1;
}

.section-standing {
  grid-area: standing;
  margin-top: 2px;
  color: var(--ink-2);
}

.view-switch {
  grid-area: switch;
  color: var(--ink-2);
}

.view-switch button {
  color: var(--ink-2);
  padding: 2px 1px;
}

.view-switch button:hover {
  color: var(--ink);
}

.view-switch button[aria-pressed="true"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.view-switch .sep {
  margin: 0 6px;
}

.footnote {
  margin-top: 10px;
  font-size: var(--t-small);
  color: var(--ink-2);
}

.view-table[hidden],
.view-map[hidden],
.races[hidden],
.cols[hidden],
.disclosure[hidden],
.footnote[hidden] {
  display: none;
}

/* Paired columns. One column on the phone (the halves stack in reading order);
   two from 1024px, with a column rule whose extent the script sets from the shorter column. */
.chambers-pair,
.cols {
  position: relative;
}

/* ---------- race rows ---------- */

.race {
  border-top: 1px solid var(--rule);
}

.row {
  display: block;
  width: calc(100% + 12px);
  margin: 0 -6px;
  padding: 8px 6px 9px;
}

button.row:hover {
  background: var(--ground-2);
}

button.row:focus-visible {
  outline-offset: -2px;
}

.row-head {
  display: grid;
  grid-template-columns: 1fr var(--col-margin);
  column-gap: var(--gap);
  align-items: baseline;
}

.race-name {
  font-size: var(--t-race);
  font-weight: 500;
  line-height: 1.25;
  min-width: 0;
}

.margin {
  text-align: right;
  font-weight: 500;
  white-space: nowrap;
}

.cand {
  display: grid;
  grid-template-columns: var(--sq) minmax(0, 1fr) var(--col-votes) var(--col-margin);
  column-gap: var(--gap);
  align-items: baseline;
  margin-top: 2px;
}

.sq {
  position: relative;
  box-sizing: border-box;
  width: var(--sq);
  height: var(--sq);
  border: 1px solid currentColor;
  align-self: start;
  margin-top: calc((var(--t-agate) * var(--lh) - var(--sq)) / 2);
}

.sq::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  transform: scale(0);
}

.sq.filled::after {
  transform: scale(1);
}

.sq.just::after {
  animation: sq-fill 560ms var(--ease-out) both;
}

@keyframes sq-fill {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

.sq-d { color: var(--blue); }
.sq-r { color: var(--red); }
.sq-i { color: var(--ink); }

.cand-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.party {
  font-weight: 500;
}

.votes,
.pct {
  text-align: right;
  white-space: nowrap;
}

.pre-close {
  grid-column: 3 / 5;
  text-align: right;
  font-style: italic;
  color: var(--ink-2);
  white-space: nowrap;
}

/* ---------- race card (unfolds beneath its row) ---------- */

.card {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur) var(--ease-out);
}

.card-inner {
  min-height: 0;
  overflow: hidden;
  visibility: hidden;
  transition: visibility 0s linear var(--dur);
}

.card.open {
  grid-template-rows: 1fr;
}

.card.open .card-inner {
  visibility: visible;
  transition-delay: 0s;
}

.card-body {
  margin: 0 0 12px calc(var(--sq) + var(--gap));
  padding-top: 6px;
  border-top: 1px solid var(--rule-faint);
}

.card-call {
  font-weight: 500;
  padding-bottom: 3px;
}

.card .item {
  display: grid;
  grid-template-columns: 9.6em minmax(0, 1fr);
  column-gap: 10px;
  padding: 2px 0;
}

.card dt {
  color: var(--ink-2);
}

/* ---------- disclosure line ---------- */

/* The jump line: ruled above and below, italic like a newspaper jump, the row's own tap treatment. */
.disclosure {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.disclosure button {
  display: block;
  width: calc(100% + 12px);
  margin: 0 -6px;
  padding: 8px 6px;
  font-style: italic;
  font-weight: 400;
}

.races.rest .race:first-child {
  border-top: 0;
}

.cols > .races.rest + .races.rest .race:first-child {
  border-top: 1px solid var(--rule);   /* stacked halves on the phone keep their hairline */
}

.disclosure button:hover {
  background: var(--ground-2);
}

.disclosure button:focus-visible {
  outline-offset: -2px;
}

/* ---------- tile map ---------- */

.view-map {
  margin-top: 10px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  grid-template-rows: repeat(8, auto);
  gap: 3px;
}

.cell {
  position: relative;
  aspect-ratio: 1;
}

.tile {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--t-small);
  font-weight: 500;
  line-height: 1;
  border: 1px solid var(--ink);
  color: var(--ink);
  background: var(--ground);
  text-align: center;
}

.tile.called-d { background: var(--blue); border-color: var(--blue); color: var(--ground); }
.tile.called-r { background: var(--red);  border-color: var(--red);  color: var(--ground); }
.tile.called-i { background: var(--ink);  border-color: var(--ink);  color: var(--ground); }

.tile.none {
  border-color: var(--rule-faint);
  color: var(--ink-3);
  cursor: default;
}

.tile.sel {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  z-index: 1;
}

.tile:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  z-index: 2;
}

/* Two races in one state: the tile splits on the diagonal (regular upper-left, special lower-right),
   with a hairline of ground left between the halves. */
.tile.half-a,
.tile.half-b {
  font-size: calc(var(--t-small) - 3px);
  letter-spacing: 0.02em;
}

.tile.half-a {
  clip-path: polygon(0 0, 95% 0, 0 95%);
  align-items: flex-start;
  justify-content: flex-start;
  padding: 2px 0 0 2px;
}

.tile.half-b {
  clip-path: polygon(100% 5%, 100% 100%, 5% 100%);
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 2px 2px 0;
}

.map-card {
  margin-top: 10px;
  border-top: 1px solid var(--rule);
  min-height: 2.5em;
}

.map-hint {
  padding: 8px 0;
  color: var(--ink-2);
  font-style: italic;
}

.map-card .row {
  margin: 0;
  width: 100%;
  padding-left: 0;
  padding-right: 0;
}

.map-card .card {
  grid-template-rows: 1fr;
}

.map-card .card-inner {
  visibility: visible;
}

/* ---------- ballot measures ---------- */

.measures {
  margin-top: 2px;
}

.measure-group {
  break-inside: avoid;
  padding-bottom: 6px;
}

.measure-state {
  font-size: var(--t-race);
  font-weight: 500;
  line-height: 1.3;
  border-top: 1px solid var(--rule);
  padding-top: 6px;
  margin-top: 6px;
}

.measure {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--col-margin);
  column-gap: var(--gap);
  padding: 3px 0 2px;
}

.measure-result {
  text-align: right;
  font-weight: 500;
}

.measure-means {
  grid-column: 1 / -1;
  font-size: var(--t-small);
  color: var(--ink-2);
}

/* ---------- poll-close schedule ---------- */

.closes {
  margin-top: 2px;
}

.closes .slot {
  display: grid;
  grid-template-columns: 5.4em minmax(0, 1fr);
  column-gap: 10px;
  padding: 5px 0;
  border-top: 1px solid var(--rule);
}

.closes dt {
  font-weight: 500;
}

/* ---------- foot ---------- */

.foot {
  margin-top: 36px;
  border-top: 1px solid var(--ink);
  padding-top: 8px;
  font-size: var(--t-small);
  color: var(--ink-2);
}

.foot p + p {
  margin-top: 2px;
}

/* ---------- desktop: the same column, wider ---------- */

@media (min-width: 1024px) {
  /* How They Stand: name, figures, flips as one agate line; the strip beneath. */
  .chamber {
    grid-template-columns: 8em max-content max-content 1fr;
    grid-template-areas:
      "name counts flips ."
      "strip strip strip strip";
    column-gap: 24px;
    align-items: baseline;
  }

  .chamber-counts {
    text-align: left;
  }

  .chamber-flips {
    margin-top: 0;
    font-size: var(--t-agate);
  }

  .chambers-pair,
  .cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 56px;
    align-items: start;
  }

  /* The column rule: starts at the first column's top, ends where the shorter column ends
     (--rule-top and --rule-h are measured by the script; without them no rule is drawn). */
  .chambers-pair::before,
  .cols::before {
    content: "";
    position: absolute;
    left: 50%;
    top: var(--rule-top, 0);
    height: var(--rule-h, 0);
    width: 1px;
    background: var(--rule);
  }

  .cols > .races.rest + .races.rest .race:first-child {
    border-top: 0;
  }
}

/* ---------- motion preference ---------- */

@media (prefers-reduced-motion: reduce) {
  .card,
  .card-inner {
    transition: none;
  }

  .sq.just::after,
  .extra.on {
    animation: none;
  }
}
