:root {
  --paper: #f5f1e8;
  --paper-deep: #ece7db;
  --surface: #fffdf8;
  --ink: #18211d;
  --muted: #67716a;
  --faint: #8c948d;
  --line: #dcd6c8;
  --accent: #1f5c48;
  --accent-soft: #e2ebe4;
  --pain: #a8503c;
  --pain-soft: #f3e4de;
  --focus: #164dba;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-width: 300px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
a { color: var(--accent); text-underline-offset: .18em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem clamp(1rem, 2.4vw, 1.9rem);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.wordmark {
  color: var(--ink);
  text-decoration: none;
  font-weight: 750;
  font-size: .82rem;
  letter-spacing: .16em;
}
.wordmark span { color: var(--faint); padding: 0 .18em; }
.topbar-note {
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
  letter-spacing: .04em;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(330px, 26vw, 410px);
}

/* ---------- stage ---------- */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
}
.model {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 18%, #fdfbf5 0%, #f1ece1 58%, #e7e1d4 100%);
}
.model canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.stage-bar {
  position: absolute;
  top: 1rem;
  left: 1.1rem;
  right: 1.1rem;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  pointer-events: none;
}
.stage-bar > * { pointer-events: auto; }
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fffdf8cc;
  backdrop-filter: blur(6px);
}
.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: .25rem .85rem;
  background: transparent;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 650;
}
.segmented button[aria-pressed="true"] { background: var(--ink); color: #fffdf8; }
.quiet-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .25rem .7rem;
  background: #fffdf8cc;
  color: var(--muted);
  font-size: .78rem;
}
.quiet-button:hover { color: var(--ink); border-color: var(--faint); }

.model-labels {
  position: absolute;
  z-index: 2;
  left: 1.1rem;
  top: 4.4rem;
  display: flex;
  align-items: flex-start;
  gap: .45rem;
  pointer-events: none;
  padding: .4rem .6rem .42rem .62rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 248, .93);
  box-shadow: 0 8px 22px rgba(24, 33, 29, .09);
}
.label-line {
  width: 6px;
  height: 6px;
  margin-top: .58rem;
  border-radius: 50%;
  background: var(--accent);
}
.label-text { display: grid; gap: .05rem; }
#label-name { font-family: var(--serif); font-size: 1rem; letter-spacing: -.01em; }
#label-meta { color: var(--muted); font-size: .7rem; letter-spacing: .04em; }

