:root {
  --paper: #ffffff;
  --linen: #f2f5f3;
  --line: #d9e1dc;
  --ink: #16302b;
  --muted: #5d6e67;
  --tomato: #d93a2b;
  --tomato-dark: #b52c1f;
  --tomato-soft: #fbe7e4;
  --basil: #2e7d4f;
  --basil-soft: #e3f2e8;
  --mustard: #f4b63f;
  --mustard-soft: #fff4d9;

  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius-sm: 8px;
  --radius: 14px;
  --shadow-ticket: 0 1px 0 var(--line), 0 18px 40px -22px rgba(22, 48, 43, .45);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  font-variation-settings: "wdth" 100;
}
main { outline: none; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.1; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Gingham: the tablecloth ---------- */
.gingham {
  background-color: #fff;
  background-image:
    linear-gradient(90deg, rgba(217, 58, 43, .42) 50%, transparent 50%),
    linear-gradient(rgba(217, 58, 43, .42) 50%, transparent 50%);
  background-size: 30px 30px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 20px; text-decoration: none; letter-spacing: -.01em;
  font-variation-settings: "wdth" 85;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: url(favicon.svg) center / cover;
}
.nav { display: flex; align-items: center; gap: 4px; }
.nav a, .nav button {
  background: none; border: 0; cursor: pointer;
  padding: 7px 12px; border-radius: 999px; text-decoration: none; font-size: 15px; color: var(--muted);
}
.nav a:hover, .nav button:hover { background: var(--linen); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--linen); font-weight: 600; }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; cursor: pointer;
  padding: 12px 22px; font-weight: 700; font-size: 16px;
  background: var(--tomato); color: #fff;
  transition: background .15s, transform .1s;
}
.btn:hover { background: var(--tomato-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.ghost:hover { background: var(--linen); }
.btn.small { padding: 7px 14px; font-size: 14px; }
.btn.quiet { background: var(--linen); color: var(--ink); }
.btn.quiet:hover { background: var(--line); }
.btn.danger { background: transparent; color: var(--tomato-dark); box-shadow: inset 0 0 0 1.5px var(--tomato-soft); }
.btn.danger:hover { background: var(--tomato-soft); }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-weight: 600; font-size: 15px; }
.field small { color: var(--muted); font-size: 14px; }
.input, select.input {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: #fff; font-size: 16px; min-height: 48px;
}
.input:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px var(--mustard-soft); }
.form-error { color: var(--tomato-dark); font-weight: 600; min-height: 1.5em; margin: 0 0 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; }

/* ---------- Hero ---------- */
.hero { padding: 36px 16px 0; }
.hero.gingham { border-bottom: 1px solid var(--line); }
.ticket {
  position: relative;
  max-width: 680px; margin: 0 auto -1px;
  background: var(--paper);
  padding: 28px 28px 34px;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-ticket);
}
.ticket::after {
  /* perforated bottom edge, like a waiter's order pad */
  content: ""; position: absolute; left: 0; right: 0; bottom: -9px; height: 10px;
  background: radial-gradient(circle at 8px 0, transparent 6px, var(--paper) 6.5px) 0 0 / 16px 10px repeat-x;
}
.ticket-day { color: var(--tomato); font-weight: 700; font-size: 17px; margin: 0 0 4px; }
.ticket h1 {
  font-size: clamp(40px, 9vw, 68px); font-weight: 800; letter-spacing: -.035em;
  font-variation-settings: "wdth" 78; line-height: .95;
}
.ticket-meta { margin: 16px 0 0; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
.stamp {
  position: absolute; right: 22px; top: 22px;
  border: 3px solid var(--basil); color: var(--basil); border-radius: 10px;
  padding: 4px 12px; font-weight: 800; font-size: 20px; letter-spacing: .02em;
  transform: rotate(-8deg); background: rgba(255, 255, 255, .85);
  font-variation-settings: "wdth" 80;
  animation: stamp .35s cubic-bezier(.2, 1.6, .4, 1) both;
}
@keyframes stamp { from { transform: rotate(-8deg) scale(1.8); opacity: 0; } }

.plates { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 18px; }
.plate { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); }
.plate.full { border-color: var(--basil); background: radial-gradient(circle, var(--basil) 0 35%, var(--basil-soft) 36%); }
.plates-label { color: var(--muted); font-size: 15px; margin: 8px 0 0; }

