:root {
  --ink: #1e211f;
  --muted: #626760;
  --paper: #fffefb;
  --canvas: #f2eee4;
  --line: #20231f;
  --valid: #17653b;
  --valid-soft: #e7f3e9;
  --invalid: #a51f2a;
  --invalid-soft: #fae8e8;
  --accent: #ba7729;
  --ignored: #9c9f9a;
  --shadow: 0 18px 45px rgba(45, 39, 25, .13);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 7% 4%, rgba(186, 119, 41, .09), transparent 26rem),
    linear-gradient(180deg, #f7f4ec 0, var(--canvas) 38rem);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.48;
}

button, a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.skip-link {
  position: fixed;
  z-index: 50;
  left: 1rem;
  top: -5rem;
  padding: .75rem 1rem;
  color: white;
  background: var(--ink);
  border-radius: .4rem;
}

.skip-link:focus { top: 1rem; }

.intro {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.75rem 0 1.4rem;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
}

.intro-copy { max-width: 780px; }

.eyebrow {
  margin: 0 0 .45rem;
  color: #7d4b18;
  font-size: .82rem;
  font-weight: 780;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.intro h1 {
  margin: 0;
  max-width: 760px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.15rem, 5vw, 4.3rem);
  font-weight: 640;
  letter-spacing: -.045em;
  line-height: .98;
}

.intro-description {
  max-width: 720px;
  margin: 1rem 0 0;
  color: #484c47;
  font-size: 1.05rem;
}

.municipality-switcher {
  margin-top: 1.15rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .55rem .75rem;
}

.municipality-label {
  color: var(--muted);
  font-size: .88rem;
  font-weight: 720;
}

.municipality-options {
  display: flex;
  flex-wrap: wrap;
  padding: .2rem;
  gap: .18rem;
  border: 1px solid #c8c3b7;
  border-radius: .55rem;
  background: rgba(255, 254, 251, .75);
}

.municipality-button {
  padding: .48rem .78rem;
  white-space: nowrap;
  color: #4d514c;
  border: 0;
  border-radius: .38rem;
  background: transparent;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 760;
}

