:root {
  color-scheme: dark;
  --page: #10191e;
  --panel: #19252b;
  --panel-top: #1e2b31;
  --line: #39494f;
  --soft-line: #304046;
  --text: #eef4f2;
  --muted: #bccacb;
  --mint: #9be1c7;
  --mono: "IBM Plex Mono", Consolas, monospace;
  background: var(--page);
  color: var(--text);
  font: 16px/1.5 Inter, "Microsoft JhengHei UI", "PingFang TC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  flex: none; width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.65;
  stroke-linecap: round; stroke-linejoin: round; fill: none; pointer-events: none;
}
.masthead {
  display: flex; align-items: center; gap: 20px; min-height: 72px;
  padding: 12px clamp(16px, 2.5vw, 40px); border-bottom: 1px solid var(--line);
  background: #142027;
}
.brand { display: inline-flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; color: var(--mint); }
.clinic-name { color: #e5eee9; font-size: 1.02rem; font-weight: 650; letter-spacing: .04em; }
.masthead-divider { height: 22px; width: 1px; background: #47575b; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.16rem; font-weight: 580; letter-spacing: .02em; }
#scope { margin-left: auto; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.workspace {
  max-width: 1800px; margin: 0 auto; padding: clamp(16px, 2vw, 32px) clamp(16px, 2.5vw, 40px);
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(245px, 300px); align-items: start; gap: 18px;
}
.viewer, .panel { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.viewer { min-width: 0; overflow: hidden; }
.series-bar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--panel-top); border-bottom: 1px solid var(--soft-line);
}
.series-label, .series-nav, h2, .action, .picker { display: flex; align-items: center; }
.series-label { flex: none; gap: 8px; font-size: .92rem; font-weight: 630; }
.series-label .icon, h2 .icon { color: var(--mint); }
select, input, button, a { font: inherit; }
button { cursor: pointer; }
button, select, a, .picker { -webkit-tap-highlight-color: transparent; }
select {
  min-width: 0; height: 42px; padding: 0 8px; background: #172328; color: var(--text);
  border: 1px solid #526366; border-radius: 6px;
}
#items { flex: 1; width: 100%; text-overflow: ellipsis; }
.series-nav { flex: none; gap: 3px; }
.icon-button, .tool-group button {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; background: transparent; color: var(--text);
  border-radius: 6px;
}
.icon-button { width: 38px; height: 40px; }
.icon-button .icon { width: 16px; height: 16px; }
.readout, #zoomValue, label output, #measureValue { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.readout { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.toolbar { display: flex; align-items: stretch; flex-wrap: wrap; gap: 6px; padding: 7px 10px; background: #202d33; }
.tool-group { display: flex; align-items: stretch; gap: 2px; }
.tool-group + .tool-group { border-left: 1px solid #445257; padding-left: 6px; }
.tool-group button { gap: 6px; min-width: 44px; min-height: 44px; padding: 3px 7px; font-size: .9rem; line-height: 1.25; }
.tool-group button[aria-pressed="true"] { color: #b8f2d8; background: #28473f; border-color: #5c8d7b; }
.tool-group button:disabled, .icon-button:disabled { cursor: default; color: #8a999e; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible,
.picker:focus-within, #stage:focus-visible { outline: 2px solid #b1efda; outline-offset: -3px; }
@media (hover: hover) {
  .tool-group button:enabled:hover, .icon-button:enabled:hover { color: white; background: #334349; }
  .tool-group button[aria-pressed="true"]:hover { background: #325648; }
  .action:hover, .picker:hover { border-color: #9cb1ad; }
  .action.primary:hover { background: #b7f0d9; color: #122e24; }
}
#stage {
  position: relative; isolation: isolate; overflow: hidden; padding: 0; border: 0;
  width: 100%; height: clamp(300px, calc(100svh - 285px), 1200px);
  background: #040607;
}
#stage[data-image-active="true"] { touch-action: none; user-select: none; }
#stage[data-image-active="true"][data-mode="pan"] { cursor: grab; }
#stage[data-image-active="true"][data-mode="pan"]:active { cursor: grabbing; }
#stage[data-image-active="true"][data-mode="length"], #stage[data-image-active="true"][data-mode="angle"] { cursor: crosshair; }
#image { position: absolute; display: block; top: 0; left: 0; margin: 0; max-width: none; max-height: none; transform-origin: 0 0; }
#marks { position: absolute; inset: 0; display: block; width: 100%; height: 100%; pointer-events: none; overflow: hidden; }
#clipVideo { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: contain; background: #040607; }
.image-status, .tool-feedback { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.image-status { min-height: 42px; padding: 8px 16px; background: #152026; border-top: 1px solid var(--soft-line); }
#status { color: #cad7d6; font-size: .9rem; line-height: 1.45; overflow-wrap: anywhere; }
#zoomValue { flex: none; color: var(--mint); font-size: .88rem; }
.tool-feedback { padding: 9px 16px; min-height: 39px; border-top: 1px solid var(--soft-line); font-size: .9rem; }
.tool-feedback:has(#measureHint:empty):has(#measureValue:empty) { display: none; }
#measureHint { color: var(--muted); }
#measureValue { color: var(--mint); white-space: nowrap; }
aside { display: grid; gap: 12px; min-width: 0; }
.panel { padding: 18px; min-width: 0; }
.panel h2 {
  gap: 9px; margin: 0 0 16px; padding-bottom: 12px; border-bottom: 1px solid var(--soft-line);
  color: var(--text); font-size: 1rem; font-weight: 620; letter-spacing: .01em;
}
.panel h2 .icon { width: 19px; height: 19px; }
.panel label { font-size: .94rem; }
.panel select { width: 100%; }
label output { float: right; color: var(--mint); font-size: .9rem; }
input[type="range"] { display: block; width: 100%; margin: 2px 0 12px; height: 29px; accent-color: var(--mint); cursor: pointer; }
.action, .picker {
  justify-content: center; gap: 8px; width: 100%; min-height: 43px;
  padding: 8px 10px; border-radius: 6px; border: 1px solid #516268;
  background: #24333a; color: var(--text); text-decoration: none; cursor: pointer;
  font-size: .94rem; font-weight: 550; line-height: 1.35; text-align: center;
}
.action .icon { width: 17px; height: 17px; }
.action.primary { border-color: var(--mint); background: var(--mint); color: #143429; font-weight: 670; }
.action:disabled { cursor: default; opacity: .63; }
.action + .action, #clipTiming:not(:empty) + .action, #packStatus:not(:empty) + .action { margin-top: 8px; }
.picker { position: relative; }
.picker input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.support, #expiry, .case-footer small { color: var(--muted); font-size: .865rem; line-height: 1.55; }
.support:not(:empty) { margin-top: 10px; }
.case-footer { padding: 2px 4px; }
#expiry:not(:empty) { margin-bottom: 8px; }
:empty:is(#packStatus, #clipTiming, #expiry, #imageCount, #measureHint, #measureValue, #zoomValue) { display: none; }
@media (min-width: 1380px) {
  .tool-group button { gap: 8px; padding-inline: 12px; }
}
@media (min-width: 841px) and (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(240px, 26vw); gap: 12px; }
  .toolbar { gap: 3px; padding-inline: 5px; }
  .tool-group { flex: 1 0 auto; }
  .tool-group + .tool-group { padding-left: 3px; }
  .tool-group button { flex: 1; flex-direction: column; gap: 3px; }
  .series-bar { gap: 7px; padding-inline: 10px; }
  .series-label .icon { display: none; }
}
@media (max-width: 840px) {
  .workspace { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 14px; }
  .masthead { min-height: 57px; gap: 12px; padding: 8px 16px; }
  .brand { gap: 8px; }
  .brand-mark { width: 31px; height: 31px; }
  .clinic-name { font-size: .94rem; }
  h1 { font-size: 1rem; }
  #scope { font-size: .815rem; }
  #stage { height: clamp(200px, 53svh, 640px); }
  aside { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .case-footer { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .workspace { padding: 0 0 20px; gap: 12px; }
  .viewer { border: 0; border-radius: 0; border-bottom: 1px solid var(--line); }
  .masthead { gap: 9px; padding-inline: 12px; }
  .masthead-divider { height: 17px; }
  .series-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 8px; padding: 8px 10px; }
  .series-label { font-size: .875rem; }
  .series-label .icon { width: 16px; height: 16px; }
  #items { grid-row: 2; grid-column: 1 / -1; height: 41px; }
  .series-nav { grid-column: 2; grid-row: 1; gap: 3px; }
  .icon-button { width: 44px; height: 38px; }
  .toolbar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding: 5px; }
  .tool-group { display: contents; }
  .tool-group button { min-width: 0; padding: 5px 2px; min-height: 44px; gap: 4px; }
  .tool-group .icon { width: 17px; height: 17px; }
  #stage { height: clamp(185px, 46svh, 520px); }
  .image-status, .tool-feedback { gap: 8px; padding: 7px 12px; }
  .tool-feedback { align-items: flex-start; flex-wrap: wrap; }
  aside { grid-template-columns: minmax(0,1fr); margin: 0 10px; gap: 10px; }
  .panel { padding: 14px; }
  .panel h2 { margin-bottom: 12px; padding-bottom: 9px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #stage { min-height: 200px; height: 73svh; }
}
