:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --card: #ffffff;
  --card-2: #f7f9f6;
  --ink: #17221d;
  --ink-2: #4c5a53;
  --muted: #7b8780;
  --line: #e2e7e2;
  --line-2: #cfd8d1;
  --brand: #0f8a66;
  --brand-2: #0b6d51;
  --brand-soft: #e2f3ec;
  --accent: #eb6834;
  --accent-soft: #fdeee6;
  --danger: #c83c3c;
  --danger-soft: #fbe9e9;
  --warn: #b77800;
  --warn-soft: #fff4dc;
  --good: #0f7d0f;
  --good-soft: #e5f5e5;
  --water: #1f8fd0;
  --water-soft: #e1f1fb;
  /* 圖表（dataviz 參考色盤，light） */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --chart-surface: #ffffff;
  --grid: #e8ebe7;
  --axis: #c3c2b7;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 4px 16px rgba(20, 40, 30, .05);
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1412; --card: #18201c; --card-2: #1d2622; --ink: #eef3f0; --ink-2: #c0cbc5; --muted: #8b9790;
    --line: #2a3530; --line-2: #36433d; --brand: #2fb98c; --brand-2: #5fd3aa; --brand-soft: #173a2e;
    --accent: #f0804f; --accent-soft: #3b261c; --danger: #ec6b6b; --danger-soft: #3b1f1f;
    --warn: #f0b33a; --warn-soft: #3a2e14; --good: #3cc23c; --good-soft: #17331a; --water: #4fb3ea; --water-soft: #15303f;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --chart-surface: #18201c; --grid: #26302b; --axis: #3a4540;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1412; --card: #18201c; --card-2: #1d2622; --ink: #eef3f0; --ink-2: #c0cbc5; --muted: #8b9790;
  --line: #2a3530; --line-2: #36433d; --brand: #2fb98c; --brand-2: #5fd3aa; --brand-soft: #173a2e;
  --accent: #f0804f; --accent-soft: #3b261c; --danger: #ec6b6b; --danger-soft: #3b1f1f;
  --warn: #f0b33a; --warn-soft: #3a2e14; --good: #3cc23c; --good-soft: #17331a; --water: #4fb3ea; --water-soft: #15303f;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --chart-surface: #18201c; --grid: #26302b; --axis: #3a4540;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }

/* ---------- 版面 ---------- */
#app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand img { width: 28px; height: 28px; border-radius: 8px; flex: none; }
.who {
  margin-left: auto; display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-2); background: var(--card); border-radius: 999px;
  padding: 4px 12px 4px 4px; cursor: pointer; min-height: 40px; max-width: 50vw;
}
.who .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  display: grid; place-items: center; cursor: pointer; font-size: 20px; flex: none;
}
.icon-btn:hover { background: var(--card); border-color: var(--line); }
a.icon-btn { text-decoration: none; color: var(--ink); }
.icon-btn.chev { font-size: 30px; line-height: 1; color: var(--brand); }

main.page { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600;
}
.tabbar a .ic { font-size: 22px; line-height: 1; filter: grayscale(.6); opacity: .8; }
.tabbar a.on { color: var(--brand); }
.tabbar a.on .ic { filter: none; opacity: 1; transform: translateY(-1px); }

@media (min-width: 960px) {
  .tabbar {
    top: 61px; bottom: 0; right: auto; width: 200px; height: auto; grid-template-columns: 1fr; grid-auto-rows: 52px;
    align-content: start; padding: 16px 12px 12px; border-top: 0; border-right: 1px solid var(--line); gap: 4px;
  }
  .tabbar a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; border-radius: 12px; font-size: 15px; }
  .tabbar a.on { background: var(--brand-soft); }
  .topbar { padding-left: 20px; padding-right: 20px; }
  main.page { padding-left: 216px; max-width: none; padding-right: 24px; padding-bottom: 40px; }
  main.page > .wrap { max-width: 880px; margin: 0 auto; }
  body .toast { bottom: 24px; }
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 14px; }
.card h2, .card h3 { margin-bottom: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.section-title { font-size: 14px; font-weight: 700; color: var(--ink-2); margin: 20px 4px 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.duo { display: grid; gap: 14px; }
.duo > .card + .card { margin-top: 0; }
.duo + .card, .card + .duo { margin-top: 14px; }
@media (min-width: 720px) { .duo { grid-template-columns: 1fr 1fr; } }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 640px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--card); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--card); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--ink-2); min-height: 34px; }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }

