:root {
  --blue: #1111b6;
  --lime: #8dff00;
  --orange: #ff5a0a;
  --ink: #181834;
  --muted: #62667a;
  --line: #e4e6ed;
  --white: #fff;
  font-family: Outfit, Arial, sans-serif;
  color: var(--white);
  background: #242629;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: #242629;
}

button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .65; }
#generate[data-busy="true"] { cursor: wait; }
a { color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 4px;
}

.shell {
  width: min(100% - 32px, 520px);
  margin: 0 auto;
  padding: 16px 0 24px;
}

.hero {
  text-align: center;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: auto;
  margin: 0 auto 10px;
  text-decoration: none;
}

.brand-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--lime);
}

.brand strong {
  font: 800 28px/1 Sora, Outfit, sans-serif;
  letter-spacing: -.04em;
  color: #fff;
}

.brand em {
  font-style: normal;
  color: var(--lime);
}

.eyebrow {
  display: block;
  font-size: 10px;
  letter-spacing: .22em;
  font-weight: 700;
  color: var(--lime);
  margin-bottom: 7px;
}

h1 {
  font: 800 clamp(34px, 8vw, 46px)/1.04 Sora, Outfit, sans-serif;
  letter-spacing: -.04em;
  margin: 0;
}

h1 em {
  font-style: normal;
  color: var(--lime);
}

.hero-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.hero-title h1 { font-size: clamp(27px, 7.2vw, 46px); }

.state-flag {
  display: block;
  flex: none;
  width: 36px;
  height: 24px;
}

.ballot-card {
  background: var(--white);
  border-radius: 22px;
  color: var(--ink);
  padding: 8px 18px;
  box-shadow: 0 14px 50px #02025340;
  border-top: 7px solid var(--lime);
}

