:root {
  color-scheme: light;
  --ink: #2f2325;
  --muted: #685459;
  --accent: #b91c2b;
  --paper: #ffffff;
  --line: #d6b9bc;
  --wash: #fff0f1;
  --row-wash: #fff6f6;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 21px;
  line-height: 1.5;
  color: var(--ink);
  background: #fff8f8;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
body, button, .button { overflow-wrap: anywhere; }
button, select, textarea { font: inherit; }
button, .button { -webkit-tap-highlight-color: transparent; }
button, a, select, label { touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(2rem, 6vw, 2.8rem); font-weight: 800; line-height: 1.12; letter-spacing: -.045em; margin: .5rem 0 1rem; color: var(--accent); }
.title-context { display: block; font-size: .68em; line-height: 1.3; letter-spacing: -.015em; text-wrap: balance; margin-top: .25rem; }
.title-place { display: block; font-size: .78em; line-height: 1.2; letter-spacing: 0; text-wrap: balance; margin-top: .35rem; }
h2 { font-size: 1.3rem; line-height: 1.25; letter-spacing: -.025em; }
h3 { font-size: 1.15rem; line-height: 1.3; }
p + p { margin-top: .65rem; }
:focus-visible { outline: 4px solid #926713; outline-offset: 4px; }
.page { max-width: 760px; margin: 0 auto; padding: 1rem 1.2rem 0; }
.eyebrow { font-size: .76rem; font-weight: 750; letter-spacing: .025em; color: var(--accent); }
.intro > p:not(.eyebrow) { max-width: 30rem; }
.section-heading { margin-bottom: .65rem; }
.section-heading p { margin-top: .4rem; color: var(--muted); }
#progress { font-weight: 650; font-size: .86rem; }
.candidate-picker { margin-top: .5rem; container: candidate-field / inline-size; }
.candidate-field { display: grid; grid-template-columns: minmax(0, 1fr) 18px; align-items: center; gap: 12px; width: 100%; min-width: 0; min-height: 64px; padding: 12px; color: var(--ink); background: white; border: 2px solid var(--line); border-radius: 8px; font-size: 1rem; font-weight: 650; line-height: 1.3; text-align: left; }
.candidate-field.has-candidate { grid-template-columns: minmax(0, 1fr) 60px 18px; column-gap: 8px; row-gap: 4px; padding: 6px 8px; }
.candidate-toggle[aria-expanded="true"] { border-color: var(--accent); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.toggle-content { min-width: 0; overflow-wrap: anywhere; }
.toggle-name, .toggle-party { display: inline; }
.toggle-party { margin-left: .25rem; font-size: .76rem; font-weight: 400; color: var(--muted); white-space: nowrap; }
.candidate-field .portrait { width: 60px; height: 72px; }
.toggle-arrow { justify-self: end; font-size: 18px; line-height: 1; }
.toggle-numbers { grid-column: 1 / -1; }
.portrait { position: relative; display: block; width: 64px; height: 78px; flex: none; overflow: hidden; background: #f4eeee; border: 1px solid var(--line); border-radius: 6px; }
.portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.photo-fallback { display: grid; place-items: center; width: 100%; height: 100%; font-size: 14px; color: var(--muted); font-weight: 400; }
.inline-options { border: 2px solid var(--accent); border-top: 0; border-radius: 0 0 8px 8px; padding: 0; margin: 0; min-width: 0; max-height: min(560px, 70vh); overflow-y: auto; scroll-padding: 12px; }
.inline-candidate { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 64px; align-items: center; gap: 12px; min-height: 100px; padding: 12px; border-bottom: 1px solid var(--line); background: white; cursor: pointer; }
.inline-candidate:last-child { border-bottom: 0; }
.inline-details { min-width: 0; overflow-wrap: anywhere; container-type: inline-size; }
.inline-name { display: inline; font-size: .9rem; font-weight: 500; line-height: 1.3; }
.inline-party { display: inline; color: var(--muted); font-size: .76rem; margin-left: .25rem; white-space: nowrap; }
.inline-number { display: block; font-size: 1.5rem; font-size: min(1.5rem, 30cqi); font-weight: 800; line-height: 1.2; margin-top: .25rem; color: #000000; white-space: nowrap; }
.inline-used { display: block; color: var(--muted); font-weight: 650; font-size: .76rem; margin-top: .25rem; }
.inline-candidate:has(input:focus-visible) { outline: 4px solid #926713; outline-offset: -4px; }
.inline-candidate:has(input:disabled) { background: #f4eeee; cursor: default; }
.inline-candidate.is-selected { background: var(--wash); box-shadow: inset 4px 0 var(--accent); }
.inline-candidate.is-selected .inline-name::after { content: " ✓"; }
.selected-summary { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 12px; margin: .5rem 0; }
.selected-details { min-width: 0; }
.selected-summary .row-name { margin: 0; }
.candidate-picker .selected-summary { display: none; }
.selection-note { display: block; margin-top: .2rem; font-size: .76rem; color: var(--muted); }
.number-area { display: block; margin-top: .5rem; }
.candidate-picker > .number-area { display: none; }
.empty-digits .digit { color: var(--muted); border-color: var(--line); }
.result { margin-top: 1.25rem; scroll-margin-top: 1rem; }
.ballot { background: var(--paper); border: 2px solid var(--accent); border-radius: 12px; overflow: hidden; margin-top: 1rem; box-shadow: 0 8px 24px #2f232510; }
.ballot-header { padding: 1rem; background: var(--accent); color: white; }
.ballot-header #progress { margin: .4rem 0; }
.ballot-rows { padding: 0; margin: 0; list-style: none; counter-reset: ballot; }
.ballot-row { padding: 14px 20px; border-bottom: 1px dashed var(--line); position: relative; }
.ballot-row:nth-child(even) { background: var(--row-wash); }
.row-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem; }
.preset-label { font-size: .7rem; color: var(--muted); }
.row-cargo { color: var(--muted); font-size: .85rem; font-weight: 700; }
.row-cargo::before { counter-increment: ballot; content: counter(ballot) ". "; }
.row-name { font-weight: 700; line-height: 1.3; margin: .25rem 0 .6rem; overflow-wrap: anywhere; }
.digits { display: grid; grid-template-columns: repeat(var(--digit-count), minmax(0, 2rem)); gap: .25rem; }
.digit { font-weight: 800; font-size: clamp(1rem, 8vw, 1.65rem); line-height: 1; border: 1px solid var(--accent); color: var(--accent); width: 100%; height: 2.2rem; display: grid; place-items: center; border-radius: 3px; }
.number-line { display: flex; align-items: center; gap: 4px; min-width: 0; width: 100%; }
.number-line > .digits { flex: 0 1 auto; width: calc(var(--digit-count) * 2rem + (var(--digit-count) - 1) * 3px); min-width: 0; gap: 3px; container-type: inline-size; }
.number-line .digit { font-size: min(clamp(1rem, 8vw, 1.65rem), calc(((100cqi - (var(--digit-count) - 1) * 3px) / var(--digit-count) - 2px) * 1.6)); }
.confirm-key { display: block; flex: 0 0 auto; width: 4.5rem; max-width: 96px; height: auto; }
.ballot-warning { background: #fff3d1; padding: 1rem; font-size: .86rem; }
.ballot-warning > strong { display: block; font-size: 1.4286rem; line-height: 1.2; text-align: center; }
.ballot-warning p { margin-top: .4rem; }
.ballot-footer { font-size: .7rem; color: var(--muted); padding: .8rem 1rem; }
.ballot-footer span { display: block; overflow-wrap: anywhere; }
.storage-status { margin-top: .6rem; font-size: .8rem; color: var(--muted); }
.actions { display: grid; gap: .65rem; margin-top: 1rem; }
button, .button { display: block; text-align: center; width: 100%; background: var(--accent); color: white; border: 2px solid var(--accent); border-radius: 9px; padding: .75rem .85rem; font-size: .94rem; font-weight: 700; line-height: 1.4; text-decoration: none; min-height: 58px; cursor: pointer; }
button.secondary, .button.secondary { background: white; color: var(--accent); }
button:disabled { opacity: .65; cursor: wait; }
.action-help { font-size: .8rem; color: var(--muted); }
.notice { padding: 1rem; background: #fff3d1; border: 1px solid #986f15; border-radius: 9px; margin-top: 1rem; }
.notice h3 { margin-bottom: .5rem; }
.notice ol { padding-left: 1.2rem; }
.notice li + li { margin-top: .5rem; }
.notice label { display: block; font-weight: 650; font-size: .86rem; }
.notice textarea { resize: vertical; width: 100%; background: white; color: var(--ink); border: 1px solid #986f15; border-radius: 6px; padding: .5rem; font-size: .8rem; margin: .4rem 0 .7rem; }
.error { background: #fff0eb; border-color: #962d14; }
.site-sharing { border-top: 1px solid var(--line); margin-top: 1.8rem; padding-top: 1.3rem; }
.site-sharing p { margin: .45rem 0 .85rem; font-size: .9rem; }
.page-footer { padding: 1.5rem 0; color: var(--muted); font-size: .76rem; text-align: center; }
.photo-credit { font-size: .7rem; }
.photo-credit a { color: var(--accent); }
.ballot-footer .print-photo-credit { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 1rem; top: -10rem; background: white; color: var(--accent); padding: .6rem; z-index: 3; }
.skip-link:focus { top: .5rem; }
.completion-notice { position: fixed; inset: 0; margin: auto; width: min(560px, calc(100vw - 32px)); max-width: calc(100vw - 32px); height: fit-content; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; padding: 24px; border: 3px solid var(--accent); border-radius: 14px; color: var(--ink); background: white; box-shadow: 0 20px 80px #0004; }
.completion-notice:not([open]) { display: none; }
.completion-notice[open] { display: block; }
.completion-notice::backdrop { background: #2f2325b3; }
.reminder-icon { display: grid; place-items: center; width: 56px; height: 56px; border: 2px solid #986f15; border-radius: 50%; background: #fff3d1; font-size: 36px; font-weight: 800; line-height: 1; }
.completion-notice h2 { margin: 16px 0 20px; font-size: 1.6rem; line-height: 1.15; }
.completion-notice h2:focus { outline: none; }
.completion-notice p { font-size: 1rem; }
.completion-notice button { margin-top: 24px; }
@media (max-width: 380px) {
  .page { padding: 21px 14px 0; }
  .ballot-header { padding: 1rem; }
  .candidate-field.has-candidate { grid-template-columns: minmax(0, 1fr) 60px 14px; column-gap: 6px; row-gap: 4px; padding: 6px; }
  .inline-candidate { grid-template-columns: minmax(0, 1fr) 56px; gap: 10px; padding: 10px; }
  .inline-candidate .portrait { width: 56px; height: 68px; }
}
/* Só coloca a foto ao lado das duas linhas quando há espaço para ler o número. */
@container candidate-field (min-width: 15rem) {
  .candidate-field.has-candidate { grid-template-columns: minmax(0, 1fr) 70px 18px; }
  .candidate-field.has-candidate .toggle-content { grid-column: 1; grid-row: 1; }
  .candidate-field.has-candidate > .portrait { grid-column: 2; grid-row: 1 / span 2; align-self: stretch; width: 100%; height: auto; min-height: 0; }
  .candidate-field.has-candidate .toggle-arrow { grid-column: 3; grid-row: 1 / span 2; align-self: center; }
  .candidate-field.has-candidate .toggle-numbers { grid-column: 1; grid-row: 2; }
}
@media (min-width: 900px) {
  .page { padding-top: 2.5rem; }
  .intro { margin-bottom: 2rem; }
}
@media (prefers-reduced-motion: no-preference) {
  button, .button { transition: background-color .15s ease; }
}
@media print {
  @page { size: A4; margin: 10mm; }
  :root { font-size: 14pt; background: white; }
  body { background: white; }
  .page { padding: 0; max-width: 140mm; }
  .intro, #result, .site-sharing, .page-footer, .skip-link, .selection-note, .candidate-field, .inline-options, .completion-notice, .preset-label, #progress, #load-error, .storage-status { display: none !important; }
  .completion-notice::backdrop { display: none; }
  body:not(.is-complete) .ballot { display: none; }
  .result { margin: 0; }
  .ballot { margin: 0; box-shadow: none; border-radius: 0; break-inside: avoid; }
  .ballot-header { background: white; color: var(--ink); border-bottom: 2px solid var(--accent); padding: .5rem .7rem; }
  .ballot-header h2 { font-size: 1.2rem; }
  .ballot-row { padding: .15rem .7rem; }
  .candidate-picker { margin-top: .25rem; }
  .preset-picker, .preset-picker > .number-area { margin-top: 0; }
  .candidate-picker .selected-summary { display: grid; }
  .candidate-picker > .number-area { display: block; }
  .selected-summary { grid-template-columns: 12mm minmax(0, 1fr); margin: .1rem 0; }
  .selected-summary .portrait { width: 12mm; height: 15mm; }
  .number-area { margin-top: .2rem; }
  .row-name { margin-bottom: .35rem; }
  .digits { grid-template-columns: repeat(var(--digit-count), 1.7rem); }
  .digit { font-size: 1.4rem; height: 1.6rem; }
  .number-line > .digits { flex: none; width: calc(var(--digit-count) * 1.7rem + (var(--digit-count) - 1) * 3px); }
  .number-line .digit { font-size: 1.4rem; }
  .confirm-key { width: auto; max-width: none; height: 1.6rem; }
  .ballot-warning { padding: .7rem; }
  .ballot-footer { padding: .5rem .7rem; }
  .ballot-footer .print-photo-credit { display: block; font-size: .6rem; margin-top: .25rem; }
}
