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

:root {
  --bg:       #090b16;
  --surface:  #111422;
  --card:     #181c30;
  --border:   #222740;
  --text:     #eaecf5;
  --muted:        #636b8a;
  --muted-strong: #9a9fbc;
  --gold:     #FFB612;
  --green:    #007A4D;
  --red:      #E03C31;
  --radius:   20px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'Outfit', system-ui, sans-serif;
}

body {
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse 150% 55% at 5% 0%,   rgba(0, 122, 77, 0.09)  0%, transparent 55%),
    radial-gradient(ellipse 100% 50% at 95% 100%, rgba(224, 60, 49, 0.07) 0%, transparent 55%),
    radial-gradient(ellipse 80% 60%  at 50% 40%,  rgba(255, 182, 18, 0.03) 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── SA Flag Stripe ─────────────────────────────────────────────────────── */
.flag-stripe {
  display: flex;
  height: 5px;
  width: 100%;
  flex-shrink: 0;
}
.fs-seg         { flex: 1; }
.fs-black       { background: #000; flex: 0.9; }
.fs-gold        { background: var(--gold); flex: 0.4; }
.fs-green       { background: var(--green); flex: 2.2; }
.fs-white       { background: rgba(255,255,255,0.85); flex: 0.25; }
.fs-red         { background: var(--red); flex: 1.5; }
.fs-blue        { background: #003DA5; flex: 1.5; }

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  text-align: center;
  padding: clamp(1.4rem, 5vw, 2.8rem) 1rem 0;
  animation: header-in 0.55s ease both;
}

@keyframes header-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.header-eyebrow {
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  margin-bottom: 0.5rem;
  display: block;
  filter: drop-shadow(0 0 16px rgba(255,182,18,0.3));
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 8vw, 5rem);
  font-weight: 900;
  letter-spacing: -1.5px;
  line-height: 1.0;
  background: linear-gradient(140deg, #fff 10%, var(--gold) 60%, #e8a000 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.7rem;
  text-wrap: balance;
}

.subtitle {
  color: #9a9fbc;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 1.4rem;
  letter-spacing: 0.1px;
  text-wrap: balance;
}

nav {
  display: inline-flex;
  gap: 0.4rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px;
  margin-bottom: clamp(1.2rem, 4vw, 2.2rem);
}

.tab {
  background: transparent;
  border: none;
  color: #9a9fbc;
  padding: 0.45rem 1.5rem;
  border-radius: 100px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.2px;
}

.tab:hover  { color: var(--text); }
.tab.active {
  background: var(--gold);
  color: #000;
  font-weight: 700;
  box-shadow: 0 2px 14px rgba(255,182,18,0.4);
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 0 clamp(0.75rem, 3vw, 1.5rem) 5rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.section        { display: none; }
.section.active { display: block; }
.hidden         { display: none !important; }

/* ── Loading ────────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  justify-content: center;
  padding: 5rem 0;
}

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

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

/* ── Matchup — always side-by-side ─────────────────────────────────────── */
.matchup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: clamp(0.35rem, 1.5vw, 0.8rem);
  align-items: stretch;
}

/* ── VS Divider ─────────────────────────────────────────────────────────── */
.vs-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 clamp(0.2rem, 1vw, 0.5rem);
  user-select: none;
}

.vs-line {
  flex: 1;
  width: 1px;
  background: linear-gradient(to bottom, transparent 0%, var(--border) 40%, var(--border) 60%, transparent 100%);
}

.vs-badge {
  width: clamp(2rem, 6.5vw, 2.8rem);
  height: clamp(2rem, 6.5vw, 2.8rem);
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.55rem, 1.8vw, 0.78rem);
  font-weight: 800;
  color: #9a9fbc;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  margin: 0.5rem 0;
  box-shadow: 0 0 18px rgba(255,182,18,0.07), inset 0 1px 0 rgba(255,255,255,0.04);
}

/* ── Candidate card ─────────────────────────────────────────────────────── */
.candidate {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s, opacity 0.3s, filter 0.3s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
  box-shadow: 0 6px 32px rgba(0,0,0,0.4);
}

.candidate:focus-visible  { outline: 2px solid var(--gold); outline-offset: 3px; }
.candidate:active         { transform: scale(0.98); }

