/* The two pinned chapters: shell (sticky stage, icon toggle, 2 px track), the phone frame, the product mock,
   the pinned geometry and the reading mode. preview.js measures every mock object once per layout (objects keep
   their natural height in every state; nothing is clipped) and writes transform / opacity on each object plus a
   few custom properties on the consuming element; native scroll is the clock. No literal colours: every value is a
   token from styles.css (the --story-* palette has light and dark values). */

/* ---------- Chapter shell ---------- */
.scroll-chapter {
  --story-viewport: 100svh;
  --stage-h: calc(var(--story-viewport) - var(--nav-height));
  position: relative;
  background: var(--surface);
  scroll-margin-top: 0;
  overflow-x: clip;
}
.care-chapter {
  background: var(--green-block-glow), var(--chapter-gradient);
}
.chapter-stage {
  position: relative;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-7) var(--gutter);
}
@media (min-width: 900px) {
  .scroll-chapter {
    --story-viewport: min(100svh, 1140px);
  }
}

/* The only control: a 44 px icon button. preview.js sets its label and hides it when the layout cannot pin. */
.motion-toggle {
  position: absolute;
  top: 10px;
  right: var(--gutter);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  color: var(--text-2);
}
.motion-toggle svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.scroll-chapter[data-mode='scroll'] .motion-toggle .icon-play,
.scroll-chapter:not([data-mode='scroll']) .motion-toggle .icon-pause {
  display: none;
}
@media (hover: hover) {
  .motion-toggle:hover {
    color: var(--text);
    border-color: var(--text-2);
  }
}

/* Progress: an unlabeled 2 px track, 160 px wide, only while pinned. The base is a quarter of the text colour, the
   fill the full primary (mint on the chapter green). */
.chapter-track {
  display: none;
  position: absolute;
  left: 0;
  bottom: 0;
  width: 160px;
  height: 2px;
  overflow: hidden;
  border-radius: 1px;
  background: color-mix(in srgb, var(--text) 25%, transparent);
}
.chapter-track i {
  display: block;
  height: 100%;
  background: var(--primary-600);
  transform: scaleX(0);
  transform-origin: left;
}
.is-pinned .chapter-track {
  display: block;
}

/* Pinned: the section is the runway, the stage sticks under the header. */
.fluid-patient.is-pinned {
  height: calc(var(--story-viewport) * 1.7);
}
.fluid-care.is-pinned {
  height: calc(var(--story-viewport) * 3.2);
}
.is-pinned .chapter-stage {
  position: sticky;
  top: var(--nav-height);
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: var(--stage-h);
  padding-top: var(--sp-5);
  padding-bottom: var(--sp-5);
}

/* ---------- Layout: copy beside the frame from 900 px, stacked below ---------- */
.fluid-layout {
  display: grid;
  grid-template-columns: minmax(280px, 520px) minmax(0, 1fr);
  align-items: start;
  gap: clamp(32px, 5vw, 72px);
}
.is-pinned .fluid-layout {
  align-items: center;
  min-height: 0;
}
.care-copy,
.recognition-copy {
  padding: 0;
}
.care-copy h3,
.recognition-copy h3 {
  color: var(--text);
}
.care-copy h3 em,
.recognition-copy h3 em {
  color: var(--primary-600);
}
.care-copy > p,
.recognition-copy > p {
  max-width: var(--measure-copy);
  margin: var(--sp-5) 0 0;
  color: var(--text-2);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  text-wrap: pretty;
}
/* The copy track: captions cross-fade inside it with a 14 px drift. A soft mask (16 px of bleed outside the track's
   box, so a caption at rest is never faded) replaces a hard clip. */
/* --track-h lives on the section so the phone frame can take the rest of the stage; preview.js raises it when a
   beat needs more room (a three-line sentence on a 340 px phone). */
.scroll-chapter.is-pinned {
  --track-h: 400px;
}
.is-pinned .care-copy-track,
.is-pinned .recognition-copy-track {
  --track-bleed: 16px;
  position: relative;
  box-sizing: content-box;
  height: var(--track-h);
  margin-block: calc(-1 * var(--track-bleed));
  padding-block: var(--track-bleed);
  -webkit-mask-image: linear-gradient(transparent, currentColor var(--track-bleed), currentColor calc(100% - var(--track-bleed)), transparent);
  mask-image: linear-gradient(transparent, currentColor var(--track-bleed), currentColor calc(100% - var(--track-bleed)), transparent);
}
.is-pinned .care-copy,
.is-pinned .recognition-copy {
  --copy-inset: 24px;
  position: absolute;
  inset: var(--track-bleed) 0 calc(var(--track-bleed) + var(--copy-inset));
  display: flex;
  flex-direction: column;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
}
.is-pinned .care-copy[data-visible='false'],
.is-pinned .recognition-copy[data-visible='false'] {
  visibility: hidden;
}
.is-pinned .chapter-track {
  bottom: var(--track-bleed);
}

/* ---------- The frame in the chapters ---------- */
/* Every device (the hero's included) carries the screen inset and the card radius, so no screen content touches
   the glass. */
