/* ============ 基础（默认亮色，html[data-theme="dark"] 覆盖为暗色） ============ */
:root {
  --bg: #f4f6f9;
  --bg-2: #ffffff;
  --bg-3: #e9edf3;
  --line: #d9dfe8;
  --text: #1b1f27;
  --muted: #5d6675;
  --accent: #3366e0;
  --accent-2: #6b4ef0;
  --green: #0d9668;
  --red: #d94444;
  --amber: #b97a10;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(30, 36, 60, 0.12);
  --topbar-bg: rgba(244, 246, 249, 0.92);
  --timerbar-bg: rgba(255, 255, 255, 0.97);
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-2: #171a21;
  --bg-3: #1f242e;
  --line: #2a3040;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --topbar-bg: rgba(15, 17, 21, 0.92);
  --timerbar-bg: rgba(23, 26, 33, 0.97);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  padding-bottom: 64px;
  transition: background 0.25s ease, color 0.25s ease;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea {
  font-family: inherit; font-size: 16px; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none; width: 100%;
  transition: background 0.25s ease, border-color 0.25s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
a { color: var(--accent); text-decoration: none; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  transition: background 0.25s ease;
}
.topbar-inner {
  max-width: 820px; margin: 0 auto; padding: 12px 16px 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo { font-size: 18px; font-weight: 700; }
.today { color: var(--muted); font-size: 13px; }
.theme-toggle {
  width: 34px; height: 34px; border-radius: 10px; font-size: 16px;
  background: var(--bg-3); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.theme-toggle:hover { transform: scale(1.06); }
.theme-toggle:active { transform: scale(0.96); }
.tabs {
  max-width: 820px; margin: 0 auto; display: flex; gap: 4px;
  padding: 0 12px 10px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1; min-width: 64px; text-align: center; padding: 8px 6px;
  border-radius: 10px; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.tab.active { background: var(--bg-3); color: var(--text); font-weight: 600; }

/* ============ 视图 ============ */
.view { max-width: 820px; margin: 0 auto; padding: 16px 14px 24px; }
.view > * { animation: fadeUp 0.22s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.spin { display: inline-block; animation: rot 0.9s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card h3 { font-size: 15px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border-radius: 12px; padding: 12px 18px;
  font-size: 15px; font-weight: 600; transition: opacity 0.15s;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--bg-3); border: 1px solid var(--line); color: var(--text); font-weight: 500; }
.btn.danger { background: rgba(248, 113, 113, 0.12); color: var(--red); border: 1px solid rgba(248, 113, 113, 0.35); font-weight: 500; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.green { background: var(--green); color: #06281c; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* 统计小卡 */
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat-card .n { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat-card .l { color: var(--muted); font-size: 12px; }
.stat-card .u { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 3px; }

/* 训练页 */
.hero { text-align: center; padding: 34px 18px; }
.hero .big { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.hero .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.hero .btn { max-width: 320px; }

.session-summary { display: flex; gap: 24px; flex-wrap: wrap; }
.session-summary .item b { font-size: 18px; display: block; }
.session-summary .item span { color: var(--muted); font-size: 12px; }

.exercise-block { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.exercise-head { padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); cursor: pointer; }
.exercise-head .name { font-weight: 600; font-size: 15px; }
.exercise-head .tag { font-size: 12px; color: var(--muted); }
.sets-list { padding: 4px 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.set-row:last-child { border-bottom: none; }
.set-row .idx { color: var(--muted); min-width: 52px; }
.set-row .val { font-variant-numeric: tabular-nums; }
.set-row .del { color: var(--muted); padding: 4px 8px; font-size: 13px; }
.set-row .del:hover { color: var(--red); }

.logging-panel { background: var(--bg-3); border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.logging-panel .ex-name { font-weight: 700; margin-bottom: 12px; font-size: 16px; }

.stepper { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stepper label { color: var(--muted); font-size: 13px; min-width: 56px; }
.stepper .ctl { display: flex; align-items: center; gap: 6px; }
.stepper .btn { width: 40px; height: 40px; padding: 0; border-radius: 10px; font-size: 18px; }
.stepper .val { min-width: 88px; text-align: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper .unit { font-size: 12px; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 12px; border-radius: 999px; background: var(--bg-3);
  border: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* 运动库 */
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ex-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; position: relative; cursor: pointer; transition: border-color 0.15s; }
.ex-card:hover { border-color: var(--accent); }
.ex-card .name { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.ex-card .meta { font-size: 12px; color: var(--muted); line-height: 1.7; }
.ex-card .custom-badge { position: absolute; top: 8px; right: 8px; font-size: 10px; background: var(--accent-2); color: #fff; padding: 2px 7px; border-radius: 999px; }
.ex-card .ex-del { position: absolute; bottom: 8px; right: 8px; font-size: 12px; color: var(--muted); padding: 2px 6px; }
.ex-card .ex-del:hover { color: var(--red); }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; }

/* 历史 */
.session-card { cursor: pointer; }
.session-card .date { font-weight: 700; font-size: 15px; }
.session-card .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.session-detail { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 12px; }
.session-detail .dex-name { font-weight: 600; font-size: 14px; margin: 10px 0 4px; }
.session-detail .dset { font-size: 13px; color: var(--muted); padding: 3px 0; display: flex; justify-content: space-between; }

/* 统计 */
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 130px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 34px; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.bar-col .v { font-size: 11px; color: var(--muted); }
.bar-col .w { font-size: 12px; color: var(--muted); }
.pr-table { font-size: 13px; }
.pr-table .pr-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.pr-table .pr-row:last-child { border-bottom: none; }

/* 设置 */
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px dashed var(--line); gap: 10px; flex-wrap: wrap; }
.setting-row:last-child { border-bottom: none; }
.setting-row .label { font-size: 14px; }
.setting-row .desc { color: var(--muted); font-size: 12px; margin-top: 3px; }
.setting-row input[type="number"], .setting-row input[type="password"] { width: 130px; }

.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { display: none; }
.switch .track { position: absolute; inset: 0; background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; transition: 0.2s; }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .track + .knob { left: 23px; }

/* ============ 休息倒计时 ============ */
.timer-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--timerbar-bg); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  transition: background 0.25s ease;
}
.timer-inner { max-width: 820px; margin: 0 auto; padding: 12px 16px 16px; display: flex; align-items: center; gap: 14px; }
.timer-ring { position: relative; width: 58px; height: 58px; flex-shrink: 0; }
.timer-ring svg { transform: rotate(-90deg); }
.timer-ring .ring-bg { stroke: var(--bg-3); }
.timer-ring .ring-fg { stroke: var(--accent); transition: stroke-dashoffset 0.3s linear; }
.timer-ring .num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer-info { flex: 1; min-width: 0; }
.timer-info .t-label { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer-info .t-time { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.timer-info .t-time.done { color: var(--green); font-size: 22px; }
.timer-actions { display: flex; gap: 6px; flex-shrink: 0; }
.timer-actions .btn.sm { padding: 9px 12px; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: slideUp 0.18s ease;
}
@media (min-width: 640px) {
  .modal-mask { align-items: center; }
  .modal { border-radius: 18px; }
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal .form-row { margin-bottom: 12px; }
.modal .form-row label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.modal-close { position: absolute; right: 12px; top: 10px; color: var(--muted); font-size: 18px; padding: 6px; }

/* toast */
#toast-root { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow);
  animation: slideDown 0.2s ease; max-width: 90vw;
}
.toast.err { border-color: rgba(248, 113, 113, 0.5); color: var(--red); }
.toast.ok { border-color: rgba(52, 211, 153, 0.5); color: var(--green); }
@keyframes slideDown { from { transform: translateY(-14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 空状态 */
.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 14px; }
.empty .icon { font-size: 40px; margin-bottom: 10px; }

.pulse { animation: pulse 1.2s ease infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }