:root {
  color-scheme: light;
  --bg: #f6f5f0;
  --ink: #242923;
  --muted: #5e655b;
  --orange: #c84a1d;
  --line: #daddd1;
  --metric-size: clamp(4.75rem, 21vw, 5.5rem);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 0.875rem; line-height: 1.5; }
button, a, button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid var(--orange); outline-offset: 4px; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
.app { max-width: 480px; margin: auto; padding: env(safe-area-inset-top) 18px calc(90px + env(safe-area-inset-bottom)); }
.header { min-height: 64px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); gap: 10px; }
.brand { font-size: 1.25rem; font-weight: 700; }
.date-label { color: var(--muted); font-size: 0.6875rem; }
.page-intro { padding: 20px 0; }
h1 { font-size: 1.625rem; line-height: 1.3; margin: 0; font-weight: 700; }
h1 span { font-size: 0.875rem; font-weight: 500; color: var(--muted); margin-left: 8px; white-space: nowrap; }
.section-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.section-top h2 { font-size: 0.875rem; font-weight: 650; margin: 0; }
.section-top > span { color: var(--muted); font-size: 0.625rem; }
.level-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.level-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 14px 8px; border: 1px solid var(--line); border-radius: 10px; background: transparent; text-align: center; }
.level-card.selected { background: #fff1e7; border-color: var(--orange); box-shadow: inset 0 0 0 1px var(--orange); }
.level-card strong { font-size: 1.1875rem; }
.level-spec { font-size: 0.6875rem; font-weight: 600; }
.level-spec small { font-size: 0.5625rem; }
.level-ratio { font-size: 0.6875rem; color: var(--muted); line-height: 1.7; }
.level-card:disabled { opacity: .6; }
.level-card.selected:disabled { opacity: 1; }
.level-option { min-width: 0; display: flex; flex-direction: column; }
.level-option .level-card { width: 100%; flex: 1; }
.level-expand, .preview-close { min-height: 44px; padding: 8px; background: none; border: 0; color: var(--muted); font-size: .75rem; }
.level-expand[aria-expanded=true] { color: var(--orange); }
.course-preview { padding: 12px; margin: -6px 0 18px; border: 1px solid var(--line); border-radius: 10px; background: #fdfcf8; }
.course-preview .section-top { margin-bottom: 6px; }
.preview-close { padding-right: 0; }
.stage-table { border-collapse: collapse; width: 100%; font-size: .75rem; font-variant-numeric: tabular-nums; }
.stage-table th, .stage-table td { padding: 10px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.stage-table th { color: var(--muted); font-weight: 500; }
.stage-table th:last-child, .stage-table td:last-child { text-align: right; white-space: nowrap; }
.stage-table tbody tr:last-child td { border-bottom: 0; }
.stage-table .work td:nth-child(2) { color: var(--orange); }
.training-active .course-preview { display: none; }
.ride-card { border-radius: 15px; padding: 16px 18px 0; background: #262e27; color: #f9faf5; }
.stage-label { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 0; min-height: 33px; font-size: 1.5rem; font-weight: 650; }
#round-label { font-size: 1.0625rem; font-weight: 500; color: #d2dec8; }
.ride-metrics { display: flex; flex-direction: column; gap: 12px; padding: 10px 0 20px; }
.metric { text-align: center; }
.metric-label { margin: 0 0 4px; font-size: 1.0625rem; color: #d2dec8; display: flex; justify-content: center; align-items: center; gap: 8px; }
.metric-value { display: block; font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif; font-size: var(--metric-size); font-weight: 600; line-height: 1.05; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
#rpm { color: #d7edb9; }
.beat-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #75856b; }
.beat-dot.pulse { background: #dbf6af; box-shadow: 0 0 0 5px #d7edb926; }
.stage-progress-top, .progress-top { display: flex; justify-content: space-between; gap: 8px; color: #d2dec8; font-size: 0.9375rem; margin-bottom: 7px; font-variant-numeric: tabular-nums; }
.stage-progress { height: 10px; border-radius: 5px; overflow: hidden; background: #4a5542; margin-bottom: 16px; }
.stage-progress > i { display: block; height: 100%; width: 0; background: #d7edb9; border-radius: inherit; }
.timeline { display: flex; gap: 3px; height: 9px; width: 100%; border-radius: 3px; overflow: hidden; }
.timeline-part { background: #46503f; position: relative; min-width: 2px; overflow: hidden; }
.timeline-part[data-type=work] { background: #786348; }
.timeline-part[data-type=build] { background: #536247; }
.timeline-part > i { display: block; height: 100%; background: #c5dfa4; width: 0; }
.timeline-part[data-type=work] > i { background: #f39563; }
.next-stage { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; border-top: 1px solid #4a5542; margin: 16px -18px 0; padding: 13px 18px; font-size: 1rem; }
.next-stage > span { color: #d2dec8; }
.next-stage strong { font-weight: 600; }
#next-spec { font-size: 0.9375rem; font-variant-numeric: tabular-nums; margin-left: auto; }
.utilities { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 12px 0; }
.sound-toggle { display: flex; flex-shrink: 0; align-items: center; gap: 7px; border: 0; background: none; min-height: 44px; padding: 0; font-size: 0.75rem; }
.sound-toggle svg { width: 21px; height: 21px; }
.sound-toggle strong { font-size: 0.6875rem; font-weight: 500; color: var(--muted); }
.switch { width: 34px; height: 22px; border-radius: 20px; background: #c8cebf; position: relative; }
.switch::after { content: ""; position: absolute; width: 16px; height: 16px; top: 3px; left: 3px; background: white; border-radius: 50%; }
.sound-toggle[aria-pressed=true] .switch { background: var(--orange); }
.sound-toggle[aria-pressed=true] .switch::after { left: 15px; }
.wake-status { font-size: 0.625rem; color: var(--muted); text-align: right; max-width: 45%; }
.wake-status.enabled { color: #42672f; }
.wake-status.failed { color: #a83e1c; }
.runtime-message { background: #fff0e4; color: #8c3c1b; border-radius: 8px; padding: 12px; margin-bottom: 12px; font-size: 0.75rem; }
.ride-actions { display: flex; gap: 10px; margin-bottom: 20px; }
.primary-button { border: 0; min-height: 58px; width: 100%; border-radius: 10px; background: var(--orange); color: white; font-size: 0.875rem; font-weight: 650; display: flex; align-items: center; justify-content: center; gap: 10px; }
.primary-button:active { background: #ad3c14; }
#main-action-icon { font-size: 0.75rem; }
.end-button { min-width: 78px; border: 0; border-radius: 10px; background: #e4e8db; font-size: 0.8125rem; }
.bottom-nav { position: fixed; left: 0; bottom: 0; width: 100%; height: calc(66px + env(safe-area-inset-bottom)); padding: 7px 0 calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; justify-content: center; gap: 20px; background: #f6f5f0f5; backdrop-filter: blur(12px); z-index: 5; }
.bottom-nav a { display: flex; align-items: center; justify-content: center; gap: 8px; width: 130px; min-height: 46px; font-size: 0.75rem; color: var(--muted); border-radius: 10px; }
.bottom-nav a.active { background: #e4e8db; color: #324729; font-weight: 650; }
.bottom-nav svg { width: 23px; height: 23px; }
.resume-banner { background: #e9eddf; border: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-radius: 10px; margin-bottom: 18px; }
.resume-banner strong { font-size: 0.75rem; }
.resume-banner p { font-size: 0.6875rem; margin: 4px 0 0; color: var(--muted); }
.small-button { min-height: 44px; padding: 10px 12px; border: 1px solid #c6cdba; border-radius: 8px; background: #fffdf7; white-space: nowrap; font-size: 0.75rem; }
.training-active .page-intro, .training-active .level-options, .has-session:has(#train-view:not([hidden])) .header { display: none; }
.training-active > .section-top { margin-top: 14px; margin-bottom: 12px; }
.stats-filter { display: flex; gap: 5px; background: #e6e9dd; border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.stats-filter button { flex: 1; min-height: 44px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 0.75rem; }
.stats-filter button.active { background: #fffdf9; color: var(--ink); font-weight: 650; }
.stats-hero { background: #e5ebda; border-radius: 13px; padding: 20px; }
.stats-hero > span { font-size: 0.75rem; color: #4e5e3e; }
.stats-hero > div { display: flex; align-items: baseline; gap: 10px; margin-top: 4px; }
.stats-hero strong { font-size: 3.375rem; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stats-hero > div > span { font-size: 0.75rem; color: #4e5e3e; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px 0 22px; }
.stats-grid > div { background: #fdfcf8; border: 1px solid var(--line); border-radius: 10px; padding: 12px 10px; }
.stats-grid > div > span { display: block; font-size: 0.625rem; color: var(--muted); margin-bottom: 8px; }
.stats-grid strong { font-size: 1.4375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats-grid small { font-size: 0.5625rem; margin-left: 3px; color: var(--muted); }
.chart-card { border: 1px solid var(--line); border-radius: 12px; background: #fdfcf8; padding: 16px 12px; }
.chart-card h2 { font-size: 0.75rem; }
.week-chart { display: flex; gap: 6px; height: 172px; padding-top: 5px; }
.chart-day { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0; }
.chart-day strong { color: #536244; font-size: 0.625rem; font-weight: 500; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.chart-bar { height: 110px; width: 100%; display: flex; align-items: flex-end; background: #edf0e5; border-radius: 4px; overflow: hidden; }
.chart-bar i { display: block; width: 100%; background: #9caf7d; border-radius: 4px; }
.chart-day:last-child .chart-bar i { background: var(--orange); }
.chart-day > span { font-size: 0.625rem; color: var(--muted); margin-top: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-heading { margin: 22px 0 12px; }
.history-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 16px 0; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.history-icon { display: none; }
.history-info { flex: 1; }
.history-info strong { font-size: 0.75rem; font-weight: 600; }
.history-info > span { display: block; font-size: 0.625rem; color: var(--muted); margin-top: 4px; }
.history-meta { text-align: right; }
.history-meta strong { font-size: 0.9375rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.history-meta small { font-size: 0.5625rem; font-weight: 400; }
.history-meta span { display: block; color: var(--muted); font-size: 0.625rem; margin-top: 4px; }
.history-meta .complete { color: #49682e; }
.history-chevron { color: #727a68; font-size: 1.125rem; }
.empty-history { padding: 24px 12px; text-align: center; border: 1px dashed #c4cdba; border-radius: 10px; color: var(--muted); font-size: 0.75rem; }
.empty-history p { font-size: 0.625rem; margin-bottom: 0; }
.load-more { display: block; width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 12px; font-size: 0.75rem; margin-top: 15px; }
.error-panel { padding: 16px; background: #fff0e4; border-radius: 10px; font-size: 0.75rem; }
.error-panel p { margin-top: 0; }
.toast { position: fixed; bottom: calc(85px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); width: max-content; background: #253023; color: white; padding: 12px 16px; border-radius: 10px; font-size: 0.75rem; z-index: 20; }
dialog { width: calc(100% - 32px); max-width: 410px; border: 0; background: #f9f8f3; color: var(--ink); border-radius: 16px; padding: 0; max-height: 85dvh; overflow: auto; }
dialog::backdrop { background: #19231980; backdrop-filter: blur(4px); }
.dialog-inner { padding: 24px 20px 16px; text-align: center; }
.dialog-inner h2 { font-size: 1.375rem; margin: 0 0 16px; }
.dialog-inner > p { color: var(--muted); font-size: 0.75rem; line-height: 1.8; }
.dialog-inner .primary-button { margin-top: 20px; }
.text-button { width: 100%; min-height: 50px; background: none; border: 0; font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.result-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 18px 0; margin: 20px 0 12px; }
.result-grid strong { display: block; font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.result-grid span { display: block; color: var(--muted); font-size: 0.625rem; margin-top: 6px; }
.detail-row { display: flex; justify-content: space-between; gap: 15px; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 0.75rem; text-align: left; }
.detail-row > span { color: var(--muted); }
.detail-row b { font-weight: 550; }
.detail-note { font-size: 0.625rem; line-height: 1.8; color: var(--muted); text-align: left; margin-top: 15px; }
@media (max-width: 360px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .ride-card { padding-left: 14px; padding-right: 14px; }
  .next-stage { margin-left: -14px; margin-right: -14px; padding-left: 14px; padding-right: 14px; }
  .level-card { padding-left: 5px; padding-right: 5px; }
  .level-spec { font-size: 0.6875rem; }
  .level-ratio { font-size: 0.6875rem; }
    .sound-toggle { font-size: 0.75rem; gap: 5px; }
  .wake-status { font-size: 0.625rem; }
  #next-spec { margin-left: 0; }
  .stats-grid > div { padding-left: 7px; padding-right: 7px; }
  .stats-grid > div > span { font-size: 0.625rem; }
  .stats-grid strong { font-size: 1.4375rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

.history-row { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.history-row .history-item { flex: 1; min-width: 0; border-bottom: 0; }
.delete-record { flex-shrink: 0; min-width: 44px; min-height: 44px; padding: 8px 0; border: 0; background: none; color: #ad3c14; font-size: .75rem; }
#delete-error { color: #ad3c14; }
button:disabled { opacity: .6; }
.calorie-form { border-bottom: 1px solid var(--line); padding-bottom: 14px; text-align: left; }
.weight-row { display: flex; align-items: center; gap: 10px; font-size: .75rem; }
.weight-row input { min-width: 0; width: 112px; margin-left: auto; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fffdf9; color: var(--ink); font: inherit; font-size: 1rem; }
.weight-row > span { color: var(--muted); }
.effort-options { padding: 0; margin: 15px 0; border: 0; }
.effort-options legend { padding: 0; margin-bottom: 8px; font-size: .75rem; }
.effort-options > div { display: flex; gap: 8px; }
.effort-options button { flex: 1; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; background: transparent; font-size: .75rem; }
.effort-options button[aria-pressed=true] { background: #fff1e7; border-color: var(--orange); color: var(--orange); }
.calorie-result { display: flex; align-items: baseline; gap: 8px; font-size: .75rem; }
.calorie-result strong { margin-left: auto; font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
#calorie-hint { color: var(--muted); font-size: .625rem; line-height: 1.7; margin: 7px 0 0; }
.stats-calories { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: -10px 0 22px; background: #fdfcf8; font-size: .75rem; }
.stats-calories strong { margin-left: auto; font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats-calories small { font-size: .625rem; font-weight: 400; color: var(--muted); }
#stat-calorie-count { width: 100%; color: var(--muted); font-size: .625rem; }
.history-info .history-calories { color: #4e703a; }