.device {
  --canvas-pad: 16px;
  --card-r: 14px;
  --status-h: 44px;
  --bar-h: 48px;
  --tabs-h: 56px;
}
.chapter-stage .device {
  --device-h: clamp(520px, calc(var(--stage-h) - 48px), 780px);
  --device-pad: 10px;
  position: relative;
  z-index: 1;
  width: clamp(300px, calc(var(--device-h) * 0.5), 360px);
  height: var(--device-h);
  margin: 0 auto;
  padding: var(--device-pad);
  isolation: isolate;
  font: 400 15px / 1.45 var(--font-sans);
  color: var(--story-ink);
}
.chapter-stage .device::before {
  content: '';
  position: absolute;
  inset: -18% -40%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--wash-green) 85%, transparent), transparent);
  pointer-events: none;
}
.care-chapter .chapter-stage .device::before {
  background: radial-gradient(closest-side, color-mix(in srgb, var(--hero-glow) 30%, transparent), transparent);
}
.fluid-patient .device {
  box-shadow:
    var(--story-elev),
    0 0 0 1px var(--device-edge),
    inset 0 0 0 1px var(--device-inner);
}
.chapter-stage .device-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--story-wash);
}

/* ---------- Mock chrome: status strip, app bar, tab bar, canvas ---------- */
.mock-status {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex: none;
  height: var(--status-h);
  padding: 0 24px 6px;
  background: var(--story-paper);
  color: var(--story-ink);
  font-size: 13px;
  font-weight: var(--w-heading);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.mock-status-glyphs {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.mock-status-glyphs svg {
  height: 11px;
  width: auto;
  fill: currentColor;
}
.care-product-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  height: var(--bar-h);
  padding: 0 var(--canvas-pad);
  border-bottom: 1px solid var(--story-line);
  background: var(--story-paper);
  color: var(--story-muted);
  font-size: 13px;
}
.care-product-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--story-ink);
  font-size: 15px;
  font-weight: 650;
}
.care-product-brand img {
  width: 20px;
  height: 20px;
  border-radius: 5px;
}
/* The app's tab bar: a glyph and a label per tab, and a pill that slides to the active tab (preview.js writes --tab;
   data-tab names the lit tab, for the colour). */
.mock-tabs {
  position: relative;
  display: flex;
  flex: none;
  height: var(--tabs-h);
  padding: 5px 8px 0;
  border-top: 1px solid var(--story-line);
  background: var(--story-paper);
}
.mock-tab {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding-top: 3px;
  color: var(--story-muted);
  font-size: 12px;
  font-weight: var(--w-ui);
  line-height: 1.3;
}
.mock-tab svg {
  width: 22px;
  height: 22px;
}
.mock-tab-pill {
  position: absolute;
  top: 5px;
  left: 8px;
  width: calc((100% - 16px) / 3);
  height: 28px;
  transform: translateX(calc(var(--tab, 0) * 100%));
}
.mock-tab-pill::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  width: 56px;
  height: 28px;
  margin-left: -28px;
  border-radius: 14px;
  background: var(--story-chip-bg);
}
.mock-tabs[data-tab='search'] .mock-tab[data-tab='search'],
.mock-tabs[data-tab='today'] .mock-tab[data-tab='today'] {
  color: var(--story-chip-fg);
  font-weight: var(--w-heading);
}
.care-canvas,
.recognition-canvas,
.mock-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: var(--canvas-pad);
  overflow: hidden;
}

