:root {
  color-scheme: light;
  --ink: #163c3a;
  --muted: #657371;
  --accent: #176d61;
  --line: #d6ded8;
  --paper: #fffdf5;
  --bg: #f3f5ef;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-width: 320px;
}
button,
input,
select {
  font: inherit;
}
button,
a,
input,
select,
summary {
  touch-action: manipulation;
}
button {
  cursor: pointer;
}
a {
  color: inherit;
}
button:disabled {
  cursor: default;
  opacity: 0.55;
}
[hidden] {
  display: none !important;
}
:focus-visible {
  outline: 3px solid #b97221;
  outline-offset: 4px;
}
h1,
h2,
h3,
p {
  margin-top: 0;
}
p {
  line-height: 1.65;
}
h1 {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.7rem, 5.7vw, 5.5rem);
  line-height: 1.03;
  letter-spacing: -0.045em;
  margin-bottom: 20px;
}
h1 em {
  font-weight: 400;
  color: var(--accent);
}
h2 {
  font-size: 1.2rem;
  letter-spacing: -0.025em;
}
small,
.small-label {
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted);
}
.small-label {
  letter-spacing: 0.09em;
}
.site-header {
  max-width: 1440px;
  margin: auto;
  padding: 24px 48px;
  display: flex;
  gap: 32px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font-size: 1.6rem;
  font-weight: 850;
  letter-spacing: -0.08em;
  text-decoration: none;
  display: flex;
  align-items: center;
}
.wordmark > span:first-child {
  font-weight: 400;
}
.wordmark-mark {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-left: 8px;
  border: 1px solid var(--accent);
  font-size: 1rem;
  border-radius: 3px;
}
.election-nav {
  display: flex;
  gap: 6px;
}
.election-nav a {
  padding: 10px 14px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 650;
}
.election-nav a[aria-current] {
  color: var(--accent);
  background: #e2eae0;
}
.election-nav a:hover {
  background: #e6ece6;
}
.account-controls {
  margin-left: auto;
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.85rem;
}
.account-controls span {
  max-width: 180px;
  overflow-wrap: anywhere;
}
.page {
  max-width: 1300px;
  margin: auto;
  padding: 54px 48px 72px;
}
.eyebrow {
  font-size: 0.69rem;
  letter-spacing: 0.15em;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.6;
}
.eyebrow span {
  margin: 0 10px;
  color: #a7b1a9;
}
.intro {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 70px;
  align-items: center;
  margin: 26px 0 40px;
}
.intro > div {
  max-width: 420px;
  color: var(--muted);
}
.intro > div > p:first-child {
  font-size: 1.2rem;
  color: var(--ink);
  margin-bottom: 8px;
}
.map-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fcfdf9;
  padding: 26px 30px 18px;
  box-shadow: 0 4px 24px #163c3a04;
}
.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}
.section-heading h2 {
  margin: 0;
}
.map-card svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 620px;
  margin: 14px auto;
}
.state-path {
  fill: #b4cfc0;
  stroke: #fcfdf9;
  stroke-width: 1.3;
  transition: fill 0.15s;
}
.state-link:hover .state-path,
.state-link:focus .state-path {
  fill: #176d61;
  stroke: #163c3a;
  stroke-width: 2;
}
.state-link:focus {
  outline: none;
}
.state-unavailable .state-path {
  fill: #d8dcd8;
}
.state-pending .state-path {
  fill: #ede6d4;
}
.state-label {
  font-size: 10px;
  fill: #234d44;
  pointer-events: none;
  font-weight: 650;
}
.map-caption {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 8px 0 0;
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b4cfc0;
  margin-left: 12px;
}
.legend-dot.unavailable {
  background: #d8dcd8;
}
.legend-dot.pending {
  background: #ede6d4;
}
.state-directory {
  margin-top: 28px;
}
summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.6;
}
.state-list {
  padding: 20px 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px 20px;
  margin: 0;
}
.state-list a,
.state-list li > span {
  font-size: 0.84rem;
  display: block;
  padding: 9px 0;
  text-decoration: none;
}
.state-list a:hover {
  text-decoration: underline;
  color: var(--accent);
}
.state-list small {
  display: block;
}
.state-list li > span {
  color: #7b837e;
}
.button {
  padding: 11px 17px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 650;
}
.button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.button.primary:hover:not(:disabled) {
  background: #11574d;
}
.button.subtle {
  background: transparent;
  color: var(--ink);
}
.button.subtle:hover {
  background: #e5ece4;
}
.back-link {
  display: inline-block;
  font-size: 0.82rem;
  margin: 14px 0 24px;
  text-decoration: none;
}
.back-link:hover {
  text-decoration: underline;
}
.state-intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.state-share {
  flex-shrink: 0;
  max-width: 100%;
}
#share-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 54px;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 750;
  box-shadow: 0 4px 12px #176d6126;
}
.state-intro #share-status {
  max-width: 260px;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}
