:root {
  --bg: #f3f6f4; --card: #ffffff; --ink: #1d2721; --sub: #5f6d65; --line: #e2e9e4;
  --brand: #2f7d5b; --brand-2: #e3f0e8; --warn: #b4542e; --warn-2: #fbe9e1;
  --g: #3c9a66; --y: #d6a12a; --r: #cf5538;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,40,30,.06), 0 4px 16px rgba(20,40,30,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#121815; --card:#1b231f; --ink:#e7eee9; --sub:#9aaaa1; --line:#2a352f;
    --brand:#5cbf8d; --brand-2:#1f3a2c; --warn:#ee8a63; --warn-2:#3a241b; --shadow:none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }

.app { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
nav.side { padding: 22px 14px; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; }
.logo { font-weight: 700; font-size: 18px; color: var(--brand); padding: 0 10px 18px; }
.logo small { display: block; font-weight: 400; font-size: 12px; color: var(--sub); }
nav.side a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px;
  text-decoration: none; color: var(--ink); margin-bottom: 2px; }
nav.side a.on { background: var(--brand-2); color: var(--brand); font-weight: 600; }
nav.side a:hover:not(.on) { background: var(--line); }
main { padding: 26px 32px 60px; max-width: 1080px; width: 100%; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--sub); font-size: 13px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: 18px; }
.card { background: var(--card); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  border: 1px solid var(--line); }
.card.wide { grid-column: 1 / -1; }
.big { font-size: 34px; font-weight: 700; line-height: 1.1; }
.big small { font-size: 15px; font-weight: 400; color: var(--sub); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }
.bar.hot > i { background: var(--warn); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer; background: var(--brand-2); color: var(--brand); font-weight: 600; }
.btn.pri { background: var(--brand); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); font-weight: 400; }
.btn.warn { background: var(--warn-2); color: var(--warn); }
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: default; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; margin-top: 8px; }
.stats b { display: block; font-size: 20px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; background: var(--line); color: var(--sub); }
.pill.ok { background: var(--brand-2); color: var(--brand); }
.pill.bad { background: var(--warn-2); color: var(--warn); }
.warnbox { background: var(--warn-2); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 10px; }
.tip { background: var(--brand-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; }

/* 训练 */
.routine { display: flex; gap: 14px; align-items: center; cursor: pointer; }
.routine .fig { width: 84px; height: 84px; flex: none; }
.routine:hover { border-color: var(--brand); }
.exlist { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ex { text-align: center; padding: 10px; cursor: pointer; }
.ex .fig { width: 100%; height: 110px; }
.ex.off { opacity: .45; }
.fig { stroke-linecap: round; stroke-linejoin: round; }
.fig .near polyline, .fig .near line { stroke: var(--brand); stroke-width: 7; fill: none; }
.fig .near circle { fill: var(--brand); }
.fig .far polyline, .fig .far line { stroke: var(--brand); opacity: .4; stroke-width: 7; fill: none; }
.fig .prop * { stroke: var(--sub); opacity: .55; stroke-width: 4; fill: var(--sub); fill-opacity: .25; }
.fig .prop rect { stroke-width: 0; fill-opacity: .55; }
.fig .band * { stroke: var(--warn); stroke-width: 2.5; fill: none; stroke-dasharray: 5 3; }
.fig .ground { stroke: var(--line); stroke-width: 2; }

.player { position: fixed; inset: 0; background: var(--bg); z-index: 50; display: flex; flex-direction: column; }
.player .top { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; border-bottom: 1px solid var(--line); }
.player .body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; grid-template-columns: minmax(260px, 1fr) minmax(260px, 420px); gap: 28px;
  padding: 24px 32px; align-items: center; max-width: 1100px; margin: 0 auto; width: 100%; }
.player .stage { background: var(--card); border-radius: 20px; border: 1px solid var(--line); aspect-ratio: 1; max-height: 62vh; margin: 0 auto; width: 100%; }
.player .stage { position: relative; }
.player .stage .xfl { position: absolute; inset: 0; }   /* 换式时上一式淡出、下一式淡入 */
.player .cuebox { background: var(--brand-2); border-radius: 12px; padding: 10px 14px; margin: 10px 0 4px; }
.player #pcue .muted { font-size: 13px; padding: 0 4px 6px; }
.player .cuebox b { font-size: 20px; display: block; }
.player .cuebox .tipline { margin-top: 4px; font-size: 16px; }
.player .stage .fig { width: 100%; height: 100%; }
.player .count { font-size: 64px; font-weight: 700; color: var(--brand); line-height: 1; font-variant-numeric: tabular-nums; }
.player .exname { font-size: 26px; font-weight: 700; margin: 6px 0 10px; }
.player ol { padding-left: 20px; margin: 8px 0 12px; }
.player .resting .count { color: var(--sub); }
.player .ctrl { display: flex; gap: 10px; justify-content: center; padding: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.player .ctrl .btn { padding: 10px 20px; font-size: 16px; }
.done-box { text-align: center; margin: auto; padding: 40px; }
.done-box .big { font-size: 48px; }

/* 饮食 */
.meal { display: grid; grid-template-columns: 90px 1fr; gap: 10px 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.meal:last-child { border-bottom: 0; }
.rate button { border: 2px solid transparent; background: var(--line); border-radius: 10px; padding: 6px 12px; cursor: pointer; }
.rate button.on.g { background: var(--g); color: #fff; }
.rate button.on.y { background: var(--y); color: #fff; }
.rate button.on.r { background: var(--r); color: #fff; }
.rate button.on.n { background: var(--sub); color: #fff; }
/* 默认选项：还没确认，虚线框、淡一点 */
.rate button.on.def { opacity: .6; border: 2px dashed var(--ink); }
.meal input[type=text] { width: 100%; border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 6px 10px; }
.flag { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 5px 14px; cursor: pointer; }
.flag.on { background: var(--warn-2); color: var(--warn); border-color: var(--warn); }
.check li { list-style: none; margin: 6px 0; }
.check li label { cursor: pointer; display: flex; gap: 8px; align-items: flex-start; }
.light { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.light > div { border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.light .lg { background: color-mix(in srgb, var(--g) 14%, transparent); }
.light .ly { background: color-mix(in srgb, var(--y) 16%, transparent); }
.light .lr { background: color-mix(in srgb, var(--r) 14%, transparent); }
.light b { display: block; margin-bottom: 4px; }

/* 表单 */
.form { display: grid; grid-template-columns: 140px 1fr; gap: 10px 14px; align-items: center; max-width: 520px; }
.form input, .form select { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 10px; width: 100%; }
.form input[type=checkbox] { width: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--sub); font-weight: 400; }
.chart { width: 100%; height: 220px; }
.chart .ln { fill: none; stroke: var(--brand); stroke-width: 2.5; }
.chart .tg { stroke: var(--warn); stroke-dasharray: 5 4; stroke-width: 1.5; }
.chart text { fill: var(--sub); font-size: 11px; }
.chart .gd { stroke: var(--line); }
.chart circle { fill: var(--brand); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 8px 18px; border-radius: 99px; font-size: 14px; z-index: 99; opacity: 0; transition: opacity .25s; pointer-events: none; }
.toast.show { opacity: 1; }
dialog { border: 0; border-radius: 16px; padding: 22px; background: var(--card); color: var(--ink); max-width: 460px; width: 92vw; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .fig { width: 180px; height: 180px; display: block; margin: 0 auto; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  /* 手机：导航放到底部，6 个按钮平分 */
  nav.side { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; display: grid; grid-template-columns: repeat(7, 1fr);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 2px; z-index: 40; background: var(--card); border-right: 0; border-top: 1px solid var(--line); }
  .logo { display: none; }
  nav.side a { flex-direction: column; gap: 0; padding: 6px 0; font-size: 12px; justify-content: center; text-align: center; margin: 0; }
  main { padding: 16px 16px 84px; }
  .toast { bottom: 80px; }
  .big { font-size: 28px; }
  h1 { font-size: 20px; }
  .player .body { grid-template-columns: 1fr; padding: 0 16px 14px; gap: 12px; align-items: start; }
  /* 手机：示范动画固定在顶部，下面的文字可以往下翻 */
  .player .stagewrap { position: sticky; top: 0; z-index: 2; background: var(--bg); padding-top: 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; box-shadow: 0 6px 10px -8px rgba(0,0,0,.25); }
  .player .stage { width: min(calc(100vw - 32px), 38vh); height: min(calc(100vw - 32px), 38vh); max-height: none; margin: 0 auto; }
  .player .cuebox { padding: 7px 12px; margin-top: 8px; }
  .player .cuebox b { font-size: 17px; }
  .player .cuebox .tipline { font-size: 14px; }
  .player .top { padding: 10px 14px; flex-wrap: wrap; gap: 6px; }
  .player .ctrl { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .light { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
}

/* 回看页、血糖图 */
table.hist tr.on td { background: var(--brand-2); }
table.hist td, table.hist th { text-align: center; }
.chart.glu path.gf { fill: none; stroke: var(--brand); stroke-width: 2.5; }
.chart.glu path.gp { fill: none; stroke: var(--warn); stroke-width: 2.5; }
.chart.glu circle.gf { fill: var(--brand); }
.chart.glu circle.gp { fill: var(--warn); }
.staple button { padding: 4px 10px; font-size: 13px; }

/* 板块切换 */
.modebar { display: inline-flex; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.modebar button { border: 0; background: transparent; padding: 7px 16px; border-radius: 9px; font: inherit; font-size: 15px; color: var(--sub); cursor: pointer; }
.modebar button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* 八段锦分栏说明 */
.exsec { margin: 8px 0; }
.exsec p { margin: 2px 0 0; }
.exsec ol { margin: 4px 0 0; }

/* 火柴人：拧转箭头、手的轨迹、丹田呼吸圈、头的朝向 */
.fig .twist path { stroke: var(--warn); stroke-width: 2.5; fill: none; }
.fig .trail { stroke: var(--brand); stroke-width: 3; fill: none; opacity: .22; }
.fig .dantian { fill: var(--brand); }
.fig .near .nose { stroke: var(--bg); stroke-width: 2.5; }
.fig .near .spine { stroke-width: 6; }
/* 🦵 对膝盖有要求 */
.kneebadge { display: inline-block; background: #fff1e6; color: #b4531a; border-radius: 8px; padding: 2px 8px; font-size: 13px; margin: 4px 0; }
.ex .kneemark { position: absolute; top: 6px; right: 8px; font-size: 14px; }
.ex { position: relative; }
/* 动作路线和虚影 */
.fig .route { stroke: var(--warn); stroke-width: 1.6; fill: none; stroke-dasharray: 1.5 4; opacity: .55; }
.fig .ghost path { stroke: var(--warn); stroke-width: 2.2; fill: none; stroke-linecap: round; }
.fig .ghost .string { stroke-width: 1.2; stroke-dasharray: 3 2; }
.fig .far .palm { fill: var(--brand); opacity: .4; }
.fig .ghosttxt { fill: var(--warn); font-size: 22px; font-weight: 700; text-anchor: middle; }
.fig .ghostsm { fill: var(--warn); font-size: 12px; font-weight: 600; text-anchor: middle; }
.fig .ghostfill { fill: var(--warn); fill-opacity: .14; stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 3 3; }

/* 斜侧面立体示范人 + 定势图 */
.fig3 { stroke-linecap: round; stroke-linejoin: round; }
.player .stage:has(.fig3) { background: #f3e8d2; overflow: hidden; }
.poseimg { display: block; width: 100%; max-width: 420px; border-radius: 14px; margin: 4px 0 12px; border: 1px solid var(--line); }
/* 热量估算 */
.kcalbox { max-width: 420px; margin: 12px auto; text-align: left; background: var(--card, #fff); border-radius: 12px; padding: 12px 16px; }
.kcalbox table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.kcalbox td { padding: 4px 2px; border-bottom: 1px solid rgba(0,0,0,.06); }
.kcalbox td:nth-child(2), .kcalbox td:nth-child(3) { text-align: right; white-space: nowrap; }
.foods { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.foodchip { background: rgba(0,0,0,.05); border-radius: 14px; padding: 3px 10px; font-size: 13px; }
.foodchip a { margin-left: 6px; color: var(--sub); text-decoration: none; }
.foodlist { max-height: 46vh; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; margin: 8px 0; }
.foodlist button { text-align: left; padding: 8px; border-radius: 8px; border: 1px solid rgba(0,0,0,.1); background: transparent; color: inherit; font-size: 14px; }
.foodlist button.on, .qtys button.on, .units button.on { border-color: var(--brand); background: rgba(0,0,0,.04); font-weight: 600; }
.qtys, .units { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.qtys button, .units button { padding: 6px 12px; border-radius: 8px; border: 1px solid rgba(0,0,0,.15); background: transparent; color: inherit; }
.kpi { margin: 4px 0 10px; padding: 8px 12px; border-radius: 10px; font-size: 15px; }
.kpi b { font-size: 24px; margin: 0 2px; }
.kpi small { color: var(--sub); font-size: 12px; margin-left: 4px; }
.kpi.burn { background: var(--warn-2); color: var(--warn); }
.kpi.eat { background: var(--brand-2); color: var(--brand); }
.netbox { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); line-height: 1.6; }
.neteq { font-size: 15px; margin: 2px 0; }
.neteq b { font-size: 20px; }
.neteq b.ok { color: var(--brand); } .neteq b.bad { color: var(--warn); }
