/*
  galvote · 样式表（移动优先）
  主题通过 :root 上的 CSS 变量切换（data-theme="midnight|sakura|light"）。
*/

/* 关键：任何带 hidden 属性的元素都必须真的隐藏。
   .modal 声明了 display:grid，与浏览器默认的 [hidden]{display:none} 同优先级，
   但作者样式胜出 —— 于是 position:fixed;inset:0 的全屏遮罩从首屏起就一直盖在页面上，
   把每一个点击都吃掉（表现为「整页点不动」）。这条兜底规则同时保护 #toast /
   #offline-banner / #vote-bar。 */
[hidden] { display: none !important; }

:root,
[data-theme='midnight'] {
  --bg: #0b0d14;
  --bg-glow-1: rgba(56, 189, 248, 0.16);
  --bg-glow-2: rgba(168, 85, 247, 0.14);
  --surface: #141824;
  --surface-2: #1b2130;
  --surface-3: #232a3c;
  --border: #2a3145;
  --border-strong: #3b4460;
  --text: #e8ecf6;
  --text-dim: #9aa4bf;
  --text-faint: #6b748f;
  --accent: #38bdf8;
  --accent-ink: #04283b;
  --gold: #f5c451;
  --gold-ink: #3a2a05;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --maxw: 1080px;
}

[data-theme='sakura'] {
  --bg: #17121a;
  --bg-glow-1: rgba(244, 114, 182, 0.18);
  --bg-glow-2: rgba(251, 191, 36, 0.12);
  --surface: #241b28;
  --surface-2: #2e2334;
  --surface-3: #3a2b41;
  --border: #43304a;
  --border-strong: #5a4063;
  --text: #fbeef8;
  --text-dim: #c9aec6;
  --text-faint: #94788f;
  --accent: #f472b6;
  --accent-ink: #3d0a26;
  --gold: #fbbf24;
  --gold-ink: #3a2a05;
  --danger: #fb7185;
  --ok: #4ade80;
}

[data-theme='light'] {
  --bg: #f5f7fb;
  --bg-glow-1: rgba(56, 189, 248, 0.18);
  --bg-glow-2: rgba(168, 85, 247, 0.12);
  --surface: #ffffff;
  --surface-2: #f1f4fa;
  --surface-3: #e6ebf5;
  --border: #d9e0ee;
  --border-strong: #b9c4da;
  --text: #1a2033;
  --text-dim: #5a6480;
  --text-faint: #8792ab;
  --accent: #0284c7;
  --accent-ink: #ffffff;
  --gold: #b45309;
  --gold-ink: #fffbeb;
  --danger: #dc2626;
  --ok: #15803d;
  --shadow: 0 8px 24px rgba(23, 32, 61, 0.1);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, 'Segoe UI', 'Noto Sans SC', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60rem 40rem at 12% -10%, var(--bg-glow-1), transparent 70%),
    radial-gradient(50rem 35rem at 100% 8%, var(--bg-glow-2), transparent 70%);
  pointer-events: none;
}

img { max-width: 100%; display: block; }

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

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
  z-index: 100;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 8px;
}

/* ------------------------------------------------------------- 顶栏 ----- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--gold); }
.brand-text { font-size: 1rem; }
.nav {
  display: flex;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}
.nav a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.is-active {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text);
}

/* ------------------------------------------------------------ 版心 ------ */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px 140px;
}
main.no-bar { padding-bottom: 40px; }

.page-head { margin: 4px 0 18px; }
.page-head h1 { margin: 0 0 6px; font-size: clamp(1.4rem, 4vw, 2rem); line-height: 1.25; }
.page-head p { margin: 0; color: var(--text-dim); }

.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 60px 0;
  color: var(--text-dim);
}
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ 卡片 ------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card > h2, .card > h3 { margin-top: 0; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.05rem; }

.grid { display: grid; gap: 16px; }
@media (min-width: 760px) {
  .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ------------------------------------------------------------ 表单 ------ */
.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}
.field .hint { font-size: 0.78rem; color: var(--text-faint); margin-top: 6px; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 160px; }