#share-status:not(:empty) {
  margin-top: 8px;
}
.state-intro h1 {
  font-size: clamp(2.7rem, 5vw, 4rem);
  margin-bottom: 14px;
}
.state-intro p {
  color: var(--muted);
  margin: 0;
}
.ballot-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 28px;
  align-items: start;
}
.selector-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.selector-heading .small-label {
  font-size: 0.59rem;
}
.selector-heading h2 {
  margin: 16px 0;
}
.ballot-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.ballot-buttons button {
  border: 1px solid #bccbc1;
  background: transparent;
  border-radius: 7px;
  padding: 12px 20px;
  font-size: 0.85rem;
  color: var(--ink);
  min-height: 46px;
}
.ballot-buttons button[aria-pressed="true"] {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.district-field {
  display: grid;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 20px;
  max-width: 450px;
}
select,
input {
  padding: 12px;
  border: 1px solid #cbd5cd;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
select {
  width: 100%;
}
.ballot-paper {
  background: var(--paper);
  border: 1px solid #d4d3c7;
  border-radius: 3px;
  box-shadow: 0 6px 18px #1e3b3110;
}
.paper-heading {
  padding: 26px 28px 20px;
  border-bottom: 3px double #bbbfae;
}
.paper-heading h2 {
  font-family: Georgia, serif;
  font-size: 1.8rem;
  margin-bottom: 8px;
}
.paper-heading p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.include-ballot {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 22px 24px 8px;
  font-size: 0.88rem;
  font-weight: 600;
}
.include-ballot input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
.ballot-instructions {
  font-size: 0.76rem;
  color: var(--muted);
  padding: 0 24px;
}
.ballot-paper fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
/* Match the presidential ballot's explicit headers and generous voting cells. */
.midterm-ballot-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  border-block: 2px solid #a7b8ad;
}
.midterm-ballot-table th,
.midterm-ballot-table td {
  border: 1px solid #c9d1c6;
  padding: 16px 10px;
  vertical-align: middle;
}
.midterm-ballot-table th:first-child {
  width: 40%;
}
.midterm-ballot-table thead th {
  background: #e9eadc;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
}
.midterm-ballot-table thead th:first-child {
  text-align: left;
  padding-left: 24px;
}
.midterm-ballot-table .candidate-name {
  padding-left: 24px;
  text-align: left;
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
  background: #ffffff66;
}
.candidate-party {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}
.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 76px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.choice input {
  appearance: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid #7b9287;
  background: #fffdf5;
  border-radius: 50%;
  margin: 0;
  padding: 0;
}
.choice input:checked {
  border-color: var(--accent);
  background: #dfebde;
}
.choice input:checked::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
}
.choice input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}
.midterm-ballot-table td:has(input:checked) {
  background: #e8f0e4;
}
.midterm-ballot-table td:hover {
  background: #eef3e9;
}
fieldset:disabled {
  opacity: 0.6;
}
.write-in-form {
  padding: 20px 24px;
  border-top: 1px solid #e1dfd3;
}
.write-in-form > label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 8px;
}
.write-in-form > div {
  display: flex;
  gap: 8px;
}
.write-in-form input {
  width: 100%;
}
.write-in-form small {
  display: block;
  margin-top: 8px;
}
.source-note {
  margin-top: 28px;
  padding: 18px 0;
  border-top: 1px solid #e1dfd3;
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.6;
}
.source-note a {
  font-weight: 600;
}
.notice {
  background: #e7eee3;
  border: 1px solid #c9d5c4;
  border-radius: 8px;
  padding: 15px 20px;
  font-size: 0.85rem;
  margin-bottom: 24px;
  line-height: 1.6;
}
.ballot-paper .notice {
  margin: 20px;
}
.cast-panel {
  margin-top: 24px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafcf8;
}
.cast-panel p,
.cast-panel li {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.6;
}
.cast-panel ul {
  padding-left: 20px;
}
.cast-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.cast-panel [role="status"] {
  margin: 14px 0 0;
  color: var(--ink);
}
[data-error="true"] {
  color: #a62e26 !important;
}
.results-card {
  margin-top: 16px;
  background: #e9eee4;
  border-radius: 10px;
  padding: 24px;
  position: sticky;
  top: 20px;
}
.results-card h2 {
  font-family: Georgia, serif;
  font-size: 1.6rem;
}
.results-card p {
  font-size: 0.78rem;
  color: var(--muted);
}
.results-card ol {
  list-style: none;
  padding: 0;
  margin: 25px 0;
}
.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border-top: 1px solid #ced8c9;
  padding: 14px 0;
  font-size: 0.85rem;
}
.result-row strong {
  font-size: 1.1rem;
}
.result-row small {
  grid-column: 1/-1;
  font-size: 0.65rem;
}
.results-note {
  border-top: 1px solid #ced8c9;
  padding-top: 18px;
}
.results-card details {
  margin-top: 25px;
}
.page-status {
  margin: 24px 0;
}
.site-footer {
  max-width: 1300px;
  padding: 24px 48px 34px;
  border-top: 1px solid var(--line);
  margin: auto;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 0.72rem;
  color: var(--muted);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (max-width: 1000px) {
  .site-header {
    padding: 20px 28px;
    gap: 20px;
  }
  .page {
    padding: 40px 28px 60px;
  }
  .ballot-layout {
    grid-template-columns: minmax(0, 1fr) 250px;
    gap: 20px;
  }
  .selector-heading {
    display: block;
  }
  .selector-heading .small-label {
    display: block;
    margin-bottom: 12px;
  }
  .intro {
    gap: 36px;
  }
  .state-list {
    grid-template-columns: repeat(4, 1fr);
  }
}
@media (max-width: 700px) {
  .site-header {
    padding: 16px 20px;
    flex-wrap: wrap;
    gap: 14px;
  }
  .wordmark {
    font-size: 1.5rem;
  }
  .account-controls {
    order: 1;
    font-size: 0.7rem;
  }
  .election-nav {
    order: 2;
    width: 100%;
    border-top: 1px solid var(--line);
    padding-top: 10px;
  }
  .election-nav a {
    flex: 1;
    text-align: center;
  }
  .page {
    padding: 28px 20px 48px;
  }
  .intro {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 22px;
    margin-bottom: 28px;
  }
  .intro h1 {
    font-size: 3.7rem;
  }
  .intro > div p {
    font-size: 0.9rem;
  }
  .intro > div {
    max-width: none;
  }
  .map-card {
    padding: 20px 10px 16px;
    margin-left: -6px;
    margin-right: -6px;
  }
  .section-heading {
    padding: 0 10px;
  }
  .section-heading .small-label {
    display: none;
  }
  .map-caption {
    font-size: 0.61rem;
    gap: 5px;
  }
  .legend-dot {
    margin-left: 5px;
  }
  .state-list {
    grid-template-columns: repeat(2, 1fr);
    gap: 2px 24px;
  }
  .state-list a {
    padding: 12px 0;
  }
  .ballot-layout {
    grid-template-columns: 1fr;
  }
  .state-intro {
    display: block;
  }
  .state-intro .button {
    width: 100%;
    margin-top: 16px;
  }
  .ballot-buttons {
    gap: 6px;
  }
  .ballot-buttons button {
    flex: 1;
    padding: 12px 10px;
    font-size: 0.78rem;
  }
  .results-card {
    position: static;
    margin-top: 0;
  }
  .paper-heading {
    padding: 23px 20px;
  }
  .include-ballot {
    padding: 20px 15px 8px;
    font-size: 0.78rem;
  }
  .ballot-instructions {
    padding: 0 15px;
  }
  .cast-panel {
    padding: 20px 16px;
  }
  .cast-actions .button {
    flex-grow: 1;
  }
  .site-footer {
    padding: 24px 20px;
    gap: 14px;
  }
  .site-footer > span:last-child {
    width: 100%;
  }
  .account-controls span {
    max-width: 110px;
  }
  .state-label {
    font-size: 12px;
  }
}
@media print {
  .site-header,
  .site-footer,
  .cast-panel,
  .results-card,
  .back-link,
  .state-intro button,
  .ballot-buttons,
  .write-in-form {
    display: none !important;
  }
  .page {
    padding: 0;
  }
  .ballot-layout {
    display: block;
  }
  .ballot-paper {
    box-shadow: none;
  }
  body {
    background: white;
  }
}

@media (max-width: 1000px) {
  /* Stack each candidate above three equal vote cells; labels remain full-size. */
  .midterm-ballot-table,
  .midterm-ballot-table tbody {
    display: block;
  }
  .midterm-ballot-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .midterm-ballot-table .candidate-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-bottom: 2px solid #a7b8ad;
  }
  .midterm-ballot-table .candidate-row:last-child {
    border-bottom: 0;
  }
  .midterm-ballot-table th.candidate-name {
    grid-column: 1 / -1;
    width: auto;
    padding: 18px 16px;
    background: #e9eadc;
  }
  .midterm-ballot-table td {
    padding: 12px 3px;
  }
  .midterm-ballot-table .choice {
    font-size: clamp(0.86rem, 2.6vw, 1rem);
  }
}
@media print {
  .midterm-ballot-table tr {
    break-inside: avoid;
  }
}

.write-in-error {
  min-height: 1.2em;
  margin: 6px 0;
  color: #9f1239;
  font-size: clamp(0.72rem, 1.2vw, 0.82rem);
  font-weight: 800;
  line-height: 1.25;
}
#add-write-in.is-shaking {
  animation: shake-add-button 360ms ease-in-out;
}
@keyframes shake-add-button {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-7px);
  }
  40% {
    transform: translateX(7px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(5px);
  }
}
@media (prefers-reduced-motion: reduce) {
  #add-write-in.is-shaking {
    animation: none;
  }
}
