/* 健身训练台 —— 移动优先，深色默认（健身房光线 + 省电）。
 *
 * 配色取自 dataviz skill 的 reference palette，两种模式都跑过
 * scripts/validate_palette.js：
 *   深色 6 系列（surface #161615）：全部 PASS
 *   浅色 6 系列：contrast WARN -> 按 relief rule，每张图都配「看数据」表格视图
 *
 * 点按目标一律 >= 48px：戴着汗手套、组间只有 90 秒。
 */

:root {
  color-scheme: dark;

  --plane: #0d0d0d;
  --surface-1: #161615;
  --surface-2: #202020;
  --surface-3: #2a2a28;

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;

  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);

  /* 分类色板（深色列），用于部位堆叠柱 —— 固定顺序，绝不循环复用 */
  --series-1: #3987e5; /* 腿 */
  --series-2: #d95926; /* 胸 */
  --series-3: #199e70; /* 背 */
  --series-4: #c98500; /* 肩 */
  --series-5: #d55181; /* 手臂 */
  --series-6: #008300; /* 核心 */

  /* 状态色 —— 保留色，绝不当第 7 个系列色用；始终配文字标签 */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  /* RPE 序数梯度（单一蓝色 hue）。深色下低值用深步、高值用浅步，
     让「更吃力」在视觉上更突出；最深不超过 step 600，保证 >= 2:1。 */
  --rpe-6: #184f95;
  --rpe-7: #256abf;
  --rpe-8: #3987e5;
  --rpe-9: #86b6ef;
  --rpe-10: #cde2fb;

  --radius: 12px;
  --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:where(:not([data-theme="dark"])) {
    color-scheme: light;
    --plane: #f9f9f7;
    --surface-1: #fcfcfb;
    --surface-2: #f2f1ee;
    --surface-3: #e8e7e2;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.1);
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --series-6: #008300;
    --rpe-6: #86b6ef;
    --rpe-7: #5598e7;
    --rpe-8: #2a78d6;
    --rpe-9: #256abf;
    --rpe-10: #184f95;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  background: var(--plane);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 16px; /* < 16px 会让 iOS Safari 自动放大页面 */
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.3;
}

/* ---------------- 顶栏 / 备份提醒 ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--plane);
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 650;
}

.topbar .date {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.banner {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid;
}

.banner.critical {
  background: color-mix(in srgb, var(--status-critical) 14%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-critical) 45%, transparent);
}

.banner.warning {
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-warning) 45%, transparent);
}

.banner button {
  margin-left: auto;
  flex: none;
  font-weight: 600;
  text-decoration: underline;
  min-height: 24px;
}

/* ---------------- 通用容器 ---------------- */

main {
  padding: 12px 16px 24px;
  max-width: 760px;
  margin: 0 auto;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card > h2 {
  font-size: 15px;
  font-weight: 650;
  margin-bottom: 4px;
}

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

.sub {
  color: var(--text-secondary);
  font-size: 14px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.wrap {
  flex-wrap: wrap;
}

.grow {
  flex: 1;
  min-width: 0;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 28px 16px;
}

/* ---------------- 按钮 ---------------- */

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-primary);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--series-1);
  border-color: transparent;
  color: #fff;
}

.btn.big {
  width: 100%;
  min-height: 60px;
  font-size: 18px;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  min-height: 38px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 500;
}

.btn.danger {
  color: var(--status-critical);
  border-color: color-mix(in srgb, var(--status-critical) 40%, transparent);
}

.btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------------- 五档色块（精力 / 压力 / RPE） ---------------- */

.scale {
  display: flex;
  gap: 6px;
}

.scale button {
  flex: 1;
  min-height: var(--tap);
  border-radius: 10px;
  background: var(--surface-2);
  border: 2px solid transparent;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  gap: 2px;
}

.scale button small {
  font-size: 10px;
  font-weight: 500;
  opacity: 0.85;
}

.scale button[aria-pressed="true"] {
  border-color: var(--text-primary);
}