/* ---------- Page body ---------- */
.page { max-width: 680px; margin: 0 auto; padding: 32px 16px 120px; }
.page.wide { max-width: 1080px; }
.section-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 6px; font-variation-settings: "wdth" 85; }
.section-lead { color: var(--muted); margin: 0 0 20px; }

/* ---------- The menu (vote list) ---------- */
.menu { list-style: none; margin: 0; padding: 0; }
.menu li { position: relative; }
.menu li + li { border-top: 1px dashed var(--line); }
.dish {
  display: grid; grid-template-columns: 28px 1fr; gap: 2px 14px; align-items: start;
  padding: 16px 10px; margin: 0 -10px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background .15s;
}
.dish:hover { background: var(--linen); }
.dish input { position: absolute; opacity: 0; pointer-events: none; }
.dish-mark {
  grid-row: span 2; margin-top: 4px;
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); background: #fff;
  transition: border-color .15s, background .15s;
}
.dish input:checked ~ .dish-mark { border-color: var(--tomato); background: radial-gradient(circle, var(--tomato) 0 45%, #fff 47%); }
.dish input:focus-visible ~ .dish-mark { outline: 3px solid var(--mustard); outline-offset: 2px; }
.dish:has(input:checked) { background: var(--tomato-soft); }
.dish-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.dish-name { font-weight: 700; font-size: 20px; letter-spacing: -.01em; }
.dish-leader { flex: 1; border-bottom: 2px dotted var(--line); transform: translateY(-5px); min-width: 20px; }
.dish-dist { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 15px; }
.dish-sub { color: var(--muted); font-size: 15px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.dish-sub a { color: var(--muted); }
.menu.locked .dish { cursor: default; grid-template-columns: 1fr; }
.menu.locked .dish:hover { background: none; }

.votebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  transform: translateY(110%); transition: transform .25s ease;
}
.votebar.show { transform: none; }
.votebar .btn { width: 100%; max-width: 680px; padding: 15px 22px; font-size: 17px; }

.note {
  background: var(--linen); border-radius: var(--radius); padding: 16px 18px; color: var(--muted); margin: 0 0 20px;
}
.note strong { color: var(--ink); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }

/* ---------- Result ---------- */
.result { margin-bottom: 40px; }
.result-winner {
  border-radius: var(--radius); padding: 22px 22px 20px; margin-bottom: 18px;
  background: var(--ink); color: #fff; position: relative; overflow: hidden;
}
.result-winner .when { color: var(--mustard); font-weight: 700; margin: 0 0 6px; }
.result-winner h2 { font-size: clamp(32px, 7vw, 48px); font-weight: 800; letter-spacing: -.03em; font-variation-settings: "wdth" 80; }
.result-winner p { margin: 8px 0 0; color: #c9d6d1; }
.result-winner .btn.ghost { color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .35); margin-top: 14px; }
.result-winner .btn.ghost:hover { background: rgba(255, 255, 255, .08); }

.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 16px; }
.bar-track { display: block; grid-column: 1 / -1; height: 10px; border-radius: 99px; background: var(--linen); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 99px; background: var(--line); width: 0; transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.bar.win .bar-fill { background: var(--tomato); }
.bar.win .bar-name { font-weight: 700; }
.bar-count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- The draw ---------- */
.draw { margin: 18px 0 0; }
.draw-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.draw-item {
  padding: 12px 16px; border-radius: var(--radius-sm); font-weight: 700; font-size: 19px;
  background: rgba(255, 255, 255, .06); color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .15);
  transition: background .08s, color .08s, transform .08s;
  display: flex; justify-content: space-between; align-items: center;
}
.draw-item.lit { background: var(--mustard); color: var(--ink); transform: scale(1.02); }
.draw-item.won { background: var(--mustard); color: var(--ink); animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
.draw-item .tag { font-size: 14px; font-weight: 700; }
@keyframes pop { 50% { transform: scale(1.06); } }

/* ---------- Auth pages ---------- */
.auth.gingham { background-size: 22px 22px; }
.auth { min-height: calc(100vh - 57px); display: grid; place-items: center; padding: 32px 16px; }
.auth .ticket { width: 100%; max-width: 420px; border-radius: var(--radius); }
.auth .ticket::after { display: none; }
.auth h1 { font-size: 38px; margin-bottom: 8px; }
.auth p.lead { color: var(--muted); margin: 0 0 24px; }
.auth .btn { width: 100%; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 28px; padding-bottom: 4px; scrollbar-width: none; }
.tabs a {
  white-space: nowrap; padding: 9px 16px; border-radius: 999px; text-decoration: none; font-weight: 600; font-size: 15px;
  box-shadow: inset 0 0 0 1.5px var(--line); color: var(--muted);
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--ink); color: #fff; box-shadow: none; }

.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list > li { display: flex; gap: 14px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list .grow { flex: 1 1 220px; min-width: 0; }
.list .title { font-weight: 700; }
.list .sub { color: var(--muted); font-size: 15px; display: flex; flex-wrap: wrap; gap: 2px 12px; }
.list .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.list li.off .title, .list li.off .emoji { opacity: .45; }
.emoji { font-size: 24px; width: 32px; text-align: center; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; background: var(--linen); color: var(--muted); }
.pill.admin { background: var(--ink); color: #fff; }
.pill.ok { background: var(--basil-soft); color: var(--basil); }
.pill.wait { background: var(--mustard-soft); color: #8a5a00; }
.pill.bad { background: var(--tomato-soft); color: var(--tomato-dark); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 40px; height: 24px; border-radius: 99px; background: var(--line); position: relative; transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--basil); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 3px solid var(--mustard); outline-offset: 2px; }

.panel { background: var(--linen); border-radius: var(--radius); padding: 20px; margin-bottom: 28px; }
.panel h3 { font-size: 19px; margin-bottom: 14px; }
.linkbox { display: flex; gap: 8px; margin-top: 12px; }
.linkbox input { flex: 1; font-size: 14px; }

.suggest { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.map { height: 460px; border-radius: var(--radius); border: 1px solid var(--line); position: sticky; top: 76px; z-index: 1; }
.map.small { height: 240px; position: static; }
.suggest .list { max-height: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.chip { border: 0; cursor: pointer; padding: 6px 12px; border-radius: 99px; background: #fff; box-shadow: inset 0 0 0 1.5px var(--line); font-size: 14px; font-weight: 600; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; box-shadow: none; }
.geo-results { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 6px; }
.geo-results button { width: 100%; text-align: left; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; font-size: 15px; }
.geo-results button:hover { border-color: var(--ink); }

table.history { width: 100%; border-collapse: collapse; font-size: 16px; }
.history th { text-align: left; font-weight: 600; color: var(--muted); font-size: 14px; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.history td { padding: 12px 6px; border-bottom: 1px solid var(--line); }
.history td.num { font-variant-numeric: tabular-nums; }

/* ---------- Dialog & toasts ---------- */
dialog {
  border: 0; border-radius: var(--radius); padding: 26px; width: min(460px, calc(100vw - 32px));
  box-shadow: 0 30px 80px -20px rgba(22, 48, 43, .5); color: var(--ink);
}
dialog::backdrop { background: rgba(22, 48, 43, .45); }
dialog h2 { font-size: 26px; margin-bottom: 10px; letter-spacing: -.02em; }
dialog p { color: var(--muted); margin: 0 0 20px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; animation: toast .25s ease; box-shadow: 0 10px 30px -10px rgba(0,0,0,.4); }
.toast.error { background: var(--tomato-dark); }
@keyframes toast { from { opacity: 0; transform: translateY(8px); } }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--tomato); animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 60px 0; text-align: center; }

@media (max-width: 820px) {
  .suggest { grid-template-columns: 1fr; }
  .map { position: static; height: 300px; }
}
@media (max-width: 520px) {
  body { font-size: 16px; }
  .topbar { padding: 10px 16px; }
  .nav a, .nav button { padding: 6px 8px; font-size: 14px; }
  .brand-text { display: none; }
  .ticket { padding: 22px 18px 28px; }
  .stamp { position: static; display: inline-block; margin-top: 14px; }
  .dish-name { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Voter links & admin login ---------- */
textarea.input { resize: vertical; min-height: 120px; line-height: 1.5; }
.admin-login { margin-top: 24px; border-top: 1px dashed var(--line); padding-top: 16px; }
.admin-login summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 15px; }
.admin-login summary:hover { color: var(--ink); }
.admin-login[open] summary { margin-bottom: 16px; }
.auth .note { margin: 0; }
.auth .btn.ghost { width: 100%; }
.links-panel { background: var(--mustard-soft); }
.links-panel .list { border-top-color: rgba(138, 90, 0, .2); }
.links-panel .list > li { border-bottom-color: rgba(138, 90, 0, .2); }
.link-text { font-size: 13px; word-break: break-all; }
.name-search { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 16px 0 0; }
