/* =====================================================================
   COMPONENTS — one recipe class per building block.
   Builders in js/components.js create the markup these classes expect.
   Role-colored parts read `--role-color`, set inline from JS as
   var(--role-<id>); those come from the poll's roles (setRoles in config.js).
   ===================================================================== */

/* ===== CARD ===== */
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
}

/* ===== BUTTON ===== */
/* BASE */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: 0 var(--space-5);
  background: var(--color-surface);
  color: var(--color-text);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  transition:
    background   var(--t-fast) var(--ease-out),
    border-color var(--t-fast) var(--ease-out),
    box-shadow   var(--t-fast) var(--ease-out),
    transform    var(--t-fast) var(--ease-out);
}

.btn--primary {
  background: var(--color-accent);
  color: var(--color-on-accent);
  border-color: var(--color-accent);
}

.btn--ghost { background: transparent; border-color: transparent; }

.btn--danger { color: var(--color-danger); border-color: var(--color-danger); }

.btn--sm {
  min-height: 2.25rem;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

.btn--block { width: 100%; }

/* :hover — mix toward text color so it works on any variant/background */
.btn:hover { background: color-mix(in srgb, var(--color-text) 6%, var(--color-surface)); }

.btn--primary:hover { background: color-mix(in srgb, var(--color-text) 15%, var(--color-accent)); }

.btn--ghost:hover { background: var(--color-surface-muted); }

/* :focus-visible */
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* :active — press feedback via transform only (no layout shift) */
.btn:active { transform: scale(0.97); }

/* .is-active — toggles like view switches. Equal specificity to :hover,
   written later → wins, so an active toggle doesn't flicker on hover. */
.btn.is-active {
  background: var(--color-text);
  color: var(--color-bg);
  border-color: var(--color-text);
}

/* :disabled — last, overrides every state above */
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ===== OPTION CARD — tappable answer (single / multi / scale / role) ===== */
/* BASE — border width stays 1.5px in every state; selection adds an inset
   ring instead of a thicker border → no layout jump. */
.option-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: left;
  font-weight: var(--weight-medium);
  transition:
    border-color var(--t-fast) var(--ease-out),
    background   var(--t-fast) var(--ease-out),
    color        var(--t-fast) var(--ease-out),
    box-shadow   var(--t-fast) var(--ease-out),
    transform    var(--t-fast) var(--ease-out);
}

.option-card__check {
  display: grid;
  flex: none;
  place-items: center;
  width: 1.375rem;
  height: 1.375rem;
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  color: transparent;
  transition:
    background   var(--t-fast) var(--ease-out),
    border-color var(--t-fast) var(--ease-out),
    color        var(--t-fast) var(--ease-out),
    opacity      var(--t-fast) var(--ease-out);
}

.option-card__check svg { width: 0.8rem; height: 0.8rem; }

.option-card--multi .option-card__check { border-radius: var(--radius-sm); }

/* Single variant: a radio — a dot instead of the check (multi keeps the
   square checkbox). The dot always exists at scale 0, so selecting only
   animates transform; its color comes from the check's `color`. */
.option-card--single .option-card__check svg { display: none; }

.option-card--single .option-card__check::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  background: currentColor;
  border-radius: var(--radius-pill);
  transform: scale(0);
  transition: transform var(--t-fast) var(--ease-out);
}

/* Role variant: colored dot instead of a check, color from --role-color */
.option-card--role .option-card__check {
  border-color: var(--role-color);
  background: color-mix(in srgb, var(--role-color) 18%, transparent);
}

/* Scale variant: big centered number, cards sit in a 5-column grid */
.option-card--scale {
  flex-direction: column;
  justify-content: center;
  gap: 0;
  padding: var(--space-3) 0;
  text-align: center;
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
}

.option-card--scale .option-card__check { display: none; }

/* :hover */
.option-card:hover { border-color: var(--color-border-strong); }

/* :focus-visible */
.option-card:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* :active */
.option-card:active { transform: scale(0.985); }

/* .is-selected — solid accent. The same look before and after voting:
   a voted pick simply stays .is-selected (cards are disabled then). */
.option-card.is-selected {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-on-accent);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--color-accent) 30%, transparent);
}

.option-card.is-selected .option-card__check {
  background: var(--color-on-accent);
  border-color: var(--color-on-accent);
  color: var(--color-accent);
}

.option-card--single.is-selected .option-card__check::after { transform: scale(1); }

/* Role picker: the same solid selection, in the role's own color.
   --role-on (black/white, picked in setRoles) keeps the text readable
   whatever color the admin chose. */
.option-card--role.is-selected {
  background: var(--role-color);
  border-color: var(--role-color);
  color: var(--role-on);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--role-color) 30%, transparent);
}

