
  :root { --fluorescent: #e4ff1a; --hl: color-mix(in srgb, var(--color-accent) 18%, transparent); }
  html { font-size: 16px; }
  html[data-font-size="xs"] { font-size: 14px; }
  html[data-font-size="sm"] { font-size: 15px; }
  html[data-font-size="lg"] { font-size: 17.5px; }
  html[data-font-size="xl"] { font-size: 19px; }

  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, ol, dl, dd, fieldset, legend { margin: 0; padding: 0; }
  fieldset { border: 0; min-width: 0; }
  body {
    background: var(--color-bg); color: var(--color-text);
    font-family: var(--font-body); line-height: 1.5;
  }
  a { color: var(--color-accent); text-decoration: none; }
  a:hover { color: var(--color-accent-hover); text-decoration: underline; }
  button, select, input, textarea { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
  [hidden] { display: none !important; }

  /* ---------- shell: header / workbench / status bar fill the viewport ---------- */
  .clinic-shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100dvh; min-height: 36rem; }

  .bar {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.55rem 1rem; border-bottom: 3px double var(--color-text);
    background: var(--color-bg); position: relative; z-index: 5;
  }
  .wordmark { font: 400 1.6rem/1 var(--font-heading); color: var(--color-text); white-space: nowrap; }
  .wordmark:hover { text-decoration: none; color: var(--color-text); }
  .wordmark sup { font-size: 0.4em; vertical-align: 1.2em; margin-left: 0.1em; }
  .purpose { font: italic 0.95rem var(--font-heading); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .bar-right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
  .reg { font: 0.75rem var(--font-mono); color: var(--color-text-muted); margin-right: 0.5rem; white-space: nowrap; }
  .tool {
    display: inline-flex; align-items: center; gap: 0.4rem; min-height: 2.25rem;
    padding: 0 0.75rem; cursor: pointer; white-space: nowrap;
    font-size: 0.8125rem; font-weight: 600;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius, 0);
  }
  .tool:hover, .tool[aria-expanded="true"] { border-color: var(--color-accent); color: var(--color-accent); }
  .tool svg { width: 1rem; height: 1rem; }

  /* ---------- comfort panel (Loomwork reader controls, in clinic voice) ---------- */
  .comfort {
    position: absolute; top: calc(100% + 0.4rem); right: 1rem; width: 17rem; max-width: calc(100vw - 2rem);
    background: var(--color-surface); border: 1px solid var(--color-text); padding: 0.9rem;
    display: grid; gap: 0.9rem; box-shadow: 0 8px 24px color-mix(in srgb, var(--color-text) 18%, transparent);
  }
  .comfort h3, .lbl {
    font: 600 0.6875rem var(--font-body); letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-text-muted);
  }
  .comfort .grp { display: grid; gap: 0.35rem; }
  .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--color-border); }
  .seg button, .seg label {
    min-height: 2.25rem; padding: 0.3rem 0.5rem; text-align: center; cursor: pointer;
    background: transparent; border: 0; font-size: 0.8125rem; display: grid; place-items: center;
  }
  .seg > * + * { border-left: 1px solid var(--color-border); }
  .seg [aria-pressed="true"] { background: var(--color-accent); color: var(--color-bg); font-weight: 600; }
  .size { display: flex; align-items: center; gap: 0.6rem; }
  .size input { flex: 1; accent-color: var(--color-accent); }
  .size span:first-child { font-size: 0.75rem; font-weight: 700; }
  .size span:last-child { font-size: 1.15rem; font-weight: 700; }
  .comfort select { width: 100%; min-height: 2.25rem; padding: 0 0.5rem; background: var(--color-bg); border: 1px solid var(--color-border); }
  .comfort .reset { justify-self: start; background: none; border: 0; padding: 0; cursor: pointer; color: var(--color-accent); font-size: 0.8125rem; }

  /* ---------- workbench ---------- */
  .work { display: grid; grid-template-columns: minmax(0, 1fr) minmax(21rem, 30rem); min-height: 0; }
  .work.is-report { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
  .specimen { border-right: 1px solid var(--color-text); }
  .pane-head {
    display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap;
    padding: 0.55rem 1rem; border-bottom: 1px solid var(--color-border);
  }
  .pane-head h2, legend, .rep-sec {
    font: 600 0.6875rem var(--font-body); letter-spacing: 0.14em; text-transform: uppercase;
  }
  .stats { font: 0.75rem var(--font-mono); color: var(--color-text-muted); }
  .pane-actions { margin-left: auto; display: flex; gap: 1rem; }
  .link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--color-accent); font-size: 0.8125rem; }
  .link:hover { text-decoration: underline; }

  .editor, .listing { flex: 1; min-height: 0; background: var(--color-code-bg); font: 0.8125rem/1.6 var(--font-mono); }
  .editor { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .clinic-code { color: var(--color-text); }
  .gutter {
    margin: 0; padding: 0.7rem 0.75rem 0.7rem 1rem; text-align: right; overflow: hidden;
    color: var(--color-text-muted); user-select: none; font: inherit; border-right: 1px solid var(--color-border);
  }
  .editor textarea {
    display: block; width: 100%; height: 100%; resize: none; border: 0; outline: 0;
    padding: 0.7rem 1rem; background: transparent; color: var(--color-text);
    font: inherit; white-space: pre; overflow: auto; tab-size: 4;
  }
  .editor:focus-within { box-shadow: inset 0 0 0 2px var(--color-accent); }
  .listing { overflow: auto; padding: 0.7rem 0; color: var(--color-text); }
  .listing div { display: flex; white-space: pre; padding-right: 1rem; }
  .listing div.on { background: var(--hl); box-shadow: inset 3px 0 0 var(--color-accent); }
  .listing i { flex: 0 0 3.6em; text-align: right; padding-right: 1em; font-style: normal; color: var(--color-text-muted); user-select: none; }

  /* ---------- orders ---------- */
  .side { overflow: auto; background: var(--color-bg); }
  #orders { display: grid; gap: 1rem; padding: 0.9rem 1rem 1rem; align-content: start; min-height: 100%; }
  legend { display: flex; align-items: baseline; gap: 0.5rem; width: 100%; padding-bottom: 0.4rem; }
  legend b { font: 400 0.75rem var(--font-mono); color: var(--color-text-muted); letter-spacing: 0; }
  .count { margin-left: auto; font: 0.75rem var(--font-mono); letter-spacing: 0; text-transform: none; color: var(--color-text-muted); }
  .att-list { border: 1px solid var(--color-text); background: var(--color-surface); }
  .att {
    display: grid; grid-template-columns: auto auto minmax(0, 1fr); align-items: center; gap: 0.6rem;
    min-height: 2.5rem; padding: 0.3rem 0.75rem; cursor: pointer;
  }
  .att + .att { border-top: 1px solid var(--color-border); }
  .att input { width: 1rem; height: 1rem; accent-color: var(--color-accent); margin: 0; }
  .att-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
  .att-spec { font-size: 0.78rem; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
  .att:hover { background: var(--color-bg-alt); }
  .att:has(input:checked) { background: var(--color-accent-light); box-shadow: inset 3px 0 0 var(--color-accent); }
  .att:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
  .inst { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--color-text); background: var(--color-surface); }
  .inst label { display: grid; gap: 0.1rem; padding: 0.5rem 0.75rem; cursor: pointer; min-height: 3rem; align-content: center; }
  .inst label + label { border-left: 1px solid var(--color-border); }
  .inst input { position: absolute; opacity: 0; }
  .inst strong { font-size: 0.9rem; }
  .inst span { font-size: 0.78rem; color: var(--color-text-muted); }
  .inst label:has(input:checked) { background: var(--color-accent-light); box-shadow: inset 0 -3px 0 var(--color-accent); }
  .inst label:has(input:focus-visible) { outline: 2px solid var(--color-accent); outline-offset: -2px; }

  .go { display: grid; gap: 0.5rem; margin-top: auto; }
  .btn {
    min-height: 3rem; padding: 0 1.25rem; cursor: pointer; border-radius: var(--radius, 0);
    font: 600 0.8125rem var(--font-body); letter-spacing: 0.14em; text-transform: uppercase;
    background: var(--color-accent); color: var(--color-bg); border: 1px solid var(--color-accent);
    display: inline-flex; align-items: center; justify-content: center; gap: 0.75rem;
  }
  .btn:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
  .btn kbd { font: 0.7rem var(--font-mono); letter-spacing: 0; text-transform: none; opacity: 0.8; border: 1px solid currentColor; padding: 0.05rem 0.35rem; }
  .btn.plain { background: transparent; color: var(--color-text); border-color: var(--color-text); min-height: 2.5rem; }
  .btn.plain:hover { background: var(--color-accent-light); }
  .fine { font-size: 0.78rem; color: var(--color-text-muted); }

  /* ---------- report ---------- */
  #report { display: flex; flex-direction: column; min-height: 100%; }
  .rep-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 0.55rem 1rem; border-bottom: 1px solid var(--color-border); }
  .rep-head h2 { font: 600 0.6875rem var(--font-body); letter-spacing: 0.14em; text-transform: uppercase; }
  .rep-head span { font: 0.75rem var(--font-mono); color: var(--color-text-muted); }
  .meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--color-text); background: var(--color-surface); }
  .meta div { padding: 0.4rem 1rem 0.5rem; border-right: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border); margin: 0 -1px -1px 0; }
  .meta dt { font: 0.625rem var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-text-muted); }
  .meta dd { font: 0.8125rem var(--font-mono); overflow-wrap: anywhere; }
  .tabs { display: flex; border-bottom: 1px solid var(--color-border); overflow-x: auto; }
  .tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 0.55rem 1rem; cursor: pointer; font-size: 0.85rem; white-space: nowrap; }
  .tabs button[aria-selected="true"] { border-bottom-color: var(--color-accent); font-weight: 600; }
  .findings { padding: 1rem 1.25rem; font-size: 0.95rem; line-height: 1.6; flex: 1; max-width: 46rem; }
  .findings ol { padding-left: 1.3rem; }
  .findings li, .findings p { margin-bottom: 0.7rem; }
  .rep-sec { margin: 1.2rem 0 0.35rem; }
  .findings code { font: 0.8125rem var(--font-mono); background: var(--color-bg-alt); padding: 0 0.3em; border: 1px solid var(--color-border); }
  .ref { color: var(--color-accent); background: none; border: 0; border-bottom: 1px dotted var(--color-accent); cursor: pointer; padding: 0; }
  .ref:hover, .ref:focus-visible { background: var(--hl); }
  .progress { display: flex; align-items: center; gap: 0.75rem; color: var(--color-text-muted); font: 0.8125rem var(--font-mono); }
  .progress::before { content: ""; width: 5rem; height: 2px; background: linear-gradient(90deg, var(--color-accent) 40%, var(--color-border) 40%); background-size: 200% 100%; animation: scan 1.1s linear infinite; }
  @keyframes scan { from { background-position: 100% 0; } to { background-position: -100% 0; } }
  .disclaimer { padding: 0 1.25rem 0.9rem; font: italic 0.8125rem var(--font-heading); color: var(--color-text-muted); }
  .rep-actions { position: sticky; bottom: 0; display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0.6rem 1rem; background: var(--color-bg); border-top: 1px solid var(--color-text); }

  /* ---------- status bar ---------- */
  .status { display: flex; align-items: center; gap: 1.25rem; padding: 0.45rem 1rem; border-top: 3px double var(--color-text); font-size: 0.75rem; color: var(--color-text-muted); }
  .note { display: flex; gap: 0.75rem; min-width: 0; font-family: var(--font-mono); color: var(--color-text); }
  .note b { font: 600 0.625rem var(--font-body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-text-muted); white-space: nowrap; padding-top: 0.15em; }
  .note span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .links { margin-left: auto; display: flex; gap: 1rem; white-space: nowrap; flex-shrink: 0; }

  /* ---------- below the fold: where people look ---------- */
  .below { display: grid; place-items: center; height: 8rem; }
  .shoes { width: 64px; color: var(--color-border); opacity: 0.8; transition: color 0.6s, filter 0.6s; }
  .shoes .fill { fill: none; transition: fill 0.6s; }
  body { transition: background 0.6s, color 0.6s; }
  body.uv {
    --color-bg: #12151d; --color-bg-alt: #161a24; --color-surface: #161a24; --color-code-bg: #161a24;
    --color-text: #4d566e; --color-text-muted: #3d4459; --color-border: #262c3d;
    --color-accent: #454d6b; --color-accent-hover: #454d6b; --color-accent-light: #1a1f2c;
  }
  body.uv .shoes { color: var(--fluorescent); opacity: 1; filter: drop-shadow(0 0 6px var(--fluorescent)) drop-shadow(0 0 22px rgba(228, 255, 26, 0.55)); }
  body.uv .shoes .fill { fill: var(--fluorescent); fill-opacity: 0.3; }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

  /* ---------- tablet and phone: one column, page scrolls ---------- */
  @media (max-width: 900px) {
    .clinic-shell { height: auto; min-height: 100dvh; }
    .work, .work.is-report { grid-template-columns: minmax(0, 1fr); }
    .specimen { border-right: 0; border-bottom: 1px solid var(--color-text); }
    .editor { height: 42dvh; min-height: 14rem; }
    .side { overflow: visible; }
    .purpose, .reg { display: none; }
    .go { position: sticky; bottom: 0; background: var(--color-bg); padding: 0.6rem 0; border-top: 1px solid var(--color-border); }
    .btn kbd { display: none; }
    /* in a report the specimen stays pinned at the top; findings scroll under it */
    .work.is-report .specimen { position: sticky; top: 0; z-index: 3; background: var(--color-bg); }
    .work.is-report .listing { height: 34dvh; flex: none; }
    .status { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
    .links { margin-left: 0; flex-wrap: wrap; white-space: normal; }
    .note span { white-space: normal; }
    .tool { min-height: 2.75rem; }
    .meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .att { min-height: 2.9rem; }
  }
  @media (min-width: 560px) and (max-width: 900px) {
    .att-list { display: grid; grid-template-columns: 1fr 1fr; }
    .att + .att { border-top: 0; }
    .att { border-bottom: 1px solid var(--color-border); border-right: 1px solid var(--color-border); margin: 0 -1px -1px 0; }
  }
  @media (max-width: 420px) {
    .att { grid-template-columns: auto minmax(0, 1fr); }
    .att-spec { grid-column: 2; text-align: left; margin-top: -0.35rem; }

  }

  /* ---------- print: one clean report ---------- */
  @media print {
    .bar-right, #orders, .rep-actions, .pane-actions, .links, .below, .tabs { display: none !important; }
    .clinic-shell { display: block; height: auto; }
    .work, .work.is-report { display: flex; flex-direction: column; }
    .side { order: 1; overflow: visible; }
    .specimen { order: 2; border: 0; margin-top: 1rem; position: static !important; }
    .listing { overflow: visible; height: auto !important; }
    .ref { border: 0; color: var(--color-text); }
    html { font-size: 12px !important; }
    .status { display: none; }
    .bar { border-bottom-width: 3px; padding: 0 0 0.4rem; }
    .listing { font-size: 0.72rem; line-height: 1.4; }
    .findings { max-width: none; padding: 0.8rem 0; }
    .disclaimer { padding: 0 0 0.5rem; }
    .pane-head, .rep-head { padding-left: 0; padding-right: 0; }
    @page { margin: 0.6in; }
  }

/* Astro islands participate in the fixed workbench grid. */
.workbench-page astro-island { display: contents; }
.leaflet-shell { height: auto; min-height: 100dvh; }
.leaflet { width: min(100% - 2rem, 46rem); margin: 2rem auto; line-height: 1.7; }
.leaflet h1 { font: 2rem var(--font-heading); margin-bottom: 1rem; }
.leaflet h2 { font: 1.25rem var(--font-heading); margin: 1.5rem 0 .5rem; }
.leaflet p, .leaflet ul { margin-bottom: 1rem; }
.leaflet ul { padding-left: 1.5rem; }
.leaflet img { width: 100%; height: auto; margin: 1rem 0; }
.legal-date { color: var(--color-text-muted); font-size: .85rem; }
.archive-bar { text-align: center; padding: .35rem; font-size: .8rem; border-bottom: 1px solid var(--color-border); }
.classic-presentation { font-size: 16px; }
.classic-document { font-size: 16px !important; }
.cm-host { flex: 1; min-height: 0; overflow: hidden; background: var(--color-code-bg); }
.cm-host > div { height: 100%; }
.cm-host .cm-editor { height: 100%; }
.cm-host .cm-focused { outline: 2px solid var(--color-accent); outline-offset: -2px; }
#orders { grid-template-rows: auto auto 1fr; }
.go { align-self: end; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.att-name { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
.notice { padding: .7rem; border-left: 3px solid var(--color-accent); background: var(--color-accent-light); font-size: .85rem; }
#report { height: 100%; min-height: 0; }
.report-scroll { overflow: auto; flex: 1; min-height: 0; }
.report-scroll > .progress, .report-scroll > .notice { margin: 1rem; }
.findings { max-width: none; overflow-wrap: anywhere; }
.findings h1, .findings h2, .findings h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.findings ul { padding-left: 1.3rem; }
.findings pre { overflow: auto; padding: .7rem; background: var(--color-code-bg); }
.findings table { border-collapse: collapse; width: 100%; }
.findings th, .findings td { border: 1px solid var(--color-border); padding: .3rem; }
.findings.inactive, .print-attending { display: none; }
.rep-actions { flex: none; position: static; }
.listing div span { white-space: pre; }
#shoes-link { display: block; line-height: 0; cursor: default; }
.uv #shoes-link { cursor: pointer; }
@media (min-width: 900px) { .workbench-page .clinic-shell { min-height: 0; } }
@media (max-width: 899px) {
  .bar { gap: .5rem; padding-inline: .75rem; }
  .tool { padding-inline: .6rem; }
  .workbench-page .editor { flex: none; }
  .work.is-report .listing { max-height: 34dvh; }
  .work.is-report .specimen { max-height: 44dvh; }
  #report { height: auto; }
  .report-scroll { overflow: visible; }
  .rep-actions { position: sticky; bottom: 0; z-index: 4; }
  .pane-actions button, .link, .ref, .tabs button { min-height: 44px; }
  .ref { min-height: 0; padding: .4rem .1rem; }
  #orders .go { position: sticky; bottom: 0; z-index: 4; }
}
@media print {
  .workbench-page astro-island, .report-scroll, #report { display: block; height: auto; overflow: visible; }
  .findings.inactive, .print-attending { display: block; }
  .findings h3.print-attending { margin: .5rem 0; }
  .findings { padding: .6rem 0; }
  .findings p, .findings li { margin-bottom: .3rem; }
  .findings h1, .findings h2, .findings h3 { margin-top: .5rem; }
  .listing div { white-space: pre-wrap; break-inside: avoid; }
  .listing div span { white-space: pre-wrap; overflow-wrap: anywhere; }
  .progress, .comfort { display: none !important; }
}
