/* 配色取自 dataviz 参考色板；浅色 / 深色随系统切换 */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  /* 单系列强调色：心率曲线 */
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  /* 心率区间：有序色阶，区间越高越显眼 */
  --zone-1: #86b6ef;
  --zone-2: #3987e5;
  --zone-3: #1c5cab;
  --zone-4: #0d366b;
  --critical: #d03b3b;
  font-family: system-ui, -apple-system, "PingFang SC", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.12);
    --zone-1: #184f95;
    --zone-2: #2a78d6;
    --zone-3: #6da7ec;
    --zone-4: #b7d3f6;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

a { color: inherit; }
button { font: inherit; }

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 8px;
}

.topbar h1 { margin: 0; font-size: 24px; font-weight: 700; }

.link-button {
  border: 0;
  background: none;
  padding: 8px 4px;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  font-size: 15px;
}
.link-button:hover { color: var(--text-primary); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

.card h2 { margin: 0; font-size: 17px; font-weight: 600; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: 13px; }
.status { padding: 48px 16px; text-align: center; color: var(--text-secondary); }
.status.error { color: var(--critical); }

/* MARK: 列表页 */

.month { margin: 24px 0 8px; font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.workout-list { display: grid; gap: 8px; }

.workout-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  text-decoration: none;
}
.workout-row:hover { background: var(--hover); }
.workout-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--page);
  font-size: 24px;
}
.workout-title { font-weight: 600; }
.workout-when { font-size: 13px; color: var(--text-secondary); }
.workout-main { text-align: right; font-weight: 700; font-size: 18px; white-space: nowrap; }
.workout-main small { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-left: 2px; }
.workout-extra { text-align: right; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
@media (max-width: 519px) { .wide-only { display: none; } }

@media (min-width: 900px) {
  .workout-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.load-more { display: block; margin: 24px auto 0; padding: 10px 20px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-primary); cursor: pointer; }

/* MARK: 详情页 */

.detail { display: grid; gap: 16px; }

@media (min-width: 900px) {
  .detail {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "overview heart" "metrics heart";
    align-items: start;
  }
  .detail-single { grid-template-columns: minmax(0, 720px); grid-template-areas: "overview" "metrics"; }
  .overview { grid-area: overview; }
  .metrics { grid-area: metrics; }
  .heart { grid-area: heart; }
}

.hero { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hero-figure { display: flex; align-items: baseline; flex-wrap: wrap; min-width: 0; }
.hero-value { font-size: clamp(56px, 17vw, 88px); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.hero-unit { margin-left: 8px; font-size: 20px; font-weight: 700; color: var(--text-secondary); }
.hero-icon { font-size: 44px; line-height: 1; }
.workout-name { margin: 20px 0 4px; font-size: 26px; font-weight: 700; }

.rank {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--grid);
}
.rank-number {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}
/* 奖杯单独成盒。和「第」写在同一个文本节点里时，紧挨着的「第」会被 emoji 字体撑大。 */
.rank-trophy {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
}
.rank-count {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 1.2;
}
.rank-text { margin: 6px 0 0; font-size: 14px; color: var(--text-secondary); }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 14px);
  gap: 0;
  flex-shrink: 0;
  box-sizing: border-box;
  border-top: 1px solid var(--axis);
  border-left: 1px solid var(--axis);
}
.calendar-cell {
  position: relative;
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  border-right: 1px solid var(--axis);
  border-bottom: 1px solid var(--axis);
  background: transparent;
  overflow: hidden;
}
.calendar-mark {
  position: absolute;
  display: grid;
  place-items: center;
  line-height: 1;
  pointer-events: none;
}

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px 12px; }
@media (max-width: 359px) { .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* 列宽不够时单位换到下一行，不和相邻指标重叠 */
.metric-value { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 3px; font-size: clamp(22px, 6.4vw, 30px); font-weight: 700; line-height: 1.15; white-space: nowrap; }
.metric-unit { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.metric-label { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--text-secondary); }
.badge { padding: 0 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 11px; font-weight: 600; line-height: 18px; }

/* MARK: 心率图 */

.chart { position: relative; margin: 0; outline: none; touch-action: pan-y; }
.chart:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: 8px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .label-strong { fill: var(--text-secondary); font-weight: 600; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-wash); }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; shape-rendering: crispEdges; }
.chart .marker { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

.tooltip {
  position: absolute;
  top: 0;
  z-index: 2;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  pointer-events: none;
  white-space: nowrap;
  font-size: 12px;
}
.tooltip strong { display: block; font-size: 15px; }
.tooltip span { color: var(--text-secondary); }

.section-title { margin: 24px 0 2px; font-size: 15px; font-weight: 600; }

.zones { position: relative; margin-top: 8px; }
.zone {
  position: relative;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 76px;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-radius: 8px;
  outline: none;
}
.zone:hover, .zone:focus-visible { background: var(--hover); }
.zone-name { font-weight: 600; font-size: 14px; }
.zone-range { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.zone-bar { height: 12px; border-radius: 0 4px 4px 0; }
.zone-time { text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }
.zone-time small { display: block; font-size: 12px; color: var(--text-muted); }

.table-view { margin-top: 16px; font-size: 13px; }
.table-view summary { cursor: pointer; color: var(--text-secondary); }
.table-view table { width: 100%; margin-top: 8px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: right; }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view th { color: var(--text-muted); font-weight: 500; }

/* MARK: 登录页 */

.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login form { width: min(400px, 100%); display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.login input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
  color: var(--text-primary);
  font-size: 16px;
}
.login button[type="submit"] {
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--text-primary);
  color: var(--surface);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.login .error { margin: 0; color: var(--critical); font-size: 14px; }
