/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent-blue: #38bdf8;
  --accent-green: #4ade80;
  --accent-yellow: #facc15;
  --accent-red: #f87171;
  --accent-orange: #fb923c;
  --radius: 12px;

  /* Harmonize Pico with the existing palette */
  --pico-background-color: var(--bg);
  --pico-color: var(--text);
  --pico-muted-color: var(--text-muted);
  --pico-h1-color: var(--text);
  --pico-h2-color: var(--text);
  --pico-h3-color: var(--text);
  --pico-primary: var(--accent-blue);
  --pico-primary-hover: var(--accent-blue);
  --pico-primary-focus: rgba(56, 189, 248, 0.25);
  --pico-card-background-color: var(--surface);
  --pico-card-border-color: var(--border);
  --pico-border-color: var(--border);
  --pico-border-radius: var(--radius);
  --pico-form-element-background-color: var(--surface);
  --pico-form-element-border-color: var(--border);
  --pico-form-element-color: var(--text);
  --pico-form-element-focus-color: var(--accent-blue);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  padding: 1.5rem 1rem 0.75rem;
}
header h1 { font-size: 1.6rem; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

main {
  flex: 1;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 1rem;
}

footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1.25rem;
}
footer a { color: var(--text-muted); }

/* ===== Cards & sections ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.panel h2 { font-size: 1.15rem; margin-bottom: 0.75rem; }
.panel h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }

.hint { color: var(--text-muted); font-size: 0.85rem; margin: 0.35rem 0 0.75rem; }

/* ===== Create form ===== */
.list-editor { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.5rem; }
.list-row { display: flex; gap: 0.5rem; align-items: center; }
.list-row input { flex: 1; margin: 0; }
.list-row button {
  flex: 0 0 auto;
  width: 2.4rem;
  margin: 0;
  padding: 0.3rem;
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
}
.add-btn {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
  width: auto;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
.toggles { display: flex; flex-direction: column; gap: 0.25rem; margin: 1rem 0; }
.toggles label { font-size: 0.95rem; }

/* ===== Share panel ===== */
.share-link {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.5rem 0 1rem;
}
.share-link input { flex: 1; margin: 0; font-size: 0.85rem; }
.share-link button { flex: 0 0 auto; width: auto; margin: 0; padding: 0.45rem 0.9rem; }
.admin-note {
  border-left: 3px solid var(--accent-yellow);
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Roster / progress ===== */
.roster { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0; }
.roster-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.9rem;
  color: var(--text-muted);
}
.roster-chip.voted { color: var(--accent-green); border-color: rgba(74, 222, 128, 0.4); }
.roster-chip.me { color: var(--accent-blue); border-color: rgba(56, 189, 248, 0.5); }

button.name-pick {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: auto;
  margin: 0;
  padding: 0.5rem 1rem;
}
button.name-pick:disabled { opacity: 0.45; }
button.name-pick[aria-pressed="true"] {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.12);
}
.name-grid { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ===== Ranking UI ===== */
.rank-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }
.rank-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
}
.rank-pos {
  flex: 0 0 1.8rem;
  height: 1.8rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-blue);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.9rem;
}
.rank-label { flex: 1; overflow-wrap: anywhere; }
.rank-item .ctl {
  flex: 0 0 auto;
  width: 2.2rem;
  height: 2.2rem;
  margin: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
}
.rank-item .ctl:disabled { opacity: 0.3; }

.pool { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pool button {
  width: auto;
  margin: 0;
  padding: 0.5rem 1rem;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  color: var(--text);
  font-size: 0.95rem;
}
.pool:empty::after {
  content: "All options ranked.";
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Results ===== */
.winner-card {
  text-align: center;
  padding: 1.5rem 1rem;
  border: 1px solid rgba(74, 222, 128, 0.4);
  background: linear-gradient(180deg, rgba(74, 222, 128, 0.08), transparent);
}
.winner-card .crown { font-size: 2rem; }
.winner-card .label { color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; }
.winner-card .name { font-size: 1.7rem; font-weight: 800; margin: 0.25rem 0; overflow-wrap: anywhere; }
.winner-card .sub { color: var(--text-muted); font-size: 0.9rem; }

.alert {
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
  border: 1px solid var(--border);
  background: var(--surface);
}
.alert strong { display: block; margin-bottom: 0.2rem; }
.alert.warn { border-color: rgba(250, 204, 21, 0.45); background: rgba(250, 204, 21, 0.07); }
.alert.info { border-color: rgba(56, 189, 248, 0.35); background: rgba(56, 189, 248, 0.06); }
.alert.ok { border-color: rgba(74, 222, 128, 0.35); background: rgba(74, 222, 128, 0.05); }

/* Round-by-round chart: labeled HTML bar rows. Identity is carried by
   the row label; color is a consistent per-candidate assist (<=8). */
.round { margin-bottom: 1.4rem; }
.round-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.4rem; }
.round-head h3 { margin: 0; font-size: 1rem; }
.round-head .meta { color: var(--text-muted); font-size: 0.8rem; }

.bar-rows { position: relative; display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr; gap: 0.6rem; align-items: center; }
.bar-row .bar-name {
  font-size: 0.85rem;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-row.eliminated .bar-name { color: var(--text-muted); text-decoration: line-through; }
.bar-row.exhausted-row .bar-name { color: var(--text-muted); font-style: italic; }
.bar-track { position: relative; height: 22px; background: var(--surface-2); border-radius: 6px; }
.bar-fill {
  position: absolute;
  inset: 2px auto 2px 2px;
  border-radius: 4px;
  min-width: 2px;
  transition: width 0.4s ease;
}
.bar-fill.zero { background: transparent !important; }
.bar-fill.exhausted-fill { background: transparent; border: 1px dashed var(--border); }
.bar-count {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.majority-line {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 0;
  border-left: 2px dashed var(--accent-yellow);
  opacity: 0.75;
  pointer-events: none;
}
.majority-tag {
  font-size: 0.72rem;
  color: var(--accent-yellow);
  margin-top: 2px;
}
.round-note { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.5rem; line-height: 1.45; }
.round-note .win { color: var(--accent-green); }

/* Ballots & pairwise tables */
details { margin-bottom: 1rem; }
details summary { cursor: pointer; color: var(--text-muted); font-size: 0.95rem; }
table.mini {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.6rem;
}
table.mini th, table.mini td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.55rem;
  text-align: left;
  background: var(--surface);
  color: var(--text);
  overflow-wrap: anywhere;
}
table.mini th { background: var(--surface-2); font-weight: 600; }
table.mini td.win-cell { color: var(--accent-green); font-weight: 600; }
table.mini td.lose-cell { color: var(--text-muted); }
.table-scroll { overflow-x: auto; }

.rank-seq { color: var(--text-muted); }
.rank-seq b { color: var(--text); font-weight: 600; }

/* ===== Misc ===== */
.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.75rem; }
.btn-row button, .btn-row a[role="button"] { width: auto; margin: 0; padding: 0.55rem 1.1rem; }
button.secondary-btn { background: var(--surface-2); border-color: var(--border); color: var(--text); }
button.danger { background: transparent; border-color: rgba(248, 113, 113, 0.5); color: var(--accent-red); }
.error-text { color: var(--accent-red); font-size: 0.9rem; margin-top: 0.5rem; }
.center { text-align: center; }
.muted { color: var(--text-muted); }

@media (max-width: 560px) {
  header h1 { font-size: 1.3rem; }
  .bar-row { grid-template-columns: minmax(70px, 100px) 1fr; }
}
