:root {
  --ink: #3c3c3c;
  --font: "Geologica", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #fff;
  color: #000;
  font-family: var(--font);
}

p, h1, ul { margin: 0; padding: 0; }

/* All sizes are in design pixels (frame 916 wide) scaled by --u. */
.election {
  position: relative;
  width: min(916px, 100%);
  margin: 0 auto;
  container-type: inline-size;
}

/* ---------- About: info button + popup ---------- */

/* Page title and lead, above the scoreboard. */
.page-head { padding: 20px calc(8 * var(--u)) 8px; }

.page-head__title {
  color: var(--ink);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.01em;
}

.page-head__lead {
  max-width: 640px;
  margin-top: 6px;
  color: #777;
  font-size: 15px;
  line-height: 1.45;
}

.page-head__link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: #c4c4c4;
  text-underline-offset: 3px;
  cursor: pointer;
}

@media (hover: hover) {
  .page-head__link:hover { text-decoration-color: currentColor; }
}

.page-head__link:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }

.about {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 0;
  border-radius: 14px;
  padding: 28px 28px 24px;
  color: #222;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}

.about::backdrop { background: rgba(20, 20, 20, .45); }

.about__title {
  margin: 0 32px 12px 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

.about p, .about ul { margin: 0 0 12px; }
.about ul { padding-left: 20px; }
.about li { margin-bottom: 6px; }
.about__note { color: #777; font-size: 13px; }

.about__subtitle {
  margin: 18px 0 8px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}
.about p.about__note { margin-bottom: 8px; }
.about p.about__note:last-child { margin-bottom: 0; }

.about__close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: none;
  color: #777;
  cursor: pointer;
}

.about__close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

@media (hover: hover) {
  .about__close:hover { color: var(--ink); background: #f2f2f2; }
}

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

.election > * { --u: calc(100cqw / 916); }

/* ---------- Scoreboard ---------- */

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: calc(29 * var(--u)) calc(8 * var(--u)) 0;
}

.candidate {
  display: flex;
  gap: calc(6 * var(--u));
  height: calc(83 * var(--u));
}

.candidate--right {
  justify-content: flex-end;
  text-align: right;
}

.candidate__electors {
  font-size: calc(54 * var(--u));
  font-weight: 800;
  line-height: calc(50 * var(--u));
}

.candidate__name {
  margin-top: calc(-2 * var(--u));
  font-size: calc(20 * var(--u));
  line-height: calc(20 * var(--u));
}

.candidate__votes {
  margin-top: calc(1 * var(--u));
  font-size: calc(12 * var(--u));
  font-weight: 600;
  white-space: pre;
}

.candidate__electors { color: var(--accent); }
.candidate__name { color: var(--name-color); }
.candidate__votes { color: var(--votes-color); }

.avatar {
  position: relative;
  flex: none;
  width: calc(80 * var(--u));
  height: calc(80 * var(--u));
  margin-top: calc(2 * var(--u));
  border-radius: 50%;
  background: var(--bg);
}

/* Photo box (--x, --y, --w, --h) comes from Figma, in design px relative to the circle. */
.avatar__photo {
  position: absolute;
  left: calc(var(--x) * var(--u));
  top: calc(var(--y) * var(--u));
  width: calc(var(--w) * var(--u));
  height: calc(var(--h) * var(--u));
  max-width: none;
  object-fit: cover;
  clip-path: circle(calc(40 * var(--u)) at calc((40 - var(--x)) * var(--u)) calc((40 - var(--y)) * var(--u)));
}

.avatar__photo:not([src]) { visibility: hidden; }

.avatar__badge {
  position: absolute;
  left: calc(60 * var(--u));
  top: calc(60.12 * var(--u));
  width: calc(20 * var(--u));
}

.avatar__badge[hidden] { display: none; }

.avatar__badge img {
  display: block;
  width: 100%;
  height: auto;
}

.avatar__badge-bg {
  position: absolute;
  top: calc(3 * var(--u));
}

.avatar__badge-icon { position: relative; }

.scoreboard__center { text-align: center; }

/* Header rhythm: the year sits on the candidates' number baseline, "113" on their
   name baseline and "для перемоги" on their vote-count baseline. */
.years {
  position: relative;
  display: inline-block;
  margin-top: calc(-5 * var(--u));
}

/* Round outlined buttons with a chevron, either side of the title. */
.years__step {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: max(calc(34 * var(--u)), 28px);
  height: max(calc(34 * var(--u)), 28px);
  border: 1.5px solid #e8e8e8;
  border-radius: 50%;
  padding: 0;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transform: translateY(-50%);
  transition: background-color .15s, border-color .15s, color .15s, transform .1s;
}

.years__step svg {
  width: 60%;
  height: 60%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.years__step[data-step="-1"] { right: calc(100% + 14 * var(--u)); }
.years__step[data-step="1"] { left: calc(100% + 14 * var(--u)); }
@media (hover: hover) {
  .years__step:hover:not(:disabled) { border-color: #ededed; background: #ededed; }
}

/* Pressed: a shade darker and slightly smaller. */
.years__step:active:not(:disabled) {
  border-color: #dcdcdc;
  background: #dcdcdc;
  transform: translateY(-50%) scale(.92);
}
.years__step:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.years__step:disabled { opacity: .3; cursor: default; }

.scoreboard__title {
  color: var(--ink);
  font-size: calc(49 * var(--u));
  font-weight: 800;
  line-height: normal;
  white-space: nowrap;
}

/* Round caption sits above the year so the title (and the arrows) never change width. */
.scoreboard__round {
  position: absolute;
  top: calc(-12 * var(--u));
  left: 50%;
  color: #777;
  font-size: max(calc(13 * var(--u)), 11px);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transform: translateX(-50%);
}

.scoreboard__round:empty { display: none; }

.map__sevastopol[hidden] { display: none; }

.scoreboard__threshold {
  margin-top: calc(-3.5 * var(--u));
  font-size: calc(14 * var(--u));
  font-weight: 600;
  line-height: calc(15.5 * var(--u));
}

/* ---------- Tally bar ---------- */

.tally {
  position: relative;
  grid-column: 1 / -1;
  margin-top: calc(9 * var(--u));
}

.tally__bar {
  display: flex;
  height: calc(12 * var(--u));
  border-radius: calc(6 * var(--u));
  overflow: hidden;
}

.tally__segment {
  flex: var(--votes) 0 0;
  min-width: 0;
  border: 0;
  border-right: 1px solid #fff;
  padding: 0;
  background: var(--c);
  cursor: pointer;
}

.tally__segment:last-child { border-right: 0; }
.tally__segment--none { background: #9f9f9f; cursor: help; }
/* Both grey ends describe the same districts, so they highlight together. */
.tally__bar:has(.tally__segment--none:hover) .tally__segment--none { background: #858585; }
.tally__segment.is-active {
  background: var(--c-active);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .4);
}
.tally__segment:focus-visible { outline: 2px solid #211f1f; outline-offset: -2px; }

/* Threshold: a dark pill inside the bar with a small pointer above it. */
.tally__marker {
  position: absolute;
  left: var(--at, 50%);
  top: 0;
  width: 5px;
  height: 100%;
  border: 1.5px solid #fff;
  border-radius: 999px;
  background: #211f1f;
  transform: translateX(-50%);
  pointer-events: none;
}

.tally__marker::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  border: 3.5px solid transparent;
  border-top: 5px solid #211f1f;
  border-bottom: 0;
  transform: translateX(-50%);
}

/* ---------- Map ---------- */

.map {
  position: relative;
  width: calc(912 * var(--u));
  margin: calc(41 * var(--u)) 0 0 calc(2 * var(--u));
  aspect-ratio: 912 / 617;
}

.map__shape {
  position: absolute;
  inset: 1.65% 1.37% 1.68% 0.88%;
}

.map__shape > img,
.map__shape > svg {
  display: block;
  width: 100%;
  height: 100%;
}

.map__shape [data-region],
.map__sevastopol {
  cursor: pointer;
}

.map__shape [data-region]:focus { outline: none; }

.map__shape .is-active,
.map__sevastopol.is-active path {
  filter: url(#inner-shadow);
}

.map__defs {
  position: absolute;
  width: 0;
  height: 0;
}

.map__overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.map__overlay {
  position: absolute;
  display: block;
  height: auto;
}

.map__sevastopol {
  position: absolute;
  left: 62.66%;
  top: 92%;
  width: 1.595%;
}

.map__sevastopol > * {
  display: block;
  width: 100%;
  height: auto;
}

.map__labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.map__label {
  position: absolute;
  transform: translateX(-50%);
  color: #fff;
  font-size: calc(11 * var(--u));
  line-height: normal;
  text-align: center;
  white-space: pre;
}

.map__label b { display: block; font-weight: 700; }

/* ---------- Legend ---------- */

.legend {
  position: absolute;
  left: calc(28 / 912 * 100%);
  top: calc(390 / 617 * 100%);
  display: grid;
  gap: calc(17 * var(--u));
  font-size: calc(11 * var(--u));
  font-weight: 700;
  list-style: none;
}

.legend__group { list-style: none; }

.legend li {
  display: flex;
  align-items: center;
  gap: calc(4 * var(--u));
  height: calc(17 * var(--u));
}

.legend__swatch {
  display: block;
  width: calc(17 * var(--u));
  height: calc(17 * var(--u));
  background: var(--c);
}

/* ---------- Caption: the year's takeaway above the ruler ---------- */

.caption {
  min-height: calc(2 * 1.45em);
  margin: 0 auto 10px;
  color: #666;
  font-size: 14.5px;
  line-height: 1.45;
  text-align: center;
  text-wrap: balance;
}

/* ---------- Year ruler ---------- */

.timeline {
  width: min(560px, 100%);
  margin: 12px auto 0;
  padding: 0 8px 18px;
}

.ruler {
  position: relative;
  border-radius: 10px;
  outline: none;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ruler:active { cursor: grabbing; }

.ruler__ticks { display: block; }

.ruler__labels {
  position: relative;
  height: 22px;
}

.ruler__label {
  position: absolute;
  top: 12px;
  color: rgba(0, 0, 0, .38);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: color .15s ease-out, opacity .15s ease-out;
}

.ruler__label.is-shown { opacity: 1; }

.ruler__label.is-current {
  color: #000;
  font-weight: 700;
}

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

/* ---------- Tooltip ---------- */

.tooltip {
  position: absolute;
  z-index: 2;
  min-width: 150px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
}

.tooltip[hidden] { display: none; }

.tooltip__name { font-size: 15px; font-weight: 700; }
.tooltip__electors { font-weight: 700; }
.tooltip__winner { display: flex; align-items: center; gap: 6px; }
.tooltip__note { color: #777; font-size: 12px; }

.tooltip__row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: #555;
}

.tooltip__row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.tooltip__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
}

/* ---------- Narrow screens ---------- */

@media (max-width: 640px) {
  body { padding: 0 16px; }
}

@container (max-width: 600px) {
  .scoreboard {
    grid-template-columns: 1fr 1fr;
    row-gap: 12px;
    padding: 16px 0 0;
  }

  .scoreboard__center { grid-column: 1 / -1; grid-row: 1; }
  .years { margin-top: 0; }
  .years__step[data-step="-1"] { right: calc(100% + 8px); }
  .years__step[data-step="1"] { left: calc(100% + 8px); }
  .scoreboard__title { font-size: 36px; }
  .scoreboard__round { top: -9px; }
  .scoreboard__threshold { margin-top: 4px; font-size: 13px; line-height: normal; }

  .candidate { height: auto; gap: 8px; align-items: center; }
  .candidate__electors { font-size: 36px; line-height: 36px; }
  .candidate__name { margin-top: 0; font-size: 16px; line-height: 18px; }
  .candidate__votes { font-size: 11px; white-space: normal; }

  .tally { margin-top: 0; }
  .tally__bar { height: 10px; border-radius: 5px; }

  .map { width: 100%; margin: 28px 0 0; }
  .map__label { font-size: max(calc(11 * var(--u)), 8px); }
  .map__label span { display: none; }
  /* Side by side so a long legend stays inside the map and off the ruler. */
  .legend { font-size: 9px; gap: 8px; grid-auto-flow: column; align-items: start; }
  /* Reserve four lines so the ruler does not jump between years. */
  .caption { min-height: calc(4 * 1.45em); font-size: 13.5px; }
  .legend li { height: 11px; gap: 3px; }
  .legend__swatch { width: 11px; height: 11px; }

  /* Avatar internals keep design proportions at a fixed 52px size. */
  .avatar { --u: calc(52px / 80); margin-top: 0; }
}

