/* ========== 设计令牌 ========== */
:root {
  color-scheme: light dark;
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-muted: #eceef5;
  --text: #191b27;
  --text-muted: #626779;
  --border: #e2e5ee;
  --accent: #5a54e6;
  --accent-strong: #4640c9;
  --accent-soft: rgb(90 84 230 / 0.1);
  --on-accent: #ffffff;
  --danger: #d14343;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 6px 20px rgb(16 24 40 / 0.06);
  --bar-height: 72px;
  --content-width: 1080px;
  --font: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016;
    --surface: #171a23;
    --surface-muted: #262a38;
    --text: #e9ebf3;
    --text-muted: #9ba1b5;
    --border: #2a2f3e;
    --accent: #8f8bff;
    --accent-strong: #a9a6ff;
    --accent-soft: rgb(143 139 255 / 0.14);
    --on-accent: #10121a;
    --danger: #ff7a7a;
    --shadow: none;
  }
}

/* ========== 基础 ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: calc(var(--bar-height) + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}

h1,
h2,
h3,
p {
  margin: 0;
}

/* 仅供读屏朗读，视觉隐藏 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

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

/* ========== 头部 ========== */
.hero {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 40px 16px 24px;
}

.hero__eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.hero__title {
  margin-top: 6px;
  font-size: clamp(26px, 5vw, 34px);
  font-weight: 700;
  line-height: 1.25;
}

.hero__desc {
  margin-top: 10px;
  color: var(--text-muted);
}

.hero__desc strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ========== 作品列表 ========== */
.container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 16px 24px;
}

.entry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.entry-grid__message {
  grid-column: 1 / -1;
  padding: 48px 0;
  color: var(--text-muted);
  text-align: center;
}

.entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.entry.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.entry audio {
  display: none;
}

/* 播放按钮 */
.entry__play {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background-color 0.15s, color 0.15s, transform 0.1s;
}

.entry__play:active {
  transform: scale(0.94);
}

.entry.is-playing .entry__play {
  background: var(--accent);
  color: var(--on-accent);
}

.entry.is-error .entry__play {
  opacity: 0.4;
  pointer-events: none;
}

.icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon--pause,
.entry.is-playing .icon--play {
  display: none;
}

.entry.is-playing .icon--pause {
  display: block;
}

/* 信息区 */
.entry__body {
  min-width: 0;
}

.entry__title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  font-size: inherit;
  font-weight: inherit;
}

.entry__id {
  flex: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.entry__name {
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.entry__heard {
  display: none;
  flex: none;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 11px;
  line-height: 18px;
}

.entry.is-heard .entry__heard {
  display: inline-block;
}

.entry__meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* 进度条：外层加大点击区域，内层为可视轨道 */
.entry__bar {
  --progress: 0;
  padding: 8px 0 2px;
  cursor: pointer;
}

.entry__track {
  position: relative;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface-muted);
}

.entry__track::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(var(--progress));
  transform-origin: left;
  transition: transform 0.25s linear;
}

/* 选择按钮 */
.entry__pick {
  min-width: 64px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.entry__pick:hover:not(:disabled):not([aria-pressed="true"]) {
  border-color: var(--accent);
  color: var(--accent);
}

.entry__pick[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.entry__pick:disabled:not([aria-pressed="true"]) {
  opacity: 0.4;
}

/* ========== 底部选票栏 ========== */
.ballot-bar {
  position: fixed;
  inset: auto 0 0;
  z-index: 10;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
}

.ballot-bar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: var(--content-width);
  margin: 0 auto;
}

.ballot-bar__status {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ballot-bar__status strong {
  margin-right: 8px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ========== 按钮 ========== */
.btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}

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

.btn--primary:hover:not(:disabled):not([aria-disabled="true"]) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ========== 确认弹窗 ========== */
.dialog {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}

.dialog::backdrop {
  background: rgb(10 12 20 / 0.5);
}

.dialog__body {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.dialog__title {
  font-size: 18px;
}

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

.dialog__summary span {
  color: var(--text);
  font-weight: 600;
}

.dialog__error {
  color: var(--danger);
  font-size: 14px;
}

.dialog__error:empty {
  display: none;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 14px;
}

.field input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* 避免 iOS 聚焦时自动缩放 */
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ========== 提示 ========== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-height) + env(safe-area-inset-bottom) + 12px);
  z-index: 20;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  text-align: center;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

/* ========== 投票码（公众号消息投票） ========== */
.dialog__note {
  color: var(--text-muted);
  font-size: 14px;
}

.dialog__code {
  display: grid;
  gap: 10px;
  justify-items: center;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  text-align: center;
}

.dialog__code[hidden] {
  display: none;
}

.dialog__command strong {
  color: var(--accent-strong);
  font-size: 26px;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  user-select: all;
  -webkit-user-select: all;
}

.dialog__status {
  color: var(--text-muted);
  font-size: 13px;
}

.btn--small {
  height: 34px;
  padding: 0 16px;
  font-size: 14px;
}

.btn[hidden],
.dialog__note[hidden] {
  display: none;
}

/* ========== 投票码引导：复制 → 关注 → 粘贴发送 ========== */
.dialog {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}

a.btn {
  color: inherit;
  text-decoration: none;
}

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

.btn--small {
  min-height: 44px;
  min-width: 88px;
}

.btn--block {
  display: flex;
  width: 100%;
  min-height: 48px;
  font-size: 16px;
}

.dialog__copy {
  font-size: 14px;
  font-weight: 600;
}

.dialog__copy.is-ok {
  color: #1f8a4c;
}

.dialog__copy.is-fail {
  color: var(--danger);
}

.dialog__copy:empty {
  display: none;
}

.guide {
  display: grid;
  gap: 12px;
}

.guide[hidden] {
  display: none;
}

.guide__steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.guide__steps li {
  position: relative;
  min-height: 28px;
  padding-left: 38px;
  line-height: 28px;
  font-size: 15px;
  counter-increment: step;
}

.guide__steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
}

.guide__steps li.is-done::before {
  content: "✓";
  background: var(--accent);
  color: var(--on-accent);
}

.guide__qr {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.guide__qr summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

.guide__qr.is-static summary {
  display: none;
}

.guide__figure {
  display: grid;
  gap: 8px;
  justify-items: center;
  margin: 0;
  padding: 12px;
}

.guide__figure img {
  display: block;
  width: 180px;
  height: 180px;
  border-radius: 8px;
  background: #fff;
  -webkit-touch-callout: default;
}

.guide__figure figcaption {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* 得票数 */
.entry__votes {
  flex: none;
  margin-left: auto;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.entry__votes b {
  font-weight: 700;
}

/* 二维码下的公众号名称 / 微信号 */
.guide__account {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  text-align: center;
}

.guide__wxid {
  padding: 2px 8px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  -webkit-user-select: all;
  user-select: all;
}