.stage-foot {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  padding: .6rem clamp(1rem, 2vw, 1.4rem) .68rem;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.stage-kicker {
  margin: 0 0 .2rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
.stage-caption {
  margin: 0;
  font-size: .88rem;
  color: #33413a;
  text-wrap: pretty;
}
.study-transport {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-top: .55rem;
  flex-wrap: wrap;
}
.play-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .15rem .55rem;
  background: #fffdf8d9;
  font-size: .75rem;
  font-weight: 650;
}
.chapters {
  display: flex;
  gap: .35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chapters li {
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--faint);
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
}
.chapters li.is-current { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- rail ---------- */
.rail {
  border-left: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.rail-body { padding: 1.7rem clamp(1.1rem, 2vw, 1.8rem) 3rem; max-width: 46ch; }

.eyebrow {
  margin: 0 0 .45rem;
  color: var(--accent);
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.rail h1, .rail h2, .rail h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.015em; }
.rail h1 { margin: 0 0 .7rem; font-size: clamp(1.7rem, 2.1vw, 2.15rem); line-height: 1.04; }
.rail h2 { margin: 0 0 .35rem; font-size: clamp(1.45rem, 1.8vw, 1.85rem); line-height: 1.1; }
.rail h3 { margin: 0 0 .2rem; font-size: 1.05rem; }
.lead { margin: 0 0 1.2rem; color: #3c4a42; font-size: .97rem; text-wrap: pretty; }
.about { margin: 0 0 1.15rem; color: #3c4a42; font-size: .95rem; }
.aka { margin: -.2rem 0 .9rem; color: var(--muted); font-size: .8rem; letter-spacing: .02em; }
.small { margin: .9rem 0 0; color: var(--muted); font-size: .78rem; }
.rule { height: 1px; margin: 1.15rem 0; background: var(--line); }

/* steps */
.steps { display: flex; gap: 0; margin: 0 0 1.35rem; padding: 0; list-style: none; }
.steps li {
  flex: 1;
  padding-top: .45rem;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: .67rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.steps li.is-done { border-top-color: var(--accent-soft); color: var(--muted); }
.steps li.is-current { border-top-color: var(--accent); color: var(--accent); font-weight: 700; }

/* fields */
.search { position: relative; margin: 0 0 1.1rem; }
.search input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .75rem;
  background: #fff;
  color: var(--ink);
}
.search input::placeholder { color: var(--faint); }

.group { margin: 0 0 1.05rem; }
.group-title {
  margin: 0 0 .35rem;
  color: var(--faint);
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.muscle-list { display: grid; gap: 0; border-top: 1px solid var(--line); }
.muscle-button {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .8rem;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: .55rem .1rem;
  background: transparent;
  text-align: left;
}
.muscle-button span:first-child { font-size: .94rem; }
.muscle-button span:last-child { color: var(--faint); font-size: .72rem; }
.muscle-button:hover { background: #f8f5ed; }
.muscle-button:hover span:first-child { color: var(--accent); }

.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; margin: .55rem 0 1.1rem; }
.chip {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .35rem .7rem;
  background: #fff;
  color: #2f3b35;
  font-size: .84rem;
  text-align: left;
  line-height: 1.3;
}
.chip:hover { border-color: #b8bdb4; }
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #143c2f;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.field-label { display: block; margin: 0 0 .1rem; font-size: .9rem; font-weight: 650; }
.field-help { margin: .15rem 0 .9rem; color: var(--muted); font-size: .78rem; }

/* actions */
.action-group { margin: 0 0 1.1rem; }
.action-list { display: grid; gap: .45rem; }
.action {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: .6rem;
  align-items: start;
  padding: .6rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  font-size: .88rem;
}
.action .box {
  width: 16px;
  height: 16px;
  margin-top: .18rem;
  border: 1px solid #a9b2aa;
  border-radius: 3px;
  background: #fff;
}
.action[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.action[aria-pressed="true"] .box { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--accent-soft); }
.action small { display: block; color: var(--muted); font-size: .76rem; line-height: 1.45; }

/* buttons */
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: .55rem 1rem;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  font-size: .92rem;
}
.primary:hover { background: #174936; }
.rail .primary { margin-top: 1.1rem; }
.primary:disabled { border-color: var(--line); background: #e9e5da; color: var(--faint); cursor: not-allowed; }
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem .8rem;
  background: #fff;
  font-size: .85rem;
}
.link-button {
  min-height: 34px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  text-decoration: underline;
  text-underline-offset: .2em;
}
.actions-row { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin-top: 1rem; }

/* explanation */
.pattern-summary { margin: 0 0 .9rem; color: #3c4a42; font-size: .95rem; }
.why { margin: 0 0 1rem; font-size: .93rem; color: #2b3831; }
.model-notes { margin: 0 0 1.1rem; padding: 0 0 0 1rem; }
.model-notes li { margin: .2rem 0; font-size: .85rem; color: var(--muted); }
details.sources { margin: 0 0 1.1rem; border-top: 1px solid var(--line); padding-top: .6rem; }
details.sources summary { cursor: pointer; color: var(--accent); font-size: .8rem; font-weight: 650; }
details.sources ul { margin: .5rem 0 0; padding-left: 1rem; color: var(--muted); font-size: .8rem; }
details.sources li { margin: .25rem 0; }
.other-pattern { margin: 0 0 1.1rem; padding: .7rem .8rem; background: #f7f3ea; border-left: 2px solid var(--line); }
.other-pattern h4 { margin: 0 0 .2rem; font-family: var(--serif); font-size: .98rem; font-weight: 600; }
.other-pattern p { margin: 0; color: var(--muted); font-size: .82rem; }

/* help */
.help-list { counter-reset: step; margin: 0 0 1.3rem; padding: 0; list-style: none; }
.help-list li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr);
  gap: .55rem;
  padding: .65rem 0;
  border-bottom: 1px solid var(--line);
}
.help-list li::before {
  content: counter(step);
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--accent);
  line-height: 1.3;
}
.help-list p { margin: .15rem 0 0; color: #3c4a42; font-size: .88rem; }
.urgent {
  margin: 0 0 1.2rem;
  padding: .8rem .85rem;
  border: 1px solid #e2c9bf;
  border-radius: 8px;
  background: var(--pain-soft);
  font-size: .85rem;
  color: #5d2c21;
}
.urgent strong { display: block; margin-bottom: .15rem; font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; }

.footer {
  border-top: 1px solid var(--line);
  padding: .55rem 1.2rem .7rem;
  background: var(--paper);
}
.footer p { margin: 0; padding-right: 9.5rem; color: var(--muted); font-size: .72rem; }
.only-thin { display: none; }
.noscript { padding: 1rem; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: 46dvh minmax(0, 1fr); overflow: hidden; }
  .model-labels { display: none; }
  .rail { min-height: 0; }
  .footer { position: relative; z-index: 5; }
  .rail { border-left: 0; border-top: 1px solid var(--line); }
  .rail-body { max-width: 62ch; padding-top: 1.3rem; padding-bottom: 2.4rem; }
  .stage-caption { max-width: 62ch; font-size: .82rem; }
}
@media (max-width: 520px) {
  .topbar-note { display: none; }
  .layout { grid-template-rows: 42dvh minmax(0, 1fr); }
  .stage-bar { top: .7rem; left: .7rem; right: .7rem; }
  .stage-foot { padding: .55rem .9rem .6rem; }
  .study-transport { display: none; }
  .chapters { display: none; }
  .only-wide { display: none; }
  .only-thin { display: inline; }
  .footer { padding: .45rem .9rem 3.4rem; }
  .footer p { padding-right: 0; font-size: .68rem; }
  .stage-foot { padding: .45rem .9rem .5rem; }
  .stage-kicker { display: none; }
  .stage-caption { font-size: .8rem; }
}


/* ---------- dock: picking lives on the model ---------- */
.dock { position: relative; margin: 0 0 .5rem; }
.dock-row { display: flex; align-items: center; gap: .6rem; }
.dock input {
  flex: 0 1 210px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .35rem .6rem;
  background: #fff;
  font-size: .86rem;
  color: var(--ink);
}
.dock input::placeholder { color: var(--faint); }
.dock-chips { display: flex; gap: .3rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.dock-chips::-webkit-scrollbar { display: none; }
.region-chip {
  flex: 0 0 auto;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .2rem .62rem;
  background: #fffdf8cc;
  color: var(--muted);
  font-size: .74rem;
  white-space: nowrap;
}
.region-chip:hover { color: var(--ink); border-color: #b8bdb4; }
.region-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fffdf8; }
.dock-results {
  position: absolute;
  bottom: calc(100% + .45rem);
  left: 0;
  right: 0;
  z-index: 8;
  max-height: 244px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 18px 40px rgba(24, 33, 29, .16);
  padding: .3rem;
}
.dock-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .1rem; }
.dock-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: .35rem .5rem;
  background: transparent;
  text-align: left;
  font-size: .85rem;
}
.dock-item span:last-child { color: var(--faint); font-size: .7rem; }
.dock-item:hover { background: #f4f0e5; }
.dock-empty { margin: .4rem .5rem; color: var(--muted); font-size: .8rem; }

/* ---------- pick screen ---------- */
.howto { margin: 1.5rem 0 0; padding: 0; list-style: none; display: grid; gap: .85rem; }
.howto li { display: grid; grid-template-columns: 1.5rem minmax(0, 1fr); gap: .45rem; font-size: .86rem; color: #3c4a42; }
.howto b { font-family: var(--serif); font-size: 1rem; color: var(--accent); line-height: 1.2; }
.howto span { display: block; margin-top: .1rem; color: var(--muted); font-size: .8rem; }

/* ---------- mechanism plate ---------- */
.mechanism {
  position: absolute;
  z-index: 5;
  left: 1.1rem;
  bottom: 5.6rem;
  width: clamp(330px, 40%, 460px);
  margin: 0;
  padding: .45rem .45rem .5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, .96);
  box-shadow: 0 16px 38px rgba(24, 33, 29, .13);
  backdrop-filter: blur(5px);
}
.mech-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .1rem; }
.mech-head > span:first-child { font-size: .64rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; color: var(--accent); }
.mech-state { font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
#mech-img { display: block; width: 100%; height: auto; border-radius: 6px; background: #efe7d6; }
.mech-struct { display: block; margin: .35rem 0 0; font-size: .66rem; line-height: 1.4; letter-spacing: .04em; color: var(--muted); }
.mech-struct:empty { display: none; }

.stage.is-study .model canvas { opacity: .92; transition: opacity .55s ease; }
.mechanism, .mech-load, .mech-halo, .mech-fray, .mech-referral { transition: opacity .45s ease; }
.mech-load, .mech-halo, .mech-fray { opacity: 0; }
#mechanism[data-state="1"] .mech-load { opacity: 1; }
#mechanism[data-state="2"] .mech-load { opacity: .45; }
#mechanism[data-state="2"] .mech-halo { opacity: 1; }
#mechanism[data-state="2"] .mech-fray { opacity: 1; }
#mechanism[data-state="0"] .mech-referral { opacity: .15; }
#mechanism[data-state="1"] .mech-referral { opacity: .55; }
#mechanism[data-state="2"] .mech-referral { opacity: 1; }

.mech-tendon, .mech-bursa, .mech-lever, .mech-band, .mech-sheath, .mech-cord {
  transform-box: fill-box;
  transition: transform .8s cubic-bezier(.4, 0, .2, 1), stroke-width .6s ease, opacity .4s ease;
}
.mech-tendon { transform-origin: 100% 100%; }
#mechanism[data-state="1"] .mech-tendon, #mechanism[data-state="2"] .mech-tendon { transform: scaleY(.9) scaleX(.97); }
.mech-bursa { transform-origin: 50% 100%; }
#mechanism[data-state="1"] .mech-bursa, #mechanism[data-state="2"] .mech-bursa { transform: scaleY(.62); }
.mech-lever { transform-origin: 50% 100%; }
#mechanism[data-state="1"] .mech-lever, #mechanism[data-state="2"] .mech-lever { transform: rotate(3deg); }
.mech-band { transform-origin: 50% 50%; }
#mechanism[data-state="1"] .mech-band, #mechanism[data-state="2"] .mech-band { transform: scaleX(.6); stroke-width: 5; }
.mech-sheath { transform-origin: 50% 50%; }
#mechanism[data-state="1"] .mech-sheath, #mechanism[data-state="2"] .mech-sheath { transform: scale(.985); stroke: var(--pain); stroke-width: 3.4; }
#mechanism[data-state="1"] .mech-cord, #mechanism[data-state="2"] .mech-cord { transform: scaleY(.72); }

.mech-ring { transform-box: fill-box; transform-origin: 50% 50%; animation: mechRing 2.6s ease-out infinite; opacity: 0; }
.mech-ring.r2 { animation-delay: .55s; }
.mech-ring.r3 { animation-delay: 1.1s; }
@keyframes mechRing {
  0% { transform: scale(.5); opacity: .75; }
  70% { opacity: .12; }
  100% { transform: scale(1.55); opacity: 0; }
}
.mech-core { animation: mechCore 1.8s ease-in-out infinite; }
@keyframes mechCore { 0%, 100% { opacity: .2; } 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) {
  .mech-ring, .mech-core { animation: none; }
  .mech-tendon, .mech-bursa, .mech-lever, .mech-band, .mech-sheath, .mech-cord { transition: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  body.is-study .layout { grid-template-rows: 58dvh minmax(0, 1fr); }
  .mechanism {
    position: absolute;
    left: .65rem;
    right: .65rem;
    bottom: 3.1rem;
    width: auto;
    padding: .5rem .6rem .5rem;
  }
  .mech-caption { font-size: .7rem; }
  .dock-results { max-height: 190px; }
}


.stage.is-picking .stage-kicker, .stage.is-picking .stage-caption { display: none; }
.stage.is-picking .stage-foot { padding-top: .5rem; }

/* ---------- mechanism tags pinned to the model ---------- */

/* ---------- mechanism plate mount ---------- */
.mech-head { padding: 0 .12rem .3rem; }

/* ============================================================
   v2 shell — the model is the page, the guide floats over it
   ============================================================ */
body { background: #eee8dc; }

.layout {
  position: relative;
  display: block;
  flex: 1;
  min-height: 0;
}
.stage {
  position: absolute;
  inset: 0;
  border: 0;
  background: transparent;
}
.model {
  flex: 1 1 auto;
  background:
    radial-gradient(105% 80% at 46% 22%, #fdfbf6 0%, #f3eee3 52%, #e8e1d3 100%);
}

/* floating rail */
.rail {
  position: absolute;
  z-index: 7;
  top: 4.4rem;
  right: 1rem;
  bottom: 1rem;
  width: clamp(330px, 27vw, 402px);
  border: 1px solid rgba(220, 214, 200, .9);
  border-radius: 15px;
  background: rgba(255, 253, 248, .95);
  box-shadow: 0 26px 64px rgba(24, 33, 29, .16), 0 2px 6px rgba(24, 33, 29, .05);
  backdrop-filter: blur(12px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.rail-body { padding: 1.5rem 1.35rem 2.5rem; max-width: 48ch; }

body[data-step="pick"] .rail { display: none; }
body:not([data-step="pick"]) .pick-note { display: none; }

/* the bottom strip: search + caption */
.stage-foot {
  padding: .55rem clamp(.9rem, 1.6vw, 1.3rem) .7rem;
  border-top: 1px solid rgba(220, 214, 200, .8);
  background: linear-gradient(to top, rgba(245, 241, 232, .97), rgba(245, 241, 232, .8));
  backdrop-filter: blur(8px);
}
body[data-step="pick"] .stage-foot { padding-bottom: 1.1rem; }

.stage-bar { top: .9rem; left: 1rem; right: auto; justify-content: flex-start; gap: .5rem; }

/* mechanism plate: a detail drawing beside the model, never the main event */
.mechanism {
  left: 1rem;
  bottom: 8.4rem;
  width: clamp(240px, 26vw, 320px);
  padding: .4rem .4rem .45rem;
  border-radius: 12px;
  background: rgba(255, 253, 248, .95);
  box-shadow: 0 18px 44px rgba(24, 33, 29, .14);
}
.mech-head { padding: 0 .1rem .3rem; }
#mech-img { border-radius: 5px; }
.mech-struct { padding: 0 .1rem; }

/* pick state: one quiet instruction, on the model */
.pick-note {
  position: absolute;
  left: 1rem;
  top: 4.2rem;
  z-index: 5;
  max-width: 330px;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, .92);
  box-shadow: 0 14px 34px rgba(24, 33, 29, .09);
  backdrop-filter: blur(8px);
}
.pick-note h1 {
  margin: 0 0 .3rem;
  font-family: var(--serif);
  font-size: 1.32rem;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.1;
}
.pick-note p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.5; }
.pick-note .pick-count { display: block; margin-top: .5rem; color: var(--faint); font-size: .72rem; letter-spacing: .04em; }
body[data-step="pick"] .stage-kicker,
body[data-step="pick"] .stage-caption { display: none; }

/* the caption strip earns its space */
.stage-caption { font-size: .86rem; }

@media (max-width: 900px) {
  .rail {
    position: fixed;
    z-index: 9;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 58dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
  }
  .rail-body { max-width: none; padding: 1.15rem 1.05rem 1.6rem; }
  body:not([data-step="pick"]) .stage-foot { display: none; }
  .mechanism { left: .6rem; right: .6rem; bottom: 3.2rem; width: auto; }
  .pick-note { left: .7rem; right: .7rem; top: 3.9rem; max-width: none; }
  .footer { display: none; }
}
@media (max-width: 520px) {
  .rail { max-height: 64dvh; }
  .model { min-height: 0; }
}

/* steps strip must never clip inside the floating card */
.steps { gap: .1rem; }
.steps li { font-size: .62rem; letter-spacing: .08em; padding-top: .4rem; }
.steps li { font-size: .58rem; letter-spacing: .06em; }
body.is-study .footer { display: none; }
body.is-study .stage-foot { padding-bottom: .55rem; }

/* ---------- small screens: keep the figure clear of the controls ---------- */
@media (max-width: 520px) {
  .pick-note { padding: .5rem .65rem .55rem; max-width: 58%; }
  .pick-note h1 { font-size: 1.02rem; margin-bottom: .1rem; }
  .pick-note p, .pick-note .pick-count { display: none; }
  .stage-bar { top: .6rem; left: .6rem; }
  .segmented button { min-height: 32px; padding: .2rem .6rem; font-size: .76rem; }
  .quiet-button { min-height: 32px; font-size: .72rem; }
}

@media (max-width: 520px) {
  .pick-note { top: auto; bottom: 4.1rem; left: .55rem; right: auto; max-width: 62%; border-radius: 999px; padding: .4rem .8rem; background: rgba(255,253,248,.96); }
  .pick-note h1 { font-size: .92rem; margin: 0; }
}

@media (min-width: 521px) and (max-width: 900px) {
  .pick-note { max-width: 380px; right: auto; }
}

/* small screens: keep the instruction a single quiet line above the picker */
@media (max-width: 1100px) {
  .pick-note {
    left: .85rem;
    right: auto;
    top: auto;
    bottom: 7.6rem;
    max-width: min(320px, 62vw);
    padding: .55rem .75rem;
  }
  .pick-note h1 { margin: 0 0 .15rem; font-size: .98rem; }
  .pick-note p { display: none; }
}

@media (max-width: 640px) {
  .pick-note {
    left: .85rem;
    right: .85rem;
    top: auto;
    bottom: 7.6rem;
    max-width: none;
    padding: .5rem .7rem;
    border-radius: 10px;
  }
  .pick-note h1 { margin: 0; font-size: .92rem; }
  .pick-note p,
  .pick-note .pick-count { display: none; }
}

/* ---------- narrow viewports: model first, guide beneath it ---------- */
@media (max-width: 1180px) {
  html, body { height: auto; min-height: 100%; }
  body { overflow-y: auto; }
  .layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-bottom: .6rem;
  }
  .stage {
    position: relative;
    inset: auto;
    height: 58dvh;
    flex: 0 0 auto;
  }
  .rail {
    position: relative;
    inset: auto;
    width: auto;
    margin: .9rem .9rem 1.1rem;
    max-height: none;
    overflow: visible;
  }
  .rail-body { max-width: 64ch; padding: 1.1rem 1rem 1.6rem; }
  .mechanism {
    position: static;
    left: auto;
    bottom: auto;
    width: auto;
    margin: .9rem .9rem 0;
    box-shadow: none;
    border: 1px solid var(--line);
  }
  .mechanism.in-rail {
    margin: 0 0 1.1rem;
    background: #fffdf8;
  }
}
@media (max-width: 640px) {
  .stage { height: 54dvh; }
}


/* before a muscle is chosen the model owns the whole screen */
@media (max-width: 1180px) {
  body[data-step="pick"] .layout { min-height: calc(100dvh - 3.6rem); }
  body[data-step="pick"] .stage { flex: 1 1 auto; height: auto; min-height: 62dvh; }
}


/* the prompt sits in the empty corner, never over the figure */
@media (max-width: 1180px) {
  .pick-note { top: 5.1rem; bottom: auto; left: .9rem; max-width: min(300px, 58vw); }
}

/* no empty control strip under the model before a muscle is chosen */
body[data-step="pick"] .stage-foot { display: none; }
.stage-foot { background: transparent; border-top: 0; backdrop-filter: none; }

/* the running mechanism caption sits on the model */
.beat-caption {
  position: absolute;
  z-index: 6;
  left: 1rem;
  right: 1rem;
  bottom: .9rem;
  max-width: 46ch;
  padding: .55rem .7rem;
  border: 1px solid rgba(220, 214, 200, .9);
  border-radius: 10px;
  background: rgba(255, 253, 248, .93);
  backdrop-filter: blur(6px);
}
.beat-step {
  display: block;
  margin-bottom: .2rem;
  color: var(--accent);
  font-size: .62rem;
  font-weight: 750;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.beat-text { margin: 0; font-size: .82rem; line-height: 1.4; color: var(--ink); }


/* keep the running caption clear of the figure on short screens */
@media (max-height: 780px) {
  .beat-caption { left: .8rem; right: auto; bottom: .5rem; max-width: 34ch; padding: .4rem .55rem; }
  .beat-text { font-size: .76rem; }
}

/* On phones the prompt moves under the model instead of covering the chest. */
@media (max-width: 640px) {
  body[data-step="pick"] .model { flex: 1 1 auto; min-height: 52dvh; }
  body[data-step="pick"] .pick-note {
    position: static;
    margin: .7rem .9rem .9rem;
    max-width: none;
    box-shadow: none;
    background: rgba(255, 253, 248, .96);
  }
  body[data-step="pick"] .pick-note h1 { font-size: 1.16rem; }
}

/* the canvas fills the stage box and never drives layout */
.model { position: relative; }
.model canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
