:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #0f1b24;
  --muted: #5d6b77;
  --line: #dfe5ea;
  --accent: #0f766e;
  --accent-2: #14b8a6;
  --accent-soft: #d5f3ee;
  --warn: #c2410c;
  --warn-soft: #ffedd5;
  --good: #15803d;
  --fig: #33444f;
  --shadow: 0 1px 2px rgba(15, 27, 36, .06), 0 6px 20px rgba(15, 27, 36, .06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1317;
    --surface: #141e24;
    --surface-2: #1b272e;
    --text: #e8eef2;
    --muted: #93a3ae;
    --line: #26343c;
    --accent: #2dd4bf;
    --accent-2: #5eead4;
    --accent-soft: #123a36;
    --warn: #fb923c;
    --warn-soft: #3a2414;
    --good: #4ade80;
    --fig: #c4d1d9;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.02em; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 600;
  background: var(--accent); color: #fff; text-decoration: none;
  transition: transform .1s ease, filter .15s ease;
}
@media (prefers-color-scheme: dark) { .btn { color: #04201d; } }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); padding: 8px 12px; }
.btn.big { width: 100%; padding: 16px; font-size: 1.05rem; }
.btn.small { padding: 7px 14px; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--surface-2); display: grid; place-items: center;
}

/* Layout */
.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 80px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff;
}
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }

