html { scrollbar-gutter: stable; }
:root {
  --bg: #F2F4EA; --surface: #FFFFFF; --ink: #1D2518; --muted: #646E55; --line: #D9DFC8;
  --accent: #5C7634; --accent-ink: #FFFFFF; --accent-soft: #E7EDD9;
  --body: #E4E7D9; --muscle: #C3CAB0; --tight: #D9952A; --pain: #C4433A; --danger-soft: #F8E3E1;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); padding: 24px 16px 64px; }
.wrap { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.wrap.wide { max-width: 1000px; }
h1 { font-size: clamp(26px, 5vw, 34px); line-height: 1.15; margin: 0; letter-spacing: -.01em; }
header p { margin: 6px 0 0; color: var(--muted); }
.logo { display: block; height: 76px; width: auto; margin: 0 0 12px; }
.logo.center { margin: 0 auto 4px; height: 64px; }
header .biz { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.card h2 { font-size: 19px; margin: 0; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lbl { font-weight: 700; font-size: 15px; }
.req { color: var(--pain); }
input[type=text], input[type=tel], input[type=email], input[type=date], input[type=password], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend.lbl { padding: 0; margin-bottom: 8px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.opt span { display: inline-block; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 8px 14px; font-size: 15px; cursor: pointer; user-select: none; }
.opt input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.opt input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.err { font-size: 14px; color: var(--pain); margin: 0; font-weight: 700; }
.fielderr input, .fielderr select, .fielderr textarea, .fielderr .sig, .fielderr .opts { border-color: var(--pain); }
.legal { font-size: 14px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 12px 14px; margin: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); margin-top: 1px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
button, .btn { font: 700 16px var(--font); border-radius: 10px; padding: 12px 22px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.small, .btn.small { font-size: 14px; padding: 7px 14px; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.link { all: unset; color: var(--accent); cursor: pointer; font-weight: 700; text-decoration: underline; }
.toast { background: var(--accent-soft); border-radius: 10px; padding: 12px 16px; font-weight: 700; }
.toast.bad { background: var(--danger-soft); color: var(--pain); }

/* signature */
.sig { border: 2px dashed var(--line); border-radius: 10px; background: #fff; position: relative; touch-action: none; }
.sig canvas { width: 100%; height: auto; display: block; aspect-ratio: 3 / 1; cursor: crosshair; touch-action: none; }
.sig .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #A3AE92; pointer-events: none; font-size: 15px; }
.sigbar { display: flex; gap: 8px; }

/* receipt / success */
.success { text-align: center; align-items: center; padding: 36px 20px; }
.tick { width: 64px; height: 64px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 34px; font-weight: 700; }
.refbox { font: 700 18px ui-monospace, Consolas, monospace; background: var(--bg); padding: 6px 12px; border-radius: 8px; }

/* staff */
.topbar { display: flex; gap: 12px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 16px; color: var(--muted); }
.tabs button[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.rows { display: flex; flex-direction: column; }
.rows .row { all: unset; box-sizing: border-box; cursor: pointer; display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; padding: 12px 6px; border-top: 1px solid var(--line); align-items: baseline; }
.rows .row:hover { background: var(--bg); }
.rows .row:focus-visible { outline: 3px solid var(--accent); }
.rows .d { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.rows .n { font-weight: 700; overflow-wrap: anywhere; }
.rows .n small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.rows .t { font-size: 13px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.empty { color: var(--muted); margin: 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 20px; margin: 0; }
.kv > div { min-width: 0; }
.kv dt { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kv dd { margin: 2px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.kv .full { grid-column: 1 / -1; }
.sigimg { background: #fff; border: 1px solid var(--line); border-radius: 8px; max-width: 320px; width: 100%; }
dialog { border: 0; border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dbody { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
dialog .dhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
dialog h2 { margin: 0; font-size: 20px; }
.subrow { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 13px; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 3px 10px; }

/* follow-up body map */
.map { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; }
.fig { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.fig svg { width: 100%; max-width: 440px; height: auto; touch-action: manipulation; }
.fig .cap { font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.sil { fill: var(--body); stroke: var(--body); }
.side { font: 700 11px var(--font); fill: var(--muted); }
.mlabel { font: 700 10.5px var(--font); fill: var(--ink); cursor: pointer; }
.mlabel[data-s="1"] { fill: var(--tight); } .mlabel[data-s="2"] { fill: var(--pain); } .mlabel[data-s="3"] { fill: var(--accent); }
.leaders polyline { stroke: var(--muted); stroke-width: .7; opacity: .7; fill: none; }
ellipse.m { fill: var(--muscle); stroke: var(--body); stroke-width: 1.2; cursor: pointer; transition: fill .15s; }
ellipse.m:hover { stroke: var(--accent); }
ellipse.m[data-s="1"] { fill: var(--tight); } ellipse.m[data-s="2"] { fill: var(--pain); } ellipse.m[data-s="3"] { fill: var(--accent); }
ellipse.m:focus-visible { outline: 3px solid var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 14px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.picked { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; }
.tag { font-size: 13px; border-radius: 6px; padding: 4px 8px; background: var(--bg); border: 1px solid var(--line); display: inline-flex; gap: 6px; align-items: center; }
.tag b { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.scale { display: flex; align-items: center; gap: 12px; }
.scale input { flex: 1; accent-color: var(--accent); }
.scale output { font: 700 22px var(--font); min-width: 2.2ch; text-align: right; font-variant-numeric: tabular-nums; }
.guide { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--bg); }
.guide summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.guide dl { margin: 12px 0 4px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 20px; }
.guide dt { font-weight: 700; } .guide dd { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
#outcome { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 16px; }
.oc { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.oc h3 { margin: 0; font-size: 16px; }
.oc ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.oc .on { display: block; font-size: 13px; color: var(--muted); }
.full { grid-column: 1 / -1; }
.prog { display: flex; align-items: center; gap: 10px; font-weight: 700; background: var(--bg); border-radius: 10px; padding: 10px 14px; flex-wrap: wrap; }
.pill { display: inline-block; min-width: 30px; text-align: center; border-radius: 6px; padding: 1px 8px; color: #fff; font-variant-numeric: tabular-nums; }
.oempty { color: var(--muted); margin: 0; grid-column: 1 / -1; }
.picker { position: relative; }
.suggest { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow: auto; }
.suggest button { all: unset; display: block; box-sizing: border-box; width: 100%; padding: 10px 12px; cursor: pointer; border-top: 1px solid var(--line); }
.suggest button:first-child { border-top: 0; }
.suggest button:hover, .suggest button:focus-visible { background: var(--accent-soft); }
.suggest small { color: var(--muted); display: block; }
.linked { display: flex; gap: 10px; align-items: center; background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; font-size: 14px; font-weight: 600; flex-wrap: wrap; }
@media (max-width: 480px) { .rows .row { grid-template-columns: 1fr auto; } .rows .d { grid-column: 1 / -1; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* follow-up map on phones: one figure at a time + tappable muscle names */
.viewtabs { display: none; gap: 8px; }
.viewtabs button { flex: 1; }
.viewtabs button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.mchips { display: none; flex-wrap: wrap; gap: 6px; }
.mchips button { font-size: 14px; font-weight: 600; padding: 8px 12px; border-radius: 999px; }
.mchips button[data-s="1"] { background: #FBEFD8; border-color: var(--tight); }
.mchips button[data-s="2"] { background: var(--danger-soft); border-color: var(--pain); }
.mchips button[data-s="3"] { background: var(--accent-soft); border-color: var(--accent); }
@media (max-width: 820px) {
  .viewtabs, .mchips { display: flex; }
  .map.compact { grid-template-columns: minmax(0, 1fr); }
  .map.compact .mlabel, .map.compact .leaders { display: none; }
  .map.compact .fig svg { max-width: 360px; }
}

/* phones: thumb-sized controls, full-width primary actions */
@media (max-width: 640px) {
  button.small, .btn.small { min-height: 42px; }
  .sigbar { gap: 10px; } .sigbar button { flex: 1; min-height: 46px; }
  .card { padding: 16px; }
  .actions { justify-content: stretch; }
  .actions > button, .actions > .btn { flex: 1 1 auto; }
  .success .actions > .btn, .success .actions > button { flex: 1 1 100%; }
  dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  dialog .dbody { padding: 16px; }
}