@media (hover: hover) {
  .candidate {
    transition: border-color 0.2s, transform 0.16s, box-shadow 0.2s, opacity 0.3s, filter 0.3s;
  }
  .candidate:hover {
    border-color: var(--gold);
    transform: translateY(-5px);
    box-shadow: 0 16px 48px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,182,18,0.25);
  }
  .candidate:hover .photo     { transform: scale(1.05); }
  .candidate:hover .pick-overlay { opacity: 1; }
}

.candidate.winner {
  border-color: #22c55e;
  animation: pulse-win 0.75s ease forwards;
}

.candidate.loser {
  opacity: 0.38;
  filter: grayscale(0.65);
  pointer-events: none;
}

@keyframes pulse-win {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
  60%  { box-shadow: 0 0 0 22px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ── Photo ──────────────────────────────────────────────────────────────── */
.photo-wrap {
  width: 100%;
  aspect-ratio: 3/4;
  overflow: hidden;
  background: var(--surface);
  position: relative;
}

.photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  transition: transform 0.35s ease;
  position: absolute;
  inset: 0;
}

.photo-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 9vw, 5rem);
  font-weight: 700;
  color: var(--border);
  background: var(--surface);
  letter-spacing: -3px;
}

.photo-gradient {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 55%;
  background: linear-gradient(to top, rgba(24, 28, 48, 0.88) 0%, transparent 100%);
  pointer-events: none;
  z-index: 1;
}

/* ── Card info ──────────────────────────────────────────────────────────── */
.info {
  padding: clamp(0.55rem, 2.5vw, 0.9rem) clamp(0.6rem, 2.5vw, 1.1rem) clamp(0.6rem, 2.5vw, 1rem);
}

.party-badge {
  display: inline-block;
  font-size: clamp(0.58rem, 1.8vw, 0.68rem);
  font-weight: 800;
  padding: 2px 9px;
  border-radius: 100px;
  margin-bottom: 0.4rem;
  background: var(--surface);
  color: var(--muted-strong);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.name {
  font-size: clamp(0.8rem, 2.8vw, 1.12rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.25rem;
  letter-spacing: -0.2px;
}

.detail {
  font-size: clamp(0.64rem, 2vw, 0.76rem);
  color: #9a9fbc;
  font-weight: 500;
}

/* ── Pick overlay ───────────────────────────────────────────────────────── */
.pick-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
  z-index: 2;
}

@media (hover: hover) {
  .pick-overlay {
    align-items: center;
    justify-content: center;
    opacity: 0;
    background: rgba(255, 182, 18, 0.07);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    transition: opacity 0.2s;
  }
  .pick-overlay span {
    font-family: var(--font-display);
    font-size: clamp(1.6rem, 5.5vw, 2.6rem);
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 18px rgba(0,0,0,0.95);
    letter-spacing: 2px;
  }
}

@media (hover: none) {
  .pick-overlay {
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0.65rem;
  }
  .pick-overlay span {
    font-size: clamp(0.58rem, 2vw, 0.7rem);
    font-weight: 700;
    background: var(--gold);
    color: #000;
    padding: 3px 10px;
    border-radius: 100px;
    letter-spacing: 0.2px;
  }
}

/* ── Leaderboard ────────────────────────────────────────────────────────── */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.lb-header {
  text-align: center;
  padding: 0.5rem 0 1.8rem;
}

h2 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5.5vw, 2.8rem);
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(140deg, #fff 10%, var(--gold) 60%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.3rem;
}