/* ---------- Mock objects (static flow; the pinned rules below position them) ---------- */
.mock-canvas > * + *,
.scroll-chapter:not(.is-pinned) .care-canvas > * + *,
.scroll-chapter:not(.is-pinned) .recognition-canvas > * + * {
  margin-top: 10px;
}
.mock-label {
  margin: 18px 0 8px;
  color: var(--story-muted);
  font-size: 13px;
  font-weight: var(--w-ui);
}
.care-object {
  padding: 14px 16px;
  border: 1px solid var(--story-line);
  border-radius: var(--card-r);
  background: var(--story-paper);
}
.care-record-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--story-muted);
  font-size: 12px;
  line-height: 1.4;
}
.care-record-meta > span:first-child {
  letter-spacing: 0.04em;
}
.care-object-title {
  margin: 8px 0 0;
  font-size: 17px;
  line-height: 1.3;
  font-weight: var(--w-heading);
  letter-spacing: -0.015em;
}
.care-text {
  margin: 6px 0 0;
  font-size: 15px;
  line-height: 1.5;
}
.care-clinician {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--story-muted);
}
.care-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--story-avatar-fg);
  background: var(--story-avatar-bg);
  font: 600 19px/1 var(--font-sans);
}
.care-avatar-cat {
  width: 40px;
  height: 40px;
  font-size: 18px;
  background: var(--story-avatar-cat-bg);
  color: var(--story-avatar-cat-fg);
}
.recognition-owner-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--story-chip-bg);
  color: var(--story-chip-fg);
  font-size: 12px;
  font-weight: var(--w-heading);
}
.care-patient,
.care-owner,
.recognition-owner,
.recognition-patient,
.recognition-milo,
.care-day-other,
.care-followup,
.care-vaccine,
.recognition-vaccine {
  display: flex;
  align-items: center;
  gap: 12px;
}
.care-patient > div,
.care-owner > div,
.recognition-owner > div,
.recognition-patient > div,
.recognition-milo > div,
.care-day-other > div,
.care-followup > div,
.care-vaccine > div,
.recognition-vaccine > div {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
/* A row's right-hand slot: the arrow, the weight and the day status share one grid cell (a cross-fade never moves the
   name line), right-aligned at least 12 px from it. */
.row-end {
  display: grid;
  flex: none;
  justify-items: end;
  align-items: center;
  margin-left: auto;
}
.row-end > * {
  grid-area: 1 / 1;
}
.care-patient {
  min-height: 56px;
  padding: 4px 0;
}
.care-patient .care-avatar {
  width: 48px;
  height: 48px;
  font-size: 20px;
}
.care-patient > div > strong {
  font-size: 20px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.care-patient > div > span,
.care-owner > div > span,
.recognition-owner > div > span,
.recognition-patient > div > span,
.recognition-milo > div > span,
.care-day-other > div > span {
  overflow: hidden;
  color: var(--story-muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.care-patient-sub {
  display: grid;
  min-width: 0;
}
.care-patient-sub > span {
  grid-area: 1 / 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.care-patient-time {
  opacity: 0;
}
/* The day sheet's summary, anchored above the tab bar. */
.care-day-totals {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  color: var(--story-muted);
  font-size: 13px;
  line-height: 1.4;
}
.care-day-totals strong {
  margin-right: 4px;
  color: var(--story-ink);
  font-size: 17px;
  font-weight: var(--w-heading);
  font-variant-numeric: tabular-nums;
}
.care-patient-weight,
.recognition-weight {
  color: var(--story-ink);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.care-patient-weight small,
.recognition-weight small {
  color: var(--story-muted);
  font-size: 12px;
}
.care-patient-status,
.care-entry-status,
.care-entry-draft,
.care-waiting {
  display: inline-flex;
  align-items: center;
  border-radius: 20px;
  padding: 3px 9px;
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0;
  white-space: nowrap;
  color: var(--story-status-ok-fg);
  background: var(--story-status-ok-bg);
}
.care-entry-draft {
  color: var(--story-chip-2-fg);
  background: var(--story-chip-2-bg);
}
.care-waiting {
  color: var(--story-status-wait-fg);
  background: var(--story-status-wait-bg);
}
.care-owner {
  padding: 2px 4px;
}
.care-owner > div > strong,
.recognition-owner > div > strong {
  font-size: 15px;
  font-weight: var(--w-heading);
}
.care-owner-action {
  margin-left: auto;
  color: var(--story-accent);
  font-size: 13px;
  font-weight: var(--w-ui);
  white-space: nowrap;
}
.care-record,
.care-complete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--story-button-bg);
  color: var(--story-button-fg);
  font-size: 15px;
  font-weight: var(--w-heading);
}
.care-record > span:last-child {
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
}
.care-vaccine,
.recognition-vaccine {
  gap: 14px;
}
.recognition-vaccine-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--story-chip-bg);
  color: var(--story-chip-fg);
  font-size: 16px;
}
.care-vaccine > div > span,
.recognition-vaccine > div > span {
  color: var(--story-muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  line-height: 1.4;
}
.care-vaccine strong,
.recognition-vaccine strong {
  font-size: 15px;
  line-height: 1.4;
  font-weight: var(--w-heading);
}
.care-vaccine p,
.recognition-vaccine p {
  margin: 1px 0 0;
  color: var(--story-muted);
  font-size: 12px;
  line-height: 1.4;
}

/* Patient chapter objects */
.recognition-heading {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.recognition-label {
  display: block;
  margin-bottom: 6px;
  color: var(--story-muted);
  font-size: 13px;
}
.recognition-search {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 50px;
  padding: 0 10px 0 14px;
  border: 1px solid var(--story-focus-line);
  border-radius: 12px;
  background: var(--story-paper);
  box-shadow: 0 0 0 3px var(--story-ring);
}
.recognition-search-icon {
  position: relative;
  flex: none;
  width: 13px;
  height: 13px;
  border: 1.6px solid var(--story-muted);
  border-radius: 50%;
}
.recognition-search-icon::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 1.6px;
  bottom: -3px;
  right: -5px;
  background: var(--story-muted);
  transform: rotate(45deg);
  border-radius: 2px;
}
.recognition-digits {
  color: var(--story-ink);
  font-size: 22px;
  font-weight: var(--w-ui);
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
}
/* The field's clear control, as in the app. */
.recognition-clear {
  display: grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--story-wash);
  color: var(--story-muted);
}
.recognition-clear svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}
.recognition-owner {
  padding: 2px 4px;
}
.recognition-patient,
.recognition-milo,
.care-day-other {
  --row-pad-x: 14px;
  position: relative;
  padding: 10px var(--row-pad-x);
  border: 1px solid var(--story-line);
  border-radius: var(--card-r);
  background: var(--story-paper);
}
.recognition-patient {
  border-color: var(--story-focus-line);
}
.recognition-patient > div > strong,
.recognition-milo > div > strong,
.care-day-other > div > strong {
  font-size: 17px;
  line-height: 1.25;
  font-weight: var(--w-heading);
  letter-spacing: -0.01em;
}
.recognition-row-arrow {
  color: var(--story-accent);
  font-size: 20px;
  line-height: 1;
}
.recognition-milo .recognition-row-arrow {
  color: var(--story-muted);
}
.recognition-weight {
  opacity: 0;
}
.recognition-keypad {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 0 0;
}
.recognition-keypad span {
  display: grid;
  place-items: center;
  height: 42px;
  border-radius: 8px;
  background: var(--story-paper);
  box-shadow: 0 1px 0 var(--story-line-strong);
  color: var(--story-ink);
  font-size: 21px;
  font-weight: var(--w-ui);
  font-variant-numeric: tabular-nums;
}
.recognition-keypad .key-blank,
.recognition-keypad .key-delete {
  background: transparent;
  box-shadow: none;
}
.recognition-keypad .key-delete svg {
  width: 22px;
  height: 16px;
  stroke: var(--story-ink);
}

/* Care chapter objects */
.care-day-heading p {
  margin: 0;
}
.care-day-title {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.care-day-heading p + p {
  margin-top: 2px;
  color: var(--story-muted);
  font-size: 13px;
}
.care-day-chips {
  display: flex;
  gap: 8px;
}
.care-day-chips span {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--story-line-strong);
  border-radius: 15px;
  color: var(--story-ink);
  font-size: 12px;
  font-weight: var(--w-ui);
}
.care-day-chips span[data-active] {
  border-color: transparent;
  background: var(--story-button-bg);
  color: var(--story-button-fg);
}
.care-patient-status {
  opacity: 0;
}
/* Today's record: a chip stack (Draft / Recorded, right-aligned at the content edge, on the date's baseline), the
   title, and a note field that reads as a text area while the visit is open: its box covers the note and the room
   under it, and fades when the visit is saved. The record keeps one height in every state. */
.care-entry {
  isolation: isolate;
  border-color: var(--story-focus-line);
}
.care-entry-state {
  display: inline-grid;
  justify-items: end;
}
.care-entry-state > span {
  grid-area: 1 / 1;
}
.care-entry-status {
  opacity: 0;
}
.care-note-field {
  position: relative;
  margin-top: 8px;
}
.care-note-field::before {
  content: '';
  position: absolute;
  inset: -7px -10px -6px;
  z-index: -1;
  border: 1px solid var(--story-line);
  border-radius: 10px;
  background: var(--story-wash);
}
.care-note-field .care-text {
  margin: 0;
}
[data-care-note] > span {
  display: inline;
}
.care-entry-foot {
  display: grid;
  gap: 2px;
  margin: 10px 0 0;
  color: var(--story-muted);
  font-size: 12px;
  line-height: 1.4;
}
.care-entry-foot .care-clinician {
  margin: 0;
}
.care-entry-followup,
.care-entry .care-clinician {
  opacity: 0;
}
.care-followup {
  gap: 14px;
}
/* The mint date tile. */
.care-date-tile {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 52px;
  border-radius: 10px;
  background: var(--story-chip-bg);
  color: var(--story-chip-fg);
}
.care-date-tile strong {
  font-size: 22px;
  line-height: 1;
  font-weight: var(--w-heading);
  font-variant-numeric: tabular-nums;
}
.care-date-tile small {
  margin-top: 3px;
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.06em;
}
.care-followup-label {
  display: block;
  color: var(--story-muted);
  font-size: 12px;
  line-height: 1.4;
}
/* "date" and "due" share one cell, so the label never doubles: the outgoing word clears before the next appears. */
.care-followup-word {
  display: inline-grid;
}
.care-followup-word > span {
  grid-area: 1 / 1;
}
.care-followup-due {
  opacity: 0;
}
.care-followup > div > strong {
  display: block;
  font-size: 17px;
  line-height: 1.35;
  font-weight: var(--w-heading);
  white-space: nowrap;
}
.care-date-check {
  margin-left: auto;
  color: var(--story-accent);
  font-size: 18px;
}
.care-complete {
  display: none;
}
/* One button in the bottom bar: "New visit" becomes "Complete visit" once the form is open. */
.care-bar-label,
.care-bar-glyph {
  display: inline-grid;
}
.care-bar-label > span,
.care-bar-glyph > span {
  grid-area: 1 / 1;
}
.care-bar-glyph {
  justify-items: end;
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
}
.care-bar-new {
  opacity: 0;
}
.care-saved-message {
  margin: 0;
  padding: 12px 0;
  color: var(--story-accent);
  text-align: center;
  font-size: 13px;
  font-weight: var(--w-ui);
}
.care-saved-message > span {
  margin-right: 6px;
}
.care-contact {
  display: flex;
  gap: 10px;
}
.care-contact > span {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--story-line-strong);
  border-radius: 10px;
  background: var(--story-paper);
  font-size: 14px;
  font-weight: var(--w-ui);
  white-space: nowrap;
}

