/* =========================================================
   Urna eletrônica — aparência e movimento
   Curvas: ease-out forte para entradas, linear só na contagem.
   Tudo que anima usa transform/opacity (GPU, sem layout).
   ========================================================= */

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* ---- tema CLARO (padrão) — só a página em volta da urna muda ---- */
  --fundo: #e6eaf1;
  --fundo-2: #ffffff;
  --texto-topo: #131a26;
  --texto-orgao: #6b7789;
  --texto-rodape: #97a1b0;
  --sombra-urna: 0 22px 48px -22px rgba(23, 33, 51, .5), 0 2px 8px rgba(23, 33, 51, .12);
  --canto-fundo: #ffffff;
  --canto-borda: #d6dce6;
  --canto-cor: #7a8698;
  --canto-cor-ativa: #1a2433;
  --dica-fundo: #ffffff;
  --dica-borda: #dde4ee;
  --dica-cor: #33404f;
  --dica-sombra: 0 10px 26px -12px rgba(23, 33, 51, .5);

  /* ---- a urna em si é um objeto físico: igual nos dois temas ---- */
  --corpo: #cfd2cb;
  --corpo-alto: #e6e8e1;
  --corpo-baixo: #9ea299;
  --corpo-borda: #7f837a;

  --lcd: #e9f0dc;
  --lcd-2: #dde6cc;
  --lcd-tinta: #14180e;
  --lcd-tinta-fraca: #4a5340;

  --tecla: #2b2f36;
  --tecla-alto: #454a53;
  --tecla-texto: #f4f5f2;
  --branco: #f6f7f3;
  --corrige: #e8901b;
  --confirma: #1a9d4d;

  --raio: 18px;
  --sombra-tecla: 0 3px 0 rgba(0, 0, 0, .38), 0 6px 14px rgba(0, 0, 0, .3);
}

/* ---- tema ESCURO ---- */
:root[data-tema="escuro"] {
  --fundo: #0b0e14;
  --fundo-2: #141a26;
  --texto-topo: #f2f5fa;
  --texto-orgao: #8b97ad;
  --texto-rodape: #5b6577;
  --sombra-urna: 0 28px 60px -18px rgba(0, 0, 0, .75), 0 3px 10px rgba(0, 0, 0, .4);
  --canto-fundo: rgba(255, 255, 255, .05);
  --canto-borda: rgba(255, 255, 255, .12);
  --canto-cor: #93a0b5;
  --canto-cor-ativa: #e8ecf3;
  --dica-fundo: #1c2430;
  --dica-borda: #2c3746;
  --dica-cor: #cdd7e6;
  --dica-sombra: none;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--fundo-2) 0%, var(--fundo) 62%),
    var(--fundo);
  color: var(--texto-topo);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- palco ---------- */

.palco {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.4vh, 26px);
  padding: clamp(14px, 3vh, 32px) 16px;
}

.cabecalho { text-align: center; max-width: 900px; }

.cabecalho__orgao {
  margin: 0 0 6px;
  font-size: clamp(11px, 1.5vw, 13px);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--texto-orgao);
}

.cabecalho__titulo {
  margin: 0;
  font-size: clamp(17px, 2.6vw, 26px);
  font-weight: 650;
  letter-spacing: -.01em;
  color: var(--texto-topo);
}

.rodape {
  margin: 0;
  font-size: 12px;
  color: var(--texto-rodape);
  display: flex;
  gap: 14px;
  align-items: center;
}

.rodape__link { color: inherit; text-decoration: none; opacity: .55; }
.rodape__link:hover { opacity: 1; }
.rodape__pendente { color: var(--corrige); }

/* ---------- corpo da urna ---------- */

.urna {
  width: min(1060px, 100%);
  border-radius: calc(var(--raio) + 8px);
  padding: 14px;
  background: linear-gradient(168deg, var(--corpo-alto), var(--corpo) 42%, var(--corpo-baixo));
  border: 1px solid var(--corpo-borda);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .7) inset,
    0 -2px 0 rgba(0, 0, 0, .12) inset,
    var(--sombra-urna);
  opacity: 0;
  transform: translateY(14px) scale(.985);
  transition: opacity .5s var(--ease-out), transform .5s var(--ease-out);
}

body:not([data-fase="carregando"]) .urna { opacity: 1; transform: none; }

