RotatyVote: in-person anonymous voting with rotating QR enrollment

Starlette backend with sqlite, rotating HMAC QR tokens pushed to a
key-protected projector page, multi-scan enrollment, optional one-time
paper codes, anonymous ballots split from participation, live question
push over websockets, e2e tests over HTTP and TLS.
This commit is contained in:
2026-08-16 12:58:26 +01:00
commit 72273d5b06
39 changed files with 3787 additions and 0 deletions
+158
View File
@@ -0,0 +1,158 @@
:root {
--bg: #f5f6fa;
--surface: #ffffff;
--ink: #1c2036;
--ink-2: #4a4f66;
--ink-3: #8a8fa3;
--line: #e4e6ee;
--mark: #ffcc00;
--mark-soft: #fff6cc;
--ok: #138a5e;
--ok-soft: #e2f4ec;
--bad: #c8322b;
--bad-soft: #fbe7e5;
--round: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
--sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
--r-card: 18px;
--r-field: 12px;
color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
margin: 0;
background: var(--bg);
color: var(--ink);
font: 16px/1.5 var(--sans);
font-variant-numeric: tabular-nums;
-webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--round); font-weight: 700; line-height: 1.15; letter-spacing: -.015em; margin: 0 0 .6em; }
h1 { font-size: 1.85rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
a { color: inherit; }
small, .muted { color: var(--ink-3); }
[hidden] { display: none !important; }
.wrap { max-width: 1060px; margin: 0 auto; padding: 20px 16px 64px; }
.narrow { max-width: 480px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 28px; }
.brand { display: inline-flex; align-items: center; gap: 9px; font: 700 1.1rem var(--round); letter-spacing: -.02em; text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.brand b { font-weight: 700; color: var(--ink-3); }
.card { background: var(--surface); border-radius: var(--r-card); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid.admin { grid-template-columns: 310px 1fr; align-items: start; } }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin: 14px 0 6px; }
label.inline { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--ink); }
.hint { font-size: .82rem; color: var(--ink-3); margin: 4px 0 0; }
input[type=text], input[type=number], input[type=password], select, textarea {
width: 100%; font: inherit; color: inherit; background: var(--bg);
border: 1.5px solid transparent; border-radius: var(--r-field); padding: 10px 12px;
transition: border-color .15s, background .15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--line); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); background: var(--surface); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }
textarea { min-height: 100px; resize: vertical; }
button:focus-visible, .btn:focus-visible { outline: 3px solid var(--mark); outline-offset: 2px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 120px; }
button, .btn {
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
font: 600 .95rem var(--round); padding: 11px 20px; border-radius: 999px; cursor: pointer;
border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none;
transition: background .15s, border-color .15s, transform .1s;
}
button:hover, .btn:hover { border-color: var(--ink-3); }
button:active, .btn:active { transform: scale(.97); }
button:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.primary { background: var(--mark); border-color: var(--mark); }
.primary:hover { background: #f5c200; border-color: #f5c200; }
.go { background: var(--ink); border-color: var(--ink); color: #fff; }
.go:hover { background: #2c3150; border-color: #2c3150; }
.danger { color: var(--bad); }
.small { padding: 7px 14px; font-size: .85rem; }
.block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.badge {
display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600;
padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--ink-2);
}
.badge.open { background: var(--ok-soft); color: var(--ok); }
.badge.open::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.8s infinite; }
.badge.public { background: var(--mark-soft); color: #7a5c00; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .badge.open::before { animation: none; } }
.notice { border-radius: var(--r-field); padding: 10px 14px; font-size: .9rem; margin: 10px 0; background: var(--bg); }
.notice.warn { background: var(--mark-soft); color: #5c4500; }
.notice.bad { background: var(--bad-soft); color: #7d1a12; }
.notice.ok { background: var(--ok-soft); color: #0b5a3c; }
.notice.info { background: var(--bg); color: var(--ink-2); }
.stat { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.stat b { font: 700 2.8rem/1 var(--round); letter-spacing: -.03em; }
.q { background: var(--surface); border-radius: var(--r-card); padding: 18px 20px; margin-bottom: 12px; border: 1.5px solid transparent; }
.q.open { border-color: var(--ink); }
.q-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.q-head > div { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.q-text { font: 700 1.15rem/1.3 var(--round); margin: 10px 0; }
.q-opts { margin: 0 0 8px; padding-left: 20px; color: var(--ink-2); }
.q-meta { font-size: .82rem; color: var(--ink-3); margin: 4px 0; }
.focus-mark { font-size: .78rem; font-weight: 600; color: var(--ink); background: var(--mark); padding: 3px 10px; border-radius: 999px; }
.templates { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.results { margin-top: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 30%) 1fr auto; gap: 12px; align-items: center; margin: 8px 0; }
.bar-label { overflow-wrap: anywhere; }
.bar-track { height: 12px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ink-3); border-radius: 99px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.bar-row.lead .bar-fill { background: var(--mark); }
.bar-row.lead .bar-label { font-weight: 700; }
.bar-num { font: 700 1rem var(--round); min-width: 80px; text-align: right; }
.bar-num small { font-weight: 500; }
.results-foot { font-size: .82rem; color: var(--ink-3); margin-top: 10px; }
.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--ink); border-radius: 99px; transition: width .3s; }
.ring { display: block; overflow: visible; }
.ring .seg { fill: none; stroke: var(--line); stroke-linecap: round; transition: stroke .3s; }
.ring .seg.on { stroke: var(--ink); }
.ring .seg.last { stroke: var(--mark); }
.ring text { font: 700 20px var(--round); fill: var(--ink); }
.codes-print { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 12px; }
.code-cell { font: 700 1.1rem var(--round); letter-spacing: .08em; text-align: center; border: 1.5px dashed var(--line); padding: 14px 6px; border-radius: var(--r-field); }
.code-cell.used { color: var(--ink-3); text-decoration: line-through; }
.linkbox { display: flex; gap: 8px; align-items: center; }
.linkbox input { font-size: .8rem; }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 400px); }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 600; text-align: center; animation: rise .25s ease-out; }
.toast.bad { background: var(--bad); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.conn { font-size: .8rem; color: var(--ink-3); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.conn.online::before { background: var(--ok); }
.conn.offline::before { background: var(--bad); }
@media print {
body { background: #fff; }
.no-print, .topbar, #toasts { display: none !important; }
.card { padding: 0; }
.code-cell { break-inside: avoid; }
}
+66
View File
@@ -0,0 +1,66 @@
body.screen {
height: 100vh; height: 100dvh; overflow: hidden;
display: grid; grid-template-rows: auto 1fr auto;
background: var(--bg);
}
.s-head, .s-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 2vh 3vw; }
.s-title { font: 700 clamp(1rem, 2vw, 2rem) var(--round); text-align: center; flex: 1; color: var(--ink-2); }
.s-tools { display: flex; gap: 10px; align-items: center; }
:fullscreen .s-tools button { display: none; }
.s-main { min-height: 0; display: grid; padding: 1vh 4vw; }
.s-enroll { display: grid; grid-template-columns: auto 1fr; gap: 5vw; align-items: center; min-height: 0; }
.qr-wrap {
height: 100%; max-height: 74vh; aspect-ratio: 1; display: grid; grid-template-rows: 1fr auto;
background: #fff; border-radius: 28px; padding: 2vh; gap: 1.4vh;
}
#qr { width: 100%; height: 100%; min-height: 0; image-rendering: pixelated; image-rendering: crisp-edges; object-fit: contain; }
.tick { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 0 1vh; }
#tick-bar { height: 100%; width: 0; background: var(--mark); border-radius: 99px; }
.s-steps h2 { font-size: clamp(2rem, 4.6vw, 5rem); letter-spacing: -.03em; margin-bottom: .5em; }
.s-steps ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 2vh; counter-reset: s; }
.s-steps li {
counter-increment: s; display: flex; align-items: center; gap: 1.2vw;
font: 600 clamp(1.1rem, 2.3vw, 2.5rem) var(--round); color: var(--ink-2);
}
.s-steps li::before {
content: counter(s); flex: none; display: grid; place-items: center;
width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--surface); color: var(--ink);
font-weight: 700; font-size: .8em;
}
/* enrollment + a question at the same time: qr shrinks to the side */
.s-main.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 5vw; }
.s-main.split .s-enroll { grid-template-columns: 1fr; justify-items: center; gap: 3vh; }
.s-main.split .qr-wrap { max-height: 52vh; }
.s-main.split .s-steps h2 { font-size: clamp(1.4rem, 2.4vw, 2.6rem); }
.s-main.split .s-steps li { font-size: clamp(1rem, 1.5vw, 1.6rem); }
.s-focus { align-self: center; max-width: 1400px; width: 100%; margin: 0 auto; }
.s-focus .q-text { font-size: clamp(1.8rem, 3.8vw, 4rem); letter-spacing: -.025em; line-height: 1.1; margin-bottom: 4vh; }
.s-focus .opts { list-style: none; padding: 0; margin: 0 0 4vh; display: grid; gap: 1.4vh; }
.s-focus .opts li { font: 600 clamp(1.1rem, 2.2vw, 2.3rem) var(--round); background: var(--surface); border-radius: 20px; padding: 1.6vh 2vw; }
.s-focus .turnout { font: 600 clamp(1rem, 1.8vw, 1.9rem) var(--round); color: var(--ink-2); }
.s-focus .turnout b { color: var(--ink); font-size: 1.5em; }
.s-focus .turnout .progress { height: 14px; margin-top: 1.2vh; background: var(--surface); }
.s-focus .results .bar-row { font-size: clamp(1rem, 2.1vw, 2.2rem); grid-template-columns: minmax(120px, 32%) 1fr auto; gap: 2vw; margin: 2vh 0; }
.s-focus .results .bar-track { height: clamp(16px, 3vh, 40px); background: var(--surface); }
.s-focus .results .bar-num { min-width: 7ch; font-size: 1em; }
.s-focus .results-foot { font-size: clamp(.9rem, 1.3vw, 1.3rem); }
.s-focus .status { font: 600 clamp(1rem, 1.8vw, 1.9rem) var(--round); color: var(--ink-2); }
.s-idle { place-self: center; text-align: center; }
.s-idle h1 { font-size: clamp(2.4rem, 5.5vw, 6rem); letter-spacing: -.03em; }
.s-idle img { width: clamp(64px, 9vw, 140px); margin-bottom: 3vh; animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .s-idle img { animation: none; } }
.s-count { font: 600 clamp(.95rem, 1.5vw, 1.5rem) var(--round); color: var(--ink-2); display: flex; align-items: baseline; gap: .4em; }
.s-count b { font-size: 2.2em; line-height: 1; color: var(--ink); letter-spacing: -.03em; }
.screen-center { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 10; padding: 16px; }
@media (max-aspect-ratio: 1/1) {
.s-enroll, .s-main.split { grid-template-columns: 1fr; }
.qr-wrap { max-height: 50vh; justify-self: center; }
}
+46
View File
@@ -0,0 +1,46 @@
body.voter { padding-bottom: env(safe-area-inset-bottom); }
body.voter h1 { font-size: 1.6rem; margin-bottom: 18px; }
.center { text-align: center; }
#v-enroll .card { padding: 28px 20px 20px; text-align: center; }
.dots { display: grid; place-items: center; margin-bottom: 14px; }
.cam { position: relative; border-radius: var(--r-card); overflow: hidden; background: var(--ink); aspect-ratio: 1; margin: 6px 0 12px; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-msg { text-align: center; min-height: 1.4em; font-size: .9rem; margin: 0 0 12px; }
.scan-msg:empty { display: none; }
.scan-msg.bad { color: var(--bad); }
.scan-msg.ok { color: var(--ok); }
#code { font: 700 1.5rem var(--round); text-align: center; letter-spacing: .12em; text-transform: uppercase; }
.enrolled-chip { margin: -8px 0 8px; }
.vq { background: var(--surface); border-radius: var(--r-card); padding: 20px; margin: 14px 0; border: 1.5px solid transparent; }
.vq.open { border-color: var(--ink); }
.vq .q-text { font: 700 1.25rem/1.3 var(--round); margin: 0 0 14px; }
.choice {
display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; font: 600 1.05rem var(--round);
padding: 14px 16px; margin: 8px 0; min-height: 56px; border-radius: 16px; border: 1.5px solid var(--line);
justify-content: flex-start; user-select: none; -webkit-user-select: none;
}
.choice:active { transform: scale(.985); }
.choice .mark { flex: none; width: 24px; height: 24px; border: 2px solid var(--ink-3); border-radius: 50%; display: grid; place-items: center; transition: border-color .15s; }
.choice.multi .mark { border-radius: 7px; }
.choice[aria-checked="true"] { background: var(--mark); border-color: var(--mark); }
.choice[aria-checked="true"] .mark { border-color: var(--ink); background: var(--ink); }
.choice[aria-checked="true"] .mark::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--mark); }
.choice.multi[aria-checked="true"] .mark::after { border-radius: 2px; }
.choice.blank { color: var(--ink-2); border-style: dashed; }
.choice.blank[aria-checked="true"] { background: var(--bg); border-color: var(--ink-3); color: var(--ink); }
.vq .go { margin-top: 10px; padding: 14px; font-size: 1.05rem; }
.voted { display: flex; gap: 10px; align-items: center; font: 600 1rem var(--round); margin: 0; color: var(--ink-2); }
.voted::before { content: "✓"; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--mark); color: var(--ink); font-weight: 800; }
.waiting { text-align: center; padding: 36px 0; color: var(--ink-3); }
dialog { border: none; border-radius: 24px; padding: 24px; width: min(92vw, 400px); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(28, 32, 54, .45); backdrop-filter: blur(2px); }
dialog[open] { animation: rise .2s ease-out; }
#confirm-choices { list-style: none; padding: 0; margin: 0 0 8px; }
#confirm-choices li { font: 700 1.2rem var(--round); background: var(--mark); border-radius: 12px; padding: 10px 14px; margin: 6px 0; }
dialog .actions button { flex: 1; }