/* ---------- Pinned geometry: every object is absolutely positioned and moved by its own transform ---------- */
.is-pinned .care-canvas > *,
.is-pinned .recognition-canvas > * {
  position: absolute;
  top: var(--canvas-pad);
  left: var(--canvas-pad);
  right: var(--canvas-pad);
  margin: 0;
  transform: translate3d(0, 0, 0);
}
.scroll-chapter[data-active='true'] .care-canvas > *,
.scroll-chapter[data-active='true'] .recognition-canvas > *,
.scroll-chapter[data-active='true'] .care-copy,
.scroll-chapter[data-active='true'] .recognition-copy {
  will-change: transform, opacity;
}
.is-pinned .care-canvas > [data-visible='false'],
.is-pinned .recognition-canvas > [data-visible='false'] {
  visibility: hidden;
}
.is-pinned .recognition-keypad {
  display: grid;
}
.is-pinned .care-complete {
  display: flex;
}
/* Furniture the layout solver dropped for this canvas (preview.js sets data-skip after measuring). */
.scroll-chapter.is-pinned [data-skip='true'] {
  display: none;
}

/* Patient chapter: the chosen row travels up and becomes the history header (its card chrome fades, the content
   meets the canvas edge, the arrow gives way to the weight). */
.is-pinned .recognition-patient {
  --selected: 0;
  --open: 0;
  z-index: 4;
  border-color: transparent;
  background: transparent;
}
.is-pinned .recognition-patient::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--card-r);
  border: 1px solid var(--story-focus-line);
  background: var(--story-paper);
  box-shadow: 0 0 0 calc(3px * var(--selected)) var(--story-ring);
  opacity: calc(1 - var(--open));
  pointer-events: none;
}
.is-pinned .recognition-patient > * {
  position: relative;
  z-index: 1;
}
.is-pinned .recognition-patient > div {
  transform: translateX(calc(-1 * var(--row-pad-x) * var(--open)));
}
.is-pinned .recognition-patient > .care-avatar {
  transform: translateX(calc(-1 * var(--row-pad-x) * var(--open))) scale(calc(1 + 0.1 * var(--open)));
}
.is-pinned .recognition-patient > .row-end {
  transform: translateX(calc(var(--row-pad-x) * var(--open)));
}
.is-pinned .recognition-patient .recognition-row-arrow {
  opacity: calc(1 - var(--open));
}
.is-pinned .recognition-patient .recognition-weight {
  opacity: clamp(0, calc(var(--open) * 2.5 - 1.5), 1);
}
.is-pinned .recognition-milo,
.is-pinned .recognition-owner {
  z-index: 1;
}
.is-pinned .recognition-history,
.is-pinned .recognition-vaccine {
  z-index: 2;
}