.option-card--role.is-selected .option-card__check {
  background: var(--role-on);
  border-color: var(--role-on);
  color: var(--role-color);
}

/* .is-dimmed — after voting, the options you didn't pick. Only colors
   change and the check keeps its slot (opacity, not display), so the list
   doesn't move when the vote lands. */
.option-card.is-dimmed {
  background: var(--color-surface-muted);
  border-color: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.option-card.is-dimmed .option-card__check { opacity: 0; }

/* .is-selected:hover — keep the selected look, just deepen the border */
.option-card.is-selected:hover { border-color: color-mix(in srgb, var(--color-text) 25%, var(--color-accent)); }

/* Role cards deepen their own color instead. Higher specificity (0,4,0)
   than the rule above → wins. */
.option-card--role.is-selected:hover { border-color: color-mix(in srgb, var(--color-text) 25%, var(--role-color)); }

/* .is-selected:focus-visible — the selected shadow would otherwise replace
   the focus ring (higher specificity than plain :focus-visible) → stack both. */
.option-card.is-selected:focus-visible {
  box-shadow:
    var(--focus-ring),
    0 8px 24px color-mix(in srgb, var(--color-accent) 30%, transparent);
}

/* :disabled — unavailable: faded */
.option-card:disabled { opacity: 0.5; cursor: not-allowed; }

/* …except a finished vote, which is read-only, not unavailable: full color.
   Higher specificity than :disabled → wins. */
.option-card:disabled:is(.is-selected, .is-dimmed) { opacity: 1; cursor: default; }

.scale-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-2);
}

.scale-row__labels {
  display: flex;
  justify-content: space-between;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ===== ROLE CHIP — dot + label (+ optional count). Also the legend. ===== */
.role-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-medium);
  transition: opacity var(--t-base) var(--ease-out);
}

.role-chip__dot {
  flex: none;
  width: 0.75em;
  height: 0.75em;
  background: var(--role-color);
  border-radius: var(--radius-pill);
}

.role-chip__count { color: var(--color-text-muted); font-variant-numeric: tabular-nums; }

/* Dimmed when a filter hides this role */
.role-chip.is-muted { opacity: 0.3; }

/* --button — the legend as a filter. BASE: same box in every state
   (transparent border always present) → hover/active never shift layout. */
.role-chip--button {
  padding: var(--space-1) var(--space-3);
  background: transparent;
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-pill);
  transition:
    opacity      var(--t-base) var(--ease-out),
    background   var(--t-base) var(--ease-out),
    border-color var(--t-base) var(--ease-out);
}

/* :hover — also un-dims a muted chip so it reads as clickable */
.role-chip--button:hover { background: var(--color-surface-muted); opacity: 1; }

/* :focus-visible */
.role-chip--button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* .is-active — the role being filtered to */
.role-chip--button.is-active { border-color: var(--role-color); }

.legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); }

/* ===== BAR — label | track with role segments | value ===== */
/* Segments always exist (one per role) and only their width/color change,
   so switching Total ↔ Stacked ↔ Filter animates instead of re-rendering. */
.bar {
  display: grid;
  grid-template-columns: minmax(8rem, 32%) 1fr 10ch;
  align-items: center;
  gap: var(--space-4);
}

.bar__label {
  overflow: hidden;
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  text-overflow: ellipsis;
}

.bar__track {
  display: flex;
  height: var(--bar-height);
  overflow: hidden;
  background: var(--color-track);
  border-radius: var(--radius-sm);
}

/* The 1px same-color shadow overlaps the next segment and hides the
   anti-aliasing seam between them (a 0-width segment casts no shadow). */
.bar__seg {
  --seg-color: var(--role-color);
  width: 0;
  height: 100%;
  background: var(--seg-color);
  box-shadow: 1px 0 0 var(--seg-color);
  transition:
    width      var(--t-slow) var(--ease-out),
    background var(--t-base) var(--ease-out),
    box-shadow var(--t-base) var(--ease-out);
}

/* Total view: every segment takes the single bar color → reads as one bar */

.bar__value {
  font-family: var(--font-numeric);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.bars { display: flex; flex-direction: column; gap: var(--space-4); }

/* ===== VOTE COUNTER — big live number ===== */
.vote-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.vote-counter__value {
  font-size: var(--text-display);
  font-weight: var(--weight-bold);
  line-height: 1;
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
}

/* Re-triggered by JS (class toggle) on every new vote */
.vote-counter__value.is-bumped { animation: counter-bump var(--t-base) var(--ease-out); }

@keyframes counter-bump {
  from { transform: scale(1.08); }
  to { transform: scale(1); }
}

.vote-counter__label { color: var(--color-text-muted); font-size: var(--text-stage-sm); }

/* ===== QR PANEL ===== */
.qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.qr-panel__code {
  width: var(--qr-size, 10rem);
  padding: calc(var(--qr-size, 10rem) * 0.07);
  background: var(--color-qr-bg);
  color: var(--color-qr-fg);
  border-radius: var(--radius-md);
}

.qr-panel__code svg { display: block; width: 100%; height: auto; }

.qr-panel__url { font-weight: var(--weight-bold); letter-spacing: var(--tracking-tight); }

/* ===== WORD CLOUD ===== */
.word-cloud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2) var(--space-5);
  max-width: 70rem;
  margin-inline: auto;
}

