/* Phone first. Every value comes from tokens.css (docs/design-system/tokens.json). */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--body-size);
  line-height: var(--body-line);
  font-weight: var(--body-weight);
}

h1,
h2 {
  font-family: var(--font-display);
  margin: 0 0 var(--space-4);
}

h1 {
  font-size: var(--h1-size);
  line-height: var(--h1-line);
  font-weight: var(--h1-weight);
}

h2 {
  font-size: var(--h2-size);
  line-height: var(--h2-line);
  font-weight: var(--h2-weight);
}

/* Contest titles, candidate and endorser names stay in the body face. */
h3,
h4 {
  font-family: var(--font-sans);
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-line);
  font-weight: var(--label-weight);
  margin: 0;
}

p {
  margin: 0 0 var(--space-4);
}

a {
  color: var(--teal);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

main:focus {
  outline: none;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  background: var(--teal);
  color: var(--on-teal);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  z-index: 10;
}

.skip:focus {
  top: var(--space-2);
}

.lede {
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-line);
}

.muted {
  color: var(--ink-muted);
}

.label {
  font-size: var(--label-size);
  line-height: var(--label-line);
  font-weight: var(--label-weight);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Header and footer */

/* The header stays pinned to the top while the page scrolls.
   Phones: a one-line wordmark over the nav, kept short so it doesn't eat the screen.
   Wider: wordmark and nav in one row. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  padding: var(--space-2) var(--space-4) 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

/* In-page links (#ballot, #register) land below the pinned header. */
html {
  scroll-padding-top: 96px;
}

@media (min-width: 768px) {
  .site-header {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    padding: var(--space-2) var(--space-10);
  }

  html {
    scroll-padding-top: 88px;
  }
}

.wordmark {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.3em;
  font-family: var(--font-display);
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-line);
  font-weight: var(--display-weight);
  color: var(--ink);
  text-decoration: none;
}

/* Wider screens: the city sits above the name, as in the design. */
@media (min-width: 768px) {
  .wordmark {
    flex-direction: column;
    font-size: var(--h2-size);
    line-height: var(--h2-line);
  }
}

.site-header ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.site-header nav a {
  display: inline-block;
  padding: var(--space-2) 0;
}

.site-footer {
  margin-top: var(--space-10);
  padding: var(--space-6) var(--space-4) var(--space-10);
  border-top: 1px solid var(--line);
}

.footer-line {
  font-weight: var(--label-weight);
}

.site-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
}

.site-footer li a {
  display: inline-block;
  padding: var(--space-2) 0;
}

/* Page sections */

.page {
  padding: 0 var(--space-4);
  max-width: 72ch;
}

.section {
  padding: 0 var(--space-4);
  margin-top: var(--space-10);
}

@media (min-width: 768px) {
  .site-header,
  .page,
  .section,
  .site-footer {
    padding-left: var(--space-10);
    padding-right: var(--space-10);
  }

  .page {
    max-width: calc(72ch + 2 * var(--space-10));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Positions. Yes / No / no-position colors only ever sit on paper-raised,
   and always come with the word and a shape (rule 7). */

.pos {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-1);
  font-weight: var(--label-weight);
}

.pos-yes {
  color: var(--yes);
}

.pos-no {
  color: var(--no);
}

.pos-none {
  color: var(--neutral-pos);
}

.pos-candidates {
  color: var(--ink);
  font-weight: var(--body-weight);
}

.checked,
.via {
  color: var(--ink-muted);
}

.report {
  display: inline-block;
  font-size: var(--data-size);
  line-height: var(--data-line);
  font-weight: var(--body-weight);
  margin-top: var(--space-1);
}

/* Lean tag and funding note. Neutral ink only: never color-coded by lean. */

.lean-tag {
  display: inline-block;
  padding: 0 var(--space-2);
  border: 1px solid var(--ink-muted);
  border-radius: var(--radius-pill);
  color: var(--ink-muted);
  font-size: var(--label-size);
  line-height: var(--label-line);
  font-weight: var(--label-weight);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.fund {
  display: inline-block;
}

.fund summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--ink-muted);
  border-radius: var(--radius-pill);
  color: var(--ink);
  font-size: var(--label-size);
  font-weight: var(--label-weight);
  list-style: none;
  cursor: pointer;
}