.municipality-button:hover { background: #eee9df; }
.municipality-button.selected { color: white; background: var(--ink); }
.municipality-button:focus-visible { outline: 3px solid #1d64c8; outline-offset: 2px; }

.legend {
  min-width: 205px;
  display: grid;
  gap: .55rem;
  color: var(--muted);
  font-size: .9rem;
}

.legend span { display: flex; align-items: center; gap: .55rem; }

.legend-swatch {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: .2rem;
  border: 2px solid currentColor;
}

.legend-swatch.counted { color: var(--valid); background: var(--valid-soft); }
.legend-swatch.ignored { color: var(--ignored); background: #efefed; border-style: dashed; }

.result-panel {
  position: sticky;
  z-index: 20;
  top: .75rem;
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto 1.5rem;
  padding: .9rem 1rem;
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: .9rem 1.15rem;
  border: 1px solid #c9c5bb;
  border-radius: .75rem;
  background: rgba(255, 254, 251, .96);
  box-shadow: 0 10px 30px rgba(42, 37, 26, .14);
  backdrop-filter: blur(12px);
}

.result-panel.valid { border-color: #94bea2; }
.result-panel.invalid { border-color: #d69ca1; }

.result-icon {
  width: 2.55rem;
  height: 2.55rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ece9e0;
}

.result-icon::before { content: "?"; font-size: 1.35rem; font-weight: 850; }
.result-panel.valid .result-icon { color: white; background: var(--valid); }
.result-panel.valid .result-icon::before { content: "✓"; }
.result-panel.invalid .result-icon { color: white; background: var(--invalid); }
.result-panel.invalid .result-icon::before { content: "!"; }

.result-kicker {
  margin: 0;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 760;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.result-copy h2 { margin: .08rem 0; font-size: 1.12rem; line-height: 1.2; }
.result-copy > p:last-of-type { margin: 0; color: #575c56; font-size: .9rem; }

.error-list { display: none; margin: .3rem 0 0; padding-left: 1.2rem; color: var(--invalid); font-size: .88rem; }
.error-list.visible { display: block; }

.counters {
  margin: 0;
  display: flex;
  gap: .35rem;
}

.counters div {
  min-width: 76px;
  padding: .38rem .6rem;
  text-align: center;
  border-left: 1px solid #dedbd3;
}

.counters dt { color: var(--muted); font-size: .7rem; font-weight: 680; text-transform: uppercase; }
.counters dd { margin: .05rem 0 0; font-size: 1.13rem; font-weight: 820; line-height: 1; }

.reset-button {
  padding: .62rem .8rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid #9c9b95;
  border-radius: .4rem;
  cursor: pointer;
  font-size: .84rem;
  font-weight: 680;
}

.reset-button:hover { background: #f1eee7; }
.reset-button:focus-visible, .mark-button:focus-visible { outline: 3px solid #1d64c8; outline-offset: 2px; }

.selection-panel {
  width: min(1180px, calc(100% - 2rem));
  margin: -.55rem auto 1.5rem;
  padding: 1.15rem 1.25rem 1.2rem;
  border: 1px solid #c9c5bb;
  border-radius: .75rem;
  background: rgba(255, 254, 251, .9);
}

.selection-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.selection-kicker {
  margin: 0 0 .12rem;
  color: #7d4b18;
  font-size: .72rem;
  font-weight: 780;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.selection-heading h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.35rem; }
.selection-heading p:last-child, #selection-description { margin: .25rem 0 0; color: var(--muted); font-size: .88rem; }

.selection-count {
  min-width: 2.65rem;
  height: 2.65rem;
  display: grid;
  place-items: center;
  color: white;
  border-radius: 50%;
  background: var(--valid);
  font-size: 1.15rem;
}

.selection-empty { margin: 1rem 0 .2rem; color: var(--muted); font-size: .9rem; }

.selection-list {
  margin: 1rem 0 0;
  padding: 0;
}

.selection-party-group + .selection-party-group {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 2px solid #d6d0c3;
}

.selection-party-heading {
  margin-bottom: .5rem;
  display: flex;
  align-items: baseline;
  gap: .55rem .8rem;
}

.selection-party-number {
  flex: 0 0 auto;
  padding: .2rem .42rem;
  color: white;
  border-radius: .3rem;
  background: var(--ink);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.selection-party-heading h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
  line-height: 1.25;
}

.selection-party-list {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .45rem .8rem;
  list-style: none;
}

.selection-item {
  min-width: 0;
  padding: .58rem .65rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .5rem;
  border: 1px solid #ddd9cf;
  border-radius: .4rem;
  background: white;
}

.selection-person { min-width: 0; display: block; }
.selection-person strong { display: block; font-size: .91rem; line-height: 1.25; }
.selection-person > span { display: block; margin-top: .08rem; overflow-wrap: anywhere; color: var(--muted); font-size: .73rem; }

.selection-source {
  padding: .22rem .42rem;
  border-radius: 999px;
  white-space: nowrap;
  font-size: .67rem;
  font-weight: 740;
}

.source-direct { color: #174f8b; background: #e8f1fa; }
.source-party { color: var(--valid); background: var(--valid-soft); }

.selection-actions { margin-top: 1rem; display: flex; justify-content: flex-end; gap: .55rem; }
.selection-button {
  padding: .62rem .9rem;
  color: var(--ink);
  border: 1px solid #8f918c;
  border-radius: .42rem;
  background: white;
  cursor: pointer;
  font-weight: 720;
}
.selection-button-primary { color: white; border-color: var(--valid); background: var(--valid); }
.selection-button:hover:not(:disabled) { filter: brightness(.96); }
.selection-button:disabled { cursor: not-allowed; opacity: .42; }
.selection-button:focus-visible { outline: 3px solid #1d64c8; outline-offset: 2px; }
.print-hint { margin: .5rem 0 0; color: var(--muted); text-align: right; font-size: .74rem; }
.print-only { display: none; }

.ballot {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  display: grid;
  gap: 2rem;
}

.paper {
  position: relative;
  padding: clamp(1.2rem, 3.5vw, 3.1rem);
  overflow: hidden;
  color: #111;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(40, 38, 31, .018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(40, 38, 31, .013) 1px, transparent 1px);
  background-size: 5px 5px;
  border: 1px solid #cac5b8;
  box-shadow: var(--shadow);
}

.ballot-heading { margin-bottom: .15rem; text-align: center; }
.ballot-heading h2 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.25rem); letter-spacing: .015em; }
.ballot-heading > p { margin: .1rem 0 .25rem; font-size: clamp(.82rem, 1.5vw, 1.05rem); }
.ballot-meta { display: flex; flex-direction: column; align-items: flex-start; margin: 0 0 .12rem; font-size: .86rem; line-height: 1.2; }

.party-grid {
  display: grid;
  grid-template-columns: repeat(var(--party-columns, 3), minmax(0, 1fr));
  gap: .72rem;
  align-items: start;
}

.party-column {
  min-width: 0;
  padding: .32rem .36rem .55rem;
  border: 1.4px solid var(--line);
  background: rgba(255, 255, 255, .66);
  transition: opacity .18s ease, box-shadow .18s ease;
}

.party-column.party-marked { box-shadow: inset 0 0 0 3px rgba(23, 101, 59, .2); }

.mark-button {
  width: 100%;
  display: grid;
  align-items: start;
  padding: 0;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.party-button { grid-template-columns: 2.55rem minmax(0, 1fr); gap: .5rem; min-height: 3.75rem; }
.candidate-button { grid-template-columns: 2.5rem 1.15rem minmax(0, 1fr); gap: .3rem; padding: .17rem 0; border-radius: .18rem; }

.mark-box {
  position: relative;
  width: 2.5rem;
  height: 2.05rem;
  flex: none;
  border: 2px solid #10110f;
  background: #fff;
}

.party-button .mark-box { height: 2.7rem; }

.mark-box::before,
.mark-box::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 82%;
  height: 3px;
  background: transparent;
  border-radius: 999px;
  transform-origin: center;
}

.is-crossed .mark-box::before { background: #151515; transform: translate(-50%, -50%) rotate(42deg); }
.is-crossed .mark-box::after { background: #151515; transform: translate(-50%, -50%) rotate(-47deg); }

.party-name { display: block; margin-top: .02rem; font-size: .9rem; font-weight: 840; line-height: 1.13; }
.party-number { display: block; margin-top: .35rem; font-size: .7rem; font-weight: 760; }
.candidate-position { padding-top: .28rem; text-align: right; font-size: .75rem; }
.candidate-copy { min-width: 0; padding-top: .19rem; font-size: .72rem; line-height: 1.23; }
.candidate-name { font-weight: 820; }
.candidate-detail { color: #30322f; }
.candidate-meta { display: block; margin-top: .08rem; color: #4d504b; }

.candidate-button:hover { background: rgba(186, 119, 41, .07); }
.candidate-button.counted { background: var(--valid-soft); box-shadow: inset 3px 0 var(--valid); }
.candidate-button.counted .mark-box { border-color: var(--valid); }
.candidate-button.counted .mark-box::before,
.candidate-button.counted .mark-box::after { background: var(--valid); }

.party-column.party-marked .candidate-copy,
.party-column.party-marked .candidate-position { opacity: .44; }
.party-column.party-marked .candidate-button.counted .candidate-copy,
.party-column.party-marked .candidate-button.counted .candidate-position { opacity: .72; }

.candidate-button.ignored-mark { background: #f1f1ef; box-shadow: inset 3px 0 var(--ignored); }
.candidate-button.ignored-mark .mark-box { border-color: var(--ignored); border-style: dashed; }
.candidate-button.ignored-mark .mark-box::before,
.candidate-button.ignored-mark .mark-box::after { background: var(--ignored); }
.candidate-button.ignored-mark .candidate-copy::after {
  content: "ruční křížek se nepočítá";
  display: block;
  margin-top: .08rem;
  color: #686b66;
  font-size: .62rem;
  font-weight: 720;
}

.candidate-button.counted.direct-also .mark-box { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5px var(--ignored); }

.continue-note { margin: 3rem 0 0; text-align: right; font-size: .92rem; }
.paper-back { min-height: 54rem; }
.back-label { margin: -.35rem 0 .9rem; display: flex; align-items: center; gap: .8rem; color: #6c6e69; font-size: .72rem; font-weight: 760; letter-spacing: .08em; text-transform: uppercase; }
.back-label::after { content: ""; height: 1px; flex: 1; background: #c9c5bb; }

.how-it-works {
  width: min(1180px, calc(100% - 2rem));
  margin: 2.25rem auto 0;
  padding: 1.35rem 1.5rem 1.5rem;
  border-top: 4px solid var(--ink);
  background: #fffdf8;
}

.how-it-works h2 { margin: 0 0 1rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; }
.rules-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; }
.rules-grid p { margin: 0; }
.rules-grid strong, .rules-grid span { display: block; }
.rules-grid strong { margin-bottom: .2rem; font-size: .94rem; }
.rules-grid span { color: var(--muted); font-size: .9rem; }

.add-municipality {
  width: min(1180px, calc(100% - 2rem));
  margin: 1rem auto 0;
  padding: 1.35rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  color: white;
  border-radius: .7rem;
  background: #252a27;
}

.add-municipality-kicker {
  margin: 0 0 .15rem;
  color: #e6b875;
  font-size: .72rem;
  font-weight: 780;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.add-municipality h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; }
.add-municipality div > p:last-child { max-width: 690px; margin: .35rem 0 0; color: #d9ddd9; font-size: .9rem; }
.contact-actions { flex: none; display: flex; gap: .55rem; }
.contact-actions a {
  padding: .66rem .82rem;
  color: white;
  border: 1px solid #858b86;
  border-radius: .42rem;
  text-decoration: none;
  font-size: .84rem;
  font-weight: 720;
}
.contact-actions a:first-child { color: #1d2821; border-color: #bada9b; background: #bada9b; }
.contact-actions a:hover { filter: brightness(1.08); }
.contact-actions a:focus-visible { outline: 3px solid #80baff; outline-offset: 2px; }

footer {
  width: min(900px, calc(100% - 2rem));
  margin: 2rem auto 4rem;
  color: #5a5e58;
  font-size: .84rem;
}

footer p { margin: .55rem 0; }
footer a { color: #174f8b; }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 1.2rem;
  max-width: min(520px, calc(100% - 2rem));
  padding: .72rem 1rem;
  color: white;
  background: #2b2e2b;
  border-radius: .45rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 1rem);
  transition: opacity .16s ease, transform .16s ease;
  font-size: .9rem;
}

.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

@media (max-width: 960px) {
  .result-panel { grid-template-columns: auto minmax(220px, 1fr) auto; }
  .reset-button { grid-column: 2 / -1; justify-self: end; }
  .party-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .intro { padding-top: 1.8rem; display: block; }
  .legend { margin-top: 1rem; grid-template-columns: repeat(2, auto); justify-content: start; }
  .municipality-switcher { align-items: flex-start; flex-direction: column; }
  .municipality-options { width: 100%; }
  .municipality-button { flex: 1 1 auto; padding-inline: .4rem; }
  .result-panel {
    position: relative;
    top: auto;
    grid-template-columns: auto minmax(0, 1fr);
    padding: .8rem;
  }
  .counters { grid-column: 1 / -1; width: 100%; }
  .counters div { flex: 1; }
  .reset-button { grid-column: 1 / -1; justify-self: stretch; }
  .selection-panel { padding: 1rem .8rem; }
  .selection-party-heading { align-items: flex-start; flex-direction: column; gap: .3rem; }
  .selection-party-list { grid-template-columns: 1fr; }
  .selection-item { align-items: start; }
  .selection-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .selection-button { padding-inline: .45rem; }
  .print-hint { text-align: left; }
  .paper { padding: 1rem .7rem 1.35rem; }
  .ballot-heading { padding: 0 .35rem; }
  .party-grid { grid-template-columns: 1fr; }
  .paper-back { min-height: 0; }
  .continue-note { margin-top: 1.5rem; }
  .rules-grid { grid-template-columns: 1fr; }
  .add-municipality { align-items: stretch; flex-direction: column; }
  .contact-actions { display: grid; grid-template-columns: 1fr; }
  .contact-actions a { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@media print {
  body { background: white; }
  .intro, .result-panel, .selection-panel, .how-it-works, .add-municipality, footer, .toast { display: none !important; }
  .ballot { width: 100%; gap: 0; }
  .paper { break-after: page; border: 0; box-shadow: none; }

  body.print-favorites .ballot { display: none !important; }
  body.print-favorites .selection-panel {
    width: 100%;
    margin: 0;
    padding: 0;
    display: block !important;
    border: 0;
    background: white;
  }
  body.print-favorites .selection-count,
  body.print-favorites .selection-actions,
  body.print-favorites .print-hint,
  body.print-favorites .selection-kicker { display: none !important; }
  body.print-favorites .print-only { display: block !important; }
  body.print-favorites .print-meta { margin: .25rem 0 1rem; color: #444; font-size: .85rem; }
  body.print-favorites .selection-party-group + .selection-party-group { margin-top: .65rem; padding-top: .65rem; border-top-color: #888; }
  body.print-favorites .selection-party-heading { margin-bottom: .35rem; break-after: avoid; }
  body.print-favorites .selection-party-number { color: #111; border: 1px solid #777; background: white; }
  body.print-favorites .selection-party-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem; }
  body.print-favorites .selection-item { break-inside: avoid; padding: .45rem .5rem; }
  body.print-favorites .selection-source { color: #222; border: 1px solid #aaa; background: white; }
}
