:root {
  color-scheme: light;
  --ink: #1d2329;
  --muted: #66707c;
  --line: #d5d1c7;
  --paper: #faf7ef;
  --paper-deep: #efe8d9;
  --surface: #f5f7fa;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-strong: #164e63;
  --shadow: rgba(31, 41, 55, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.1), transparent 38%),
    linear-gradient(315deg, rgba(22, 78, 99, 0.1), transparent 34%),
    var(--surface);
}

.app {
  display: grid;
  min-height: 100vh;
  padding: clamp(20px, 4vw, 48px);
}

.ballot-simulator {
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  gap: clamp(20px, 3vw, 36px);
  align-items: stretch;
}

.ballot-paper,
.results-panel {
  min-height: min(760px, calc(100vh - 96px));
  border-radius: 8px;
}

.ballot-paper {
  display: flex;
  flex-direction: column;
  padding: clamp(26px, 4vw, 48px);
  border: 1px solid var(--line);
  background:
    linear-gradient(rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0.2)),
    repeating-linear-gradient(
      0deg,
      rgba(29, 35, 41, 0.025),
      rgba(29, 35, 41, 0.025) 1px,
      transparent 1px,
      transparent 28px
    ),
    var(--paper);
  box-shadow:
    0 20px 50px var(--shadow),
    inset 0 0 0 6px rgba(255, 255, 255, 0.38);
}

.ballot-header {
  padding-bottom: clamp(18px, 3vw, 28px);
  border-bottom: 3px double #2f3740;
  text-align: center;
}

.ballot-header h1 {
  margin: 0;
  color: #161b22;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 3.9rem);
  line-height: 1.04;
  text-transform: uppercase;
}

.ballot-header p {
  margin: 12px 0 0;
  color: #3f4852;
  font-size: clamp(1rem, 1.7vw, 1.2rem);
  font-weight: 700;
}

.ballot-body {
  flex: 1;
  min-height: 360px;
  padding: clamp(22px, 3vw, 36px) 0 0;
}

.rules-disclosure {
  margin: 0 0 clamp(18px, 3vw, 28px);
}

.rules-copy {
  position: relative;
  overflow: hidden;
  transition: max-height 280ms ease;
}

.rules-copy::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3.2em;
  background: linear-gradient(rgba(250, 247, 239, 0), var(--paper) 78%);
  content: "";
  opacity: 1;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.rules-disclosure.is-expanded .rules-copy::after {
  opacity: 0;
}

.ballot-rules {
  margin: 0;
  color: #3f4852;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.95rem, 1.55vw, 1.08rem);
  line-height: 1.6;
}

.rules-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  padding: 3px 0;
  border: 0;
  color: var(--accent-strong);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
}

.rules-toggle:hover {
  color: #0f3f50;
}

.rules-toggle:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 3px;
}

.chevron {
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 180ms ease;
}

.rules-disclosure.is-expanded .chevron {
  transform: translateY(2px) rotate(225deg);
}

.ballot-table-wrap {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid rgba(47, 55, 64, 0.42);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.ballot-lock-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(107, 114, 128, 0.34);
  backdrop-filter: grayscale(0.25);
}

.ballot-lock-overlay[hidden] {
  display: none;
}

.edit-ballot {
  min-width: 132px;
  min-height: 52px;
  padding: 12px 24px;
  border: 2px solid rgba(22, 78, 99, 0.56);
  border-radius: 8px;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 14px 30px rgba(31, 41, 55, 0.18);
  cursor: pointer;
  font-size: 1.08rem;
  font-weight: 850;
}

.edit-ballot:hover {
  border-color: var(--accent-strong);
  background: #ffffff;
}

.edit-ballot:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.3);
  outline-offset: 3px;
}

.ballot-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  color: #1f2933;
  font-family: Georgia, "Times New Roman", serif;
}

.ballot-table th,
.ballot-table td {
  padding: clamp(10px, 1.8vw, 16px) clamp(6px, 1.4vw, 14px);
  border-right: 1px solid rgba(47, 55, 64, 0.22);
  border-bottom: 1px solid rgba(47, 55, 64, 0.24);
}