.fund summary::-webkit-details-marker {
  display: none;
}

.fund[open] summary {
  background: var(--sand);
  border-color: var(--ink);
}

.fund-pop {
  margin-top: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-size: var(--data-size);
  line-height: var(--data-line);
}

.fund-pop p {
  margin: 0 0 var(--space-1);
}

.fund[open] {
  flex-basis: 100%;
}

/* Charts: one square per group. Counts only. */

.chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--data-size);
  line-height: var(--data-line);
}

.chart p {
  margin: 0;
}

.chart-units,
.units {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.unit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1;
  font-weight: var(--label-weight);
}

.unit-yes {
  background: var(--yes);
  color: var(--paper-raised);
}

.unit-no {
  background: var(--no);
  color: var(--paper-raised);
}

.unit-none {
  border: 1px solid var(--neutral-pos);
  color: var(--neutral-pos);
}

.unit-cand {
  background: var(--ink);
  color: var(--paper-raised);
}

.chart-counts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  font-weight: var(--label-weight);
  font-variant-numeric: tabular-nums;
}

.chart-name {
  font-weight: var(--label-weight);
}

.chart-name .muted {
  font-weight: var(--body-weight);
}

.chart-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.chart-filtered {
  color: var(--ink-muted);
}

[hidden] {
  display: none !important;
}

/* Smaller squares in the grid's row headers. */
.grid .unit {
  width: 14px;
  height: 14px;
  font-size: 10px;
}

/* Grid view */

.grid-note {
  margin: 0 0 var(--space-2);
  font-size: var(--data-size);
  line-height: var(--data-line);
  color: var(--ink-muted);
}

.grid-scroll {
  overflow: auto;
  max-height: calc(100vh - 120px); /* room for the pinned header */
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.grid {
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--data-size);
  line-height: var(--data-line);
  font-variant-numeric: tabular-nums;
}

.grid th,
.grid td {
  padding: var(--space-2);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--paper-raised);
}

.grid td {
  min-width: 10rem;
}

/* No position, or nothing listed: the quieter paper ground, plus words and a dash. */
.grid td.cell-quiet {
  background: var(--paper);
}

.cell-link {
  display: block;
  text-decoration: none;
}

.cell-link .pos {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.grid td .via,
.grid td .checked {
  display: block;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  min-width: 10rem;
  border-bottom: 2px solid var(--ink-muted);
}

.grid-endorser {
  display: block;
  font-weight: var(--label-weight);
}

.grid thead .lean-tag {
  margin-top: var(--space-1);
}

.grid-funding {
  display: block;
  margin-top: var(--space-1);
  font-weight: var(--body-weight);
}

.grid .grid-corner,
.grid .grid-contest {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 14rem;
  max-width: 16rem;
  border-right: 2px solid var(--ink-muted);
}

.grid .grid-corner {
  z-index: 3;
}

.grid .grid-contest {
  font-weight: var(--body-weight);
}

.contest-title {
  display: block;
  font-weight: var(--label-weight);
}

.grid-level th {
  background: var(--paper);
  padding-top: var(--space-4);
}

.grid-level th span {
  position: sticky;
  left: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--h2-size);
  line-height: var(--h2-line);
  font-weight: var(--h2-weight);
}

/* Endorser filter */

.is-off {
  display: none !important;
}

.filter {
  margin-bottom: var(--space-4);
}

.filter-panel {
  background: var(--paper-raised);
  border: 1px solid var(--ink-muted);
  border-radius: var(--radius-md);
}

.filter-panel summary {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
}

.filter-title {
  font-weight: var(--label-weight);
}

.filter-title::before {
  content: '▸ ';
}

.filter-panel[open] .filter-title::before {
  content: '▾ ';
}

.filter-panel summary::-webkit-details-marker {
  display: none;
}