/* ---------- 表單 ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--card); font-size: 16px; outline: none;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }

/* ---------- 進度 ---------- */
.meter { height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; border: 1px solid var(--line); }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--brand); max-width: 100%; transition: width .4s; }
.meter.water > i { background: var(--water); }
.meter.over > i { background: var(--danger); }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .lbl { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .lbl b { font-size: 26px; line-height: 1.1; }
.ring .lbl small { color: var(--muted); font-size: 12px; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; min-width: 0; box-shadow: var(--shadow); }
.stat .k { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 22px; font-weight: 700; margin: 2px 0 6px; white-space: nowrap; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 500; }
a.stat { text-decoration: none; color: inherit; display: block; }

/* ---------- 教練建議 ---------- */
.tips { display: grid; gap: 8px; }
.tip { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); }
.tip .ti { font-size: 20px; line-height: 1.3; flex: none; }
.tip.good { background: var(--good-soft); border-color: transparent; }
.tip.warn { background: var(--warn-soft); border-color: transparent; }
.tip.info { background: var(--brand-soft); border-color: transparent; }
.tip .ta { margin-top: 6px; }
.coach-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.coach-head .av { width: 40px; height: 40px; border-radius: 12px; background: var(--brand-soft); display: grid; place-items: center; font-size: 22px; }

/* ---------- 清單 ---------- */
.list { display: grid; gap: 0; }
.li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); min-height: 52px; }
.li:last-child { border-bottom: 0; }
.li .main { flex: 1; min-width: 0; }
.li .main .t { font-weight: 600; overflow-wrap: anywhere; }
.li .main .s { font-size: 13px; color: var(--muted); }
.li .end { text-align: right; flex: none; }
.empty { padding: 20px 8px; text-align: center; color: var(--muted); font-size: 14px; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; flex: none;
  background: var(--card-2); box-shadow: inset 0 0 0 2px var(--c, var(--brand));
}
.avatar.lg { width: 48px; height: 48px; font-size: 26px; }

/* ---------- 飲食 ---------- */
.meal-slot + .meal-slot { margin-top: 12px; }
.meal-slot .slot-head { display: flex; align-items: center; justify-content: space-between; }
.meal-slot .slot-head h3 { display: flex; align-items: center; gap: 6px; margin: 0; }
.meal-entry { display: flex; gap: 10px; padding: 10px 0; border-top: 1px dashed var(--line); cursor: pointer; }
.meal-entry img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; flex: none; background: var(--card-2); }
.macro-bars { display: grid; gap: 8px; }
.macro { display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.macro .meter > i { background: var(--mc); }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--mc); margin-right: 4px; }

