/* Quick Vote: mobile-first, no build step. Dark first, light via prefers-color-scheme or [data-theme]. */

:root {
  color-scheme: dark;
  --bg: #141414;
  --card: #1f1f1f;
  --surface: #2a2a2a;
  --text: #f5f5f5;
  --text-2: #a3a3a3;
  --text-3: #909090;
  --divider: #303030;
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --accent: #22c55e;
  --accent-text: #4ade88;
  --accent-on: #06210f;
  --accent-muted: rgba(34, 197, 94, 0.14);
  --error: #ef4444;
  --error-text: #f87171;
  --error-muted: #3a1f22;
  --warn: #fbbf24;
  --warn-muted: rgba(251, 191, 36, 0.12);
  --shadow-btn: 0 6px 16px -8px rgba(0, 0, 0, 0.55);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
  --gutter: 16px;

  --f-serif: 'Noto Serif', Georgia, 'Times New Roman', Times, 'Liberation Serif', serif;
  --f-num: system-ui, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    color-scheme: light;
    --bg: #f8fafc;
    --card: #ffffff;
    --surface: #f1f5f9;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #64748b;
    --divider: #e2e8f0;
    --hairline: rgba(15, 23, 42, 0.08);
    --hairline-strong: rgba(15, 23, 42, 0.14);
    --accent: #34d399;
    --accent-text: #047857;
    --accent-on: #042f1c;
    --accent-muted: rgba(52, 211, 153, 0.16);
    --error: #dc2626;
    --error-text: #dc2626;
    --error-muted: #fdecec;
    --warn: #b45309;
    --warn-muted: rgba(180, 83, 9, 0.1);
    --shadow-btn: 0 6px 16px -8px rgba(15, 23, 42, 0.14);
  }
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f8fafc;
  --card: #ffffff;
  --surface: #f1f5f9;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --divider: #e2e8f0;
  --hairline: rgba(15, 23, 42, 0.08);
  --hairline-strong: rgba(15, 23, 42, 0.14);
  --accent: #34d399;
  --accent-text: #047857;
  --accent-on: #042f1c;
  --accent-muted: rgba(52, 211, 153, 0.16);
  --error: #dc2626;
  --error-text: #dc2626;
  --error-muted: #fdecec;
  --warn: #b45309;
  --warn-muted: rgba(180, 83, 9, 0.1);
  --shadow-btn: 0 6px 16px -8px rgba(15, 23, 42, 0.14);
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-serif);
  font-size: 17px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px var(--gutter) 48px;
}

h1,
h2 {
  margin: 0 0 8px;
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.05;
}

h1 {
  font-size: clamp(1.9rem, 1.4rem + 2.4vw, 2.6rem);
  margin-bottom: 14px;
}

h2 {
  font-size: 1.4rem;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent-text);
}

:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sr-copy {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

.muted {
  color: var(--text-2);
}

.small {
  font-size: 0.875rem;
}

.center {
  text-align: center;
}

/* ---- top bar ---- */

.topbar {
  width: 100%;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  height: 56px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--accent-text);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* dark shows the moon, light shows the sun */
.icon-sun {
  display: none;
}

.icon-moon {
  display: block;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) .icon-sun {
    display: block;
  }

  :root:not([data-theme='dark']) .icon-moon {
    display: none;
  }
}

:root[data-theme='light'] .icon-sun {
  display: block;
}

:root[data-theme='light'] .icon-moon {
  display: none;
}

/* ---- hero ---- */

.hero {
  margin: 28px 0 24px;
}

.hero h1 {
  margin-bottom: 0;
  font-size: clamp(2.4rem, 1.4rem + 5vw, 3.6rem);
}

.lead {
  max-width: 34ch;
  margin: 12px 0 0;
  color: var(--text-2);
  font-size: 1.1rem;
}

/* ---- page head / badges ---- */

.page-head {
  margin-bottom: 16px;
}

.page-head h1 {
  margin-bottom: 12px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-2);
  font-family: var(--f-num);
  font-size: 0.8rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge-ok {
  border-color: transparent;
  background: var(--accent-muted);
  color: var(--accent-text);
}

.badge-closed {
  border-color: transparent;
  background: var(--error-muted);
  color: var(--error-text);
}

/* ---- cards ---- */

.card {
  margin-bottom: 16px;
  padding: 20px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--card);
}

.card > :last-child {
  margin-bottom: 0;
}

/* ---- buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s, transform 0.1s, filter 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  border-color: var(--hairline-strong);
  background: var(--surface);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-danger {
  border-color: var(--error);
  background: transparent;
  color: var(--error-text);
}

.btn-danger:hover:not(:disabled) {
  background: var(--error-muted);
}

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

.btn-sm {
  min-height: 40px;
  padding: 0 14px;
}

.btn-icon {
  width: 48px;
  padding: 0;
  font-size: 1.4rem;
}

/* ---- forms ---- */