.filter-panel summary {
  list-style: none;
}

.filter-status {
  font-size: var(--data-size);
  line-height: var(--data-line);
  color: var(--ink-muted);
}

.filter-body {
  padding: 0 var(--space-4) var(--space-4);
}

.filter-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
}

.filter-hint,
.filter-note {
  margin: 0;
}

.filter-note {
  margin-top: var(--space-2);
  font-size: var(--data-size);
  line-height: var(--data-line);
  color: var(--ink-muted);
}

.filter-group-label {
  margin: var(--space-4) 0 var(--space-2);
  color: var(--ink-muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--ink-muted);
  border-radius: var(--radius-pill);
  background: var(--paper-raised);
  color: var(--ink);
  font: inherit;
  font-size: var(--data-size);
  line-height: var(--data-line);
  cursor: pointer;
}

.chip-mark {
  display: none;
}

.chip[aria-pressed='true'] {
  background: var(--sand);
  border-color: var(--ink);
  font-weight: var(--label-weight);
}

.chip[aria-pressed='true'] .chip-mark {
  display: inline;
}

.button-quiet {
  min-height: 44px;
  padding: var(--space-2) 0;
  border: 0;
  background: transparent;
  color: var(--teal);
  font: inherit;
  font-weight: var(--label-weight);
  text-decoration: underline;
  cursor: pointer;
}

/* Views. Phones always get tiles; the toggle appears from 768px. */

.ballot-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-6);
}

.ballot-bar .checked {
  margin: 0;
  font-size: var(--data-size);
  line-height: var(--data-line);
}

.views {
  display: none;
  gap: var(--space-2);
}

.view-button {
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--ink-muted);
  border-radius: var(--radius-pill);
  background: var(--paper-raised);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.view-button[aria-pressed='true'] {
  background: var(--sand);
  border-color: var(--ink);
  font-weight: var(--label-weight);
}

.grid-wrap {
  display: none;
}

@media (min-width: 768px) {
  .views:not([hidden]) {
    display: flex;
  }

  [data-view='grid'] .tiles {
    display: none;
  }

  [data-view='grid'] .grid-wrap {
    display: block;
  }
}

/* Tiles view */

.level {
  margin-bottom: var(--space-10);
}

.level-heading {
  font-family: var(--font-display);
  font-size: var(--h2-size);
  line-height: var(--h2-line);
  font-weight: var(--h2-weight);
  margin-bottom: var(--space-2);
}

.level-intro {
  color: var(--ink-muted);
}

.tile-list {
  display: grid;
  gap: var(--space-6);
}

/* Tiles in a row share one height; the error link sits at the bottom. */
@media (min-width: 768px) {
  .tile-list {
    grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
    align-items: stretch;
  }
}

.tile {
  display: flex;
  flex-direction: column;
  background: var(--paper-raised);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--space-1) var(--space-1) 0 color-mix(in srgb, var(--ink) 15%, transparent);
}

.tile-title {
  margin-bottom: 0;
}

.tile-positions {
  margin-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.tile-positions li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
}

.tile-endorser {
  font-weight: var(--label-weight);
}

.tile-positions .pos {
  justify-self: end;
  text-align: right;
}

.tile-positions .pos-candidates {
  grid-column: 1 / -1;
  justify-self: start;
  text-align: left;
}

.row-meta {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin-top: var(--space-1);
  font-size: var(--data-size);
  line-height: var(--data-line);
}

.tile-empty {
  margin: var(--space-4) 0 0;
  color: var(--ink-muted);
}

.tile .report {
  margin-top: auto;
  padding-top: var(--space-4);
}

/* Pier */

.pier {
  display: block;
  width: 100%;
  max-width: 220px;
  height: auto;
}

.pier-teal {
  fill: var(--teal);
}

.pier-coral {
  fill: var(--coral);
}

.pier-sand {
  fill: var(--sand);
}

.pier-paper {
  fill: var(--paper);
}

.pier-ink {
  fill: var(--ink);
}

