:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #101114;
  --muted: #6b7280;
  --line: #e6e8ec;
  --accent: #2f6fed;
  --accent-fg: #ffffff;
  --accent-soft: #eef3ff;
  --meter: #eceef3;
  --danger: #c62828;
  --radius: 14px;
  --gap: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --fg: #f3f4f6;
    --muted: #9aa0ab;
    --line: #2c2f36;
    --accent: #5b8cff;
    --accent-fg: #0b0c0f;
    --accent-soft: #232735;
    --meter: #2a2d34;
    --danger: #ef6b6b;
  }
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любые display из классов —
   иначе скрытые кнопки продолжают показываться. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
}

.card { display: block; }

.card.center {
  text-align: center;
  padding-top: 72px;
}

h1 {
  font-size: 23px;
  line-height: 1.25;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 24px;
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin: 14px 0 0;
}

/* --- создание опроса --- */

.field {
  display: block;
  margin-bottom: 24px;
}

.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

textarea,
input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  resize: vertical;
}

textarea:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.option-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.btn-remove {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.btn-remove:active { background: var(--meter); }

.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 28px;
  font-size: 15px;
}

.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

/* --- кнопки --- */

.btn-primary,
.btn-ghost {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  margin-top: 4px;
}

.btn-primary:disabled { opacity: 0.55; cursor: default; }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--line);
  font-weight: 500;
  margin-top: 10px;
}

.btn-ghost:active { background: var(--accent-soft); }

/* --- голосование --- */

.options-vote { margin: 0 0 28px; }

.option {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.option:first-child { padding-top: 4px; }
.option:last-child { border-bottom: none; padding-bottom: 4px; }

.option input {
  margin: 2px 0 0;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

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

.option-title {
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.option.chosen .option-title { font-weight: 600; }

.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--meter);
  margin: 10px 0 8px;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  min-width: 2px;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.option-stats {
  font-size: 13px;
  color: var(--muted);
}

.voters {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

/* Один и тот же человек в Telegram и MAX — разные участники опроса,
   поэтому рядом с именем показывается площадка. */
.voter { display: inline-flex; align-items: baseline; gap: 5px; }

.voter-platform {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--meter);
  color: var(--muted);
}

/* --- публикация --- */

.publish {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.publish .muted { margin-bottom: 0; }

/* --- загрузка --- */

.loader { text-align: center; padding-top: 72px; }

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  .meter span { transition: none; }
}
