:root {
  --ink: var(--text);
  --green: #15803d;
  --paper: #ffffff;
  --background: var(--bg);
  --gold: var(--orange);
  --gold-light: #fef3c7;
  --primary: var(--navy);
  --primary-light: var(--blue);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--ink);
  font-family: var(--font);
}

button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1120px) / 2));
  background: linear-gradient(110deg, #0f172a, #1e3a8a);
  border-bottom: 4px solid var(--gold);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
}

.brand { display: flex; align-items: center; gap: 12px; color: white; font-weight: 700; letter-spacing: -0.025em; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 12px; color: white;
  background: linear-gradient(145deg, #fcd34d, #d97706);
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.3);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand small { display: block; margin-top: 2px; color: #cbd5e1; font-size: 11px; font-weight: 500; }
.demo-badge {
  border: 1px solid rgba(255,255,255,0.2); color: white;
  background: rgba(255,255,255,0.1); border-radius: 999px;
  padding: 7px 11px; font-size: 11px; font-weight: 700; letter-spacing: 0.07em;
}

main { width: min(100% - 40px, 1080px); margin: 0 auto; padding: 46px 0 64px; }

.intro {
  position: relative; isolation: isolate; overflow: hidden;
  margin-bottom: 27px; padding: 28px 30px; border-radius: 22px; color: white;
  background: linear-gradient(112deg, #1e3a8a 0%, #3b82f6 68%, #60a5fa 100%);
  box-shadow: 0 18px 38px rgba(30, 58, 138, 0.18);
}
.intro:before, .intro:after {
  content: ""; position: absolute; z-index: 0; border: 1px solid rgba(255,255,255,.1); border-radius: 50%; pointer-events: none;
}
.intro:before { width: 280px; height: 280px; top: -170px; right: 7%; box-shadow: 0 0 0 24px rgba(255,255,255,.05), 0 0 0 48px rgba(255,255,255,.02); }
.intro:after { width: 170px; height: 170px; right: -54px; bottom: -132px; }
.intro > * { position: relative; z-index: 1; }
.eyebrow {
  color: var(--gold-light); background: rgba(0,0,0,0.15); padding: 4px 10px; border-radius: 20px;
  display: inline-block; text-transform: uppercase; letter-spacing: 0.1em; font-size: 11px; font-weight: 800; margin-bottom: 8px;
}
h1 { margin: 0 0 8px; font-size: clamp(28px, 4vw, 39px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; }
.intro p { margin: 0; color: rgba(255,255,255,.9); font-size: 15px; }

.layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 22px; align-items: start; }
.card { border: 1px solid var(--line); border-radius: 20px; background: var(--paper); box-shadow: 0 10px 30px -10px rgba(0,0,0,0.05); }
.scanner-card, .voter-card, .info-card { padding: 22px; }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
h2 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.02em; color: var(--primary); }
.subheading { color: var(--muted); margin: 5px 0 0; font-size: 13px; line-height: 1.5; }
.step { flex: 0 0 auto; color: white; background: var(--gold); border-radius: 8px; padding: 6px 10px; font-size: 10px; font-weight: 800; letter-spacing: 0.06em; }

.camera-frame {
  position: relative; display: grid; place-items: center; overflow: hidden;
  width: 100%; aspect-ratio: 16 / 10; margin-top: 19px; border: 1px solid var(--line); border-radius: 15px;
  background: #0f172a; color: white;
}
#camera { width: 100%; height: 100%; position: absolute; inset: 0; object-fit: cover; }
.camera-shade {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 22px;
  background: linear-gradient(180deg, rgba(15,23,42,.2), rgba(15,23,42,.6));
}
.scan-target {
  width: min(58%, 240px); aspect-ratio: 1; position: absolute; border: 2px solid rgba(255,255,255,.9);
  border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.2), 0 0 22px rgba(217, 119, 6, .3);
}
.scan-target:before, .scan-target:after {
  content: ""; position: absolute; left: 10%; right: 10%; height: 2px; background: var(--gold); box-shadow: 0 0 13px var(--gold);
}
.scan-target:before { top: 20%; }
.scan-target:after { bottom: 20%; opacity: .6; }
.camera-message { position: relative; z-index: 1; max-width: 310px; margin-top: min(34vw, 220px); text-shadow: 0 1px 5px #000; }
.camera-message strong { display: block; font-size: 15px; }
.camera-message span { display: block; margin-top: 5px; font-size: 12px; opacity: .85; line-height: 1.45; }
.camera-frame.no-camera { background: #f8fafc; color: var(--ink); border: 2px dashed #cbd5e1; }
.camera-frame.no-camera .camera-shade { background: transparent; }
.camera-frame.no-camera .scan-target { border-color: #cbd5e1; box-shadow: none; border-style: dashed; }
.camera-frame.no-camera .camera-message { align-self: end; margin-top: 0; text-shadow: none; }
.camera-frame.no-camera .camera-message span { opacity: 1; color: var(--muted); }
.camera-frame.no-camera .scan-target:before,
.camera-frame.no-camera .scan-target:after { display: none; }

.scan-status { min-height: 20px; margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; font-weight: 600; }
.scan-status.error { color: #dc2626; }
.scan-status.success { color: var(--green); }

.manual-form { display: flex; gap: 9px; margin-top: 13px; }
.manual-form input {
  min-width: 0; flex: 1; height: 45px; border: 1px solid var(--line); border-radius: 11px;
  padding: 0 13px; outline: none; background: #f8fafc;
}
.manual-form input:focus { border-color: var(--primary-light); background: #fff; box-shadow: 0 0 0 3px rgba(59,130,246,.25); }

.button {
  min-height: 42px; border: 0; border-radius: 11px; padding: 0 16px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: white; font-weight: 700;
  box-shadow: 0 4px 12px rgba(29, 78, 216, .3);
}
.button:hover { filter: brightness(1.05); }
.button:disabled { background: #cbd5e1; color: white; box-shadow: none; cursor: not-allowed; }
.button.secondary { color: var(--primary-light); border: 1px solid #bfdbfe; background: #eff6ff; box-shadow: none; }
.button.danger { background: #dc2626; box-shadow: 0 4px 12px rgba(220, 38, 38, .25); }
.qr-image-button, .scan-again { width: 100%; margin-top: 10px; }

.demo-code { margin-top: 16px; border: 1px solid var(--line); border-radius: 14px; padding: 13px; background: #f8fafc; }
.demo-code summary { color: var(--primary-light); cursor: pointer; font-size: 13px; font-weight: 700; }
.demo-code-content { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.demo-code-content img {
  width: 112px; height: 112px; flex: 0 0 112px; border: 1px solid var(--line);
  border-radius: 9px; background: white; padding: 4px;
}
.demo-code-info { min-width: 0; font-size: 12px; line-height: 1.5; }
.demo-code-info strong { display: block; overflow-wrap: anywhere; }
.demo-code-info p { margin: 4px 0 0; color: var(--muted); }

.side-column { display: grid; gap: 16px; }
.voter-row {
  display: flex; align-items: center; gap: 12px; margin-top: 15px; padding: 12px;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px;
}
.avatar {
  width: 42px; height: 42px; display: grid; place-items: center; color: white;
  background: var(--green); border-radius: 50%; font-size: 15px; font-weight: 800;
}
.voter-name { font-weight: 800; font-size: 14px; color: var(--primary); }
.voter-id { color: var(--muted); margin-top: 3px; font-size: 12px; overflow-wrap: anywhere; }
.empty-voter {
  color: var(--muted); margin: 13px 0 1px; font-size: 13px; line-height: 1.55;
  padding: 12px; background: #f8fafc; border: 1px dashed var(--line); border-radius: 8px; text-align: center;
}
.notice {
  display: flex; gap: 10px; align-items: flex-start; color: #92400e; background: #fffbeb;
  border: 1px solid #fde68a; border-radius: 14px; padding: 14px; font-size: 12px; line-height: 1.5;
}
.info-list { display: grid; gap: 12px; margin-top: 15px; }
.info-item { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.info-item:last-child { border-bottom: none; padding-bottom: 0; }
.info-item span:first-child { color: var(--muted); }
.info-item strong { text-align: right; }
.footer { margin-top: 25px; color: var(--muted); text-align: center; font-size: 11px; }
.footer a { color: var(--primary-light); font-weight: 700; }

.voting-screen {
  position: relative; width: min(980px, 100%); min-height: 630px; margin: 0 auto; overflow: hidden;
  border: 1px solid var(--line); border-radius: 22px; background: var(--paper);
  box-shadow: 0 24px 58px rgba(15, 23, 42, .15);
}
.voting-screen-header {
  min-height: 70px; display: grid; place-content: center; padding: 10px 18px; color: white;
  background: linear-gradient(135deg, #1e3a8a, #3b82f6); text-align: center;
}
.voting-screen-header strong { font-size: 14px; letter-spacing: .05em; }
.voting-screen-header span { display: block; margin-top: 4px; color: rgba(255,255,255,.9); font-size: 11px; }
.voting-content { width: min(100% - 24px, 960px); margin: 22px auto 30px; text-align: center; }

.candidate-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); justify-content: center; gap: 22px; margin-top: 22px; }
.candidate {
  position: relative; width: 100%; min-height: 300px; display: flex; flex-direction: column; align-items: center;
  padding: 26px 10px 14px; color: var(--ink); background: white; border: 2px solid var(--line);
  border-radius: 16px; box-shadow: 0 8px 18px rgba(0,0,0,.05);
}
.candidate.selected { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(217, 119, 6, .15); background: #fffbeb; }
.candidate-number {
  position: absolute; z-index: 1; top: 0; left: 50%; display: grid; place-items: center;
  width: 42px; height: 42px; transform: translate(-50%, -50%); border: 4px solid white; border-radius: 50%;
  background: var(--gold); color: white; font-size: 16px; font-weight: 800;
}
.candidate-photo {
  width: min(100%, 180px); aspect-ratio: 3 / 3.6; height: auto; display: grid; place-items: center; overflow: hidden;
  border: 1px solid var(--line); border-radius: 12px; background: #f8fafc;
}
.candidate-photo img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.candidate-name { display: block; margin-top: 14px; font-weight: 800; font-size: 13px; line-height: 1.4; }
.ballot-actions { display: flex; justify-content: center; gap: 10px; margin-top: 24px; }
.ballot-actions .button { width: min(100%, 280px); min-height: 48px; }

.confirmation-card { width: min(100%, 336px); margin: 20px auto 0; padding: 24px 14px; border: 1px solid var(--line); border-radius: 16px; background: #f8fafc; }
.confirmation-photo { display: flex; justify-content: center; }
.confirmation-photo .candidate-photo { width: 126px; height: 151px; border: 4px solid var(--gold); }
.confirmation-name { display: block; margin-top: 16px; font-size: 18px; font-weight: 800; }
.confirmation-number { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }
#retry-selection { background: #dc2626; }

.success-overlay {
  position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: 24px;
  background: rgba(15,23,42,.72); backdrop-filter: blur(4px);
}
.success-card { width: min(360px, 100%); padding: 46px 24px 34px; border-radius: 24px; background: white; text-align: center; }
.success-icon {
  width: 80px; height: 80px; display: grid; place-items: center; margin: 0 auto 20px; border-radius: 50%;
  background: var(--green); color: white;
}
.success-icon svg { width: 40px; height: 40px; }
.success-card h2 { margin: 0 0 8px; font-size: 24px; }
.success-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.results-section { padding: 8px 8px 0; text-align: left; }
.chart-wrap { height: 240px; margin-top: 12px; min-width: 0; max-width: 100%; }
.chart-wrap canvas { max-width: 100%; }
.result-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 12px; background: #f8fafc; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); min-width: 0; }
.result-label { width: auto; flex: 1 1 140px; min-width: 0; font-size: 13px; font-weight: 700; }
.result-track { height: 12px; flex: 1; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.result-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #3b82f6, #1e3a8a); transition: width .45s ease; }
.result-count { width: 92px; text-align: right; color: var(--muted); font-size: 12px; font-weight: 700; }
.results-total { margin-top: 16px; font-weight: 800; text-align: right; }
.results-section .ballot-actions { flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 18px; }
.results-section .ballot-actions .button { width: auto; }

body.voting-active { background: #cbd5e1; }
body.voting-active .topbar,
body.voting-active .intro,
body.voting-active .layout,
body.voting-active .footer { display: none; }
body.voting-active main { width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }

@media (max-width: 991px) {
  .layout { grid-template-columns: 1fr; }
  main { width: min(100% - 28px, 1080px); }
}
@media (min-width: 577px) and (max-width: 991px) {
  .candidate-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .candidate { max-width: none; }
}
@media (max-width: 576px) {
  .topbar { height: auto; min-height: 64px; padding: 10px 12px; }
  .brand { min-width: 0; }
  .brand small { display: block; }
  main { width: min(100% - 20px, 1080px); padding-top: 20px; }
  .intro { padding: 20px 16px; }
  .layout, .candidate-grid { grid-template-columns: 1fr; }
  .candidate { max-width: 420px; margin: 0 auto; }
  .candidate-photo { width: min(100%, 240px); }
  .camera-frame { aspect-ratio: 4 / 3; }
  .manual-form, .ballot-actions { flex-direction: column; }
  .manual-form .button, .ballot-actions .button, .qr-image-button { width: 100%; }
  .result-label, .result-count { width: 100%; flex-basis: 100%; text-align: left; }
  .voting-screen { min-height: calc(100dvh - 24px); border-radius: 16px; }
  .confirmation-card, .success-card { width: min(100%, 420px); }
  .demo-code-content { flex-direction: column; align-items: flex-start; }
}
