/* 打卡积分榜 —— 手机优先，支持深色模式 */

:root {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-soft: #f0f1f7;
  --text: #1a1c25;
  --text-muted: #6b7280;
  --border: #e4e6ef;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-text: #ffffff;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --gold: #f5b400;
  --silver: #a8adb8;
  --bronze: #cd7f32;
  --shadow: 0 1px 2px rgba(16, 18, 35, 0.04), 0 8px 24px rgba(16, 18, 35, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --bg-card: #181b24;
    --bg-soft: #212533;
    --text: #eceef5;
    --text-muted: #9aa1b1;
    --border: #2a2f3e;
    --accent: #7c7cf8;
    --accent-soft: #232744;
    --accent-text: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  padding: 0 0 32px;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.05rem; font-weight: 650; }
h2 { font-size: 1rem; font-weight: 650; margin-bottom: 8px; }

.muted { color: var(--text-muted); font-size: 0.82rem; margin: 0; }

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

/* ---------------------------------------------- 顶栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  /* 不支持 color-mix 的老浏览器用不透明背景兜底，否则这个吸顶栏会变透明 */
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

@supports (background: color-mix(in srgb, red 50%, blue)) {
  .topbar {
    background: color-mix(in srgb, var(--bg-card) 88%, transparent);
  }
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; flex: none; fill: var(--accent); }
.brand-text { min-width: 0; }
.brand-text p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 顶栏右侧：账号入口 + 实时状态 */
.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.topbar-account {
  white-space: nowrap;
  /* 顶栏里要更醒目一点，否则又会被忽略 */
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-soft);
  padding: 6px 14px;
}
.topbar-account:hover { color: var(--accent); border-color: var(--accent); }
/* 「规则」是一个链接而不是按钮，去掉下划线、保持与按钮一致 */
a.topbar-account {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.conn {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
}
.conn-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 0 currentColor;
}
.conn[data-state="online"] .conn-dot { background: var(--ok); animation: pulse 2.4s ease-out infinite; }
.conn[data-state="offline"] .conn-dot { background: var(--danger); }
.conn[data-state="connecting"] .conn-dot { background: var(--warn); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* ---------------------------------------------- 布局 */

main {
  max-width: 620px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card > h2 + .muted { margin-bottom: 14px; }

.footer { padding: 0 4px; text-align: center; line-height: 1.7; }

/* ---------------------------------------------- 表单 */

input[type="text"],
input[type="password"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

#joinForm { display: flex; flex-direction: column; gap: 14px; }

/* 带标签与提示的字段块 */
.field { display: flex; flex-direction: column; gap: 6px; }
/* .field 的 display:flex 会盖掉浏览器默认的 [hidden]{display:none}，
   必须显式声明，否则 hidden 属性形同虚设。 */
.field[hidden] { display: none; }
.field-label { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.field-hint {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-muted);
  min-height: 1.1em;
}
.field-hint.is-ok { color: var(--ok); }
.field-hint.is-taken { color: var(--warn); }

/* 密码输入框 + 显示/隐藏按钮 */
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { padding-right: 68px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font: inherit;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
.pw-toggle:hover { color: var(--text); border-color: var(--text-muted); }

/* 安全提醒块 */
.notice {
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  margin: 0 0 14px;
  font-size: 0.8rem;
  line-height: 1.65;
}
.notice-warn {
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--text);
}
.notice-warn strong { color: color-mix(in srgb, var(--warn) 70%, var(--text)); }

/* 临时密码提示条：比普通提醒更"要紧"，所以做成实心强调块 */
.notice-temp {
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  border: 1.5px solid var(--warn);
  color: var(--text);
  margin-bottom: 16px;
}
.notice-temp strong { display: block; color: color-mix(in srgb, var(--warn) 72%, var(--text)); }
.notice-temp p { margin: 4px 0 10px; }
.btn-small { padding: 9px 16px; font-size: 0.85rem; }

/* ---------------------------------------------- 我的打卡记录 */

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.history-row {
  display: grid;
  /* 凭证缩略图 · 时间 · 分数 · 备注 · 删除 */
  grid-template-columns: auto auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: none; }

.history-when { display: flex; flex-direction: column; line-height: 1.25; }
.history-date { font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.history-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.history-score {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  white-space: nowrap;
  min-width: 2.6em;
}

.history-note {
  font-size: 0.85rem;
  word-break: break-word;
  /* 备注可能很长，允许换行而不是撑破布局 */
  min-width: 0;
}
.history-note.is-empty { color: var(--text-muted); font-style: italic; }

.history-more {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
}

/* ---------------------------------------------- 打卡凭证 */

.evidence-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.evidence-field input[type="file"] {
  font: inherit;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  cursor: pointer;
}
/* 选中文件后浏览器自带的那行文字太长，窄屏会溢出 */
.evidence-field input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 0.8rem;
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}

/* 已选凭证的提示条。
   注意这里【不放缩略图】：浏览器解不开的格式（典型是 iPhone 的 HEIC）会显示成破图，
   alt 文字还会把固定尺寸的容器撑破、把按钮挤到错位。所以改成一列：
   文件名大小 + 一个「不传这张」按钮。 */
.evidence-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  padding: 10px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}
.evidence-preview[hidden] { display: none; }
.evidence-preview .field-hint {
  margin: 0;
  word-break: break-all;
}

/* 历史记录里的凭证缩略图 / 无凭证标记 */
.history-thumb {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.history-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.history-thumb.is-none {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--warn) 45%, var(--border));
}

.history-actions { flex: none; margin-left: auto; }
.btn-delete { color: var(--text-muted); }
.btn-delete.is-confirming {
  color: var(--danger);
  border-color: var(--danger);
  font-weight: 600;
}

/* 「无凭证」徽章：榜单与历史共用 */
.badge-missing {
  font-size: 0.68rem;
  line-height: 1.4;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
  color: color-mix(in srgb, var(--warn) 78%, var(--text));
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 32%, transparent);
  flex: none;
}