.pier-shadow {
  flood-color: var(--ink);
  flood-opacity: 0.18;
}

.pier-lines path,
.pier-smile {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
}

.pier-lines path {
  stroke-opacity: 0.35;
}

/* Hero: the cut-paper banner, with the headline in its empty framed area.
   Phones get the tall illustration, wider screens the wide one. */

.hero {
  margin-top: var(--space-6);
}

.hero-banner {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  aspect-ratio: 725 / 1300;
  padding: 12% 10% 0;
  border-radius: var(--radius-md);
  background: var(--sand) url(/images/sf-banner-tall.jpg) center / cover no-repeat;
  color: var(--ink);
}

.hero-banner h1,
.hero-banner p {
  margin: 0;
}

/* Phones: smaller type so the text fits the frame above the bridge. */
.hero-banner h1 {
  font-size: var(--h2-size);
  line-height: var(--h2-line);
}

.hero-banner .lede {
  font-size: var(--body-size);
  line-height: var(--body-line);
}

@media (min-width: 768px) {
  .hero-banner {
    aspect-ratio: 1600 / 678;
    padding: 0 0 0 7%;
    justify-content: center;
    background-image: url(/images/sf-banner-wide.jpg);
  }

  .hero-banner h1 {
    max-width: 40%;
    font-size: var(--h1-size);
    line-height: var(--h1-line);
  }

  .hero-banner .lede {
    max-width: 36%;
    font-size: var(--body-lg-size);
    line-height: var(--body-lg-line);
  }

}

@media (min-width: 1440px) {
  .hero-banner h1 {
    font-size: var(--display-size);
    line-height: var(--display-line);
    font-weight: var(--display-weight);
  }
}

/* The illustration is light in both themes, so its text stays dark.
   In dark mode --paper is the dark ground color. */
@media (prefers-color-scheme: dark) {
  .hero-banner {
    color: var(--paper);
  }
}

/* Pier's welcome on About and the 404. */

.welcome {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: var(--space-4);
  align-items: center;
  background: var(--paper-raised);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.welcome p {
  margin: 0;
}

@media (min-width: 768px) {
  .welcome {
    grid-template-columns: 180px 1fr;
  }
}

/* Text pages */

.prose h2 {
  margin-top: var(--space-10);
}

.prose .welcome {
  margin-bottom: var(--space-6);
}

.bullets {
  list-style: disc;
  padding-left: var(--space-6);
}

.bullets li {
  margin-bottom: var(--space-2);
}

/* Deadline banner. coral holds only on-coral text at 18px bold or larger. */

.deadline-banner {
  background: var(--coral);
  color: var(--on-coral);
  padding: var(--space-2) var(--space-4);
}

.deadline-banner p {
  margin: 0;
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-line);
  font-weight: var(--label-weight);
}

.deadline-banner a {
  color: var(--on-coral);
}

@media (min-width: 768px) {
  .deadline-banner {
    padding-left: var(--space-10);
    padding-right: var(--space-10);
  }
}

/* Register */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-6);
}

.button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--teal);
  color: var(--on-teal);
  font-weight: var(--label-weight);
  text-decoration: none;
}

.button:hover {
  text-decoration: underline;
}

.button-secondary {
  background: var(--paper-raised);
  color: var(--teal);
  border: 1px solid var(--ink-muted);
}

.deadlines {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.deadlines li {
  display: grid;
  gap: var(--space-1);
  background: var(--paper-raised);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.deadline-label {
  font-weight: var(--label-weight);
}

.deadline-date {
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-line);
}

.unverified {
  color: var(--ink-muted);
  font-style: italic;
}

@media (min-width: 768px) {
  .deadlines {
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  }
}

/* Policy tables and open placeholders */

.table-scroll {
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

.policy-table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--data-size);
  line-height: var(--data-line);
}

.policy-table th,
.policy-table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.policy-table thead th {
  border-bottom: 2px solid var(--ink-muted);
}

/* Bracketed questions for counsel stay visible until resolved. */
.placeholder {
  background: var(--sand);
  color: var(--ink);
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
}
