:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --card: #ffffff;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;   /* blue    - fitness, pace */
  --s2: #eb6834;   /* orange  - fatigue */
  --s3: #1baf7a;   /* aqua    - form */
  --s4: #eda100;   /* yellow */
  --s5: #e87ba4;   /* magenta */
  --s6: #008300;   /* green */
  --s7: #6250d6;   /* violet  - cadence */
  --s8: #e34948;   /* red     - heart rate */
  --seq1: #86b6ef; --seq2: #5598e7; --seq3: #2a78d6; --seq4: #1c5cab; --seq5: #104281;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --good-ink: #006300;
  --hl: #2a78d6;
  --neutral: #b9b8b0;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --card: #1a1a19;
    --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq1: #184f95; --seq2: #1c5cab; --seq3: #2a78d6; --seq4: #5598e7; --seq5: #86b6ef;
    --good-ink: #0ca30c; --hl: #3987e5; --neutral: #55544f;
  }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --card: #1a1a19;
    --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq1: #184f95; --seq2: #1c5cab; --seq3: #2a78d6; --seq4: #5598e7; --seq5: #86b6ef;
    --good-ink: #0ca30c; --hl: #3987e5; --neutral: #55544f;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--s1); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 4px 0 14px; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 13px; margin: 10px 0 6px; font-weight: 600; color: var(--ink2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; }