/* Care chapter: one property per state change, read by the consuming element. Swaps inside one cell are sequential:
   the outgoing part is gone by the middle of the window and the incoming part starts there, so a label never doubles. */
.is-pinned .care-patient {
  --team: 0;
  z-index: 6;
}
.is-pinned .care-patient-weight {
  opacity: clamp(0, calc(1 - var(--team) / 0.4), 1);
}
.is-pinned .care-patient-sub > span:first-child {
  opacity: clamp(0, calc(1 - var(--team) / 0.5), 1);
}
.is-pinned .care-patient-time {
  opacity: clamp(0, calc((var(--team) - 0.5) / 0.5), 1);
}
/* Done lands last, once the day sheet is complete. */
.is-pinned .care-patient-status {
  opacity: var(--done, 0);
}
.is-pinned .care-previous {
  z-index: 1;
}
.is-pinned .care-entry {
  --saved: 0;
  --note: 1;
  z-index: 3;
}
.is-pinned .care-entry-draft {
  opacity: clamp(0, calc(1 - var(--saved) / 0.5), 1);
}
.is-pinned .care-entry-status {
  opacity: clamp(0, calc((var(--saved) - 0.5) / 0.5), 1);
}
.is-pinned .care-note-field::before {
  opacity: calc(1 - var(--saved));
}
.is-pinned .care-entry .care-clinician,
.is-pinned .care-entry-followup {
  opacity: clamp(0, calc((var(--saved) - 0.5) / 0.5), 1);
}
.is-pinned [data-care-note] > span {
  opacity: clamp(0, calc(var(--note) * 9 - var(--i)), 1);
}
[data-care-note] > span:nth-child(1) { --i: 0; }
[data-care-note] > span:nth-child(2) { --i: 1; }
[data-care-note] > span:nth-child(3) { --i: 2; }
[data-care-note] > span:nth-child(4) { --i: 3; }
[data-care-note] > span:nth-child(5) { --i: 4; }
[data-care-note] > span:nth-child(6) { --i: 5; }
[data-care-note] > span:nth-child(7) { --i: 6; }
[data-care-note] > span:nth-child(8) { --i: 7; }
[data-care-note] > span:nth-child(9) { --i: 8; }
.is-pinned .care-followup {
  --recall: 0;
  z-index: 3;
}
.is-pinned .care-followup-set {
  opacity: clamp(0, calc(1 - var(--recall) / 0.5), 1);
}
.is-pinned .care-followup-due {
  opacity: clamp(0, calc((var(--recall) - 0.5) / 0.5), 1);
}
.is-pinned .care-date-check {
  opacity: calc(1 - var(--recall));
}
.is-pinned .care-complete {
  --bar: 1;
  z-index: 4;
}
.is-pinned .care-complete .care-bar-new {
  opacity: clamp(0, calc(1 - var(--bar) / 0.5), 1);
}
.is-pinned .care-complete .care-bar-done {
  opacity: clamp(0, calc((var(--bar) - 0.5) / 0.5), 1);
}
.is-pinned .care-saved-message {
  z-index: 4;
}
.is-pinned .care-contact {
  z-index: 2;
}
.is-pinned .care-day-other,
.is-pinned .care-day-totals {
  z-index: 2;
}
.is-pinned .care-day-heading,
.is-pinned .care-day-chips {
  z-index: 5;
}

