/* Theme system. Every color comes from a CSS variable. Themes set the
   variables; the rest of the stylesheet doesn't know what theme is on.
   --bg-grad-* are radial-gradient stops used for the page background. */
:root,
[data-theme="dark"] {
  --bg: #0f1115;
  --bg-grad-1: #1a1f2b;
  --bg-card: #181b21;
  --bg-elev: #20242c;
  --border: #2b2f38;
  --fg: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #7c8cff;
  --accent-strong: #5b6cf0;
  --ok: #5dd6a0;
  --warn: #ffb86c;
  --danger: #ff6b6b;
  --rank-1: #7c8cff;
  --rank-2: #5dd6a0;
  --rank-3: #ffb86c;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-grad-1: #ffffff;
  --bg-card: #ffffff;
  --bg-elev: #f0f2f5;
  --border: #d8dce3;
  --fg: #1a1d22;
  --muted: #6b7280;
  --accent: #5b6cf0;
  --accent-strong: #4a5be3;
  --ok: #2c9b66;
  --warn: #c87413;
  --danger: #d83a3a;
  --rank-1: #5b6cf0;
  --rank-2: #2c9b66;
  --rank-3: #c87413;
  color-scheme: light;
}

[data-theme="midnight"] {
  --bg: #0a0d1a;
  --bg-grad-1: #1a1230;
  --bg-card: #131830;
  --bg-elev: #1c2240;
  --border: #2a3055;
  --fg: #e6e8f8;
  --muted: #8b91b3;
  --accent: #b87cff;
  --accent-strong: #9b5bf0;
  --ok: #5dd6a0;
  --warn: #ffb86c;
  --danger: #ff6b8c;
  --rank-1: #b87cff;
  --rank-2: #5dd6a0;
  --rank-3: #ffb86c;
  color-scheme: dark;
}

[data-theme="paper"] {
  /* Warm cream + brown ink, like an old planner. */
  --bg: #f5efe2;
  --bg-grad-1: #fbf6ea;
  --bg-card: #fcf8ed;
  --bg-elev: #efe7d4;
  --border: #d5c9af;
  --fg: #3a2e22;
  --muted: #8a7a64;
  --accent: #b3582d;
  --accent-strong: #a04a23;
  --ok: #4f7a3a;
  --warn: #b3582d;
  --danger: #b03030;
  --rank-1: #b3582d;
  --rank-2: #4f7a3a;
  --rank-3: #b87f3a;
  color-scheme: light;
}

[data-theme="forest"] {
  --bg: #0e1a14;
  --bg-grad-1: #142b1f;
  --bg-card: #14241c;
  --bg-elev: #1a2e24;
  --border: #2a4034;
  --fg: #e3ece6;
  --muted: #8aa39a;
  --accent: #6fcf97;
  --accent-strong: #4fa775;
  --ok: #8be0a5;
  --warn: #ffc56f;
  --danger: #ff7e7e;
  --rank-1: #6fcf97;
  --rank-2: #ffc56f;
  --rank-3: #b8a37a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(900px 500px at 70% -10%, var(--bg-grad-1) 0%, var(--bg) 55%);
  color: var(--fg);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--fg); text-decoration: none; }
a:hover { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tinier { font-size: 11px; }
.inline { display: inline; }
.center { text-align: center; }
.mt-2 { margin-top: 16px; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 17px; }
.spacer { flex: 1; }
.nav { color: var(--muted); font-size: 14px; }
.nav:hover { color: var(--fg); }
.btn-link {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 0; font: inherit;
}
.btn-link:hover { color: var(--fg); }

.main { max-width: 920px; margin: 0 auto; padding: 28px 24px 80px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span, .field > legend { font-size: 13px; color: var(--muted); }
.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
input[type=text], input[type=email], input[type=password], input[type=datetime-local],
textarea, select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
fieldset { border: none; padding: 0; margin: 0 0 14px; }
.radio {
  display: flex; gap: 10px; padding: 8px 0;
  cursor: pointer; font-size: 14px;
}
.radio input { margin-top: 4px; }

.btn {
  font: inherit; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--fg);
  padding: 10px 16px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent-strong); border-color: var(--accent-strong); color: white;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-block { width: 100%; }
.btn-danger {
  background: transparent; color: var(--danger); border-color: rgba(255,107,107,0.4);
}
.btn-danger:hover { background: var(--danger); color: white; }

.banner { border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.banner-err  { background: rgba(255,107,107,0.1);  border: 1px solid rgba(255,107,107,0.4); color: var(--danger); }
.banner-warn { background: rgba(255,184,107,0.08); border: 1px solid rgba(255,184,107,0.35); color: var(--warn); }
.banner-ok   { background: rgba(93,214,160,0.10);  border: 1px solid rgba(93,214,160,0.35); color: var(--ok); }

.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 10px;
}
.empty p { margin: 0 0 12px; }

/* ---------- hero ---------- */
.hero { padding: 36px 0 24px; }
.hero h1 { font-size: 32px; margin: 0 0 12px; letter-spacing: -0.02em; }
.hero .lead { color: var(--muted); max-width: 56ch; font-size: 16px; }
.cta-row { display: flex; gap: 12px; margin-top: 20px; }

.grid-3 {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-top: 28px;
}
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

.auth-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px;
  max-width: 380px; margin: 40px auto;
}
.auth-card h1 { margin: 0 0 16px; font-size: 20px; }