.food-res { max-height: 46vh; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.food-item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.food-item:hover { background: var(--card-2); }
.food-item .add { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.cart { background: var(--card-2); border-radius: 12px; padding: 8px 12px; }
.cart .li { min-height: 44px; padding: 6px 0; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; }
.qty button { width: 34px; height: 34px; border: 0; background: var(--card); cursor: pointer; font-size: 18px; }
.qty span { min-width: 36px; text-align: center; font-weight: 600; }

/* ---------- 健身 ---------- */
.ex-card { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ex-card:last-child { border-bottom: 0; }
.ex-card .em { width: 44px; height: 44px; border-radius: 12px; background: var(--card-2); display: grid; place-items: center; font-size: 24px; flex: none; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--card-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.brand { background: var(--brand-soft); color: var(--brand-2); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week-strip .d { text-align: center; padding: 8px 0; border-radius: 12px; background: var(--card-2); font-size: 13px; border: 1px solid var(--line); }
.week-strip .d b { display: block; font-size: 18px; line-height: 1.4; }
.week-strip .d.plan { border-color: var(--brand); }
.week-strip .d.done { background: var(--brand); color: #fff; border-color: var(--brand); }
.week-strip .d.today { box-shadow: 0 0 0 2px var(--accent); }

/* 跟練播放器 */
.player { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column; }
.player .ptop { display: flex; align-items: center; gap: 10px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
.player .pbar { height: 6px; background: var(--card-2); border-radius: 99px; overflow: hidden; flex: 1; }
.player .pbar i { display: block; height: 100%; background: var(--brand); transition: width .3s linear; }
.player .pbody { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 20px; text-align: center; gap: 10px; overflow-y: auto; }
.player .phase { font-size: 14px; font-weight: 700; color: var(--brand); letter-spacing: .05em; }
.player.rest .phase { color: var(--water); }
.player .pem { font-size: 72px; line-height: 1; }
.player .pname { font-size: 28px; font-weight: 800; }
.player .ptimer { position: relative; width: min(56vw, 240px); aspect-ratio: 1; }
.player .ptimer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.player .ptimer .tv { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(48px, 15vw, 76px); font-weight: 800; font-variant-numeric: tabular-nums; }
.player .pcues { text-align: left; max-width: 420px; margin: 0; padding-left: 20px; color: var(--ink-2); }
.player .pnext { font-size: 14px; color: var(--muted); }
.player .pctl { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; padding: 12px 16px calc(16px + var(--safe-b)); max-width: 520px; width: 100%; margin: 0 auto; }
.player .pctl .btn { min-height: 56px; font-size: 17px; }
.feel { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.feel button { border: 1px solid var(--line-2); background: var(--card); border-radius: 14px; padding: 10px 4px; cursor: pointer; font-size: 13px; }
.feel button b { display: block; font-size: 26px; }
.feel button.on { border-color: var(--brand); background: var(--brand-soft); }

/* ---------- 管家 ---------- */
.water-glass { display: flex; align-items: center; gap: 16px; }
.glass { width: 64px; height: 88px; border: 3px solid var(--water); border-top-width: 2px; border-radius: 6px 6px 16px 16px; position: relative; overflow: hidden; flex: none; background: var(--card); }
.glass i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--water); opacity: .75; transition: height .5s; }
.habit { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; min-height: 48px; user-select: none; }
.habit:last-child { border-bottom: 0; }
.habit .box { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line-2); display: grid; place-items: center; flex: none; font-size: 16px; color: #fff; }
.habit.on .box { background: var(--brand); border-color: var(--brand); }
.habit.on .lb { color: var(--muted); text-decoration: line-through; }
.shop-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); min-height: 48px; }
.shop-item .box { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-2); display: grid; place-items: center; flex: none; cursor: pointer; color: #fff; font-size: 14px; }
.shop-item.done .box { background: var(--brand); border-color: var(--brand); }
.shop-item.done .t { color: var(--muted); text-decoration: line-through; }
.menu-day { border-bottom: 1px solid var(--line); padding: 10px 0; }
.menu-day:last-child { border-bottom: 0; }
.menu-day .dh { font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.menu-day.today .dh { color: var(--accent); }
.menu-slot { display: grid; grid-template-columns: 44px 1fr; gap: 8px; padding: 4px 0; font-size: 14px; cursor: pointer; border-radius: 8px; }
.menu-slot:hover { background: var(--card-2); }
.menu-slot .sl { color: var(--muted); }
.rank { display: grid; gap: 10px; }
.rank-row { display: grid; grid-template-columns: 28px 36px 1fr auto; gap: 10px; align-items: center; }
.rank-row .medal { font-size: 20px; text-align: center; }
.rank-bar { height: 10px; border-radius: 0 4px 4px 0; background: var(--c); min-width: 2px; }
.family-strip { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 6px; }
.family-strip .fm { flex: none; width: 72px; text-align: center; cursor: pointer; font-size: 13px; }
.family-strip .fm .avatar { margin: 0 auto 4px; width: 48px; height: 48px; font-size: 26px; }
.family-strip .fm.me .avatar { box-shadow: inset 0 0 0 3px var(--c), 0 0 0 3px var(--card), 0 0 0 5px var(--c); }
.family-strip .dots { display: flex; justify-content: center; gap: 3px; margin-top: 2px; }
.family-strip .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); }
.family-strip .dots i.on { background: var(--brand); }

/* ---------- 圖表 ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .tt {
  position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 6px 10px; font-size: 13px; box-shadow: var(--shadow); white-space: nowrap; transform: translate(-50%, -110%); z-index: 2;
}
.chart .tt b { font-size: 15px; }
.chart .tt .lk { display: inline-block; width: 12px; height: 2px; background: var(--s1); vertical-align: middle; margin-right: 4px; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.chart-legend .lk { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 4px; }
.chart-legend .lk.dash { background: repeating-linear-gradient(90deg, var(--muted) 0 4px, transparent 4px 7px) !important; }
details.tbl summary { cursor: pointer; font-size: 13px; color: var(--brand); margin-top: 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
table.data th, table.data td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { text-align: left; }

/* ---------- 底部抽屜／對話框 ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 70; background: rgba(10, 20, 15, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line-2); margin: 4px auto 10px; }
.sheet .sh-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; position: sticky; top: -8px; background: var(--card); padding: 6px 0; z-index: 1; }
@media (min-width: 700px) {
  .sheet-back { align-items: center; }
  .sheet { border-radius: 20px; max-height: 86vh; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 80; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); animation: up .2s;
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- 登入 ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate .card { width: 100%; max-width: 400px; }
.gate .logo { width: 72px; height: 72px; border-radius: 20px; display: block; margin: 0 auto 12px; }

.date-nav { display: flex; align-items: center; gap: 6px; }
.date-nav .dl { font-weight: 700; min-width: 0; text-align: center; flex: 1; }
.banner { padding: 10px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--ink); font-size: 14px; margin-bottom: 12px; }
.help h3 { margin-top: 18px; }
.help p, .help li { color: var(--ink-2); }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.spin { width: 28px; height: 28px; border: 3px solid var(--line-2); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- 時間表／作息 ---------- */
.timeline { display: grid; gap: 2px; }
.tl { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; min-height: 48px; }
.tl .tl-t { width: 44px; font-size: 13px; color: var(--ink-2); flex: none; }
.tl .tl-i { width: 26px; text-align: center; font-size: 18px; flex: none; }
.tl .tl-l { font-weight: 600; }
.tl.past .tl-l, .tl.past .tl-t { color: var(--muted); }
.tl.done .tl-l { color: var(--muted); text-decoration: line-through; }
.tl.next { background: var(--accent-soft); }
.plan-day { border-bottom: 1px solid var(--line); padding: 10px 0; }
.plan-day:last-child { border-bottom: 0; }
.plan-day .dh { font-weight: 700; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.plan-day.today .dh { color: var(--accent); }
.plan-day .ev { display: grid; grid-template-columns: 44px 22px 1fr; gap: 6px; font-size: 14px; padding: 2px 0; }
.plan-day .ev .t { color: var(--ink-2); }
.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.meal-row { display: grid; grid-template-columns: 52px 1fr 92px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.meal-row:last-child { border-bottom: 0; }
.meal-row input[type=time] { min-width: 0; }
.pct { display: flex; align-items: center; gap: 4px; }
.pct input { width: 64px; text-align: right; }
input[type=time] { width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--card); font-size: 16px; }
.band { display: flex; gap: 12px; align-items: flex-start; }
.band .bi { font-size: 30px; line-height: 1; }

/* ---------- 鏡頭 ---------- */
.cam { position: relative; width: 100%; max-width: 520px; margin: 0 auto; aspect-ratio: 4 / 3; background: #0d1210; border-radius: 16px; overflow: hidden; }
.cam video, .cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam .cam-count { position: absolute; left: 12px; top: 10px; color: #fff; font-weight: 800; font-size: 44px; line-height: 1; text-shadow: 0 2px 8px rgba(0,0,0,.6); font-variant-numeric: tabular-nums; }
.cam .cam-count small { font-size: 16px; font-weight: 600; opacity: .9; }
.cam .cam-hint { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 12px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); font-size: 15px; font-weight: 600; }
.cam .cam-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #fff; padding: 20px; font-size: 15px; }
.cam .cam-bar { position: absolute; right: 10px; top: 10px; bottom: 44px; width: 10px; border-radius: 6px; background: rgba(255,255,255,.25); overflow: hidden; }
.cam .cam-bar i { position: absolute; left: 0; right: 0; bottom: 0; background: #3cc28c; border-radius: 6px; transition: height .1s; }
.player .pcamwrap { padding: 0 16px; }
.player.cam-on .pem { display: none; }
.player.cam-on .ptimer { width: min(30vw, 120px); }
.player.cam-on .ptimer .tv { font-size: clamp(28px, 8vw, 40px); }
.player.cam-on .pcues { display: none; }
.player.cam-on .pname { font-size: 22px; }
.sets-list { display: grid; gap: 6px; margin-top: 8px; }
.sets-list .srow { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; background: var(--card-2); border-radius: 10px; font-size: 14px; }