.badge { font-size: 10px; font-weight: 600; background: var(--warn); color: #0b0b0b; padding: 2px 6px;
  border-radius: 4px; margin-left: 6px; vertical-align: 2px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav a { color: var(--ink2); padding: 6px 10px; border-radius: 6px; }
nav a.active { background: var(--page); color: var(--ink); font-weight: 600; }
nav a:hover { text-decoration: none; background: var(--page); }
.sync { display: flex; gap: 10px; align-items: center; font-size: 12px; }
main { padding: 18px 20px 60px; max-width: 1280px; margin: 0 auto; }
.btn { font: inherit; border: 1px solid var(--border); background: var(--card); color: var(--ink);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.btn:hover { border-color: var(--axis); }
.btn.primary { background: var(--s1); color: #fff; border-color: transparent; }
.btn.danger { color: var(--crit); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.tile .label { color: var(--ink2); font-size: 12px; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12px; }
.hero { font-size: 48px; font-weight: 600; line-height: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.st-good { background: var(--good); } .st-warn { background: var(--warn); }
.st-serious { background: var(--serious); } .st-crit { background: var(--crit); } .st-na { background: var(--neutral); }
.light { display: flex; gap: 14px; align-items: center; }
.light .big { width: 54px; height: 54px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-size: 22px; font-weight: 700; }
.light .big.st-warn { color: #0b0b0b; }
ul.recs { list-style: none; padding: 0; margin: 0; }
ul.recs li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--grid); }
ul.recs li:first-child { border-top: 0; }
.sev { font-size: 11px; font-weight: 700; min-width: 64px; display: inline-flex; gap: 6px; align-items: center; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-weight: 600; color: var(--ink2); font-size: 12px; cursor: default; position: sticky; top: 0; background: var(--card); }
td.num, th.num { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--page); }
.tablewrap { overflow: auto; max-height: 70vh; }
.chart-host { position: relative; width: 100%; }
.chart-svg { display: block; overflow: visible; }
.chart-grid { stroke: var(--grid); stroke-width: 1; }
.chart-axis { stroke: var(--axis); stroke-width: 1; }
.chart-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-ptitle { fill: var(--ink2); font-size: 11px; font-weight: 600; }
.chart-band-label { fill: var(--ink2); font-size: 10px; }
.chart-cross { stroke: var(--ink2); stroke-width: 1; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-brush { fill: var(--s1); opacity: 0.12; }
.chart-marker { stroke: var(--ink2); stroke-width: 1; }
.chart-marker-label { fill: var(--ink2); font-size: 10px; }
.chart-planned { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.chart-hit:focus { outline: none; }
.chart-tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); font-size: 12px; z-index: 5; min-width: 140px; }
.tip-head { color: var(--ink2); margin-bottom: 4px; font-weight: 600; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { font-variant-numeric: tabular-nums; }
.tip-key { width: 12px; height: 2px; display: inline-block; }
.tip-label { color: var(--ink2); }
.tip-extra { color: var(--muted); margin-top: 4px; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink2); margin-bottom: 6px; }
.lg-item { display: inline-flex; align-items: center; gap: 6px; }
.lg-line { width: 14px; height: 2px; display: inline-block; }
.lg-box { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.lg-outline { width: 12px; height: 0; border-top: 2px solid; display: inline-block; }
.seg { display: flex; height: 28px; border-radius: 4px; overflow: hidden; gap: 2px; }
.seg div { display: flex; align-items: center; padding-left: 8px; font-size: 12px; font-weight: 600; color: #fff; min-width: 0; white-space: nowrap; }
.seg div.dark { color: #0b0b0b; }
.zbar { display: grid; grid-template-columns: 140px 1fr 70px; gap: 8px; align-items: center; font-size: 12px; margin: 4px 0; }
.zbar .track { height: 10px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.zbar .fill { height: 100%; border-radius: 0 4px 4px 0; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.seggroup { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seggroup button { font: inherit; font-size: 12px; border: 0; background: var(--card); color: var(--ink2); padding: 5px 10px; cursor: pointer; }
.seggroup button.on { background: var(--page); color: var(--ink); font-weight: 600; }
/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 150px; gap: 6px; }
.cal .hd { font-size: 12px; color: var(--ink2); font-weight: 600; padding: 2px 4px; }
.day { background: var(--card); border: 1px solid var(--border); border-radius: 8px; min-height: 110px; padding: 6px; font-size: 12px; min-width: 0; }
.day.today { outline: 2px solid var(--s1); }
.day.other { opacity: 0.55; }
.day .dn { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.item { border-radius: 6px; padding: 4px 6px; margin-bottom: 4px; cursor: pointer; border: 1px solid var(--border); overflow: hidden; }
.item .t { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .m { color: var(--ink2); font-size: 11px; }
.item.planned { background: transparent; border-style: dashed; }
.item.done { background: var(--page); }
.item .cbar { height: 3px; border-radius: 2px; margin-top: 3px; }
.weekcell { background: var(--page); border-radius: 8px; padding: 6px 8px; font-size: 12px; }
/* forms */
label.f { display: block; margin: 8px 0 4px; font-size: 12px; color: var(--ink2); }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--card); color: var(--ink); }
input[type=number] { width: 110px; }
textarea { width: 100%; min-height: 90px; }
.scale { display: flex; gap: 4px; flex-wrap: wrap; }
.scale button { font: inherit; width: 34px; height: 30px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--ink); cursor: pointer; }
.scale button.on { background: var(--s1); color: #fff; border-color: transparent; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: grid; place-items: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); border-radius: 12px; padding: 20px 22px; width: min(620px, 94vw); max-height: 88vh; overflow: auto; position: relative; }
.modal-x { position: absolute; right: 10px; top: 6px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--ink2); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page);
  padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
pre.out { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 10px; max-height: 340px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
pre.md { white-space: pre-wrap; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--page);
  border: 1px solid var(--border); border-radius: 8px; padding: 14px; max-height: 70vh; overflow: auto; }
.note { background: var(--page); border-radius: 8px; padding: 10px 12px; color: var(--ink2); font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv div:nth-child(odd) { color: var(--ink2); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.loading { opacity: 0.55; transition: opacity 0.2s; }

/* ---------------------------------------------------------------- 3.0: app shell, phone layout, login */
.chart-svg { touch-action: pan-y; }
.iconbtn { font: inherit; border: 1px solid var(--border); background: var(--card); color: var(--ink); width: 36px; height: 36px;
  border-radius: 8px; display: inline-grid; place-items: center; cursor: pointer; padding: 0; }
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tabbar { display: none; }
.sheet-list { list-style: none; padding: 0; margin: 8px 0 0; }
.sheet-list a, .sheet-list button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 6px; font: inherit;
  font-size: 15px; color: var(--ink); background: none; border: 0; border-top: 1px solid var(--grid); text-align: left; cursor: pointer; }
.sheet-list li:first-child a { border-top: 0; }
.sheet-list svg { width: 20px; height: 20px; color: var(--ink2); flex: none; }
.agenda { display: none; }
.agenda .wk { margin: 14px 0 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.agenda .wk b { font-size: 13px; }
.agenda .wkcard { background: var(--page); border-radius: 8px; padding: 8px 10px; font-size: 12px; margin-bottom: 8px; }
.agenda .aday { display: grid; grid-template-columns: 46px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--grid); }
.agenda .aday.today .dlabel b { color: var(--s1); }
.agenda .dlabel { font-size: 11px; color: var(--muted); line-height: 1.2; }
.agenda .dlabel b { display: block; font-size: 18px; color: var(--ink); font-weight: 600; }
.agenda .item { margin-bottom: 6px; }
.agenda .item .t { -webkit-line-clamp: 3; }
.agenda .rest { color: var(--muted); font-size: 12px; padding-top: 6px; }
.alist { display: none; }
.alist a { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 10px 2px; border-top: 1px solid var(--grid); color: var(--ink); }
.alist a:hover { text-decoration: none; }
.alist .an { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alist .am { color: var(--ink2); font-size: 12px; }
.alist .ar { text-align: right; font-size: 12px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.alist .ar b { display: block; color: var(--ink); font-size: 14px; }
.login-page { min-height: 100vh; }
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; max-width: none; }
.login-card { width: min(380px, 100%); padding: 24px; }
.login-card input { width: 100%; font-size: 16px; padding: 10px 12px; }
.login-card .btn { width: 100%; margin-top: 12px; padding: 10px; font-size: 15px; }
.login-card #msg { min-height: 1.4em; margin-top: 10px; color: var(--crit); }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; margin-bottom: 10px; }
.login-brand img { border-radius: 9px; }

@media (max-width: 760px) {
  body { font-size: 15px; }
  .top { gap: 10px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); flex-wrap: nowrap; }
  .top nav#nav { display: none; }
  .brand { flex: 1; }
  .sync { gap: 8px; }
  #syncText { max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
  #syncBtn { display: none; }
  main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 19px; }
  .card { padding: 12px; }
  .hero { font-size: 36px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font: inherit;
    font-size: 11px; color: var(--ink2); background: none; border: 0; cursor: pointer; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .active { color: var(--s1); font-weight: 600; }
  .cal { display: none; }
  .agenda { display: block; }
  .tablewrap.has-alist table { display: none; }
  .alist { display: block; }
  .toolbar { gap: 6px; }
  .toolbar h1 { width: 100%; }
  .modal { place-items: end center; }
  .modal-card { width: 100vw; max-height: 92vh; border-radius: 14px 14px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .zbar { grid-template-columns: 110px 1fr 56px; }
  .kv { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
  input, select, textarea { font-size: 16px; }
  .scale button { width: 40px; height: 38px; }
  th, td { padding: 6px 6px; }
}
.iconbtn.mobile-only { display: none; }
@media (max-width: 760px) { .iconbtn.mobile-only { display: inline-grid; } }
@media (max-width: 760px) { .tablewrap.has-alist { max-height: none; overflow: visible; } }
@media (max-width: 760px) {
  .card table { display: block; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
  .tablewrap.has-alist table { display: none; }
}
select { max-width: 100%; }
/* ---------------------------------------------------------------- 3.1: plans, builder, vault */
a.navcard { display: block; color: var(--ink); }
a.navcard:hover { text-decoration: none; border-color: var(--axis); }
.wlist { margin-top: 6px; }
details.wrow { border-top: 1px solid var(--grid); }
details.wrow > summary { list-style: none; display: grid; grid-template-columns: 22px 92px minmax(0, 1fr) 64px 130px; gap: 8px; align-items: center; padding: 8px 2px; cursor: pointer; }
details.wrow > summary::-webkit-details-marker { display: none; }
details.wrow .wt { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.wrow .we { text-align: right; font-variant-numeric: tabular-nums; }
details.wrow .wbody { padding: 0 4px 12px 30px; }
details.wrow[open] > summary .wt { white-space: normal; }
.selbar { position: sticky; bottom: 12px; display: flex; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.15); z-index: 15; margin-top: 10px; flex-wrap: wrap; }
.selbar[hidden] { display: none; }
.step { border: 1px solid var(--border); border-left: 4px solid var(--neutral); border-radius: 8px; padding: 8px 10px; margin-top: 8px; background: var(--card); }
.step.k-warmup { border-left-color: var(--s4); } .step.k-cooldown { border-left-color: var(--s7); }
.step.k-interval { border-left-color: var(--s2); } .step.k-recovery, .step.k-rest { border-left-color: var(--s3); }
.step.k-exercise { border-left-color: var(--s1); }
.step.repeat { border-left-color: var(--ink2); background: var(--page); }
.repeat-inner { padding-left: 10px; }
.steptools .btn { padding: 2px 8px; }
.glrow { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--grid); }
.glrow:first-child { border-top: 0; }
.glrow .an { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.builder-actions { position: sticky; bottom: 12px; background: var(--page); padding: 8px 0; z-index: 5; }
@media (max-width: 760px) {
  details.wrow > summary { grid-template-columns: 22px minmax(0, 1fr) auto; grid-template-areas: "c t e" "c d s"; row-gap: 2px; }
  details.wrow > summary input { grid-area: c; } details.wrow .wt { grid-area: t; } details.wrow .we { grid-area: e; }
  details.wrow .wd { grid-area: d; font-size: 12px; color: var(--ink2); } details.wrow .ws { grid-area: s; text-align: right; }
  details.wrow .wbody { padding-left: 4px; }
  .selbar { bottom: calc(66px + env(safe-area-inset-bottom)); }
  .builder-actions { bottom: calc(58px + env(safe-area-inset-bottom)); }
  .step .row { gap: 6px; }
}
label.chk { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; font-size: 13px; cursor: pointer; }
label.chk input { margin-top: 3px; flex: none; }
@media (max-width: 760px) {
  .builder-actions { flex-wrap: nowrap; overflow-x: auto; }
  .builder-actions .btn, .builder-actions input { white-space: nowrap; flex: none; }
}