.urna__topo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px 10px;
}

.urna__marca {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: #5f645b;
}

.urna__selo {
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #5f645b;
  border: 1px solid #a8ac9f;
  border-radius: 99px;
  padding: 3px 10px;
  background: rgba(255, 255, 255, .35);
}

.urna__corpo {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 14px;
  align-items: stretch;
}

/* ---------- tela (LCD) ---------- */

.tela { min-width: 0; }

.tela__moldura {
  position: relative;
  height: 100%;
  min-height: 420px;
  border-radius: 10px;
  padding: 3px;
  background: linear-gradient(180deg, #3b3f38, #242721);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35) inset;
  overflow: hidden;
}

.tela__conteudo {
  position: relative;
  height: 100%;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--lcd), var(--lcd-2));
  color: var(--lcd-tinta);
  font-family: "Arial Narrow", "Helvetica Neue", system-ui, sans-serif;
  padding: clamp(14px, 2.4vw, 26px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* leve varredura horizontal, como um LCD antigo */
.tela__brilho {
  position: absolute;
  inset: 3px;
  border-radius: 7px;
  pointer-events: none;
  z-index: 3;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0) 32%),
    repeating-linear-gradient(180deg, rgba(0, 0, 0, .035) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
  opacity: .5;
}

.tela__flash {
  position: absolute;
  inset: 3px;
  border-radius: 7px;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.tela__flash.piscar { animation: piscar .18s var(--ease-out); }

@keyframes piscar {
  0% { opacity: .42; }
  100% { opacity: 0; }
}

/* ---------- conteúdo: votação ---------- */

.cena { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.cena--entrando { animation: cenaEntra .24s var(--ease-out) both; }

@keyframes cenaEntra {
  from { opacity: 0; transform: translateX(26px); }
  to   { opacity: 1; transform: none; }
}

.cena__faixa {
  font-size: clamp(11px, 1.4vw, 13px);
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--lcd-tinta-fraca);
}

.cena__cargo {
  margin: 2px 0 clamp(10px, 2vh, 18px);
  font-size: clamp(20px, 3.1vw, 34px);
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.05;
  text-transform: uppercase;
}

.cena__passo {
  margin-left: auto;
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--lcd-tinta-fraca);
}

.cena__cabeca { display: flex; align-items: baseline; gap: 12px; }

/* caixas de dígito */

.numero { display: flex; align-items: center; gap: clamp(8px, 1.4vw, 14px); }