.word-cloud__item {
  color: var(--role-color, var(--color-text));
  font-size: var(--word-size);
  font-weight: var(--weight-bold);
  line-height: 1.1;
  letter-spacing: var(--tracking-tight);
  transition:
    font-size var(--t-slow) var(--ease-out),
    color     var(--t-base) var(--ease-out),
    opacity   var(--t-base) var(--ease-out);
}

/* Total view ignores role colors */

/* ===== OPTION LIST EDITOR — handle | input | remove, plus an "add" row ===== */
.option-editor { display: flex; flex-direction: column; gap: var(--space-2); }

/* position: relative → rows' offsetTop is measured from the list (drag math) */
.option-editor__list {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* BASE */
.option-editor__row {
  display: grid;
  grid-template-columns: 2rem 1fr 2.25rem;
  align-items: center;
  gap: var(--space-1);
  border-radius: var(--radius-md);
  transition:
    box-shadow var(--t-fast) var(--ease-out),
    background var(--t-fast) var(--ease-out);
}

/* Add row has no remove button → input spans to the end */
.option-editor__row--add { grid-template-columns: 2rem 1fr; }

.option-editor__row--add .input { border-style: dashed; }

.option-editor__plus {
  color: var(--color-text-muted);
  font-size: var(--text-lg);
  text-align: center;
}

/* .is-dragging — lifted look via shadow only, size never changes */
.option-editor__row.is-dragging {
  position: relative;
  z-index: 1;
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
}

/* Handle + remove share one icon-button recipe */
.option-editor__handle,
.option-editor__remove {
  display: grid;
  place-items: center;
  height: var(--tap-min);
  padding: 0;
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  border-radius: var(--radius-sm);
  transition:
    background var(--t-fast) var(--ease-out),
    color      var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out);
}

.option-editor__handle svg,
.option-editor__remove svg { width: 1rem; height: 1rem; }

/* touch-action: none → dragging the handle on a phone doesn't scroll the page */
.option-editor__handle { cursor: grab; touch-action: none; }

/* :hover */
.option-editor__handle:hover,
.option-editor__remove:hover { background: var(--color-surface-muted); color: var(--color-text); }

.option-editor__remove:hover { color: var(--color-danger); }

/* :focus-visible */
.option-editor__handle:focus-visible,
.option-editor__remove:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* .is-dragging — higher specificity than :hover → wins while dragging */
.option-editor__row.is-dragging .option-editor__handle { color: var(--color-accent); cursor: grabbing; }

/* :disabled (locked question) */
.option-editor__handle:disabled,
.option-editor__remove:disabled { visibility: hidden; }

/* ===== FIELD ===== */
.field { display: flex; flex-direction: column; gap: var(--space-1); }

.field__label { font-size: var(--text-sm); font-weight: var(--weight-medium); }

.field__hint { color: var(--color-text-muted); font-size: var(--text-xs); }

.input {
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition:
    border-color var(--t-fast) var(--ease-out),
    box-shadow   var(--t-fast) var(--ease-out);
}

textarea.input { min-height: 7rem; resize: vertical; }

.input:hover { border-color: var(--color-text-muted); }

.input:focus-visible {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring);
}

.input:disabled { background: var(--color-surface-muted); color: var(--color-text-muted); }

/* ===== BADGE ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem var(--space-2);
  background: var(--color-surface-muted);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}

.badge--accent { background: var(--color-accent-soft); color: var(--color-accent); }

.badge--live { background: var(--color-danger-soft); color: var(--color-danger); }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  z-index: 10;
  max-width: calc(100% - var(--space-6));
  padding: var(--space-3) var(--space-4);
  background: var(--color-text);
  color: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 1rem);
  transition:
    opacity   var(--t-base) var(--ease-out),
    transform var(--t-base) var(--ease-out);
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ===== CONNECTION STATUS ===== */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.status::before {
  width: 0.5rem;
  height: 0.5rem;
  background: var(--color-danger);
  border-radius: var(--radius-pill);
  content: "";
  transition: background var(--t-base) var(--ease-out);
}

.status.is-online::before { background: var(--color-success); }