.ballot-table th:last-child,
.ballot-table td:last-child {
  border-right: 0;
}

.ballot-table tbody tr:last-child th,
.ballot-table tbody tr:last-child td {
  border-bottom: 0;
}

.ballot-table thead th {
  color: #111827;
  background: rgba(239, 232, 217, 0.76);
  font-size: clamp(0.62rem, 1.3vw, 0.86rem);
  letter-spacing: 0;
  text-align: center;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.ballot-table thead th:first-child,
.ballot-table tbody th {
  text-align: left;
}

.ballot-table tbody th {
  width: 40%;
  background: rgba(255, 255, 255, 0.36);
  font-size: clamp(0.9rem, 1.7vw, 1.22rem);
  line-height: 1.25;
  overflow-wrap: anywhere;
  vertical-align: middle;
}

.ballot-table td {
  width: 20%;
  text-align: center;
  vertical-align: middle;
}

.candidate-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.candidate-name-text {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.edit-candidate {
  display: inline-grid;
  width: clamp(28px, 6vw, 34px);
  height: clamp(28px, 6vw, 34px);
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(47, 55, 64, 0.42);
  border-radius: 4px;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-size: clamp(1rem, 2.8vw, 1.15rem);
  line-height: 1;
}

.edit-candidate:hover {
  border-color: var(--accent-strong);
  background: rgba(15, 118, 110, 0.08);
}

.edit-candidate:focus-visible,
.candidate-edit-input:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.candidate-edit-input {
  width: 100%;
  min-width: 0;
  padding: 8px 7px;
  border: 1px solid rgba(47, 55, 64, 0.42);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  font: inherit;
}

.edit-confirm-cell {
  text-align: center;
}

.confirm-edit {
  display: inline-grid;
  width: clamp(44px, 8vw, 60px);
  height: clamp(44px, 8vw, 60px);
  place-items: center;
  border: 2px solid rgba(22, 78, 99, 0.5);
  border-radius: 8px;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4.4vw, 2.35rem);
  font-weight: 700;
  line-height: 1;
}

.confirm-edit:hover {
  border-color: var(--accent-strong);
  background: rgba(15, 118, 110, 0.08);
}

.confirm-edit:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.choice {
  display: inline-grid;
  width: 100%;
  min-width: 0;
  place-items: center;
  gap: clamp(6px, 1.2vw, 10px);
  color: #3f4852;
  cursor: pointer;
  font-size: clamp(0.58rem, 1.25vw, 0.84rem);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.choice input {
  width: clamp(18px, 4.8vw, 22px);
  height: clamp(18px, 4.8vw, 22px);
  margin: 0;
  accent-color: var(--accent-strong);
}

.write-in-row th,
.write-in-row td {
  background: rgba(250, 247, 239, 0.72);
}

.write-in-field {
  display: grid;
  gap: 8px;
  color: #3f4852;
  font-size: clamp(0.72rem, 1.3vw, 0.86rem);
  font-weight: 700;
}

.write-in-field input {
  width: 100%;
  min-width: 0;
  padding: 10px 9px;
  border: 1px solid rgba(47, 55, 64, 0.38);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  font: inherit;
  font-size: clamp(0.9rem, 1.6vw, 1rem);
}

.write-in-field input:focus-visible,
.add-candidate:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.write-in-error {
  min-height: 1.2em;
  color: #9f1239;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: clamp(0.72rem, 1.2vw, 0.82rem);
  font-weight: 800;
  line-height: 1.25;
}

.add-candidate {
  display: inline-grid;
  width: clamp(44px, 8vw, 60px);
  height: clamp(44px, 8vw, 60px);
  place-items: center;
  border: 2px solid rgba(22, 78, 99, 0.5);
  border-radius: 8px;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 700;
  line-height: 1;
}

.add-candidate:hover {
  border-color: var(--accent-strong);
  background: rgba(15, 118, 110, 0.08);
}

.add-candidate.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);
  }
}