/* Home */
.hero { padding: 40px 0 32px; max-width: 680px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 800; }
.hero p { font-size: 1.15rem; color: var(--muted); margin-top: 14px; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.home-card { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; cursor: pointer; border: 0; text-align: left; }
.home-card h2 { font-size: 1.25rem; }
.home-card .figure { width: 120px; height: 120px; }
.how { margin-top: 40px; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.how .num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .875rem; margin-bottom: 8px; }

/* Forms */
label.field { display: block; }
label.field > span { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea.input { resize: vertical; min-height: 70px; }

/* Builder */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .builder { grid-template-columns: 1fr; } }
.section-title { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; margin-bottom: 14px; }
.section-title .num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .8rem; }
.slug { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; background: var(--surface-2); padding: 8px 12px; border-radius: 10px; overflow-wrap: anywhere; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 14px; border-radius: 999px; font-size: .875rem; font-weight: 500; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.lib-card { border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.lib-card .figure { width: 100%; height: 120px; background: var(--surface-2); border-radius: 10px; }
.lib-card h4 { margin: 0; font-size: .9rem; }
.lib-card .add { margin-top: auto; }
.lib-card.custom { border-style: dashed; align-items: center; justify-content: center; text-align: center; min-height: 200px; cursor: pointer; color: var(--muted); }
.lib-card.added { border-color: var(--accent); }

.rx-list { display: flex; flex-direction: column; gap: 12px; }
.rx { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface); }
.rx-head { display: flex; gap: 10px; align-items: center; }
.rx-head .thumb { width: 52px; height: 52px; flex: none; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.rx-head .thumb .figure, .rx-head .thumb img, .rx-head .thumb video { width: 100%; height: 100%; object-fit: cover; }
.rx-head h4 { margin: 0; font-size: .95rem; flex: 1; }
.rx-nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.rx-nums label span { font-size: .7rem; color: var(--muted); font-weight: 600; display: block; margin-bottom: 2px; }
.rx-nums input { width: 100%; padding: 7px 8px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); }
.days { display: flex; gap: 4px; margin-top: 10px; }
.day-toggle { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 0; font-size: .75rem; font-weight: 600; }
.day-toggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.rx details { margin-top: 8px; font-size: .875rem; }
.rx details summary { cursor: pointer; color: var(--muted); }
.rx details .input { margin-top: 6px; font-size: .875rem; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; border: 1px dashed var(--line); border-radius: 14px; }
.sticky { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
@media (max-width: 900px) { .sticky { position: static; max-height: none; } }
.link-box { display: flex; gap: 8px; }
.link-box .input { font-family: ui-monospace, Menlo, monospace; font-size: .75rem; }

/* Dialog */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(5, 15, 20, .55); }
dialog form { padding: 22px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: .9rem; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Figure */
.figure { display: block; }
.figure line, .figure polyline { stroke-linecap: round; stroke-linejoin: round; fill: none; }
.fig-body { stroke: var(--fig); stroke-width: 7; }
.fig-body.thin { stroke-width: 4; }
.fig-body.fat { stroke-width: 14; }
.fig-body.muted { opacity: .45; }
.fig-head { fill: var(--fig); }
.fig-move { stroke: var(--accent); stroke-width: 7; }
.fig-move.thin { stroke-width: 6; }
.fig-hand { fill: var(--accent); }
.fig-hand.muted { fill: var(--fig); opacity: .45; }
.fig-handshape { fill: var(--accent); }
.fig-prop { fill: var(--fig); }
.fig-ball { fill: var(--warn); opacity: .85; }
.fig-table { fill: var(--muted); opacity: .5; }
.fig-wall { stroke: var(--muted); stroke-width: 5; opacity: .5; stroke-dasharray: 2 0; }
.fig-helper { fill: var(--fig); opacity: .35; }
.fig-helper.strong { opacity: .6; }
.fig-heatpack { fill: #f97316; opacity: .85; }
.fig-icepack { fill: #38bdf8; opacity: .85; }
.fig-wave { stroke: #f97316; stroke-width: 4; fill: none; stroke-linecap: round; }
.fig-snow line { stroke: #38bdf8; stroke-width: 4; stroke-linecap: round; }
.fig-floor { fill: var(--fig); opacity: .08; }
.media-frame { width: 100%; aspect-ratio: 16 / 10; border: 0; border-radius: 14px; background: #000; display: block; }
img.media-frame, video.media-frame { object-fit: contain; }

/* ===== Patient app ===== */
.patient { max-width: 520px; margin: 0 auto; padding: 20px 16px 110px; min-height: 100vh; }
.p-header { margin-bottom: 18px; }
.p-clinic { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); font-weight: 500; }
.p-clinic .dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; }
.p-header h1 { font-size: 1.9rem; font-weight: 800; margin-top: 6px; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 18px; }
.wday { border: 0; background: var(--surface); border-radius: 14px; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: var(--shadow); }
.wday .l { font-size: .7rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.wday .d { font-weight: 700; }
.wday .s { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.wday .s.done { background: var(--good); }
.wday .s.part { background: var(--accent-2); }
.wday .s.rest { background: transparent; border: 1.5px solid var(--line); }
.wday.sel { background: var(--accent); }
.wday.sel .l, .wday.sel .d { color: #fff; }
@media (prefers-color-scheme: dark) { .wday.sel .l, .wday.sel .d { color: #04201d; } }
.wday.today:not(.sel) { outline: 2px solid var(--accent); outline-offset: -2px; }

.day-summary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
@media (prefers-color-scheme: dark) { .day-summary { color: #04201d; } }
.day-summary h2 { font-size: 1.3rem; }
.bar { height: 8px; background: rgba(255,255,255,.3); border-radius: 99px; margin-top: 14px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #fff; border-radius: 99px; transition: width .4s ease; }
@media (prefers-color-scheme: dark) { .bar > i { background: #04201d; } .bar { background: rgba(0,0,0,.2); } }

.ex-card { display: flex; gap: 14px; align-items: center; background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); border: 0; width: 100%; text-align: left; margin-bottom: 10px; }
.ex-card .thumb { width: 76px; height: 76px; flex: none; background: var(--surface-2); border-radius: 14px; overflow: hidden; }
.ex-card .thumb .figure, .ex-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.ex-card .info { flex: 1; min-width: 0; }
.ex-card h3 { font-size: 1rem; }
.ex-card .meta { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.status-pill { font-size: .75rem; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.status-pill.done { background: var(--accent-soft); color: var(--good); }

.notice { background: var(--warn-soft); color: var(--warn); padding: 12px 14px; border-radius: 14px; font-size: .875rem; font-weight: 500; }
.rest-day { text-align: center; padding: 36px 16px; }
.rest-day .big { font-size: 2.6rem; }

.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); display: flex; justify-content: center; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); z-index: 10; }
.bottom-nav .inner { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; max-width: 520px; }
.nav-btn { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; font-weight: 600; color: var(--muted); padding: 6px 0; }
.nav-btn svg { width: 24px; height: 24px; }
.nav-btn.on { color: var(--accent); }

.plan-item { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.plan-item summary { list-style: none; display: flex; gap: 12px; align-items: center; padding: 12px; cursor: pointer; }
.plan-item summary::-webkit-details-marker { display: none; }
.plan-item .thumb { width: 60px; height: 60px; border-radius: 12px; background: var(--surface-2); overflow: hidden; flex: none; }
.plan-item .thumb .figure, .plan-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.plan-item .body { padding: 0 16px 16px; }
.plan-item .body .figure { width: 100%; height: 220px; background: var(--surface-2); border-radius: 14px; }
.steps { padding-left: 0; list-style: none; counter-reset: s; margin: 14px 0 0; }
.steps li { counter-increment: s; position: relative; padding-left: 36px; margin-bottom: 10px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .8rem; display: grid; place-items: center; }
.clin-note { background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; font-size: .9rem; margin-top: 12px; }
.clin-note b { color: var(--accent); }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: .75rem; font-weight: 600; padding: 4px 10px; background: var(--surface-2); border-radius: 99px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.stat .v { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
.stat .k { font-size: .75rem; color: var(--muted); font-weight: 600; }
.chart { width: 100%; height: 160px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .ln { fill: none; stroke: var(--warn); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--warn); }
.history-day { margin-top: 14px; }
.history-day h4 { margin: 0 0 6px; font-size: .85rem; color: var(--muted); }
.history-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: .9rem; }

/* Player */
.player { position: fixed; inset: 0; background: var(--bg); z-index: 50; overflow-y: auto; animation: up .25s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.player-inner { max-width: 520px; margin: 0 auto; padding: 16px 16px 40px; }
.player-media { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; margin: 12px 0 16px; }
.player-media .figure { width: 100%; height: 280px; }
.set-dots { display: flex; gap: 6px; justify-content: center; margin: 12px 0; }
.set-dots i { width: 34px; height: 6px; border-radius: 99px; background: var(--line); }
.set-dots i.done { background: var(--accent); }
.set-dots i.cur { background: var(--accent-2); }
.counter { text-align: center; }
.counter .big { font-size: 3.6rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.counter .lbl { color: var(--muted); font-weight: 600; margin-top: 4px; }
.ring { width: 150px; height: 150px; margin: 6px auto; display: block; }
.ring .bg { stroke: var(--line); }
.ring .fg { stroke: var(--accent); transition: stroke-dashoffset .25s linear; }
.ring.rest .fg { stroke: var(--accent-2); }
.ring text { fill: var(--text); font-weight: 800; }
.player-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.pain-scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; margin-top: 8px; }
.pain-scale button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 10px 0; font-weight: 700; font-size: .85rem; }
.pain-scale button.on { color: #fff; border-color: transparent; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.seg button { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px; font-weight: 600; }
.seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.celebrate { text-align: center; font-size: 3rem; }

/* Additions for real-world plans */
.rx-nums.five { grid-template-columns: repeat(5, 1fr); }
.rx-nums.three { grid-template-columns: repeat(3, 1fr); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; margin-top: 12px; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
.rule-card { background: var(--surface); border-left: 4px solid var(--warn); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; font-size: .9rem; }
.rule-card strong { display: block; margin-bottom: 4px; }
.half-banner { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: .9rem; text-align: center; margin-top: 10px; }
.variation { display: inline-block; background: var(--accent-soft); color: var(--accent); font-weight: 700; padding: 4px 12px; border-radius: 99px; margin-top: 6px; }
.dur-chips { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.status-pill.half { background: var(--warn-soft); color: var(--warn); }