/* ---------- Reading mode (reduced motion, user choice, a layout that cannot pin, no JS) ----------
   One coherent screen per chapter: chapter 1 is Tommy's page (the search led there), chapter 2 is the day sheet with
   today's record in it. The beats stack as a list with hairline rules between them. */
.scroll-chapter:not(.is-pinned) .fluid-layout {
  padding: 0;
}
.scroll-chapter:not(.is-pinned) .care-copy,
.scroll-chapter:not(.is-pinned) .recognition-copy {
  padding: var(--sp-6) 0;
}
.scroll-chapter:not(.is-pinned) .care-copy:first-child,
.scroll-chapter:not(.is-pinned) .recognition-copy:first-child {
  padding-top: 0;
}
.scroll-chapter:not(.is-pinned) .care-copy + .care-copy,
.scroll-chapter:not(.is-pinned) .recognition-copy + .recognition-copy {
  border-top: 1px solid var(--border);
}
.scroll-chapter:not(.is-pinned) .care-copy h3,
.scroll-chapter:not(.is-pinned) .recognition-copy h3 {
  font-size: var(--fs-title);
  line-height: var(--lh-title);
  letter-spacing: var(--track-title);
}
.scroll-chapter:not(.is-pinned) .care-copy > p,
.scroll-chapter:not(.is-pinned) .recognition-copy > p {
  margin-top: var(--sp-4);
}
.scroll-chapter:not(.is-pinned) .device {
  --device-h: auto;
  width: min(100%, 360px);
  height: auto;
  margin: 0 auto;
}
.scroll-chapter:not(.is-pinned) .device-screen {
  height: auto;
}
@media (min-width: 900px) {
  .scroll-chapter:not(.is-pinned) .fluid-layout > .device {
    position: sticky;
    top: calc(var(--nav-height) + var(--sp-5));
  }
}
.scroll-chapter:not(.is-pinned) .care-canvas,
.scroll-chapter:not(.is-pinned) .recognition-canvas {
  padding: 18px var(--canvas-pad) 22px;
}
/* Chapter 1 reads as Tommy's page (the pinned chapter's end state): the lookup steps aside, the row is the page header
   and the owner line sits under it. */
