:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #13202e;
  --muted: #5a6a7b;
  --line: #dce3ea;
  --primary: #1f4e78;
  --primary-soft: #e3edf7;
  --on-primary: #ffffff;
  --accent: #d9652b;
  --accent-soft: #fbeadf;
  --fig: #17232f;
  --fig-far: #9fb0c0;
  --prop: #d3dce5;
  --prop-line: #a9b7c5;
  --load: #d9652b;
  --band: #2f8f6b;
  --figbg: #f6f8fb;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 16px rgba(16, 32, 48, .06);
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b;
    --surface: #16202a;
    --surface-2: #1c2834;
    --text: #e5ecf2;
    --muted: #93a3b3;
    --line: #253240;
    --primary: #6aa9e0;
    --primary-soft: #1b2d40;
    --on-primary: #0e141b;
    --accent: #f08a4f;
    --accent-soft: #3a2518;
    --fig: #e8eef4;
    --fig-far: #5d6f81;
    --prop: #2b3947;
    --prop-line: #4a5b6c;
    --load: #f08a4f;
    --band: #4fc095;
    --figbg: #121b24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
button { font: inherit; color: inherit; }
main { max-width: 860px; margin: 0 auto; padding: 16px 16px 32px; outline: none; }

/* ---------- Top bar & tab bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  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);
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; }
.brand-mark rect { fill: var(--primary); }
.brand-mark path { stroke: var(--on-primary); stroke-width: 2.4; stroke-linecap: round; fill: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 200px; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--primary); }

/* ---------- Generic ---------- */
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.page-head { margin: 8px 0 18px; }
.page-head h1 { font-size: 28px; letter-spacing: -.02em; margin-top: 4px; }
.page-head p { color: var(--muted); margin: 8px 0 0; }
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.callout {
  background: var(--primary-soft); border-radius: 12px; padding: 12px 14px; font-size: 15px;
  display: flex; gap: 10px; align-items: flex-start;
}
.callout svg { flex: none; width: 20px; height: 20px; margin-top: 1px; stroke: var(--primary); fill: none; stroke-width: 2; stroke-linecap: round; }
.callout.warn { background: var(--accent-soft); }
.callout.warn svg { stroke: var(--accent); }
.back {
  display: inline-flex; align-items: center; gap: 4px; margin: 0 0 6px -6px; padding: 6px;
  color: var(--primary); text-decoration: none; font-weight: 600; font-size: 15px; background: none; border: 0; cursor: pointer;
}
.back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.chip.primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- Home ---------- */
.plan-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .plan-grid { grid-template-columns: 1fr 1fr; } }
.plan-card {
  display: flex; gap: 14px; align-items: center; padding: 14px; text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease;
}
.plan-card:active { transform: scale(.99); }
.plan-badge {
  flex: none; width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; font-weight: 800; font-size: 20px; letter-spacing: -.02em;
  background: var(--primary); color: var(--on-primary);
}
.plan-badge.home { background: var(--accent); color: #fff; }
.plan-card h3 { font-size: 17px; }
.plan-card .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.plan-card .chev { margin-left: auto; flex: none; width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { padding: 14px; text-decoration: none; display: flex; flex-direction: column; gap: 4px; }
.tile strong { font-size: 16px; }
.tile span { color: var(--muted); font-size: 14px; }

/* ---------- Plan ---------- */
.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 18px -16px 0; padding: 0 16px 4px;
  position: sticky; top: calc(49px + env(safe-area-inset-top)); z-index: 5;
  background: var(--bg); padding-top: 8px; padding-bottom: 10px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.block-sub { color: var(--muted); font-size: 15px; margin: 6px 0 14px; }
.ex-list { display: grid; gap: 12px; list-style: none; margin: 0; padding: 0; }
.ex-card { position: relative; padding: 12px; }
.ex-top { display: grid; grid-template-columns: 136px 1fr; gap: 12px; align-items: start; }
@media (min-width: 620px) { .ex-top { grid-template-columns: 200px 1fr; } }
.ex-top .meta { grid-template-columns: 1fr; gap: 0; }
.ex-top .meta dt { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-top: 6px; }
.ex-figs { display: grid; gap: 6px; }
.fig-box { background: var(--figbg); border-radius: 12px; overflow: hidden; line-height: 0; }
.ex-title { display: flex; gap: 8px; align-items: baseline; }
.ex-num {
  flex: none; font-size: 13px; font-weight: 800; color: var(--primary);
  background: var(--primary-soft); border-radius: 6px; padding: 1px 7px;
}
.ex-card h3 { font-size: 17px; }
.stretch { text-decoration: none; }
.stretch::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 6px 8px; min-width: 0; }
.stat b { display: block; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.stat small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.meta { margin: 10px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.hint { margin: 10px 0 0; font-size: 14px; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 10px; }
.links { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.links a {
  font-size: 14px; font-weight: 600; text-decoration: none; color: var(--primary);
  background: var(--primary-soft); border-radius: 999px; padding: 5px 12px;
}
.footnote { margin-top: 16px; }

/* ---------- Exercise detail ---------- */
.detail-fig { padding: 8px; margin: 14px 0 6px; }
.detail-fig .fig-box { border-radius: 10px; }
.fig-caption { text-align: center; font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.plan-dose { padding: 14px; margin-bottom: 16px; border-color: var(--primary); }
.plan-dose .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.detail-section { padding: 14px 16px; margin-bottom: 12px; }
.detail-section h2 { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.detail-section p { margin: 0; }
.usage { list-style: none; margin: 0; padding: 0; }
.usage li + li { border-top: 1px solid var(--line); }
.usage a { display: block; padding: 10px 0; text-decoration: none; }
.usage strong { display: block; }
.usage span { color: var(--muted); font-size: 14px; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.pager a { padding: 12px 14px; text-decoration: none; font-size: 14px; }
.pager a small { display: block; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- Library ---------- */
.search {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 16px;
}
.search:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.filter { margin-top: 10px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 2px; }
.filter::-webkit-scrollbar { display: none; }
.filter button { border: 1px solid var(--line); background: var(--surface); cursor: pointer; white-space: nowrap; }
.filter button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.lib-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 620px) { .lib-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.lib-card { padding: 8px; text-decoration: none; display: flex; flex-direction: column; gap: 8px; }
.lib-card strong { font-size: 15px; line-height: 1.25; padding: 0 4px; }
.lib-card span { font-size: 13px; color: var(--muted); padding: 0 4px 4px; margin-top: -4px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

/* ---------- Guidance ---------- */
.guide-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; counter-reset: g; }
.guide-list li { padding: 14px 16px 14px 52px; position: relative; counter-increment: g; }
.guide-list li::before {
  content: counter(g); position: absolute; left: 14px; top: 13px;
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 800; font-size: 14px;
}
.sources a { color: var(--primary); overflow-wrap: anywhere; }

/* ---------- Figure (SVG) ---------- */
svg.fx { width: 100%; height: auto; display: block; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.fx-ground { stroke: var(--prop-line); stroke-width: 2; }
.fx-limb { fill: none; stroke: var(--fig); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.fx-trunk { stroke-width: 9; }
.fx-arm { stroke-width: 6; }
.fx-foot { stroke-width: 6; }
.fx-far { stroke: var(--fig-far); }
.fx-head { fill: var(--fig); }
.fx-prop { fill: var(--prop); }
.fx-far-prop { opacity: .6; }
.fx-prop-line { fill: none; stroke: var(--prop-line); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.fx-prop-rail { stroke: var(--prop-line); stroke-width: 2; stroke-dasharray: 4 5; }
.fx-load { fill: var(--load); }
.fx-far-load { opacity: .55; }
.fx-hub { fill: var(--figbg); }
.fx-band { stroke: var(--band); stroke-width: 2.5; stroke-linecap: round; }
.fx-band-thick { stroke-width: 5; }
.fx-platform { stroke: var(--prop-line); stroke-width: 7; stroke-linecap: round; }
.fx-pad { fill: var(--prop-line); }
.fx-marker { stroke: var(--load); stroke-width: 3; }
.fx-label { font-size: 11.5px; font-weight: 600; fill: var(--muted); font-family: inherit; text-anchor: middle; }
.fx-topview-bg { fill: var(--surface-2); }
.fx-topview-ray { stroke: var(--prop-line); stroke-width: 1.5; stroke-dasharray: 2 3; }
.fx-topview-origin { fill: var(--prop-line); }
.fx-topview-dot { fill: var(--load); }
.fx-topview-text { font-size: 9px; fill: var(--muted); text-anchor: middle; font-weight: 600; }
.fx-paused .fx-body { opacity: .85; }
.thumb .fx-label { display: none; }

@media (prefers-reduced-motion: reduce) {
  .plan-card { transition: none; }
}
