:root {
  --background: #f5f4ef;
  --panel: #ffffff;
  --text: #222222;
  --muted: #6b6b6b;
  --border: #dedbd2;
  --accent: #1f4f7a;
  --accent-strong: #163a5a;
  --accent-soft: #eaf1f8;
  --success: #1f6f5f;
  --soft-success: #eef7f4;
  --danger: #a12c2c;
  --soft-danger: #fff0f0;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.45;
}

a {
  color: var(--accent);
}

[hidden] {
  display: none !important;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2rem);
  background: rgba(245, 244, 239, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
}

.lang-switch a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}

.lang-switch a.active {
  color: var(--accent);
}

/* ---------- Layout ---------- */

.page {
  width: min(1000px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2rem);
}

.hero,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: clamp(1.25rem, 4vw, 2rem);
  margin-bottom: 1rem;
}

.hero h1,
.panel h1,
.panel h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.panel h2 {
  font-size: 1.2rem;
}

.hero p {
  margin: 0.75rem 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.hero .eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.panel {
  padding: clamp(1rem, 3vw, 1.5rem);
  margin-bottom: 1rem;
}

.panel.narrow {
  max-width: 680px;
  margin: 2rem auto;
}

.narrow-inline {
  display: grid;
  justify-items: start;
  gap: 0.25rem;
}

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

.hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.section-header p {
  margin: 0;
}

.page-links {
  text-align: center;
  margin: 1.5rem 0;
}

/* ---------- Buttons ---------- */

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.65rem;
  padding: 0.65rem 1.1rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.secondary-button,
.small-button.secondary-button {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.secondary-button:hover {
  background: #dce7f2;
}

.small-button {
  min-height: 2.25rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
}

.icon-button {
  min-height: 2.45rem;
  width: 2.45rem;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  flex: 0 0 auto;
}

.danger {
  color: var(--danger);
  background: var(--soft-danger);
}

.danger:hover {
  background: #ffe3e3;
}

/* ---------- Forms ---------- */

input,
textarea,
select {
  width: 100%;
  min-height: 2.45rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  background: #ffffff;
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

textarea {
  resize: vertical;
}

.stacked-form {
  display: grid;
  gap: 1.1rem;
  margin-top: 1.25rem;
}

.panel.stacked-form {
  margin-top: 0;
}

.stacked-form label,
.compact-label {
  display: grid;
  gap: 0.35rem;
}

.stacked-form label > span,
.compact-label > span:first-child {
  font-weight: 700;
  font-size: 0.92rem;
}

fieldset.block {
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  min-width: 0;
}

fieldset.block legend {
  padding: 0 0.4rem;
  font-weight: 800;
}

.rows {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.field-card {
  display: grid;
  gap: 0.6rem;
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fffdf9;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto auto;
  gap: 0.6rem;
  align-items: end;
}

.stacked-form .checkbox-line,
.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  font-size: 0.92rem;
  min-height: 2.45rem;
  white-space: nowrap;
}

.checkbox-line input {
  width: 1.1rem;
  height: 1.1rem;
  min-height: auto;
}

.copy-line {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.link-grid {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* ---------- Notices ---------- */

.notice {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8faf9;
  color: var(--accent-strong);
  margin-bottom: 1rem;
}

.notice.success {
  background: var(--soft-success);
  border-color: #c8e3da;
  color: var(--success);
  font-weight: 700;
}

.notice.error {
  background: var(--soft-danger);
  border-color: #f1c5c5;
  color: var(--danger);
}

fieldset .notice.error {
  margin: 0.75rem 0 0;
}

/* ---------- Ballot ---------- */

.voter-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}

.stacked-form label.choice,
.choice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
}

.stacked-form label.choice > span {
  font-weight: 600;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.choice input {
  width: 1.15rem;
  height: 1.15rem;
  min-height: auto;
  flex: 0 0 auto;
  margin: 0;
}

.choice.is-checked {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.counter {
  margin: 0.75rem 0 0;
  font-size: 0.92rem;
}

/* ---------- Results ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  margin: 0 0 1rem;
  padding: 0.5rem 0.25rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  min-width: 0;
}

.toolbar-title {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.filter select {
  width: auto;
  max-width: 14rem;
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.9rem;
}

.filter select.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.reset-link {
  font-size: 0.88rem;
}

.toolbar .small-button {
  min-height: 2rem;
  padding: 0.3rem 0.85rem;
}

.copy-results {
  margin-left: auto;
}

.offscreen {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

.scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.score {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1.2fr) minmax(0, 2fr) auto 3.2rem;
  gap: 0.75rem;
  align-items: center;
}

.score-rank {
  color: var(--muted);
  font-weight: 800;
  text-align: right;
}

.score-label {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.score-bar {
  height: 0.75rem;
  border-radius: 999px;
  background: #efede6;
  overflow: hidden;
}

.score-bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
}

.score-votes {
  white-space: nowrap;
  font-weight: 700;
  text-align: right;
}

.score-percent {
  text-align: right;
  white-space: nowrap;
}

details > summary {
  cursor: pointer;
  list-style: none;
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary::before {
  content: "▸";
  display: inline-block;
  width: 1.2rem;
  color: var(--accent);
}

details[open] > summary::before {
  content: "▾";
}

details > summary h2 {
  display: inline;
}

details[open] > summary {
  margin-bottom: 1rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: break-word;
  max-width: 22rem;
}

.data-table th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .nowrap {
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #fbfaf6;
}

.ballots-table td:last-child {
  min-width: 12rem;
}

.empty-state {
  margin: 0;
  padding: 1rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 14px;
}

/* ---------- Responsive ---------- */

@media (max-width: 700px) {
  .field-grid {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .field-grid label:nth-child(1),
  .field-grid label:nth-child(2) {
    grid-column: 1 / -1;
  }

  .score {
    grid-template-columns: 1.6rem minmax(0, 1fr) auto;
    gap: 0.3rem 0.6rem;
  }

  .score-bar {
    grid-column: 2 / -1;
    grid-row: 2;
  }

  .score-percent {
    display: none;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding-inline: 1rem;
  }

  .page {
    padding: 0.8rem;
  }

  .panel,
  .hero {
    border-radius: 14px;
  }

  .panel.narrow {
    margin: 1rem auto;
  }

  .two-columns {
    grid-template-columns: 1fr;
  }
}