.ballot-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: clamp(22px, 3.5vw, 34px);
}

.cast-ballot {
  width: min(100%, 320px);
  min-height: 56px;
  padding: 14px 26px;
  border: 2px solid #123f4f;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent-strong);
  box-shadow: 0 10px 24px rgba(22, 78, 99, 0.24);
  cursor: pointer;
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  font-weight: 800;
}

.cast-ballot:hover {
  background: #0f3f50;
}

.cast-ballot:disabled {
  cursor: wait;
  opacity: 0.72;
}

.cast-ballot:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.34);
  outline-offset: 3px;
}

.results-panel {
  display: flex;
  flex-direction: column;
  padding: clamp(24px, 3.6vw, 42px);
  border: 1px solid #dde3ea;
  background: var(--panel);
  box-shadow: 0 18px 46px rgba(31, 41, 55, 0.1);
}

.results-panel h2 {
  margin: 0;
  color: #17202a;
  font-size: clamp(1.55rem, 2.4vw, 2.25rem);
  line-height: 1.12;
}

.empty-results {
  display: grid;
  flex: 1;
  min-height: 300px;
  place-items: center;
  margin-top: 24px;
  padding: 28px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: clamp(1rem, 1.5vw, 1.15rem);
  line-height: 1.6;
  text-align: center;
}

.results-message {
  display: grid;
  flex: 1;
  min-height: 300px;
  place-items: center;
  margin-top: 24px;
  padding: 28px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: clamp(1rem, 1.5vw, 1.15rem);
  line-height: 1.6;
  text-align: center;
}

.results-message.is-error {
  border-color: rgba(159, 18, 57, 0.24);
  color: #9f1239;
  background: rgba(255, 241, 242, 0.75);
  font-weight: 750;
}

.results-list {
  flex: 1;
  margin-top: 24px;
  padding: 0;
}

.results-list ol {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.results-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #17202a;
  font-weight: 750;
}

.results-list strong {
  display: inline-grid;
  min-width: 44px;
  min-height: 36px;
  place-items: center;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent-strong);
  font-size: 1.1rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 39, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.network-limit-modal {
  width: min(100%, 520px);
  padding: clamp(24px, 5vw, 34px);
  border: 1px solid rgba(22, 78, 99, 0.2);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.network-limit-modal h2 {
  margin: 0;
  color: #17202a;
  font-size: clamp(1.45rem, 4vw, 2rem);
  line-height: 1.12;
}

.network-limit-modal p {
  margin: 16px 0 0;
  color: #4b5563;
  font-size: 1rem;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.modal-button {
  min-height: 46px;
  padding: 11px 18px;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.modal-button.secondary {
  border-color: #cbd5e1;
  color: #243342;
  background: #ffffff;
}

.modal-button.primary {
  border-color: #123f4f;
  color: #ffffff;
  background: var(--accent-strong);
}

.modal-button:hover {
  filter: brightness(0.96);
}

.modal-button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.34);
  outline-offset: 3px;
}

.panel {
  width: min(100%, 720px);
  padding: clamp(28px, 5vw, 56px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(21, 32, 43, 0.12);
}

.panel-small {
  width: min(100%, 560px);
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.35rem, 4.8vw, 4.5rem);
  line-height: 0.98;
}

.lede {
  max-width: 56ch;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  line-height: 1.6;
}

.home-link {
  display: inline-block;
  margin-top: 26px;
  color: var(--accent-strong);
  font-weight: 700;
}

@media (max-width: 820px) {
  .ballot-simulator {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .ballot-paper,
  .results-panel {
    min-height: auto;
  }

  .ballot-body,
  .empty-results {
    min-height: 260px;
  }
}

@media (max-width: 520px) {
  .ballot-paper {
    padding: 22px 12px;
  }

  .ballot-table th,
  .ballot-table td {
    padding: 10px 4px;
  }

  .ballot-table tbody th {
    width: 36%;
  }
}