.scale.rpe button[data-rpe="6"] { background: var(--rpe-6); color: #fff; }
.scale.rpe button[data-rpe="7"] { background: var(--rpe-7); color: #fff; }
.scale.rpe button[data-rpe="8"] { background: var(--rpe-8); color: #fff; }
.scale.rpe button[data-rpe="9"] { background: var(--rpe-9); color: #0b0b0b; }
.scale.rpe button[data-rpe="10"] { background: var(--rpe-10); color: #0b0b0b; }

.scale.mood button[aria-pressed="true"] {
  background: var(--series-1);
  color: #fff;
}

.scale-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

/* ---------------- 数字步进器 ---------------- */

.stepper {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
}

.stepper button {
  width: 52px;
  min-height: var(--tap);
  font-size: 22px;
  font-weight: 500;
  background: var(--surface-3);
  flex: none;
}

.stepper input {
  border: none;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  padding: 0;
  min-width: 0;
}

.stepper-wrap {
  flex: 1;
  min-width: 0;
}

.stepper-wrap > label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ---------------- 动作卡 ---------------- */

.exercise {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.exercise-head {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
}

.exercise-head .name {
  font-weight: 650;
  font-size: 16px;
}

.exercise-head .last {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.exercise-body {
  padding: 12px 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.chip.warmup {
  opacity: 0.55;
  font-style: italic;
}

.chip .rpe-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-left: 5px;
  vertical-align: 1px;
}

.target-hint {
  font-size: 13px;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--series-1) 12%, var(--surface-1));
  border-left: 3px solid var(--series-1);
  padding: 8px 10px;
  border-radius: 0 8px 8px 0;
  margin-bottom: 10px;
}

.target-hint b {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.target-hint > div + div {
  margin-top: 4px;
}

.entry-note {
  margin-top: 10px;
}

.entry-note textarea {
  min-height: 44px;
  resize: vertical;
}

/* ---------------- 洞察 ---------------- */

.insight {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-1);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.insight.warn { border-left-color: var(--status-critical); }
.insight.action { border-left-color: var(--status-warning); }
.insight.info { border-left-color: var(--axis); }
.insight.insufficient { border-left-color: var(--axis); opacity: 0.72; }

/* 状态色永不单独承载含义 —— 每条结论都带一个文字徽标 */
.insight .tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 5px;
  margin-bottom: 6px;
  border: 1px solid;
}

.insight.warn .tag {
  color: var(--status-critical);
  border-color: color-mix(in srgb, var(--status-critical) 50%, transparent);
  background: color-mix(in srgb, var(--status-critical) 12%, transparent);
}

.insight.action .tag {
  color: var(--status-warning);
  border-color: color-mix(in srgb, var(--status-warning) 50%, transparent);
  background: color-mix(in srgb, var(--status-warning) 12%, transparent);
}

.insight.info .tag,
.insight.insufficient .tag {
  color: var(--text-muted);
  border-color: var(--border);
}

.insight h3 {
  font-size: 15px;
  font-weight: 650;
  margin-bottom: 4px;
}

.insight p {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.insight details {
  font-size: 12px;
  color: var(--text-muted);
}

.insight details summary {
  cursor: pointer;
  min-height: 28px;
  display: flex;
  align-items: center;
}

.insight details p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------------- 图表 ---------------- */

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.chart-head h2 {
  font-size: 15px;
  font-weight: 650;
}

.chart-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

svg.chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

svg.chart text {
  font-family: var(--font);
  fill: var(--text-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

svg.chart .grid-line {
  stroke: var(--grid);
  stroke-width: 1;
}

svg.chart .axis-line {
  stroke: var(--axis);
  stroke-width: 1;
}

svg.chart .value-label {
  fill: var(--text-primary);
  font-size: 11px;
  font-weight: 650;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.small-multiples {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 420px) {
  .small-multiples {
    grid-template-columns: 1fr;
  }
}

.sm-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
}

.sm-panel .sm-title {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 2px;
}

.sm-panel .sm-value {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sm-panel .sm-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.delta-up { color: var(--status-good); }
.delta-down { color: var(--status-critical); }
.delta-flat { color: var(--text-muted); }

/* 表格视图 —— 浅色模式 contrast WARN 的 relief，也是无障碍兜底 */
table.data-view {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: 10px;
}

table.data-view th,
table.data-view td {
  border-bottom: 1px solid var(--border);
  padding: 6px 4px;
  text-align: right;
  color: var(--text-secondary);
}

table.data-view th:first-child,
table.data-view td:first-child {
  text-align: left;
}

table.data-view th {
  color: var(--text-muted);
  font-weight: 600;
}

.chart-tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--surface-3);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  max-width: 220px;
  opacity: 0;
  transition: opacity 0.12s;
}

.chart-tooltip.show {
  opacity: 1;
}

/* ---------------- 历史 ---------------- */

.history-item {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  min-height: 32px;
}

.history-item .h-date {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.history-item .h-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ---------------- 组间计时器 ---------------- */

.rest-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(72px + env(safe-area-inset-bottom) + 8px);
  z-index: 30;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 736px;
  margin: 0 auto;
}

.rest-bar[hidden] {
  display: none;
}

.rest-bar .t {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 74px;
}

.rest-bar.done .t {
  color: var(--status-good);
}

.rest-bar .track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-1);
  overflow: hidden;
}

.rest-bar .fill {
  height: 100%;
  background: var(--series-1);
  transition: width 0.3s linear;
}

/* ---------------- 底部 tab ---------------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar button {
  flex: 1;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-muted);
}

.tabbar button .ic {
  font-size: 20px;
  line-height: 1;
}

.tabbar button[aria-selected="true"] {
  color: var(--series-1);
  font-weight: 650;
}

/* ---------------- 弹层 ---------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
}

.sheet[hidden] {
  display: none;
}

.sheet-inner {
  background: var(--surface-1);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 760px;
  margin: 0 auto;
}

.sheet-inner h2 {
  font-size: 17px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pick-list button {
  display: block;
  width: 100%;
  text-align: left;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 8px;
}

.pick-list button .g {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 8px;
}

.group-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
}

.ai-output {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
  color: var(--text-secondary);
}

.field {
  margin-bottom: 12px;
}

.field > label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 5px;
  font-weight: 500;
}

/* 不写成 .field .hint —— 有些说明文字直接挂在 .card 下（导出说明、危险操作说明），
   那样它们会掉回正文大小，抢掉标题和按钮的视觉权重。 */
.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(140px + env(safe-area-inset-bottom));
  z-index: 90;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: 88vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
}