.numero__rotulo {
  font-size: clamp(12px, 1.6vw, 15px);
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.caixas { display: flex; gap: 8px; }

.caixa {
  width: clamp(38px, 5vw, 54px);
  height: clamp(48px, 6.4vw, 68px);
  border: 2px solid var(--lcd-tinta);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: clamp(26px, 4vw, 40px);
  font-weight: 700;
  line-height: 1;
  background: rgba(255, 255, 255, .35);
  overflow: hidden;
}

.caixa--ativa { box-shadow: 0 0 0 2px rgba(20, 24, 14, .22); }

/* cursor piscando na caixa que está sendo preenchida */
.caixa--ativa::after {
  content: "";
  width: 60%;
  height: 3px;
  background: var(--lcd-tinta);
  animation: cursor 1.06s steps(1, end) infinite;
}

@keyframes cursor { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

.caixa__digito { animation: digitoEntra .13s var(--ease-out) both; }

@keyframes digitoEntra {
  from { opacity: 0; transform: translateY(-9px); }
  to   { opacity: 1; transform: none; }
}

/* ficha do candidato */

.ficha {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: clamp(12px, 2vw, 22px);
  align-items: start;
  margin-top: clamp(12px, 2.4vh, 22px);
  flex: 1;
  min-height: 0;
}

.ficha__linha { margin: 0 0 6px; font-size: clamp(13px, 1.8vw, 17px); }
.ficha__linha b { font-weight: 700; }
.ficha__nome {
  font-size: clamp(19px, 2.8vw, 30px);
  font-weight: 700;
  line-height: 1.1;
  margin: 0 0 4px;
  text-transform: uppercase;
}
.ficha__legenda { font-size: clamp(13px, 1.7vw, 16px); color: var(--lcd-tinta-fraca); }

.ficha__foto {
  width: clamp(110px, 15vw, 190px);
  aspect-ratio: 1;
  object-fit: contain;
  border: 2px solid var(--lcd-tinta);
  border-radius: 6px;
  background: #fff;
  padding: 4px;
}

.revela { animation: revela .26s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }

@keyframes revela {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

/* estados grandes: branco / nulo */

.aviso-grande {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 6px;
}

.aviso-grande strong {
  font-size: clamp(32px, 6vw, 62px);
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  animation: revela .26s var(--ease-out) both;
}

/* instruções do rodapé da tela */

.instrucoes {
  margin-top: auto;
  padding-top: 12px;
  border-top: 2px solid rgba(20, 24, 14, .25);
  font-size: clamp(12px, 1.6vw, 15px);
  line-height: 1.55;
}

.instrucoes b { font-weight: 700; }
.instrucoes__titulo { font-weight: 700; margin-bottom: 2px; }

/* ---------- fim / computado / intervalo ---------- */

.fim {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
}

.fim__texto {
  font-size: clamp(76px, 17vw, 190px);
  font-weight: 800;
  letter-spacing: .1em;
  line-height: 1;
  animation: fimEntra .34s var(--ease-out) both;
}

@keyframes fimEntra {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: none; }
}

.computado {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: clamp(10px, 2vh, 18px);
}

.computado__selo {
  width: clamp(96px, 13vw, 132px);
  height: clamp(96px, 13vw, 132px);
  position: relative;
  display: grid;
  place-items: center;
}

.computado__anel {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid var(--confirma);
  animation: seloPulso .6s var(--ease-out) both;
}

@keyframes seloPulso {
  0%   { opacity: 0; transform: scale(.82); }
  60%  { opacity: 1; transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}

.computado__check {
  width: 56%;
  height: 56%;
  stroke: var(--confirma);
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.computado__check path {
  stroke-dasharray: 32;
  stroke-dashoffset: 32;
  animation: risca .42s var(--ease-out) .16s forwards;
}

@keyframes risca { to { stroke-dashoffset: 0; } }

.computado__titulo {
  font-size: clamp(24px, 4.4vw, 44px);
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  animation: revela .3s var(--ease-out) .1s both;
}

.computado__sub {
  font-size: clamp(13px, 1.8vw, 17px);
  color: var(--lcd-tinta-fraca);
  animation: revela .3s var(--ease-out) .2s both;
  max-width: 34ch;
}

/* contagem para liberar de novo */

.intervalo { display: grid; justify-items: center; gap: 8px; margin-top: clamp(8px, 2vh, 16px); }

.intervalo__anel { width: 74px; height: 74px; transform: rotate(-90deg); }
.intervalo__trilho { fill: none; stroke: rgba(20, 24, 14, .16); stroke-width: 6; }

.intervalo__barra {
  fill: none;
  stroke: var(--lcd-tinta);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 201;
  stroke-dashoffset: 0;
  animation: esvazia linear forwards;
  animation-duration: var(--duracao, 10s);
}

@keyframes esvazia { to { stroke-dashoffset: 201; } }

.intervalo__num {
  position: absolute;
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.intervalo__caixa { position: relative; display: grid; place-items: center; }
.intervalo__texto { font-size: clamp(12px, 1.6vw, 14px); color: var(--lcd-tinta-fraca); letter-spacing: .06em; }

/* ---------- tela fechada ---------- */

.fechada {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: 10px;
  animation: revela .3s var(--ease-out) both;
}

.fechada__icone { opacity: .55; }
.fechada__titulo { font-size: clamp(20px, 3vw, 30px); font-weight: 800; text-transform: uppercase; }
.fechada__sub { font-size: 15px; color: var(--lcd-tinta-fraca); max-width: 38ch; }

/* ---------- teclado ---------- */

.teclado {
  background: linear-gradient(180deg, #b9bdb4, #a3a79e);
  border-radius: 12px;
  padding: 14px;
  border: 1px solid #8d9188;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .18) inset;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-content: start;
}

.teclado__numeros {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.teclado__acoes { display: grid; gap: 9px; }

.tecla-vazia { display: block; }

.tecla {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  border-radius: 9px;
  color: var(--tecla-texto);
  background: linear-gradient(180deg, var(--tecla-alto), var(--tecla));
  box-shadow: var(--sombra-tecla);
  transition: transform .12s var(--ease-out), box-shadow .12s var(--ease-out), filter .12s var(--ease-out);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tecla--num {
  aspect-ratio: 1 / .82;
  font-size: clamp(20px, 2.6vw, 27px);
  font-weight: 700;
}

.tecla--branco,
.tecla--corrige,
.tecla--confirma {
  padding: 14px 10px;
  font-size: clamp(12px, 1.5vw, 15px);
  font-weight: 800;
  letter-spacing: .08em;
}

.tecla--branco { background: linear-gradient(180deg, #fff, var(--branco)); color: #24271f; }
.tecla--corrige { background: linear-gradient(180deg, #f5a63c, var(--corrige)); color: #2a1a04; }
.tecla--confirma { background: linear-gradient(180deg, #2bbb63, var(--confirma)); color: #04240f; }

@media (hover: hover) and (pointer: fine) {
  .tecla:hover { filter: brightness(1.08); }
}

.tecla:active,
.tecla.pressionada {
  transform: translateY(3px);
  box-shadow: 0 0 0 rgba(0, 0, 0, .38), 0 2px 6px rgba(0, 0, 0, .3);
  filter: brightness(.94);
}

.tecla:focus-visible { outline: 3px solid #4f9dff; outline-offset: 2px; }

/* urna travada (fim do voto, intervalo, urna fechada) */
.teclado--inativo .tecla { filter: saturate(.5) brightness(.88); cursor: default; }

/* erro: sacode o teclado de leve */
.teclado.erro { animation: sacode .3s var(--ease-in-out); }

@keyframes sacode {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ---------- extras ---------- */

#confete {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

.canto {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  gap: 6px;
}

.botao-canto {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--canto-borda);
  background: var(--canto-fundo);
  color: var(--canto-cor);
  cursor: pointer;
  opacity: .55;
  transition: color .15s var(--ease-out), opacity .15s var(--ease-out);
}

.botao-canto:focus-visible { outline: 2px solid #4f9dff; outline-offset: 2px; opacity: 1; }

@media (hover: hover) and (pointer: fine) {
  .botao-canto:hover { color: var(--canto-cor-ativa); opacity: 1; }
}

/* o ícone mostrado é sempre o do tema para o qual o botão leva */
.icone-lua { display: none; }
:root[data-tema="escuro"] .icone-sol { display: none; }
:root[data-tema="escuro"] .icone-lua { display: block; }

.dica {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 12px);
  z-index: 30;
  padding: 10px 18px;
  border-radius: 99px;
  background: var(--dica-fundo);
  border: 1px solid var(--dica-borda);
  color: var(--dica-cor);
  box-shadow: var(--dica-sombra);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s var(--ease-out), transform .18s var(--ease-out);
}

.dica.aparece { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsivo ---------- */

@media (max-width: 900px) {
  .urna__corpo { grid-template-columns: 1fr; }
  .tela__moldura { min-height: 320px; }
  .teclado { max-width: 420px; margin: 0 auto; width: 100%; }
  .cabecalho__titulo { font-size: 18px; }
}

@media (max-width: 520px) {
  .palco { justify-content: flex-start; }
  .cabecalho { padding: 0 44px; }
  .urna { padding: 10px; }
  .tela__moldura { min-height: 290px; }
  .ficha { grid-template-columns: 1fr; }
  .ficha__foto { width: 116px; justify-self: start; }
}

/* ---------- movimento reduzido ---------- */

@media (prefers-reduced-motion: reduce) {
  .urna { transition: opacity .3s ease; transform: none; }
  .cena--entrando { animation: apenasFade .2s ease both; }
  .caixa__digito,
  .revela,
  .fim__texto,
  .computado__titulo,
  .computado__sub,
  .fechada { animation: apenasFade .2s ease both; }
  .computado__anel { animation: apenasFade .2s ease both; }
  .computado__check path { animation: none; stroke-dashoffset: 0; }
  .caixa--ativa::after { animation: none; opacity: 1; }
  .teclado.erro { animation: none; }
  .tecla { transition: filter .1s ease; }
  .tecla:active, .tecla.pressionada { transform: none; }
  #confete { display: none; }
}

@keyframes apenasFade { from { opacity: 0; } to { opacity: 1; } }
