:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-weak: #eef2ff;
  --success: #059669;
  --success-weak: #ecfdf5;
  --danger: #dc2626;
  --danger-weak: #fef2f2;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 500px at 50% -180px, #e9e7ff 0%, var(--bg) 55%) fixed;
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 247, 251, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(229, 231, 235, 0.8);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}
.brand-sub { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- 通用 ---------- */
.page-head {
  padding: 40px 0 8px;
}
.page-head h1 {
  font-size: 32px;
  line-height: 1.3;
  margin: 0 0 8px;
  letter-spacing: -0.5px;
}
.page-head p { margin: 0; color: var(--muted); font-size: 15px; }

.card {
  background: var(--card);
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card + .card { margin-top: 20px; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 32px 0 14px;
}
.section-title h2 {
  font-size: 18px;
  margin: 0;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
  color: var(--text);
  background: #f3f4f6;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.25);
}
.btn-primary:hover { background: linear-gradient(135deg, #4338ca, #5558e8); }
.btn-ghost {
  background: #fff;
  border-color: var(--line);
}
.btn-ghost:hover { background: #f9fafb; }
.btn-danger {
  background: var(--danger-weak);
  color: var(--danger);
  border-color: #fecaca;
}
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 18px; }
.field > label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.field .hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
input[type="text"],
input[type="datetime-local"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus,
input[type="datetime-local"]:focus,
textarea:focus {
  border-color: #a5b4fc;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}
textarea { resize: vertical; min-height: 74px; }
input::placeholder, textarea::placeholder { color: #9ca3af; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  background: #fff;
}
.check-row:hover { background: #fafaff; }
.check-row input { margin-top: 4px; accent-color: var(--primary); }
.check-row .desc { display: block; font-size: 12px; color: var(--muted); }
.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option-editor { display: flex; flex-direction: column; gap: 8px; }
.option-editor-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.option-index {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary-weak);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.option-editor-row input { flex: 1; }
.icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}
.icon-btn:hover { color: var(--danger); border-color: #fecaca; background: var(--danger-weak); }

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}
.form-error {
  background: var(--danger-weak);
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- 列表 ---------- */
.tabs { display: inline-flex; background: #eef0f5; border-radius: 10px; padding: 3px; }
.tabs button {
  border: 0;
  background: transparent;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.tabs button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 2px 6px rgba(17, 24, 39, 0.08);
}

.vote-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.vote-item {
  display: block;
  background: var(--card);
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: 14px;
  padding: 20px;
  color: inherit;
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.04);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.vote-item:hover {
  text-decoration: none;
  transform: translateY(-3px);
  box-shadow: 0 14px 30px rgba(17, 24, 39, 0.09);
  border-color: #dcd9fb;
}
.vote-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.vote-item h3 {
  font-size: 16px;
  margin: 0;
  line-height: 1.45;
  word-break: break-word;
}
.vote-item .desc {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 21px;
}
.vote-item .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 12px;
}
.vote-count strong { color: var(--primary); font-size: 15px; }

.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-open { background: var(--success-weak); color: var(--success); }
.badge-ended { background: #f3f4f6; color: #6b7280; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 14px;
  font-size: 14px;
}

/* ---------- 投票页 ---------- */
.vote-header { margin-bottom: 18px; }
.vote-header h1 {
  font-size: 26px;
  line-height: 1.35;
  margin: 0 0 10px;
  word-break: break-word;
}
.vote-header .desc {
  color: #4b5563;
  font-size: 15px;
  margin: 0 0 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #4b5563;
  background: #f3f4f6;
  border-radius: 999px;
  padding: 4px 11px;
}
.chip-strong { background: var(--primary-weak); color: var(--primary); font-weight: 600; }

.notice {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
}
.notice-success {
  background: var(--success-weak);
  border-color: #a7f3d0;
  color: #065f46;
}
.notice-info {
  background: var(--primary-weak);
  border-color: #c7d2fe;
  color: #3730a3;
}

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
  min-height: 54px;
}
.choice:hover { border-color: #c7d2fe; background: #fbfbff; }
.choice.is-selected {
  border-color: var(--primary);
  background: var(--primary-weak);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-mark {
  flex: none;
  width: 22px;
  height: 22px;
  border: 2px solid #cbd5e1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  transition: all 0.14s ease;
}
.choice-multi .choice-mark { border-radius: 6px; }
.choice.is-selected .choice-mark {
  border-color: var(--primary);
  background: var(--primary);
}
.choice.is-selected .choice-mark::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}
.choice-text { flex: 1; font-size: 15px; word-break: break-word; }
.choice-count {
  flex: none;
  font-size: 12px;
  color: var(--muted);
}

.vote-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.vote-actions .btn-primary { min-width: 130px; }

/* 结果 */
.results { display: flex; flex-direction: column; gap: 16px; margin-top: 4px; }
.result-row .result-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 7px;
  font-size: 14px;
}
.result-text { font-weight: 600; word-break: break-word; }
.result-num { color: var(--muted); font-size: 13px; white-space: nowrap; }
.result-num b { color: var(--text); font-size: 15px; }
.result-num .pct { color: var(--primary); font-weight: 700; }
.result-row.is-mine .result-text::after {
  content: "我的选择";
  font-size: 11px;
  color: var(--primary);
  background: var(--primary-weak);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 8px;
  font-weight: 600;
  vertical-align: 2px;
}
.bar {
  height: 10px;
  background: #eef0f5;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.result-row.is-mine .bar-fill { background: linear-gradient(90deg, #4f46e5, #6366f1); }

.results-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.results-summary strong { color: var(--text); font-size: 20px; margin-right: 4px; }

/* 分享与管理 */
.share-box { display: flex; gap: 8px; }
.share-box input {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  background: #f9fafb;
}
.section-label {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 10px;
}
.divider { height: 1px; background: var(--line); margin: 24px 0; }

.manage-zone {
  background: #fbfbfd;
  border: 1px dashed #d9d6fe;
  border-radius: 12px;
  padding: 18px;
}
.manage-zone .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.manage-zone .row + .row { margin-top: 10px; }
.manage-zone input { flex: 1; min-width: 200px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.token-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  word-break: break-all;
}

/* ---------- 提示 ---------- */
#toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  background: rgba(17, 24, 39, 0.9);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.2s ease;
}
.toast.toast-error { background: rgba(185, 28, 28, 0.95); }
.toast.toast-success { background: rgba(5, 122, 85, 0.95); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
  font-size: 14px;
}

.footer {
  text-align: center;
  color: #9ca3af;
  font-size: 12px;
  padding: 28px 0 8px;
}

.error-card { text-align: center; padding: 48px 24px; }
.error-card h2 { margin: 0 0 8px; font-size: 20px; }
.error-card p { color: var(--muted); margin: 0 0 20px; }

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .container { padding: 0 16px 48px; }
  .topbar-inner { padding: 12px 16px; }
  .page-head { padding-top: 26px; }
  .page-head h1 { font-size: 25px; }
  .card { padding: 18px; border-radius: 14px; }
  .vote-grid { grid-template-columns: 1fr; gap: 12px; }
  .check-grid { grid-template-columns: 1fr; }
  .vote-header h1 { font-size: 21px; }
  .choice { padding: 13px 14px; min-height: 52px; }
  .choice-text { font-size: 14px; }
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .form-actions .btn { width: 100%; }
  .vote-actions { flex-direction: column; align-items: stretch; }
  .vote-actions .btn { width: 100%; }
  .share-box { flex-direction: column; }
  .share-box .btn { width: 100%; }
  .results-summary strong { font-size: 18px; }
  .section-title { margin-top: 24px; }
}