.lb-note {
  color: #9a9fbc;
  font-size: 0.84rem;
  font-weight: 500;
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lb-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  animation: fade-up 0.28s ease;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.lb-item:hover { border-color: rgba(255,182,18,0.28); box-shadow: 0 4px 16px rgba(0,0,0,0.25); }

.lb-item:nth-child(1) {
  background: linear-gradient(135deg, rgba(255,182,18,0.09) 0%, var(--card) 55%);
  border-color: rgba(255,182,18,0.28);
  box-shadow: 0 4px 24px rgba(255,182,18,0.06);
}
.lb-item:nth-child(2) {
  background: linear-gradient(135deg, rgba(192,192,192,0.07) 0%, var(--card) 55%);
  border-color: rgba(192,192,192,0.2);
}
.lb-item:nth-child(3) {
  background: linear-gradient(135deg, rgba(205,127,50,0.07) 0%, var(--card) 55%);
  border-color: rgba(205,127,50,0.2);
}

.lb-rank {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--muted-strong);
  min-width: 2rem;
  text-align: center;
}
.lb-rank.gold   { color: #FFB612; font-size: 1.35rem; }
.lb-rank.silver { color: #c8c8c8; font-size: 1.2rem; }
.lb-rank.bronze { color: #cd7f32; font-size: 1.12rem; }

.lb-photo {
  width: 48px; height: 48px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top;
  flex-shrink: 0;
  background: var(--surface);
  border: 2px solid var(--border);
}

.lb-info   { flex: 1; min-width: 0; }
.lb-name   { font-weight: 700; font-size: 0.93rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-party  { font-size: 0.76rem; color: var(--muted-strong); margin-top: 3px; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }

.lb-stats  { text-align: right; flex-shrink: 0; }
.lb-elo    { font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; color: var(--gold); }
.lb-record { font-size: 0.74rem; color: var(--muted-strong); }

.lb-empty {
  text-align: center;
  color: var(--muted-strong);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

/* ── Party colours ──────────────────────────────────────────────────────── */
.p-ANC          { background: #005b2e; color: #fff; }
.p-DA           { background: #003DA5; color: #fff; }
.p-MK           { background: #111; color: #4ade80; border: 1px solid #4ade80; }
.p-EFF          { background: #b50000; color: #fff; }
.p-IFP          { background: #b8860b; color: #fff; }
.p-PA           { background: #e05c00; color: #fff; }
.p-ActionSA     { background: #c94800; color: #fff; }
.p-FFPlus       { background: #1a3468; color: #ffad00; }
.p-UDM          { background: #003f7f; color: #fff; }
.p-ACDP         { background: #1a1a6e; color: #fff; }
.p-RISEMZANSI  { background: #6d28d9; color: #fff; }
.p-BOSA         { background: #0369a1; color: #fff; }
.p-ATM          { background: #111; color: #fbbf24; }
.p-NCC          { background: #374151; color: #fff; }
.p-GOOD         { background: #047857; color: #fff; }
.p-UAT          { background: #4b5563; color: #fff; }
.p-PAC          { background: #7f1d1d; color: #fff; }
.p-ALJAMAAAH   { background: #064e3b; color: #a7f3d0; }
.p-default      { background: var(--surface); color: var(--muted); }

/* ── Neither button ─────────────────────────────────────────────────────── */
.matchup-actions {
  text-align: center;
  margin-top: 0.8rem;
}

.neither-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted-strong);
  padding: 0.45rem 1.4rem;
  border-radius: 100px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, transform 0.15s;
  letter-spacing: 0.2px;
}

.neither-btn:hover  { border-color: var(--muted); color: var(--text); transform: translateY(-1px); }
.neither-btn:active { transform: scale(0.97); }
.neither-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

/* Both cards dim equally when neither is chosen */
.candidate.neither {
  opacity: 0.45;
  filter: grayscale(0.55);
  pointer-events: none;
}

.status-line {
  text-align: center;
  color: #9a9fbc;
  font-size: 0.76rem;
  margin-top: 0.5rem;
  min-height: 1.1rem;
  letter-spacing: 0.1px;
}

/* ── Desktop fit — vote screen fits within the viewport without scrolling ── */
@media (min-width: 1024px) {
  main {
    padding-bottom: 1.2rem;
  }
  header {
    padding-top: 0.75rem;
  }
  .header-eyebrow {
    font-size: 1.3rem;
    margin-bottom: 0.2rem;
  }
  h1 {
    font-size: 3.2rem;
    margin-bottom: 0.3rem;
  }
  .subtitle {
    margin-bottom: 0.75rem;
  }
  nav {
    margin-bottom: 0.65rem;
  }
  .photo-wrap {
    max-height: 42vh;
  }
  .matchup-actions {
    margin-top: 0.5rem;
  }
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  header            { animation: none; }
  .candidate        { transition: border-color 0.18s, opacity 0.3s, filter 0.3s; }
  .candidate:active { transform: none; }
  .candidate.winner { animation: none; }
  .photo            { transition: none; }
  .result           { animation: none; }
  .lb-item          { animation: none; }
}
