:root {
  --bg: #FFFFFF;
  --surface: #F5F6FB;
  --surface-2: #ECEEF8;
  --paper: #FFFFFF;
  --ink: #101562;
  --ink-soft: #63698F;
  --navy: #101562;
  --navy-deep: #0C1147;
  --gold: #EFAC1F;
  --gold-soft: #F9E4B4;
  --green: #1E9E5A;
  --red: #D64545;
  --text: #101562;
  --text-dim: #6B7299;
  --line: #E4E7F3;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(16, 21, 98, 0.1);
  --font-display: "Barlow Condensed", "Kantumruy Pro", "Arial Narrow", sans-serif;
  --font-body: "Kantumruy Pro", "Inter", system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

.center { text-align: center; }

/* ---------- Masthead ---------- */

.masthead {
  padding: 28px 20px 20px;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.masthead::after {
  content: "";
  position: absolute;
  left: 20px; right: 20px; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--navy) 0 96px, var(--gold) 96px 128px, transparent 128px);
}

.masthead-club {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.masthead-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 40px;
  line-height: 0.98;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  color: var(--navy);
  margin-top: 6px;
}

.masthead-title .gold { color: var(--gold); }

.masthead-sub {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------- Screens ---------- */

.screen { padding: 24px 20px 40px; min-height: 40vh; }

.spinner {
  width: 34px; height: 34px;
  margin: 64px auto 14px;
  border: 3px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.screen-note { color: var(--text-dim); font-size: 14px; margin-top: 10px; }

.screen-heading {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--navy);
  margin-top: 14px;
}

.screen-fail {
  width: 56px; height: 56px;
  margin: 40px auto 0;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--gold);
}

/* ---------- Welcome / ID card ---------- */

.id-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.id-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy), var(--navy-deep));
  color: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  display: grid;
  place-items: center;
  flex: none;
}

.id-greeting { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.id-name { font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1.1; color: var(--navy); }
.id-handle { color: var(--text-dim); font-size: 13px; }

.screen#screen-welcome .screen-note { margin: 16px 0; }

/* ---------- Ballot ---------- */

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy);
}

.ballot-head { margin-bottom: 22px; }

.ballot-rule { color: var(--text-dim); font-size: 14px; margin-top: 6px; }

.dept { margin-bottom: 26px; }

.dept-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
  padding-left: 12px;
  border-left: 3px solid var(--gold);
}

.dept-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy);
}

.dept-count { color: var(--text-dim); font-size: 12px; }

/* ---------- Ticket ---------- */

.ticket {
  display: flex;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(16, 21, 98, 0.06);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative;
}

.ticket:active { transform: scale(0.985); box-shadow: none; }

.ticket-stub {
  width: 54px;
  flex: none;
  background: linear-gradient(180deg, var(--navy), var(--navy-deep));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #fff;
}

.ticket-stub .stub-word {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.9;
}

.ticket-stub .stub-no { font-family: var(--font-display); font-weight: 800; font-size: 20px; }

.ticket-body {
  flex: 1;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

.ticket-fringe {
  position: absolute;
  right: -8px;
  top: 0;
  bottom: 0;
  width: 16px;
  background: var(--bg);
  -webkit-mask-image: radial-gradient(circle 7px at 8px 22px, transparent 6px, black 6.5px);
  mask-image: radial-gradient(circle 7px at 8px 22px, transparent 6px, black 6.5px);
  -webkit-mask-repeat: repeat-y;
  mask-repeat: repeat-y;
  -webkit-mask-size: 16px 44px;
  mask-size: 16px 44px;
}

.ticket-top {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--navy);
}

.ticket-name { font-family: var(--font-display); font-weight: 700; font-size: 22px; line-height: 1.05; color: var(--navy); }

.ticket-title { font-size: 13px; color: var(--ink-soft); }

.ticket-body.has-photo { padding-right: 64px; }

.ticket-photo {
  position: absolute;
  top: 10px; right: 12px;
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold);
}

.ticket-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(16, 21, 98, 0.3);
}

.ticket-foot span {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.ticket-arrow { color: var(--gold); font-size: 14px; }

/* ---------- Done / stamp ---------- */

.stamp {
  width: 76px; height: 76px;
  margin: 40px auto 0;
  border-radius: 50%;
  border: 3px solid var(--green);
  color: var(--green);
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 700;
  transform: rotate(-8deg);
}

.stamp.error { border-color: var(--red); color: var(--red); }

.done-fine {
  margin-top: 26px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.06s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.98); }

.btn.full { width: 100%; margin-top: 10px; }

.btn-gold { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: var(--navy); }
.btn-gold:hover { filter: brightness(1.04); }

.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { filter: brightness(1.12); }

.btn-ghost {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--line);
}
.btn-ghost:hover { border-color: var(--text-dim); }

/* ---------- Modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  background: rgba(16, 21, 98, 0.35);
  animation: fade-in 0.18s ease;
}

.modal.centered { align-items: center; padding: 0 24px; }

@keyframes fade-in { from { opacity: 0; } }

.sheet {
  width: 100%;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slide-up 0.22s ease;
}

@keyframes slide-up { from { transform: translateY(24px); opacity: 0.6; } }

.sheet-ticket {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.sheet-avatar {
  width: 52px; height: 52px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--navy), var(--navy-deep));
  color: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
}

.sheet-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.sheet-name { font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1.05; color: var(--navy); }
.sheet-title { font-size: 13px; color: var(--ink-soft); }

.sheet-note { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }

.dialog {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 20px 20px;
  animation: pop 0.16s ease;
}

@keyframes pop { from { transform: scale(0.95); opacity: 0.5; } }

.dialog-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  text-transform: uppercase;
  color: var(--navy);
  margin-top: 4px;
}

.dialog-note { color: var(--text-dim); font-size: 14px; margin-top: 6px; }
.dialog-note strong { color: var(--navy); }

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.dialog-actions .btn { flex: 1; padding: 13px 10px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 20px; right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 60;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 14px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: slide-up 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}