/*
 * Tela do eleitor. O fundo muda de cor conforme a etapa, com o mesmo significado
 * das placas de segurança: azul instrui, âmbar pede atenção antes de confirmar,
 * verde indica condição segura, vermelho é parada. O conteúdo fica sempre em um
 * cartão branco, para manter o contraste alto em qualquer etapa.
 */
:root {
  --ink: #101c2b;
  --ink-2: #4b5a6c;
  --blue: #0a58a8;
  --blue-soft: #e6f0fa;
  --line: #d5deea;
  --display: Bahnschrift, "DIN Alternate", "Roboto Condensed", "Segoe UI", Arial, sans-serif;
  --text: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100vh;
  overflow: hidden;
  background: #17324d;
  color: var(--on-bg);
  font-family: var(--text);
  cursor: none;
}

/* Uma camada por tom: a troca de cor é uma transição de opacidade */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg);
  transition: opacity 160ms linear;
}

body[data-tone="neutral"] { --bg: linear-gradient(150deg, #142a42, #1f4266); --on-bg: #fff; --rule: rgba(255, 255, 255, .22); --accent: #1f4266; }
body[data-tone="blue"]    { --bg: linear-gradient(150deg, #07457f, #0a58a8 55%, #0f7a9c); --on-bg: #fff; --rule: rgba(255, 255, 255, .25); --accent: #0a58a8; }
body[data-tone="yellow"]  { --bg: linear-gradient(150deg, #f7b500, #fdd23e); --on-bg: var(--ink); --rule: rgba(16, 28, 43, .22); --accent: #8a5a00; }
body[data-tone="green"]   { --bg: linear-gradient(150deg, #05603d, #0a8a59); --on-bg: #fff; --rule: rgba(255, 255, 255, .25); --accent: #0a7a4f; }
body[data-tone="red"]     { --bg: linear-gradient(150deg, #8c141d, #c0202b); --on-bg: #fff; --rule: rgba(255, 255, 255, .28); --accent: #c0202b; }

[hidden] { display: none !important; }

.icon { flex: none; width: 1.15em; height: 1.15em; vertical-align: -.2em; }

/* Topo */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  min-height: 5rem;
  padding: .9rem clamp(1rem, 3.5vw, 3rem);
}
.top-title { min-width: 0; font-family: var(--display); font-size: clamp(1rem, 1.9vw, 1.5rem); font-weight: 600; }
.top-company {
  display: flex;
  flex: none;
  align-items: center;
  max-width: 45%;
  font-family: var(--display);
  font-size: clamp(1rem, 1.9vw, 1.5rem);
  text-align: right;
}
.company-logo {
  display: block;
  max-width: min(18rem, 100%);
  max-height: 3.6rem;
  padding: .4rem .7rem;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  object-fit: contain;
}

/* Cartão central */
.stage { display: grid; min-height: 0; padding: 0 clamp(1rem, 3.5vw, 3rem); }
.card {
  display: grid;
  min-height: 0;
  padding: clamp(1.25rem, 3.5vw, 3.5rem);
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(5, 20, 38, .32);
  color: var(--ink);
}
.screen { display: flex; flex-direction: column; justify-content: center; min-width: 0; min-height: 0; animation: screen-in 180ms ease-out; }
.screen-center { align-items: center; text-align: center; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }

h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2rem, 5vw, 4.25rem);
  font-weight: 700;
  line-height: 1.08;
}
.prompt { font-size: clamp(1.6rem, 3.4vw, 2.9rem); }
.huge { color: #075c3b; font-size: clamp(2.8rem, 8.5vw, 7.5rem); }

.lead {
  max-width: 52rem;
  margin: 1.25rem 0 0;
  color: var(--ink-2);
  font-size: clamp(1.1rem, 2vw, 1.6rem);
  line-height: 1.35;
}

.status-icon {
  display: grid;
  place-items: center;
  width: clamp(4.5rem, 10vh, 7rem);
  height: clamp(4.5rem, 10vh, 7rem);
  margin-bottom: 1.5rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
  font-size: clamp(2.2rem, 5vh, 3.4rem);
}

/* Campos do número */
.digits {
  display: flex;
  justify-content: center;
  gap: clamp(.4rem, 1.2vw, 1.1rem);
  margin-top: clamp(1.25rem, 3.5vh, 2.5rem);
}
.digit {
  display: grid;
  place-items: center;
  width: clamp(2.8rem, calc(74vw / var(--count, 4)), 10rem);
  aspect-ratio: 4 / 5;
  max-height: 38vh;
  border: 3px solid var(--line);
  border-radius: 20px;
  background: #f4f7fb;
  font-family: var(--display);
  font-size: clamp(2.4rem, 11vh, 8rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.digits[data-count="2"], .digits[data-count="3"], .digits[data-count="4"] { --count: 5; }
.digits[data-count="5"], .digits[data-count="6"] { --count: 6.5; }
.digits[data-count="7"], .digits[data-count="8"] { --count: 8.5; }
.digits[data-count="9"], .digits[data-count="10"] { --count: 11; }
.digit.filled { border-color: var(--blue); background: var(--blue); color: #fff; animation: digit-in 130ms ease-out; }
.digit.next { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 6px var(--blue-soft); }
@keyframes digit-in { from { transform: scale(.88); } }

/* Candidato */
.who { display: flex; align-items: center; justify-content: center; gap: clamp(1.5rem, 5vw, 4.5rem); min-width: 0; min-height: 0; }
.photo {
  flex: none;
  width: clamp(11rem, 27vw, 24rem);
  aspect-ratio: 4 / 5;
  max-height: 58vh;
  overflow: hidden;
  border-radius: 22px;
  background: #eef2f7;
  box-shadow: 0 14px 40px rgba(16, 28, 43, .22);
}
.photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.photo-initials {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--ink-2);
  font-family: var(--display);
  font-size: clamp(4rem, 11vw, 9rem);
  font-weight: 700;
}
.who-text { min-width: 0; max-width: 60rem; }
.eyebrow {
  display: inline-block;
  margin: 0 0 1rem;
  padding: .3em .85em;
  border-radius: 999px;
  background: #fdf0c4;
  color: #6b4500;
  font-family: var(--display);
  font-size: clamp(1.05rem, 2.2vw, 1.8rem);
  font-weight: 700;
}
.name { overflow-wrap: anywhere; }
.number {
  margin: 1rem 0 0;
  color: var(--ink-2);
  font-family: var(--display);
  font-size: clamp(1.3rem, 3vw, 2.6rem);
  font-variant-numeric: tabular-nums;
}

/* Registrando */
.spinner {
  width: 5rem;
  height: 5rem;
  margin-bottom: 1.75rem;
  border: 7px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Voto computado: o único momento encenado da tela */
.done-mark { width: clamp(6rem, 20vh, 11rem); height: clamp(6rem, 20vh, 11rem); margin-bottom: clamp(.75rem, 3vh, 1.75rem); }
.done-ring, .done-tick { fill: none; stroke: #0a7a4f; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }
.done-ring { stroke-dasharray: 327; stroke-dashoffset: 327; transform: rotate(-90deg); transform-origin: center; animation: draw 420ms ease-out forwards; }
.done-tick { stroke-dasharray: 80; stroke-dashoffset: 80; animation: draw 240ms 340ms ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Teclas */
.bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 5.25rem;
  padding: .9rem clamp(1rem, 3.5vw, 3rem);
}
.keys { display: flex; flex-wrap: wrap; gap: .6rem clamp(1rem, 3vw, 2.75rem); margin: 0; padding: 0; list-style: none; }
.keys li { display: flex; align-items: center; gap: .65rem; font-size: clamp(1.02rem, 1.7vw, 1.4rem); font-weight: 600; }
kbd {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  padding: .32em .7em;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(5, 20, 38, .35);
  color: var(--ink);
  font-family: var(--display);
  font-size: .95em;
  font-weight: 700;
}
.connection { display: flex; align-items: center; gap: .5rem; margin: 0; font-weight: 700; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .who { flex-direction: column; text-align: center; }
  .photo { width: min(60vw, 14rem); }
}

@media (prefers-reduced-motion: reduce) {
  .screen, .digit.filled { animation: none; }
  .done-ring, .done-tick { animation: none; stroke-dashoffset: 0; }
  .spinner { animation-duration: 2.5s; }
}