/* ---------------------------------------------- 称号徽章
   Lv.1–10 按段位配色：越高级越"贵重"。
   颜色台阶本身也是进阶感的一部分 —— 只换文字的话，一眼看不出谁更靠前。 */
.badge-title {
  font-size: 0.68rem;
  line-height: 1.4;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
  flex: none;
  font-weight: 600;
  color: var(--tier-fg, var(--text));
  background: color-mix(in srgb, var(--tier-bg, var(--accent)) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--tier-bg, var(--accent)) 40%, transparent);
}

/* Lv.1–3 绿（起步） */
.badge-title[data-level="1"],
.badge-title[data-level="2"],
.badge-title[data-level="3"] { --tier-bg: #16a34a; --tier-fg: #15803d; }

/* Lv.4–6 蓝（发力） */
.badge-title[data-level="4"],
.badge-title[data-level="5"],
.badge-title[data-level="6"] { --tier-bg: #2563eb; --tier-fg: #1d4ed8; }

/* Lv.7–8 紫（稀缺） */
.badge-title[data-level="7"],
.badge-title[data-level="8"] { --tier-bg: #7c3aed; --tier-fg: #6d28d9; }

/* Lv.9–10 金（封顶） */
.badge-title[data-level="9"],
.badge-title[data-level="10"] {
  --tier-bg: #d97706;
  --tier-fg: #b45309;
  box-shadow: 0 0 0 1px color-mix(in srgb, #d97706 25%, transparent);
}

@media (prefers-color-scheme: dark) {
  .badge-title[data-level="1"],
  .badge-title[data-level="2"],
  .badge-title[data-level="3"] { --tier-fg: #4ade80; }
  .badge-title[data-level="4"],
  .badge-title[data-level="5"],
  .badge-title[data-level="6"] { --tier-fg: #93c5fd; }
  .badge-title[data-level="7"],
  .badge-title[data-level="8"] { --tier-fg: #c4b5fd; }
  .badge-title[data-level="9"],
  .badge-title[data-level="10"] { --tier-fg: #fbbf24; }
}

/* ---------------------------------------------- 月度目标 */

/* ---------------------------------------------- 本月目标（置顶大卡） */

/* 这是打开页面第一眼要看到的，所以做得比其它卡片更大、字更重。 */
.goal-hero {
  padding: 20px 20px 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 7%, var(--bg-card)), var(--bg-card));
}

.goal-hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.goal-hero-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.goal-hero-month {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.goal-hero-body { margin-bottom: 4px; }

/* 大号 "12 / 20 天" */
.goal-hero-nums {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}
.goal-done {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
}
.goal-of {
  font-size: 1.1rem;
  color: var(--text-muted);
}
.goal-target {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}
.goal-unit {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* 加粗加高的进度条 */
.progress-lg { height: 16px; border-width: 1px; }
.progress-lg .progress-fill {
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #22c55e));
}

.goal-hero-text {
  margin: 10px 0 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

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

.goal-body {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 4px 0 12px;
}
.goal-progress { flex: 1 1 220px; min-width: 0; }

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #22c55e));
  transition: width 0.3s ease;
}
/* 起始宽度写在 CSS 里，不用内联 style 属性 ——
   CSP 的 style-src 是 nonce 制、没有 unsafe-inline，行内 style 会被浏览器拦掉。 */
#goalFill { width: 0; }
.goal-text {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.goal-achieved {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent);
  white-space: nowrap;
}

/* ---------------------------------------------- 运动时长（必填，放大） */

.duration-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

/* 必填项做得比普通输入框大一截，避免"太小容易看漏" */
.duration-input {
  width: 100%;
  font: inherit;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--text);
  background: var(--bg-soft);
  border: 2px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: var(--radius-sm);
  padding: 16px 14px;
  font-variant-numeric: tabular-nums;
}
.duration-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}
.duration-input::placeholder {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* 输完时长立刻显示"本次将记几分" */
.score-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 2px 0 14px;
  border-radius: var(--radius-sm);
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.score-preview-num {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}
.score-preview-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------------------------------------------- 月度目标表单 */

.goal-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
/* 与 .field[hidden] 同理：这条规则里的 display:flex 会盖掉浏览器默认的
   [hidden]{display:none}，不显式声明的话 JS 设 hidden=true 也藏不住表单。 */
.goal-form[hidden] { display: none; }
.goal-form-row { display: flex; gap: 8px; align-items: stretch; }
.goal-form-row input {
  width: 110px;
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}
.goal-form-row .btn-primary { padding: 9px 16px; }

/* 身份行里的称号块 */
.me-badge-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
  text-align: right;
}
.me-badge-wrap .field-hint { margin: 0; }

/* 历史记录里的运动时长 */
.history-duration {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* 时长输入的提示条紧跟在输入框下面，少一点视觉空隙 */
.duration-hint { margin-top: -8px; margin-bottom: 14px; }

/* 忘记密码说明 */
.forgot {
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.forgot summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  padding: 4px 0;
}
.forgot p { margin: 6px 0; line-height: 1.7; }
.forgot code {
  display: inline-block;
  font-size: 0.72rem;
  word-break: break-all;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 7px;
  color: var(--text);
}

/* ---------------------------------------------- 账号区 */

.account-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 16px;
  background: var(--bg-soft);
}
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { color: var(--danger); border-color: var(--danger); }

/* 「添加到桌面」：只在支持安装的环境里出现（见 public/pwa.js）。
   必须显式写 [hidden] 规则 —— 下面用了 display:flex，否则 hidden 属性会被压过去
   （本项目在 .goal-form 上踩过一次）。 */
.install-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.install-row[hidden] { display: none; }
.install-row .field-hint { margin: 0; flex: 1 1 220px; }
.install-row .btn-small { flex: none; }

.pw-form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.pw-form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pw-form-actions .btn-primary { flex: 1; min-width: 140px; padding: 11px 16px; }

.btn-primary {
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
/* 离线页的「重新加载」是个 <a>；按钮样式是按 <button> 设计的，
   给链接补上 inline-block，否则内边距会压到相邻文字上。 */
a.btn-primary { display: inline-block; text-decoration: none; }
.empty .offline-retry { margin: 16px 0 0; }

.btn-ghost {
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.field-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin: 8px 0 0;
  min-height: 1.2em;
}

.shake { animation: shake 0.32s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------------------------------------------- 身份行 */

.me-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.me-row strong { display: block; font-size: 1.05rem; }
.me-row .muted { display: block; }

/* 分数选择器已移除：分数由运动时长自动判定（见 .duration-field / .score-preview）。 */

.note-field { display: block; margin-bottom: 14px; }
.note-field .muted { display: block; margin-bottom: 6px; }

.btn-checkin {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent-text);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #a855f7));
  border: none;
  border-radius: 14px;
  padding: 16px;
  cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
  touch-action: manipulation;
}
.btn-checkin:active { transform: scale(0.98); box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 25%, transparent); }
.btn-checkin:disabled { opacity: 0.65; cursor: default; }

/* ---------------------------------------------- 个人统计 */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.stats div { text-align: center; min-width: 0; }
.stats dt {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stats dd {
  margin: 2px 0 0;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------- 排行榜 */

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.board-head h2 { margin: 0; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-soft);
  border-radius: 999px;
}
.tab {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 6px 16px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab.is-active {
  color: var(--text);
  background: var(--bg-card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.board-body { position: relative; }

.board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.board-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, transform 0.25s;
}
.board-row:nth-child(odd) { background: var(--bg-soft); }
.board-row.is-me {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}
.board-row.is-me .row-name { color: var(--accent); }

.rank-badge {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.board-row.is-gold .rank-badge,
.board-row.is-silver .rank-badge,
.board-row.is-bronze .rank-badge { font-size: 1.05rem; }
.board-row.is-gold { background: color-mix(in srgb, var(--gold) 12%, transparent); }
.board-row.is-silver { background: color-mix(in srgb, var(--silver) 12%, transparent); }
.board-row.is-bronze { background: color-mix(in srgb, var(--bronze) 12%, transparent); }

.row-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 名字、称号、「无凭证」同组，徽章才不会被 grid 推到分数那一列旁边 */
.board-row .row-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  /* 长昵称 + 称号 + 无凭证 三样并排时允许换行，避免把分数列挤掉 */
  flex-wrap: wrap;
}
.row-count { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.score-num {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 2.5em;
  text-align: right;
}

.empty { padding: 28px 12px; text-align: center; }
.empty p { margin: 0; color: var(--text-muted); font-size: 0.88rem; }

/* ---------------------------------------------- Toast */

.toast-wrap {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  padding: 10px 18px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--ok);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  transition: opacity 0.4s, transform 0.4s;
}
.toast-warn { background: var(--warn); }
.toast.is-out { opacity: 0; transform: translateY(-8px); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------------------------------------------- 战绩海报 */

.poster-entry { margin-top: 18px; text-align: center; }
.poster-btn {
  width: 100%;
  padding: 11px 14px;
  font-size: 0.86rem;
  font-weight: 600;
}
.poster-entry .muted { margin-top: 8px; }

/* 弹层出现时锁住背景滚动，否则手机上滑到一半会"透"到排行榜 */
body.poster-open { overflow: hidden; }

.poster-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 11, 22, 0.78);
  backdrop-filter: blur(4px);
}
.poster-modal[hidden] { display: none; }

.poster-sheet {
  width: min(400px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: poster-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

@keyframes poster-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.poster-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.poster-head h2 { margin: 0; }

.poster-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  /* 手机上长按图片才是存图的常规动作，别让系统菜单把它吃掉 */
  -webkit-touch-callout: default;
}

.poster-actions { display: flex; gap: 10px; margin-top: 12px; }
.poster-actions .btn-primary {
  flex: 1;
  display: block;
  text-align: center;
  text-decoration: none;
  padding: 12px 16px;
}
.poster-tip { margin-top: 10px; text-align: center; }

/* ---------------------------------------------- AI 短视频 */

.video-prompt {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  resize: vertical;
  min-height: 86px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.video-prompt:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.video-options { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0 14px; }
.video-option { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 130px; }
.video-option select {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.video-submit { width: 100%; }

.video-progress { margin-top: 14px; }
.video-bar {
  height: 8px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.video-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #a855f7));
  transition: width 0.4s ease;
}
.video-progress .muted { margin-top: 8px; }

.video-result { margin-top: 14px; }
.video-player {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  background: #000;
}

/* ---------------------------------------------- 规则页（rules.html） */

.rules-list {
  margin: 0;
  padding-left: 20px;
  line-height: 1.85;
  font-size: 0.9rem;
}
.rules-list li + li { margin-top: 8px; }
.rules-list strong { color: var(--text); }

.rules-table {
  width: 100%;
  margin: 12px 0 10px;
  border-collapse: collapse;
  font-size: 0.86rem;
  line-height: 1.6;
}
.rules-table th,
.rules-table td {
  padding: 10px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.rules-table thead th {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-soft);
  white-space: nowrap;
}
.rules-table tbody tr:last-child td { border-bottom: none; }

.rules-score {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 800;
  white-space: nowrap;
  color: var(--accent);
  background: var(--accent-soft);
}

.rules-note {
  margin: 10px 0 0;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.75;
  color: var(--text-muted);
  background: var(--bg-soft);
  border-left: 3px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  border-radius: 6px;
}

/* 窄屏把表格转成"每条一块"，避免横向滚动 */
@media (max-width: 560px) {
  .rules-table thead { display: none; }
  .rules-table,
  .rules-table tbody,
  .rules-table tr,
  .rules-table td { display: block; width: 100%; }
  .rules-table tr {
    padding: 10px 12px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
  }
  .rules-table td {
    padding: 2px 0;
    border: none;
  }
  .rules-table td::before {
    content: attr(data-label) '：';
    font-weight: 700;
    color: var(--text-muted);
  }
}

/* ---------------------------------------------- 视图与底部导航 */

/* 三个 tab 各自一个 .view 容器：切换就是换个容器显示，卡片本身的 hidden
   逻辑（未登录 / 没配 AI 能力）保持原样，两套互不干扰。 */
.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.view[hidden] { display: none; }

/* 底部导航是 fixed 的，给 body 垫出同高的空隙，否则最后一张卡片会被压住。
   只在登录后加这个类（见 public/app.js 的 applyView）。 */
body.has-tabbar { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px rgba(16, 18, 35, 0.06);
}

/* 半透明毛玻璃；老浏览器用上面那条不透明背景兜底 */
@supports (background: color-mix(in srgb, red 50%, blue)) {
  .tabbar {
    background: color-mix(in srgb, var(--bg-card) 97%, transparent);
    backdrop-filter: blur(14px);
  }
}
/* 导航靠 hidden 属性隐藏，而 .tabbar 设了 display:grid，必须显式兜底 */
.tabbar[hidden] { display: none; }

.tabbar-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  padding: 4px 6px;
  font: inherit;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, transform 0.12s;
}
.tabbar-item:hover { color: var(--text); }
.tabbar-item:active { transform: scale(0.96); }
.tabbar-item.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 650;
}
.tabbar-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.tabbar-icon { width: 22px; height: 22px; }

/* 「我的」右上角的小红点：有临时密码之类的待办时提示一下 */
.tabbar-dot {
  position: absolute;
  top: 7px;
  right: calc(50% - 16px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--bg-card);
}
.tabbar-dot[hidden] { display: none; }

/* ---------------------------------------------- 记录页 */

.range-tabs {
  display: flex;
  flex: none;
  gap: 3px;
  padding: 3px;
  background: var(--bg-soft);
  border-radius: 999px;
}
.range-tabs .tab {
  padding: 5px 12px;
  font-size: 0.76rem;
}

.records-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 8px;
  margin-bottom: 4px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
}
.summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.summary-num {
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  /* 数字等宽，7/30 切换时整块不会左右跳 */
  font-variant-numeric: tabular-nums;
}
.summary-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.chart-figure {
  position: relative;
  margin: 12px 0 2px;
}
.chart-host {
  padding: 6px 2px 0;
  border-radius: var(--radius-sm);
  background-image: radial-gradient(circle at 50% 0%, var(--accent-soft), transparent 72%);
}
.chart-host svg { display: block; width: 100%; height: auto; }

/* 图表内部全用类名控制配色：颜色写在 SVG 属性里的话，深色模式下改不动 */
.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}
.chart-baseline { stroke: var(--border); stroke-width: 1; }
.chart-label {
  fill: var(--text-muted);
  font-size: 9px;
  font-family: inherit;
}
.chart-area { fill: url(#chartGrad); }
.chart-grad-top { stop-color: var(--accent); stop-opacity: 0.3; }
.chart-grad-bottom { stop-color: var(--accent); stop-opacity: 0; }
.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-dot {
  fill: var(--bg-card);
  stroke: var(--accent);
  stroke-width: 1.6;
  transition: r 0.12s;
}
.chart-dot.is-today { r: 3.2; stroke-width: 2.2; }
.chart-halo { fill: var(--accent); fill-opacity: 0.16; }
.chart-dot.is-active { r: 4.6; }

.chart-tip {
  position: absolute;
  z-index: 2;
  padding: 5px 9px;
  font-size: 0.72rem;
  line-height: 1.45;
  white-space: nowrap;
  color: #fff;
  background: #1f2333;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  transform: translate(-50%, -125%);
}
.chart-tip[hidden] { display: none; }

.chart-caption {
  margin: 8px 2px 0;
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
}

/* 记录页的空态里放了一个按钮，居中一点才像话 */
.records-card .empty .btn-primary { margin-top: 12px; }

/* ---------------------------------------------- 我的 */

.mine-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.mine-links a { text-decoration: none; }

/* 平板 / 桌面：导航跟正文一样宽并居中，别把三个按钮拉得满屏都是 */
@media (min-width: 700px) {
  .tabbar {
    max-width: 620px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
  }
}

/* ---------------------------------------------- 小屏微调 */

@media (max-width: 420px) {
  main { padding: 12px; gap: 12px; }
  .card { padding: 15px; }
  .board-row { grid-template-columns: 34px minmax(0, 1fr) auto auto; gap: 8px; padding: 8px 6px; }
  .stats dd { font-size: 1.1rem; }

  /* 顶栏空间紧张：把实时状态收成只留一个圆点，
     给「账号」按钮让出位置。title 与 aria-label 仍在，不影响可访问性。 */
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar-account { padding: 6px 12px; font-size: 0.8rem; }
  .conn-text { display: none; }
  .conn { padding: 6px; }

  /* 历史记录：日期和时间并排，省一行高度 */
  .history-when { flex-direction: row; align-items: baseline; gap: 6px; }
  .history-row { gap: 7px; padding: 9px 2px; }
  /* 窄屏上缩略图和小按钮都要收一点，否则备注那列就没地方了 */
  .history-thumb { width: 36px; height: 36px; }
  .history-thumb.is-none { font-size: 0.6rem; }
  .history-actions .btn-small { padding: 6px 9px; }

  /* 三个榜的 tab 在窄屏要收紧，否则会换行或溢出 */
  .tabs { gap: 2px; padding: 2px; }
  .tab { padding: 6px 10px; font-size: 0.76rem; }

  /* 身份行放不下时改成上下两行，称号块靠左 */
  .me-row { flex-wrap: wrap; }
  .me-badge-wrap { align-items: flex-start; text-align: left; }
  .goal-form-row input { width: 88px; }

  /* 置顶目标卡在小屏也保持醒目，但别把版面撑得太高 */
  .goal-hero { padding: 16px 15px; }
  .goal-done { font-size: 2rem; }

  /* 记录页：四个数字块在小屏要收紧，否则「有效天数」这类标签会换行 */
  .records-summary { gap: 4px; padding: 10px 4px; }
  .summary-num { font-size: 0.92rem; }
  .summary-label { font-size: 0.66rem; }
  .range-tabs .tab { padding: 5px 9px; font-size: 0.72rem; }
  .tabbar-item { font-size: 0.68rem; }
  .tabbar-icon { width: 20px; height: 20px; }
}

/* ---------------------------------------------- 装到桌面后（standalone） */

/* 独立窗口里没有浏览器地址栏，页面会顶到状态栏底下。
   iOS 的刘海/灵动岛与底部手势条要靠 safe-area 让位，否则标题被切、按钮难点。 */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
  body { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  /* 有底部导航时，让位高度以导航为准（否则最后一张卡会被导航压住） */
  body.has-tabbar { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast-wrap { top: calc(66px + env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