/* ---------- events list ---------- */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 16px;
}
.page-head h1 { margin: 0; font-size: 22px; }
.page-head-actions { display: flex; gap: 8px; }
.section-h { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em;
             color: var(--muted); margin: 28px 0 12px; font-weight: 600; }

.event-list { display: flex; flex-direction: column; gap: 8px; }
.event-row {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  text-decoration: none; color: inherit; transition: border-color .15s;
}
.event-row:hover { border-color: var(--accent); }
.event-main { flex: 1; min-width: 0; }
.event-title { font-weight: 600; }

.mode-pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
}
.mode-availability { background: rgba(93,214,160,0.12);  color: var(--ok); }
.mode-ranking      { background: rgba(124,140,255,0.15); color: var(--accent); }
.mode-elimination  { background: rgba(255,184,107,0.12); color: var(--warn); }
.mode-irv          { background: rgba(192,134,255,0.15); color: #c086ff; }
.rank-irv          { background: rgba(192,134,255,0.18); color: #c086ff; }

.irv-row {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
}
.irv-select { width: 80px; text-align: center; }

.irv-rounds { display: flex; flex-direction: column; gap: 10px; }
.irv-round {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.irv-round-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.irv-counts { list-style: none; padding: 0; margin: 0; }
.irv-counts li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; font-size: 14px;
}
.irv-counts li.eliminated { color: var(--muted); text-decoration: line-through; }
.irv-counts li.round-winner { color: var(--ok); font-weight: 600; }
.elim-tag {
  display: inline-block; margin-left: 8px;
  background: rgba(255,107,107,0.12); color: var(--danger);
  font-size: 11px; padding: 1px 6px; border-radius: 3px; text-decoration: none;
}
.win-tag {
  display: inline-block; margin-left: 8px;
  background: rgba(93,214,160,0.15); color: var(--ok);
  font-size: 11px; padding: 1px 6px; border-radius: 3px;
}

.past-list { display: flex; flex-direction: column; gap: 4px; opacity: 0.65; }
.past-row { padding: 6px 0; font-size: 14px; }
.strike { text-decoration: line-through; color: var(--muted); }
.past-hint { margin: 4px 0 12px; opacity: 0.7; }

/* ---------- event form ---------- */
.event-form { max-width: 640px; }
.options-block {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; margin: 14px 0;
}
.opts-header { display: flex; justify-content: space-between; margin-bottom: 10px; }
.opt-row {
  /* Order: [datetime] [notes] [location] [×]. Datetime picker gets its own
     min-width because Chrome's calendar icon eats horizontal space. */
  display: grid; grid-template-columns: minmax(190px, 1.2fr) 1fr 1fr auto;
  gap: 8px; margin-bottom: 8px;
}

/* ---- theme picker (radio swatches) ---- */
.theme-picker {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px; margin-top: 6px;
}
.theme-swatch {
  position: relative; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 6px 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; transition: border-color 0.12s;
}
.theme-swatch:hover { border-color: var(--accent); }
.theme-swatch.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.theme-swatch input[type=radio] {
  position: absolute; opacity: 0; pointer-events: none;
}
.swatch-preview {
  width: 100%; max-width: 110px; height: 56px;
  border-radius: 8px; overflow: hidden;
  display: grid; grid-template-rows: 1fr; grid-template-columns: 1fr 1fr;
  position: relative;
  border: 1px solid rgba(0,0,0,0.2);
}
.swatch-preview .sw-bg { position: absolute; inset: 0; }
.swatch-preview .sw-card {
  position: absolute; left: 8px; right: 8px; top: 10px; bottom: 18px;
  border-radius: 4px;
}
.swatch-preview .sw-accent {
  position: absolute; left: 14px; bottom: 6px; width: 28px; height: 6px;
  border-radius: 3px;
}
.swatch-name {
  margin-top: 6px; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.theme-swatch.selected .swatch-name { color: var(--accent); }

/* Each swatch shows its OWN theme regardless of the page theme, so the
   picker always looks the same. Hard-coded colors here on purpose. */
.theme-dark .sw-bg     { background: #0f1115; }
.theme-dark .sw-card   { background: #181b21; }
.theme-dark .sw-accent { background: #7c8cff; }

.theme-light .sw-bg     { background: #f5f6f8; }
.theme-light .sw-card   { background: #ffffff; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.theme-light .sw-accent { background: #5b6cf0; }

.theme-midnight .sw-bg     { background: linear-gradient(135deg, #0a0d1a, #1a1230); }
.theme-midnight .sw-card   { background: #131830; }
.theme-midnight .sw-accent { background: #b87cff; }

.theme-paper .sw-bg     { background: #f5efe2; }
.theme-paper .sw-card   { background: #fcf8ed; }
.theme-paper .sw-accent { background: #b3582d; }

.theme-forest .sw-bg     { background: linear-gradient(135deg, #0e1a14, #142b1f); }
.theme-forest .sw-card   { background: #14241c; }
.theme-forest .sw-accent { background: #6fcf97; }
.opt-row .btn-link { font-size: 18px; color: var(--muted); }
.opt-row .btn-link:hover { color: var(--danger); }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- dashboard ---------- */
.share-card {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px;
}
.share-card > div { flex: 1; }
.share-input {
  font-family: ui-monospace, monospace;
  font-size: 13px; margin-top: 4px;
}

.tallies { display: flex; flex-direction: column; gap: 10px; }
.tally {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  overflow: hidden;
}
.tally.winner { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tally.leading { border-color: rgba(124,140,255,0.55); }
.winner-pill {
  background: var(--accent); color: white;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 700; padding: 2px 6px; border-radius: 4px; margin-right: 6px;
}
.leading-pill {
  background: transparent; color: var(--accent);
  border: 1px solid rgba(124,140,255,0.55);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; padding: 1px 6px; border-radius: 4px; margin-right: 6px;
}
.tally-bar {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  background: transparent; z-index: 0;
}
.tally-fill {
  height: 100%; background: rgba(124,140,255,0.08);
}
.tally-row { position: relative; z-index: 1;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
}
.tally-label { font-size: 15px; }
.tally-score { font-size: 16px; font-weight: 600; text-align: right; }
.tally-score .muted { font-weight: 400; }
.tally-detail { position: relative; z-index: 1; margin-top: 6px; }

.vote-table-wrap { overflow-x: auto; }
.vote-table {
  width: 100%; border-collapse: collapse;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
.vote-table th, .vote-table td {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top; font-size: 13px;
}
.vote-table th {
  background: var(--bg-elev); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted);
}
.vote-cell { text-align: center; }
.check { color: var(--ok); font-weight: 700; }
.cant  { color: var(--danger); font-weight: 700; }
.dash  { color: var(--border); }
.rank {
  display: inline-block; padding: 2px 6px; border-radius: 4px;
  font-size: 11px; font-weight: 700;
}
.rank-1 { background: rgba(124,140,255,0.2); color: var(--rank-1); }
.rank-2 { background: rgba(93,214,160,0.18);  color: var(--rank-2); }
.rank-3 { background: rgba(255,184,107,0.18); color: var(--rank-3); }

/* ---------- voter pages ---------- */
.name-form { max-width: 360px; margin-top: 16px; }
.instr { color: var(--muted); margin: 12px 0 14px; }
.opt-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.opt-pick {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer;
}
.opt-pick:hover { border-color: var(--accent); }
.opt-pick input { transform: scale(1.2); }
.opt-info strong { display: block; }