.candidate-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.candidate-row:last-child { border-bottom: 0; }
.editable-row { cursor: text; }
.editable-row:focus-within { background: #1111b604; }

.candidate-photo {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: start;
  width: 80px;
  height: 80px;
  overflow: hidden;
  border-radius: 9px;
  background: #eff0f5;
}

.candidate-photo svg,
.candidate-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.candidate-info {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.role-label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 4px;
}

.candidate-identity {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.candidate-name {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
  margin: 0;
  overflow-wrap: anywhere;
}

.candidate-party {
  font-size: 10px;
  line-height: 1.2;
  color: var(--muted);
  margin: 0;
}

.candidate-party:empty { display: none; }

.found-row .candidate-name { color: var(--blue); }

.digit-group {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  gap: 5px;
  align-self: end;
}

.digit-input {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid #d5d8e2;
  border-radius: 7px;
  text-align: center;
  font: 700 26px/38px Outfit, Arial, sans-serif;
  background: #f1f3f9;
  color: var(--blue);
  min-width: 0;
}

.digit-input::placeholder { color: #abb0c3; }

.digit-input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
  background: #e5e9ff;
}

.digit-input[aria-invalid="true"] { border-color: #b12626; }

.field-error {
  grid-column: 2 / -1;
  color: #b12626;
  font-size: 11px;
  margin: 0;
  line-height: 1.4;
}

.button {
  min-height: 50px;
  border-radius: 12px;
  padding: 14px 20px;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .15s, transform .15s;
}

.button:hover { transform: translateY(-1px); }

.primary {
  background: var(--lime);
  color: #101051;
}

.primary:hover { background: #a7ff38; }

.primary span { font-size: 22px; line-height: 1; }

.full { width: 100%; }

.secondary {
  color: var(--white);
  border-color: #ffffff60;
  background: #ffffff08;
}

.secondary:hover { background: #ffffff18; }

.message {
  font-size: 12px;
  line-height: 1.5;
  margin: 12px 0;
}

.message:empty { display: none; }

#generate { margin-top: 10px; }

#generate.generate-attention {
  box-shadow: 0 0 0 3px #b5ff0033, 0 6px 20px #b5ff0029;
  animation: generate-cue 1.1s ease-in-out 2;
}

@keyframes generate-cue {
  50% { box-shadow: 0 0 0 6px #b5ff0018, 0 6px 26px #b5ff0044; }
}

.paper-note {
  display: flex;
  gap: 12px;
  margin: 26px 0;
  padding: 17px 0;
  border-top: 1px solid #ffffff2a;
  border-bottom: 1px solid #ffffff2a;
}

.paper-note > span {
  color: var(--lime);
  font-size: 27px;
}

.paper-note p {
  font-size: 11px;
  line-height: 1.7;
  color: #d5d5d5;
  margin: 0;
}

.paper-note strong {
  color: var(--white);
  font-size: 12px;
}

footer {
  text-align: center;
  color: #bdbdbd;
  font-size: 9px;
  line-height: 1.7;
}

footer nav {
  display: flex;
  justify-content: center;
  gap: 22px;
  font-size: 11px;
  margin-top: 14px;
}

footer a { text-underline-offset: 3px; }
footer p { margin: 7px 0; }

html:has(.result-modal[open]) { overflow: hidden; }

.result-modal {
  width: min(460px, calc(100% - 24px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 20px;
  border: 1px solid #ffffff24;
  border-radius: 20px;
  background: #242629;
  color: #fff;
  overflow: auto;
  box-shadow: 0 24px 80px #0008;
}

.result-modal::backdrop { background: #000a; }

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.result-title {
  font: 700 24px Sora, Outfit, sans-serif;
  text-align: center;
  margin: 0 0 18px;
}

.modal-heading .result-title {
  font-size: 22px;
  text-align: left;
  margin: 0;
}

.modal-close {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: #ffffff12;
  color: #fff;
  font: 28px Arial, sans-serif;
}

#print-art { display: none; }

.action-icon { flex: none; }

#result[open] {
  display: grid;
  grid-template-rows: auto auto minmax(160px, 1fr) auto auto;
  gap: 10px;
  width: min(560px, calc(100% - 24px));
  height: calc(100dvh - 24px);
  max-height: calc(100dvh - 24px);
  padding: 16px;
}

#result .modal-heading { grid-row: 1; margin: 0; }
#result .result-secondary-actions { grid-row: 2; }
#result .result-image { grid-row: 3; }
#result .result-actions { grid-row: 4; }
#result #result-status { grid-row: 5; margin: 0; }

.result-secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#result .result-image {
  align-self: stretch;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  margin: 0;
  object-fit: contain;
  border-radius: 8px;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, auto);
  gap: 8px;
}

#result .result-actions #share {
  grid-column: 1 / -1;
  grid-row: 1;
  font-size: 15px;
}

#result .result-actions #share span { font-size: inherit; }

#result .result-actions #download { grid-column: 1; grid-row: 2; }
#result .result-actions #copy { grid-column: 2; grid-row: 2; }
#result .result-actions #print { grid-column: 3; grid-row: 2; }

#copy.copied {
  background: #b5ff00;
  border-color: #d9ff80;
  color: #101051;
  box-shadow: 0 0 0 3px #b5ff0044, 0 4px 18px #b5ff0040;
}

.model-picker {
  width: min(720px, calc(100% - 16px));
  padding: 14px;
  background: #191b1e;
}

.model-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.model-option {
  --card-color: #0A168B;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 2px solid #ffffff35;
  border-radius: 12px;
  overflow: hidden;
  background: var(--card-color);
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 3px 12px #ffffff24;
}

.model-option[data-model="verde"] { --card-color: #B5FF00; }
.model-option[data-model="laranja"] { --card-color: #FF6A00; }
.model-option[data-model="papel"] { --card-color: #fff; }

.model-option:hover {
  filter: brightness(1.06);
  box-shadow: 0 4px 18px #ffffff40;
}

.model-option img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 9 / 16;
  object-fit: fill;
}

.model-option-footer {
  display: block;
  width: 100%;
  padding: 10px 8px 12px;
  background: linear-gradient(var(--card-color), #111827);
}

.model-choose {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  margin: 0;
  padding: 8px 4px;
  border-radius: 8px;
  background: var(--lime);
  color: #101051;
  font-weight: 700;
  font-size: 13px;
  border: 0;
}

.loading {
  padding: 40px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 600px) {
  .shell {
    width: calc(100% - 20px);
    padding-top: 10px;
  }

  .hero { margin-bottom: 10px; }
  .brand { width: auto; margin-bottom: 8px; }
  .brand strong { font-size: 22px; }
  .eyebrow { font-size: 8px; margin-bottom: 5px; }
  .hero-title h1 { font-size: 29px; }
  .hero-title .state-flag { width: 30px; height: 20px; }

  .ballot-card {
    padding: 5px 12px;
    border-radius: 16px;
    border-top-width: 5px;
  }

  .candidate-row {
    grid-template-columns: 72px minmax(0, 1fr);
    column-gap: 10px;
    padding: 6px 0;
    min-height: 85px;
  }

  .candidate-photo {
    width: 72px;
    height: 72px;
    align-self: center;
  }

  .digit-input {
    width: 36px;
    height: 36px;
    line-height: 34px;
    font-size: 24px;
  }

  .model-picker {
    width: calc(100% - 8px);
    max-height: calc(100dvh - 8px);
    padding: 10px;
    border-radius: 14px;
  }

  .model-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
}

@media (max-width: 420px) {
  #result .result-actions .secondary {
    padding: 10px 4px;
    font-size: 11px;
    gap: 4px;
  }

  #result .result-actions .secondary .action-icon {
    width: 16px;
    height: 16px;
  }

  .candidate-row { grid-template-columns: 64px minmax(0, 1fr); }
  .candidate-photo { width: 64px; height: 64px; }
  .digit-input { width: 32px; height: 32px; font-size: 23px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
  #generate.generate-attention { animation: none; }
}

@media print {
  @page { size: A4; margin: 15mm; }
  html, body { background: #fff !important; }
  .shell { display: none !important; }
  .result-modal, .result-modal::backdrop { display: none !important; }
  #print-art {
    display: block;
    width: 50mm;
    margin: 0 auto;
    break-inside: avoid;
  }
  #print-art.digital-print { width: 90mm; }
  #print-art img {
    display: block;
    width: 100%;
    height: auto;
  }
}