.field {
  min-width: 0;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.label,
label.label,
legend.label {
  display: block;
  margin: 0 0 6px;
  padding: 0;
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 600;
}

.field > label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 600;
}

input[type='text'],
input[type='search'],
input[type='number'],
input:not([type]),
.input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input[type='text']:focus,
input[type='search']:focus,
input[type='number']:focus,
input:not([type]):focus,
.input:focus {
  border-color: var(--accent);
}

input::placeholder {
  color: var(--text-3);
  opacity: 1;
}

.error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--error-muted);
  color: var(--error-text);
  font-weight: 600;
}

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--r-md);
}

.notice p {
  flex: 1 1 200px;
  margin: 0;
  font-size: 0.9rem;
}

.notice-warn {
  border: 1px solid var(--hairline-strong);
  background: var(--warn-muted);
  color: var(--text);
}

/* Option rows on the create page */

.option-list {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}

.option-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.option-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.option-row .btn {
  flex: none;
}

/* Segmented control (single / multiple) */

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  background: var(--bg);
}

.segmented label {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 9px;
  color: var(--text-2);
  font-weight: 600;
  text-align: center;
}

.segmented input:checked + span {
  background: var(--accent);
  color: var(--accent-on);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

/* Switch (toggle) */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  margin-bottom: 16px;
  cursor: pointer;
}

.toggle-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toggle-title {
  font-weight: 700;
}

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.switch[aria-checked='true'] {
  border-color: var(--accent);
  background: var(--accent);
}

.switch[aria-checked='true']::after {
  transform: translateX(22px);
}

/* ---- home ---- */

.poll-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  min-height: 44px;
  padding: 8px 0;
  color: var(--text);
  text-decoration: none;
}

.poll-link-title {
  font-weight: 700;
}

.poll-link-pin {
  color: var(--text-2);
  font-family: var(--f-num);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* ---- lists ---- */

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-height: 52px;
  padding: 8px 0;
  border-top: 1px solid var(--hairline);
}

.list-item:first-child {
  border-top: 0;
}

.item-main {
  display: flex;
  flex: 1 1 140px;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  min-width: 0;
}

.item-name {
  font-weight: 700;
}

.item-sub {
  flex: 1 1 100%;
  margin: 0;
}

.item-actions {
  display: flex;
  gap: 8px;
}

/* ---- admin ---- */

.pin-card {
  text-align: center;
}

.pin {
  margin: 0 0 12px;
  font-family: var(--f-num);
  font-size: clamp(2.8rem, 14vw, 4rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.copy-row {
  display: flex;
  gap: 8px;
  text-align: left;
}

.copy-row .input {
  flex: 1 1 auto;
  min-width: 0;
}

.copy-row .btn {
  flex: none;
}

.pin-card .notice {
  text-align: left;
}

/* ---- results ---- */

.results {
  margin: 0;
  padding: 0;
  list-style: none;
}

.result {
  margin: 0 0 14px;
}

.result:last-child {
  margin-bottom: 0;
}

#multi-note {
  margin-top: 12px;
}

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.result-text {
  min-width: 0;
}

.result.mine .result-text::after {
  content: ' \2713';
  color: var(--accent-text);
  font-weight: 700;
}

.result-num {
  flex: none;
  color: var(--text-2);
  font-family: var(--f-num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.bar {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface);
  overflow: hidden;
}

.bar-fill {
  width: 0;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--accent);
  transition: width 0.5s ease;
}

/* ---- ballot ---- */

.choices {
  min-width: 0;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  margin-bottom: 8px;
  padding: 8px 14px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  background: var(--card);
  cursor: pointer;
}

.choice input {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.choice-text {
  min-width: 0;
}

.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.choice:has(input:focus-visible) {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.poll-title {
  margin: 0 0 12px;
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.big-check {
  color: var(--accent-text);
  font-size: 2.4rem;
  line-height: 1;
}

/* ---- status bits ---- */

.conn {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 8px var(--gutter);
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
  box-shadow: inset 0 0 0 999px var(--warn-muted);
  color: var(--warn);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

/* Admin error toast: fixed to the bottom of the viewport so it is seen wherever the host has scrolled to. */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  width: calc(100% - 2 * var(--gutter));
  max-width: 520px;
  padding: 10px 8px 10px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--error);
  border-radius: var(--r-md);
  background: var(--error-muted);
  color: var(--error-text);
  font-weight: 600;
}

.toast-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.toast-close:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: -2px;
}

.pulse {
  width: 14px;
  height: 14px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pulse {
    animation: none;
  }

  .bar-fill,
  .switch,
  .switch::after,
  .btn {
    transition: none;
  }

  .btn:active:not(:disabled) {
    transform: none;
  }
}

@media (min-width: 480px) {
  .container {
    padding-top: 32px;
  }
}