.fluid-patient:not(.is-pinned) .recognition-canvas {
  display: flex;
  flex-direction: column;
}
.fluid-patient:not(.is-pinned) .recognition-patient {
  order: -2;
}
.fluid-patient:not(.is-pinned) .recognition-owner {
  order: -1;
  margin-top: 12px;
}
.scroll-chapter:not(.is-pinned) .recognition-heading,
.scroll-chapter:not(.is-pinned) .recognition-query,
.scroll-chapter:not(.is-pinned) .recognition-milo,
.scroll-chapter:not(.is-pinned) .recognition-keypad,
.scroll-chapter:not(.is-pinned) .recognition-row-arrow {
  display: none;
}
.scroll-chapter:not(.is-pinned) .recognition-patient {
  margin-top: 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
}
.scroll-chapter:not(.is-pinned) .recognition-patient .care-avatar {
  width: 48px;
  height: 48px;
  font-size: 20px;
}
.scroll-chapter:not(.is-pinned) .recognition-weight {
  opacity: 1;
}
.scroll-chapter:not(.is-pinned) .recognition-visits-label {
  margin-top: 18px;
}
.scroll-chapter:not(.is-pinned) .recognition-history {
  margin-top: 8px;
}
.scroll-chapter:not(.is-pinned) .recognition-vaccinations-label {
  margin-top: 18px;
}
.scroll-chapter:not(.is-pinned) .recognition-vaccine {
  margin-top: 8px;
}
.scroll-chapter:not(.is-pinned) .recognition-record {
  margin-top: 18px;
}
/* Chapter 2 reads as the day sheet: Tommy done, today's record with its follow-up, Milo waiting, the day's summary. */
.fluid-care:not(.is-pinned) .care-owner,
.fluid-care:not(.is-pinned) .care-previous,
.fluid-care:not(.is-pinned) .care-vaccine,
.fluid-care:not(.is-pinned) .care-followup,
.fluid-care:not(.is-pinned) .care-contact,
.fluid-care:not(.is-pinned) .care-record,
.fluid-care:not(.is-pinned) .care-complete,
.fluid-care:not(.is-pinned) .care-saved-message,
.fluid-care:not(.is-pinned) .care-entry-draft,
.fluid-care:not(.is-pinned) .care-patient-weight,
.fluid-care:not(.is-pinned) .care-patient-sub > span:first-child,
.fluid-care:not(.is-pinned) .care-note-field::before {
  display: none;
}
.scroll-chapter:not(.is-pinned) .care-patient-status,
.scroll-chapter:not(.is-pinned) .care-patient-time,
.scroll-chapter:not(.is-pinned) .care-entry-status,
.scroll-chapter:not(.is-pinned) .care-entry-followup,
.scroll-chapter:not(.is-pinned) .care-entry .care-clinician {
  opacity: 1;
}
.scroll-chapter:not(.is-pinned) .care-day-chips {
  margin-top: 12px;
}
.scroll-chapter:not(.is-pinned) .care-patient {
  margin-top: 14px;
}
.scroll-chapter:not(.is-pinned) .care-entry {
  margin-top: 6px;
}
.scroll-chapter:not(.is-pinned) .care-day-other,
.scroll-chapter:not(.is-pinned) .care-day-totals {
  margin-top: 12px;
}
/* Reading mode flows naturally (no engine measures it), so a row's subtitle wraps instead of truncating on a 320 px
   phone ("Arrived 09:15 · Skin r…"). */
.scroll-chapter:not(.is-pinned) .care-patient > div > .care-patient-sub,
.scroll-chapter:not(.is-pinned) .care-patient-sub > span,
.scroll-chapter:not(.is-pinned) .care-day-other > div > span {
  white-space: normal;
}
/* Reading mode has no engine: the tab bar's pill sits on the tab the markup names. */
.scroll-chapter:not(.is-pinned) .mock-tabs[data-tab='today'] .mock-tab-pill {
  --tab: 1;
}

/* ---------- Short landscape screens (laptops, landscape tablets): a wider phone that keeps its status strip and tab
   bar, with slimmer chrome ---------- */
@media (min-width: 900px) and (max-height: 760px) {
  .chapter-stage .device {
    --device-h: clamp(520px, calc(var(--stage-h) - 68px), 780px);
    --device-pad: 7px;
    --status-h: 32px;
    --bar-h: 44px;
    --tabs-h: 52px;
    width: 380px;
    border-radius: 40px;
  }
  .chapter-stage .device-screen {
    border-radius: 33px;
  }
  .chapter-stage .mock-status {
    padding-bottom: 5px;
  }
  .chapter-stage .device-notch {
    top: 8px;
    width: 84px;
    height: 22px;
  }
}

/* ---------- Stacked layouts: tablet 601-899 px, and portrait 900-1100 px ---------- */
@media (max-width: 899.98px) {
  /* minmax(0, 1fr), not 1fr: a 1fr column grows to its widest min-content (the reading-mode day sheet's Milo row is
     287 px), which at 320 px pushed the column to 327 px and the copy past the viewport edge (clipped by overflow-x). */
  .fluid-layout {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: var(--sp-6);
  }
  .care-copy-track,
  .recognition-copy-track {
    width: 100%;
    max-width: 640px;
  }
  .care-copy,
  .recognition-copy {
    text-align: center;
  }
  .care-copy > p,
  .recognition-copy > p {
    margin-left: auto;
    margin-right: auto;
  }
  .chapter-track {
    left: 50%;
    transform: translateX(-50%);
  }
  .is-pinned .fluid-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-5);
  }
  .scroll-chapter.is-pinned {
    --track-h: 220px;
  }
  .is-pinned .care-copy-track,
  .is-pinned .recognition-copy-track {
    flex: none;
  }
  .is-pinned .care-copy > p,
  .is-pinned .recognition-copy > p {
    margin-top: var(--sp-4);
  }
  .chapter-stage .device {
    --device-h: clamp(520px, calc(var(--stage-h) - 316px), 780px);
  }
}
@media (min-width: 900px) and (max-width: 1100px) and (orientation: portrait) {
  .fluid-layout {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
  }
  .care-copy-track,
  .recognition-copy-track {
    width: 100%;
    max-width: 640px;
  }
  .care-copy,
  .recognition-copy {
    text-align: center;
  }
  .care-copy > p,
  .recognition-copy > p {
    margin-left: auto;
    margin-right: auto;
  }
  .chapter-track {
    left: 50%;
    transform: translateX(-50%);
  }
  .is-pinned .fluid-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-5);
  }
  .scroll-chapter.is-pinned {
    --track-h: 220px;
  }
  .is-pinned .care-copy-track,
  .is-pinned .recognition-copy-track {
    flex: none;
  }
  .is-pinned .care-copy > p,
  .is-pinned .recognition-copy > p {
    margin-top: var(--sp-4);
  }
  .chapter-stage .device {
    --device-h: clamp(520px, calc(var(--stage-h) - 316px), 780px);
  }
}