input[type='text'], input[type='password'], input[type='number'],
input[type='datetime-local'], input[type='url'], textarea, select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
textarea { min-height: 88px; resize: vertical; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.check input { width: 18px; height: 18px; }

/* ------------------------------------------------------------ 按钮 ------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-gold {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
}
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 0.85rem; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* -------------------------------------------------------- 活动头部 ------ */
.event-hero {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 20px;
  background: var(--surface);
}
.event-hero-body { padding: 18px; }
.event-hero-body h1 { margin: 0 0 6px; font-size: clamp(1.4rem, 5vw, 2.1rem); }
.event-hero-body .sub { color: var(--text-dim); margin: 0 0 12px; }
.event-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.82rem; }
.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
}
.pill.is-open { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill.is-closed { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.pill.is-gold { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); }

.rules {
  white-space: pre-wrap;
  color: var(--text-dim);
  font-size: 0.92rem;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0 0 20px;
}

/* ------------------------------------------------------------ 题目 ------ */
.question {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.question.is-done { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.q-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.q-index {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-dim);
  display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 700;
}
.q-title { margin: 0; font-size: 1.1rem; line-height: 1.35; }
.q-note { color: var(--text-dim); font-size: 0.88rem; margin: 6px 0 0; }
.q-kind {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: auto;
  white-space: nowrap;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
}
.q-kind.is-weighted { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 50%, transparent); }

/* 加权题提示行（不再有「模式切换」：每张票直接点在选项上） */
.vote-hint { font-size: 0.82rem; color: var(--text-faint); margin: 10px 0 0; line-height: 1.55; }

/* ★ 加权票开关（每题最多 1 张） */
.weighted-chip {
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.weighted-chip:hover { border-color: var(--gold); color: var(--text); }
.weighted-chip.is-on { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }

/* 普通票步进器：− n +（同一选项可以叠投多张） */
.option-stepper {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
}
.step-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.step-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.step-btn:disabled { opacity: 0.32; cursor: not-allowed; }
.step-num { min-width: 20px; text-align: center; font-size: 0.9rem; }

/* 叠投快捷操作：把剩下的普通票一次给它 */
.fill-chip {
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.74rem;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.fill-chip:hover { border-color: var(--accent); color: var(--text); }

/* 选项 */
.options { display: grid; gap: 10px; margin-top: 12px; }
@media (min-width: 760px) {
  .options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .options.dense { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.option {
  position: relative;
  display: flex;
  gap: 10px;
  align-items: stretch;
  text-align: left;
  padding: 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s ease, background 0.12s ease;
}
.option:hover { border-color: var(--border-strong); background: var(--surface-3); }
/* 选项主体是按钮，右侧留给 ★加权 / 步进器，两者互不抢点击 */
.option-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  font: inherit;
  text-align: left;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.option-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
  justify-content: center;
}
.option-title { font-weight: 700; font-size: 0.98rem; }
.option-desc { color: var(--text-dim); font-size: 0.84rem; white-space: pre-wrap; }
.option-body.no-text { justify-content: center; }

.option-badges { display: flex; gap: 4px; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-faint);
}
.badge.is-weighted { color: var(--gold-ink); background: var(--gold); border-color: var(--gold); font-weight: 700; }
.badge.is-normal { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 700; }
.badge.is-locked { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }

.option.is-picked { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }
.option.is-weighted { border-color: var(--gold); border-width: 2.5px; background: color-mix(in srgb, var(--gold) 14%, var(--surface-2)); }

/* ------------------------------------------------------- 底部提交栏 ----- */
.vote-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
}
.vote-bar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.vote-progress { flex: 1 1 auto; min-width: 0; }
.vote-progress-text { font-size: 0.82rem; color: var(--text-dim); margin-bottom: 5px; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }
/* 提交被拦住时直接说清"还差什么"，而不是只留一个灰掉的按钮 */
.vote-blocked {
  margin-top: 6px;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--danger);
}
.vote-blocked.is-jump { cursor: pointer; text-decoration: underline dotted; }
.vote-restored { margin-top: 4px; font-size: 0.76rem; color: var(--text-faint); }

/* ------------------------------------------------------------ 结果 ------ */
.rank { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.rank li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.rank-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rank-no { font-weight: 700; color: var(--text-faint); font-size: 0.85rem; }
.rank-title { font-weight: 700; }
.rank-score { margin-left: auto; font-weight: 700; color: var(--accent); }
.rank-sub { font-size: 0.78rem; color: var(--text-faint); margin: 4px 0 6px; }
.rank li:nth-child(1) .rank-no { color: var(--gold); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; min-width: 420px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--text-dim); font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ 表格/列表 - */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  min-height: 40px;
  padding: 8px 16px;
  font: inherit;
  font-size: 0.9rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
}
.tab.is-active { background: var(--surface-3); color: var(--text); border-color: var(--accent); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.list-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.list-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-item-head strong { font-size: 1rem; }
.spacer { margin-left: auto; }

.empty { color: var(--text-faint); text-align: center; padding: 28px 10px; }

/* ------------------------------------------------------------ 提示 ------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 460px);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  text-align: center;
}
.toast.is-error { border-color: var(--danger); color: var(--danger); }
.toast.is-ok { border-color: var(--ok); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.62);
}
.modal-card {
  width: min(560px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 10px; }

.offline {
  position: fixed;
  left: 0; right: 0; top: 0;
  z-index: 80;
  background: var(--gold);
  color: var(--gold-ink);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
}

.noscript { max-width: var(--maxw); margin: 40px auto; padding: 0 16px; }

.warn {
  background: color-mix(in srgb, var(--gold) 14%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin: 10px 0;
}
.err {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88rem;
  margin: 10px 0;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.copy-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.copy-row input { flex: 1 1 220px; min-width: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
