/* View: the recipient's viewer. Phone first; the viewer screen fills 100dvh without page scroll. */
body.view { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
body.view.scrolling { overflow: auto; height: auto; min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: calc(6px + var(--safe-t)) calc(12px + var(--safe-r)) 6px calc(12px + var(--safe-l));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-back { padding-left: 6px; padding-right: 10px; flex: none; }
.topbar-title { flex: 1; min-width: 0; }
.top-kicker:empty { display: none; }
.top-kicker { font-size: 0.75rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trust-badge {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 36px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent);
  background: var(--ok-soft); color: var(--ok);
  font: inherit; font-size: 0.8125rem; font-weight: 600; cursor: pointer;
}
.trust-badge .icon { width: 16px; height: 16px; }
@media (pointer: coarse) { .trust-badge { min-height: 44px; min-width: 44px; justify-content: center; } }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; }
.center-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px calc(var(--gutter) + var(--safe-r)) calc(24px + var(--safe-b)) calc(var(--gutter) + var(--safe-l));
  overflow: auto;
}
.center-card { width: 100%; max-width: 420px; padding: 28px 24px; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.center-card .center-title { font-size: 1.25rem; margin: 0; }
.center-card p { margin: 0; }
.big-icon { width: 44px; height: 44px; margin: 0 auto; color: var(--text-3); }
.wide { width: 100%; }
.center-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.form-msg { min-height: 1.5em; color: var(--danger); font-size: 0.9rem; }
.paste-form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.error-foot { margin-top: 6px !important; }
#input-passcode { text-align: center; font-size: 1.25rem; letter-spacing: 0.15em; }

.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Overview */
.overview { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.overview-inner {
  max-width: 880px; margin: 0 auto;
  padding: 20px calc(var(--gutter) + var(--safe-r)) calc(28px + var(--safe-b)) calc(var(--gutter) + var(--safe-l));
}
.ov-shared { color: var(--text-2); margin: 0 0 4px; font-size: 0.9375rem; }
.ov-patient { font-size: 1.5rem; margin: 0 0 2px; }
.overview-head { margin-bottom: 16px; }
.study-list { display: grid; gap: 14px; }
@media (min-width: 760px) { .study-list { grid-template-columns: 1fr 1fr; } }
.study-card { display: flex; flex-direction: column; overflow: hidden; }
.study-open {
  display: grid; grid-template-columns: 112px 1fr; gap: 14px; align-items: center;
  padding: 14px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; width: 100%;
}
.study-open:hover { background: var(--surface-2); }
.study-thumb { width: 112px; height: 112px; border-radius: var(--radius-sm); }
/* Thumbnail tiles: neutral until an image is drawn; the bar and byte count over it while it loads. */
.thumb-tile { position: relative; display: inline-flex; flex: none; align-self: center; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.thumb-tile.has-image { background: #000; }
.thumb-tile canvas { display: block; }
.thumb-over { position: absolute; inset: auto 0 0 0; display: flex; flex-direction: column; gap: 3px; padding: 4px 5px 5px; font-size: 0.6875rem; line-height: 1.2; color: var(--text-2); text-align: center; }
.thumb-tile.has-image .thumb-over { background: rgba(0, 0, 0, 0.6); color: #fff; }
.thumb-over.thumb-error { inset: 0; justify-content: center; color: var(--text-2); }
.thumb-label { overflow-wrap: anywhere; }
.thumb-bar { display: block; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.thumb-fill { display: block; height: 100%; width: 0; background: var(--accent); }
.study-title { font-weight: 650; font-size: 1.0625rem; margin: 0 0 2px; overflow-wrap: anywhere; }
.study-sub { color: var(--text-2); font-size: 0.875rem; margin: 0; }
.study-tech { color: var(--text-3); font-size: 0.8125rem; margin: 4px 0 0; }
.study-open .open-hint { color: var(--accent); font-weight: 600; font-size: 0.875rem; margin-top: 6px; display: inline-block; }
.report { border-top: 1px solid var(--border); padding: 12px 14px; font-size: 0.9375rem; }
.report h3 { font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); margin: 0 0 4px; }
.report p { margin: 0; white-space: pre-wrap; }
.report details summary { cursor: pointer; color: var(--accent); font-size: 0.875rem; margin-top: 6px; min-height: 32px; display: flex; align-items: center; }
.study-actions { display: flex; gap: 8px; border-top: 1px solid var(--border); padding: 10px 14px; }
.study-actions .btn { flex: 1; }

/* Viewer: grid areas. Phone portrait: stage / toolbar / strip. */
.viewer {
  display: grid;
  grid-template-columns: 100%;
  grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas: "stage" "toolbar" "strip";
  background: #000;
}
.stage {
  grid-area: stage; position: relative; overflow: hidden; background: #000;
  touch-action: none; user-select: none; -webkit-user-select: none; outline: none; cursor: ns-resize;
}
.stage .vp-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hud {
  position: absolute; z-index: 2; pointer-events: none;
  color: #e6e6e6; font: 12px/1.35 var(--mono); text-shadow: 0 0 3px #000, 0 0 2px #000;
  white-space: pre-line; max-width: calc(50% - 20px); overflow-wrap: anywhere;
}
.hud-tl { top: 8px; left: calc(10px + var(--safe-l)); }
.hud-tr { top: 8px; right: calc(10px + var(--safe-r)); text-align: right; }
.hud-bl { bottom: 8px; left: calc(10px + var(--safe-l)); }
/* What the stage is waiting for: words, and a bar when the amount is known (bytes, slices). */
.stage-busy { position: absolute; right: 12px; bottom: 12px; z-index: 3; pointer-events: none; display: flex; flex-direction: column; gap: 4px; min-width: 150px; max-width: 60%; padding: 6px 10px; border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.75rem; }
.stage-track { display: block; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.stage-fill { display: block; height: 100%; width: 0; background: #fff; }
.stage-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3;
  max-width: min(90%, 360px); padding: 12px 16px; border-radius: var(--radius-sm);
  background: rgba(20, 20, 20, 0.85); color: #fff; font-size: 0.9rem; text-align: center;
}

.toolbar {
  grid-area: toolbar; display: flex; align-items: center; gap: 12px;
  padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  background: var(--surface); border-top: 1px solid var(--border);
}
.slice-ctl { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.slice-ctl input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); height: 32px; }
.slice-label { font-size: 0.8125rem; color: var(--text-2); min-width: 5.5ch; text-align: right; }
.tool-btns { display: flex; gap: 8px; flex: none; }
/* Narrow screens: the slider gets its own row; the tools scroll sideways if they still do not fit. */
@media (max-width: 600px) {
  .toolbar { flex-wrap: wrap; row-gap: 6px; }
  .slice-ctl { flex-basis: 100%; }
  .tool-btns { flex: 1 1 100%; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
  .tool-btns > * { flex: none; max-width: 100%; }
}
.preset { width: auto; min-height: 40px; padding: 4px 8px; }
.toolbar .btn { min-height: 40px; padding: 6px 12px; }
@media (pointer: coarse) {
  .toolbar .btn, .preset { min-height: 44px; }
  .slice-ctl input[type="range"] { height: 44px; }
  .slice-ctl input[type="range"]::-webkit-slider-thumb { width: 30px; height: 30px; }
}

.strip {
  grid-area: strip; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden;
  padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  background: var(--surface); border-top: 1px solid var(--border);
  scrollbar-width: thin; overscroll-behavior: contain;
}
.series-btn {
  flex: none; display: flex; flex-direction: column; align-items: stretch; gap: 4px;
  width: 92px; padding: 4px; border-radius: var(--radius-sm);
  border: 2px solid transparent; background: none; color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.series-btn canvas { width: 80px; height: 80px; }
.series-btn .s-name { font-size: 0.75rem; font-weight: 600; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.series-btn .s-count { font-size: 0.6875rem; color: var(--text-3); }
.series-btn[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* Desktop and wide screens: series down the side. */
@media (min-width: 900px) {
  .viewer {
    grid-template-columns: 220px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "strip stage" "strip toolbar";
  }
  .strip { flex-direction: column; overflow-x: hidden; overflow-y: auto; border-top: 0; border-right: 1px solid var(--border); padding: 10px; }
  .series-btn { width: 100%; flex-direction: row; align-items: center; gap: 10px; padding: 6px; }
  .series-btn canvas { width: 64px; height: 64px; flex: none; }
  .series-btn .s-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .series-btn .s-name { font-size: 0.8125rem; }
  .hud { font-size: 13px; }
}
/* Phone landscape: image fills the height; series beside it; compact toolbar. */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { min-height: 48px; padding-top: calc(2px + var(--safe-t)); padding-bottom: 2px; }
  .viewer {
    grid-template-columns: minmax(0, 1fr) 112px;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "stage strip" "toolbar strip";
  }
  .strip { flex-direction: column; overflow-x: hidden; overflow-y: auto; border-top: 0; border-left: 1px solid var(--border); padding: 6px calc(6px + var(--safe-r)) calc(6px + var(--safe-b)) 6px; }
  /* The strip is a narrow column: each series is its thumbnail with the name below. */
  .series-btn { width: 100%; flex-direction: column; align-items: stretch; }
  .series-btn canvas { width: 64px; height: 64px; }
  .series-btn .s-text { width: 100%; }
  .series-btn .s-name, .series-btn .s-count { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .toolbar { padding-top: 2px; padding-bottom: calc(2px + var(--safe-b)); }
  .top-kicker { display: none; }
}
@media (max-width: 420px) {
  .trust-text { display: none; }
  .trust-badge { padding: 4px 10px; }
  .dl-text { display: none; }
  .back-text { display: none; }
}

/* Sheets: bottom sheet on phones, centred dialog on wide screens. */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.45); }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0;
  max-height: 85dvh; overflow-y: auto;
  padding: 10px calc(20px + var(--safe-r)) calc(16px + var(--safe-b)) calc(20px + var(--safe-l));
  background: var(--surface); color: var(--text);
  border-radius: 16px 16px 0 0; box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
}
.sheet h2 { font-size: 1.125rem; margin: 6px 0 6px; }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 8px; }
.sheet-close { width: 100%; margin-top: 8px; }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 480px; border-radius: 16px; }
  .sheet-grip { display: none; }
}
/* Download: the main part saves the default choice; the arrow opens the menu of choices. */
.dl-split { display: flex; align-items: stretch; flex: none; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.dl-split .btn { border-radius: 0; min-height: 44px; }
.dl-main { gap: 6px; padding-right: 8px; }
.dl-more { padding: 0 10px; min-width: 44px; border-left: 1px solid var(--border); }
.dl-size { color: var(--text-3); font-variant-numeric: tabular-nums; }
.dl-option[disabled] { cursor: default; background: var(--surface-2); }
.dl-option[disabled] strong { color: var(--text-3); }
/* Angle and slab sheet. */
.plane-ctl { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px 14px; margin: 12px 0; }
.plane-ctl input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); }
.plane-slab { display: flex; gap: 8px; flex-wrap: wrap; }
#plane-reset { width: 100%; }
.dl-options { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.dl-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  width: 100%; padding: 12px 14px; min-height: 56px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.dl-option:hover { background: var(--surface-2); }
.dl-option strong { font-weight: 650; }
.dl-option span { font-size: 0.8125rem; color: var(--text-3); overflow-wrap: anywhere; }
.dl-progress { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.trust-facts { margin: 8px 0 12px; display: grid; gap: 12px; }
.trust-facts dt { font-weight: 650; }
.trust-facts dd { margin: 2px 0 0; color: var(--text-2); font-size: 0.9375rem; }

/* Whole-slide view (wsi-view.ts): a tile layer over the stage, minimap top right, stats bottom left. */
.wsi { position: absolute; inset: 0; z-index: 1; cursor: grab; touch-action: none; }
.wsi.dragging { cursor: grabbing; }
.wsi-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.wsi-mini {
  position: absolute; top: 8px; right: calc(8px + var(--safe-r)); z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 4px; background: #2a2a2a; cursor: pointer;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); touch-action: none;
}
.wsi-stats {
  position: absolute; left: calc(8px + var(--safe-l)); bottom: 8px; z-index: 2; max-width: calc(100% - 16px);
  padding: 6px 9px; border-radius: 6px; background: rgba(10, 10, 10, 0.72); color: #f0f0f0;
  font: 11.5px/1.45 var(--mono); white-space: pre; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.wsi-stats::first-line { color: #8fd0ff; font-weight: 700; }
.wsi-stats.collapsed { max-height: 1.45em; padding-top: 4px; padding-bottom: 4px; }
.wsi .stage-msg { z-index: 3; }
@media (min-width: 900px) { .wsi-stats { font-size: 12.5px; } }
body.slide-mode .slice-ctl, body.slide-mode #preset { display: none; }
body.slide-mode .toolbar { justify-content: flex-end; }
body.slide-mode .hud-tl { z-index: 3; max-width: 55%; }
.label-images { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0; }
.label-fig { margin: 0; flex: 1 1 160px; display: flex; flex-direction: column; gap: 4px; }
.label-fig canvas { width: 100%; height: auto; max-height: 50dvh; object-fit: contain; background: #000; border-radius: 6px; }

/* Reports (FHIR DiagnosticReport): a panel beside the images on wide screens, full screen on phones. */
.report-panel {
  position: fixed; z-index: 15; inset: 0; display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  padding-top: var(--safe-t);
}
.report-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 52px; padding: 4px calc(12px + var(--safe-r)) 4px calc(16px + var(--safe-l));
  border-bottom: 1px solid var(--border);
}
.report-panel-title { font-weight: 650; }
.report-panel-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
@media (min-width: 1100px) {
  .report-panel { inset: 56px 0 0 auto; width: 440px; border-left: 1px solid var(--border); padding-top: 0; box-shadow: var(--shadow); }
  body.report-open main { margin-right: 440px; }
}
.report-doc + .report-doc { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.report-title { font-size: 1.125rem; margin: 0 0 4px; }
.report-source { color: var(--text-3); font-size: 0.875rem; margin: 0 0 12px; }
.report-guess { color: var(--warn); }
.report-h { font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); margin: 12px 0 4px; }
.report-conclusion { margin: 0 0 12px; white-space: pre-wrap; }
.report-tabs { display: flex; gap: 8px; margin: 8px 0; }
.report-tab[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); }
.report-text { white-space: pre-wrap; overflow-wrap: anywhere; font: 0.8125rem/1.5 var(--mono); margin: 8px 0; }
.pdf-pages { display: flex; flex-direction: column; gap: 12px; margin: 8px 0; }
.pdf-page { display: block; box-shadow: var(--shadow); background: #fff; max-width: 100%; }
.report-dl { margin-top: 4px; }
.report-from { margin: 0 0 4px; }
.report-sum { margin: 0 0 8px; white-space: pre-wrap; }
.report-read { margin-top: 2px; }
.loose-title { font-size: 1rem; margin: 14px 14px 0; }
@media (max-width: 420px) { .rep-text { display: none; } }

/* Non-image objects (object-view.ts), shown in place of the slice viewer. */
.object-view {
  position: absolute; inset: 0; z-index: 4; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); color: var(--text); cursor: auto; touch-action: auto; user-select: text; -webkit-user-select: text;
  padding: 14px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
body.object-mode #toolbar { display: none; }
body.object-mode .hud { visibility: hidden; }
.obj-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.obj-title { font-size: 1.125rem; margin: 0; flex-basis: 100%; }
.obj-sub { margin: 0; flex: 1; min-width: 12em; }
.obj-actions { display: flex; gap: 8px; align-items: center; }
.obj-pick { width: auto; }
.obj-error { color: var(--danger); }
.obj-body h3 { font-size: 1.0625rem; margin: 8px 0 6px; }
.sr-tree { display: flex; flex-direction: column; gap: 2px; }
.sr-container { margin: 4px 0; padding-left: 4px; }
.sr-container > .sr-container, .sr-container > .sr-group, .sr-container > .sr-item { margin-left: 14px; }
.sr-heading { font-weight: 650; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.sr-item { display: grid; grid-template-columns: minmax(8em, 38%) 1fr; gap: 10px; padding: 3px 0; border-bottom: 1px dotted var(--border); }
.sr-name { color: var(--text-2); overflow-wrap: anywhere; }
.sr-value { overflow-wrap: anywhere; }
.sr-children { margin-left: 14px; }
.sr-ref-missing { color: var(--text-3); font-style: italic; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; text-align: left; min-height: 32px; min-width: 32px; }
@media (pointer: coarse) { .linkish { min-height: 44px; min-width: 44px; } }
.cda-section { margin: 12px 0; }
.cda-section h4 { margin: 0 0 4px; }
.cda-text table { border-collapse: collapse; }
.cda-text td, .cda-text th { border: 1px solid var(--border); padding: 4px 6px; }
.wf-group { margin: 6px 0 18px; }
.wf-scroll { overflow-x: auto; max-width: 100%; border: 1px solid var(--border); border-radius: 6px; }
.wf-canvas { display: block; }
.wf-audio { width: 100%; margin: 6px 0; }
.model-holder { position: relative; width: 100%; height: min(70vh, 640px); }
.model-canvas { width: 100%; height: 100%; display: block; border-radius: 8px; touch-action: none; }
.ko-list { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ko-open { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; width: 100%; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.ko-thumb { width: 96px; height: 96px; background: #000; border-radius: 4px; }
.obj-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.obj-facts dt { color: var(--text-3); }
.obj-facts dd { margin: 0; overflow-wrap: anywhere; }

/* Layers over the image (layers.ts). */
.layer-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.stage .vp-canvas, .stage .layer-canvas { transform: var(--ps-transform, none); }
body.object-mode .layer-canvas, body.slide-mode .layer-canvas { display: none; }
.layers-list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.layers-h { font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); margin: 10px 0 2px; }
.layer-row { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.legend { list-style: none; margin: 0 0 6px 30px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.legend-item { display: flex; align-items: center; gap: 8px; min-height: 36px; }
@media (pointer: coarse) { .legend-item { min-height: 44px; } }
.map-legend { margin: 0 0 8px 30px; display: flex; flex-direction: column; gap: 4px; }
.map-scale { width: min(240px, 100%); height: 12px; border-radius: 2px; image-rendering: auto; }
.map-range { font-size: 0.875rem; color: var(--text-3); }
.swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; border: 1px solid var(--border); }
.study-contents { border-top: 1px solid var(--border); padding: 4px 14px 10px; font-size: 0.9375rem; }
.study-contents summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--text-2); }
.contents-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.contents-item { overflow-wrap: anywhere; }
.measure-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.hud-br { bottom: 8px; right: calc(10px + var(--safe-r)); text-align: right; }
body.measuring .stage { cursor: crosshair; }
body.object-mode .measure-canvas, body.slide-mode .measure-canvas { display: none; }
body.slide-mode .measure-tool, body.slide-mode #btn-measure { display: none; }

/* Narrow screens (phones either way up): progressive disclosure. The top bar keeps back, the
   title (two lines) and one More button; the report, downloads and the encryption details are
   in the More sheet. Below the image: Display, Measure and Reset, whose choices open as sheets. */
.btn-more, .compact-only { display: none; }
.toolbar.single .slice-ctl { display: none; }
.toolbar.single { justify-content: flex-end; }
@media (max-width: 600px), (max-height: 500px) {
  #btn-trust, #btn-report, #dl-split { display: none !important; }
  .btn-more:not(.hidden) { display: inline-flex; flex: none; min-width: 44px; padding: 8px 10px; }
  .compact-only:not(.hidden) { display: inline-flex; }
  #preset, #view-plane, #measure-tool, #btn-plane-opts { display: none !important; }
  .topbar { gap: 4px; }
  .top-title { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; line-height: 1.25; }
  .toolbar { flex-wrap: wrap; row-gap: 6px; }
  .tool-btns { flex: 1 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
  /* The video and cine controls (video-view.ts) wrap rather than run off the screen. */
  .toolbar .play-bar { flex-wrap: wrap; row-gap: 4px; max-width: 100%; }
  .tool-btns > * { flex: none; max-width: 100%; }
}
.more-title { overflow-wrap: anywhere; }
.more-items { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.choice-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 4px; }
.choice {
  display: flex; align-items: center; width: 100%; min-height: 44px; padding: 10px 14px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; overflow-wrap: anywhere;
}
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* Window/level on touch screens is a mode: the hint says so and has Done. */
.adjust-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 24px);
  padding: 6px 6px 6px 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.72); color: #fff; font-size: 0.875rem;
}
.adjust-hint .btn { min-height: 36px; padding: 4px 14px; flex: none; }
@media (pointer: coarse) { .adjust-hint .btn { min-height: 44px; } }
.first-hint {
  position: absolute; left: 50%; top: 56px; transform: translateX(-50%); z-index: 4; pointer-events: none;
  max-width: calc(100% - 24px); padding: 6px 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.72); color: #fff; font-size: 0.875rem; text-align: center;
}
#btn-adjust[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
body.slide-mode #btn-adjust, body.slide-mode .adjust-hint { display: none !important; }
.gestures { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 8px 16px; margin: 12px 0; }
.gestures dt { font-weight: 600; overflow-wrap: anywhere; }
.gestures dd { margin: 0; color: var(--text-2); overflow-wrap: anywhere; }
@media (max-width: 600px), (max-height: 500px) { .wide-only { display: none !important; } }