/* ---------- Phones (320-600 px): 56 px header, 128 px copy track, the frame from the remainder ---------- */
@media (max-width: 600px) {
  .chapter-stage {
    padding: var(--sp-6) var(--gutter);
  }
  /* 8 px, not 4: the stage starts at the header's edge, and the toggle's 5 px focus ring must clear it. */
  .motion-toggle {
    top: 8px;
    right: 8px;
  }
  .scroll-chapter:not(.is-pinned) .care-copy h3,
  .scroll-chapter:not(.is-pinned) .recognition-copy h3 {
    font-size: var(--fs-title);
  }
  .is-pinned .chapter-stage {
    padding-top: 8px;
    padding-bottom: 10px;
  }
  .is-pinned .fluid-layout {
    gap: 12px;
  }
  .scroll-chapter.is-pinned {
    --track-h: 128px;
  }
  .is-pinned .care-copy-track,
  .is-pinned .recognition-copy-track {
    --track-bleed: 12px;
  }
  .is-pinned .care-copy,
  .is-pinned .recognition-copy {
    --copy-inset: 10px;
  }
  /* The headline keeps clear of the 44 px toggle at the stage's top-right; each clause takes its own line. */
  .is-pinned .care-copy h3,
  .is-pinned .recognition-copy h3 {
    padding-inline: clamp(36px, 12vw, 48px);
    font-size: 29px;
    line-height: 1.06;
    letter-spacing: -0.025em;
  }
  .is-pinned .care-copy > p,
  .is-pinned .recognition-copy > p {
    max-width: 24em;
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.45;
  }

  .device {
    --canvas-pad: 14px;
  }
  .chapter-stage .device {
    --device-h: clamp(380px, calc(100svh - 86px - var(--track-h, 128px)), 480px);
    --device-pad: 6px;
    width: min(100%, 360px);
    border-radius: 32px;
  }
  .chapter-stage .device-screen {
    border-radius: 26px;
  }
  .chapter-stage .mock-status,
  .chapter-stage .device-notch,
  .is-pinned .mock-tabs {
    display: none;
  }
  .scroll-chapter:not(.is-pinned) .device {
    width: 100%;
  }
  .care-product-bar {
    --bar-h: 44px;
  }
  .care-object {
    padding: 11px 14px;
  }
  .care-text {
    font-size: 14px;
    line-height: 1.4;
  }
  .care-object-title {
    font-size: 16px;
  }
  .care-patient {
    min-height: 52px;
    padding: 2px 0;
  }
  .care-patient .care-avatar {
    width: 44px;
    height: 44px;
    font-size: 19px;
  }
  .care-patient > div > strong {
    font-size: 19px;
  }
  .recognition-heading {
    font-size: 22px;
  }
  .recognition-search {
    height: 46px;
  }
  .recognition-patient,
  .recognition-milo,
  .care-day-other {
    --row-pad-x: 12px;
    padding: 9px var(--row-pad-x);
  }
  .care-followup {
    gap: 12px;
  }
  /* Milo's day-sheet row: tighter gaps and chip so "Arrived 09:30 · Check-up" fits whole from 360 px (it was cut to
     "Check-…" at 360); under 353 px the visit reason steps aside rather than truncate. */
  .is-pinned .care-day-other {
    gap: 10px;
  }
  .is-pinned .care-waiting {
    padding-inline: 6px;
  }
  .care-date-tile {
    width: 44px;
    height: 48px;
  }
  .care-date-tile strong {
    font-size: 20px;
  }
  .care-followup > div > strong {
    font-size: 16px;
  }
  .care-complete,
  .care-record {
    height: 44px;
  }
  .care-contact > span {
    height: 42px;
    padding: 0 12px;
    font-size: 13px;
  }
  /* A phone's record shows the clinician line only; the follow-up date is on the tile beside it. */
  .care-entry-followup {
    display: none;
  }
  /* A 560 px stage (short phones in Safari with its bars) keeps the sentence but tightens every slot. */
  .scroll-chapter.is-pinned[data-density='compact'] {
    --track-h: 104px;
  }
  .is-pinned[data-density='compact'] .care-copy h3,
  .is-pinned[data-density='compact'] .recognition-copy h3 {
    font-size: 25px;
  }
  .is-pinned[data-density='compact'] .care-copy > p,
  .is-pinned[data-density='compact'] .recognition-copy > p {
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.4;
  }
  .is-pinned[data-density='compact'] .device {
    --device-h: clamp(350px, calc(100svh - 86px - var(--track-h, 104px)), 420px);
  }
}

/* The narrowest phones (under 353 px): Milo's visit reason steps aside so the row never truncates. */
@media (max-width: 352.98px) {
  .is-pinned .care-day-other .care-reason {
    display: none;
  }
}
