:root {
  color-scheme: light;
  --ink: #183136;
  --muted: #5f7275;
  --line: #dce6e4;
  --surface: #fcfdfb;
  --soft: #edf5f2;
  --accent: #116e60;
  --dark: #102e34;
  font-family: "Inter", "PingFang TC", "Noto Sans TC", -apple-system, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: #f1f6f4;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { opacity: .5; cursor: wait; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid #188e78; outline-offset: 3px; }
button[hidden], [hidden] { display: none !important; }
button, select { background: white; border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; }
button:hover:not(:disabled) { background: var(--soft); }
button[aria-pressed="true"] { background: #d9f0e9; border-color: #9fcfc0; color: #085748; font-weight: 650; }
input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { width: 15px; height: 15px; margin: 0; flex: 0 0 15px; }
h1, h2, p { margin: 0; }
h2 { font-size: 15px; letter-spacing: .025em; }
.topbar { height: 70px; background: #fcfdfb; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 26px; gap: 15px; }
.brand, .top-actions { display: flex; gap: 13px; align-items: center; }
.brand h1 { font-size: 21px; line-height: 1.25; letter-spacing: .04em; font-weight: 700; }
.brand p { margin-top: 4px; color: var(--accent); font: 700 9px ui-monospace, monospace; letter-spacing: .25em; }
.mark { height: 39px; width: 39px; flex: 0 0 39px; position: relative; border-radius: 12px; background: #126b5e; }
.mark::before, .mark::after, .mark span { content: ""; position: absolute; inset: 12px 8px; border: 1px solid #defff3; border-radius: 50%; }
.mark::after { transform: rotate(60deg); }
.mark span { transform: rotate(-60deg); }
.prototype-status, .scene-status { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.prototype-status { color: var(--muted); font-size: 12px; }
.prototype-status i, .collision i { width: 7px; height: 7px; border-radius: 50%; background: #49a98a; flex: 0 0 7px; }
.top-actions #export { background: #126b5e; color: white; border-color: #126b5e; }
.top-actions #export:hover:not(:disabled) { background: #0b564b; }
.workspace { display: grid; grid-template-columns: 262px minmax(300px,1fr) 307px; grid-template-rows: minmax(0, 1fr); min-height: 480px; height: calc(100dvh - 70px); }
.sidebar, .inspector { min-width: 0; background: var(--surface); display: flex; flex-direction: column; }
.sidebar { border-right: 1px solid var(--line); min-height: 0; overflow: hidden; }
.inspector { border-left: 1px solid var(--line); overflow: auto; }
.layer-section, .structure-section, .detail-section, .clip-section, .implant-section, .route-section { padding: 18px; }
.layer-section, .detail-section, .implant-section { border-bottom: 1px solid var(--line); }
.structure-section { min-height: 0; display: flex; flex: 1; flex-direction: column; padding-bottom: 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 26px; margin-bottom: 12px; }
.text-button { border: 0; background: transparent; padding: 4px; color: var(--accent); font-size: 12px; }
.count { font: 600 11px ui-monospace, monospace; color: var(--muted); }
.layers { display: grid; gap: 6px; }
.layer { background: #f6f9f7; padding: 8px 9px; border: 1px solid #e8eeeb; border-radius: 8px; }
.layer label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.layer label span:last-child { flex: 1; }
.layer .layer-opacity { width: 100%; height: 14px; margin: 6px 0 0; }
.layer .opacity-row { padding-left: 38px; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 10px; border: 1px solid #0002; background: var(--swatch); }
.search { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 7px; gap: 8px; padding: 0 10px; background: white; }
.search span { font-size: 23px; line-height: 1; color: var(--accent); }
.search input { width: 100%; min-width: 0; background: transparent; border: 0; padding: 9px 0; color: var(--ink); outline: none; }
.search:focus-within { outline: 2px solid #188e78; }
.visible-filter, .check-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.visible-filter { margin: 10px 0 8px; }
.structure-list { overflow: auto; flex: 1; min-height: 0; padding-bottom: 12px; }
.structure { width: 100%; display: flex; align-items: center; gap: 9px; text-align: left; background: transparent; border-color: transparent; padding: 8px 7px; }
.structure span:nth-child(2) { min-width: 0; flex: 1; }
.structure strong, .structure small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.structure strong { font-size: 13px; font-weight: 600; }
.structure small { color: var(--muted); font-size: 10px; padding-top: 2px; }
.structure .pin-mark { color: var(--accent); font-size: 10px; }
.viewport {
  min-height: 0; min-width: 0; position: relative; isolation: isolate; overflow: hidden; color: #f5fff9;
  background: radial-gradient(ellipse at 50% 48%, #305358 0%, #1b3a42 52%, #10272f 100%);
}
.viewport::before { content: ""; position: absolute; inset: 0; opacity: .23; pointer-events: none; background: linear-gradient(#bad8cc16 1px, transparent 1px),linear-gradient(90deg,#bad8cc16 1px,transparent 1px); background-size: 28px 28px; mask-image: radial-gradient(ellipse,#000 25%,transparent 85%); }
.scene, .scene-labels { position: absolute; inset: 0; }
.scene canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.scene canvas:active { cursor: grabbing; }
.scene-labels {
  --leader-ink: #ffd29a;
  --leader-outline: #45281e;
  --label-ink: #fff7ed;
  --label-selected-bg: #ffd0a2;
  --label-selected-ink: #422517;
  pointer-events: none; overflow: hidden;
}
.viewport-heading { position: absolute; z-index: 1; top: 21px; left: 22px; right: 22px; display: flex; justify-content: space-between; align-items: start; gap: 8px; pointer-events: none; }
.viewport-heading h2 { font-size: 17px; letter-spacing: .08em; }
.viewport-heading p { margin-top: 4px; color: #b6d6cc; font-size: 11px; }
.scene-status { font-size: 11px; border: 1px solid #b8e2d342; background: #0d2a30b5; border-radius: 20px; color: #d2ece3; padding: 6px 9px; }
.side-labels { position: absolute; top: 46%; left: 22px; right: 22px; display: flex; justify-content: space-between; font: 600 14px ui-monospace, monospace; color: #d5ebe3; pointer-events: none; }
.side-labels span { background: #102a32aa; border: 1px solid #99cbb84a; border-radius: 7px; padding: 5px 8px; }
.side-labels small { font: 400 10px system-ui; }
.canvas-controls { position: absolute; bottom: 15px; left: 0; right: 0; text-align: center; pointer-events: none; }
.camera-views { display: inline-flex; gap: 3px; border: 1px solid #a8c9bf45; border-radius: 10px; padding: 4px; background: #102b33d9; pointer-events: auto; }
.camera-views button { background: transparent; color: #e5f3ef; border-color: transparent; }
.camera-views button:hover { color: var(--ink); }
.camera-views button[aria-pressed="true"] { color: #073f35; background: #ccece0; }
.canvas-controls p { font-size: 11px; color: #a8c9c4; margin-top: 9px; }
.scene-error { position: absolute; top: 40%; left: 10%; right: 10%; padding: 18px; background: #421c22; border: 1px solid #ca8788; border-radius: 10px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 12px 14px; background: #f4f8f6; border-bottom: 1px solid var(--line); }
.tabs button { white-space: nowrap; }
.selected-card { background: #f4f9f6; padding: 13px; border-radius: 9px; border: 1px solid #dfebe6; }
.selected-card strong { display: block; font-size: 20px; margin: 5px 0 3px; }
.selected-card p, .hint, .pinned-note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.selected-card .source-id { font: 11px ui-monospace, monospace; margin-top: 9px; color: #627878; }
.tissue { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--accent); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.detail-actions button { font-size: 12px; padding: 6px 7px; }
.pinned-note { margin-top: 7px; }
.part-display {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px;
  margin-top: 10px; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--soft);
}
.part-display button { padding: 5px 2px; font-size: 12px; line-height: 1.25; }
.part-display button:disabled { cursor: default; }
.part-display small { display: block; margin-top: 2px; font-size: 9px; }
.selection-help { margin-top: 5px; }
.switch-label { cursor: pointer; position: relative; display: flex; }
.switch-label input { position: absolute; opacity: 0; }
.switch-label span { display: inline-flex; padding: 3px; width: 36px; height: 21px; border-radius: 20px; background: #cbd6d3; }
.switch-label span::after { content: ""; display: block; width: 15px; height: 15px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch-label input:checked + span { background: var(--accent); }
.switch-label input:checked + span::after { transform: translateX(15px); }
.switch-label input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; margin: 10px 0; }
.field > span, .range-field span { font-size: 12px; font-weight: 600; }
.range-field { display: grid; gap: 3px; margin: 10px 0; }
.range-field span { display: flex; justify-content: space-between; gap: 8px; }
.range-field output { color: var(--accent); font: 600 11px ui-monospace, monospace; }
.range-field input { width: 100%; margin: 0; height: 19px; }
.clip-section .hint { margin-top: 8px; }
.segmented { display: grid; grid-template-columns: repeat(2,1fr); gap: 5px; margin: 11px 0; }
.implant-options { display: grid; gap: 8px; margin: 12px 0 8px; }
.collision { display: flex; align-items: center; gap: 7px; min-height: 34px; padding: 7px 9px; font-size: 12px; color: #295a4d; border-radius: 7px; background: #edf6f1; }
.collision.overlap { color: #874417; background: #fff0d8; }
.collision.overlap i { background: #dc861f; }
.stages { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; margin-bottom: 9px; }
.stages button { padding: 5px 3px; font-size: 12px; }
.stages span { font: 600 10px ui-monospace, monospace; margin-right: 4px; }
.route-actions { display: flex; gap: 7px; margin-top: 12px; }
.route-actions #play { background: var(--accent); border-color: var(--accent); color: white; }
dialog { max-width: min(520px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: 14px; padding: 20px; color: var(--ink); line-height: 1.7; }
dialog::backdrop { background: #10282c85; }
dialog li + li { margin-top: 8px; }
dialog a { color: var(--accent); }
.toast { position: fixed; bottom: 17px; right: 17px; z-index: 5; max-width: 330px; background: var(--dark); color: white; padding: 10px 16px; border-radius: 8px; box-shadow: 0 5px 16px #0003; }
@media (max-width: 1050px) { .workspace { grid-template-columns: 216px minmax(240px,1fr) 264px; } .layer-section, .structure-section, .detail-section, .clip-section, .implant-section, .route-section { padding-left: 13px; padding-right: 13px; } }
@media (max-width: 780px) {
  .topbar { height: 61px; padding: 0 12px; }
  .brand { gap: 8px; }
  .brand h1 { font-size: 17px; }
  .brand p { font-size: 8px; }
  .mark { flex-basis: 32px; width: 32px; height: 32px; border-radius: 9px; }
  .mark::before,.mark::after,.mark span { inset: 10px 7px; }
  .top-actions { gap: 5px; }
  .top-actions button { font-size: 11px; padding: 6px; }
  .prototype-status { display: none; }
  .workspace { height: auto; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: none; }
  .viewport { height: max(430px, 57dvh); grid-row: 1; grid-column: 1 / -1; }
  .sidebar { grid-column: 1; min-height: 430px; max-height: 620px; }
  .inspector { grid-column: 2; border-left: 0; max-height: 620px; }
  .viewport-heading { left: 14px; right: 14px; top: 14px; }
  .side-labels { left: 13px; right: 13px; }
}
@media (max-width: 430px) {
  .workspace { grid-template-columns: 1fr; }
  .viewport, .sidebar, .inspector { grid-column: 1; }
  .viewport { position: sticky; top: 0; z-index: 2; height: clamp(285px, 46dvh, 380px); }
  .canvas-controls p { margin-top: 5px; }
  .inspector { grid-row: 2; max-height: none; }
  .sidebar { grid-row: 3; border-right: 0; border-top: 1px solid var(--line); max-height: 550px; }
  .layers { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 430px) {
  .viewport { scroll-margin-top: 0; }
  .inspector :is(button,input,select), .sidebar :is(button,input,select) { scroll-margin-top: 49dvh; }
}

@media (min-width: 781px) and (max-height: 700px) {
  .layer-section, .structure-section { padding-top: 10px; }
  .layer-section { padding-bottom: 10px; }
  .layer { padding: 5px 8px; }
  .layer .opacity-row:has(input:disabled) { display: none; }
  .layer .layer-opacity { margin-top: 2px; }
}

.view-section { padding: 12px 18px; border-bottom: 1px solid var(--line); }
.view-section summary, .landmark-section summary { cursor: pointer; font-weight: 650; }
.preset-grid, .landmark-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 9px; }
.preset-grid button, .landmark-grid button, .save-view-form button, .saved-views button { font-size: 12px; }
.save-view-form { display: flex; gap: 5px; margin-top: 9px; }
.save-view-form input { min-width: 0; flex: 1; font: inherit; font-size: 12px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; }
.saved-view { display: flex; gap: 5px; margin-top: 5px; }
.saved-view button:first-child { flex: 1; min-width: 0; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; text-align: start; }
.landmark-section { margin-top: 14px; }
.landmark-section .check-field { margin-top: 9px; }
.landmark-markers { position: absolute; inset: 0; pointer-events: none; }
.landmark-marker { position: absolute; width: 13px; height: 13px; padding: 0; border-radius: 50%; border: 2px solid #eefcf5; background: #1d7464; box-shadow: 0 0 0 2px #1d7464a3; transform: translate(-50%,-50%); pointer-events: auto; }
.landmark-marker:hover:not(:disabled), .landmark-marker[aria-pressed="true"] { background: #f0c672; border-color: #183c39; }
@media (max-width: 1050px) { .view-section { padding-inline: 13px; } }

/* Bilingual controls and two non-overlapping callout rails. */
.label-controls { display: grid; grid-template-columns: 1fr; gap: 6px; padding-top: 8px; }
.label-controls select { width: 100%; min-width: 0; font-size: 11px; padding: 4px; }
.label-pages { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 11px; }
.label-pages button { padding: 0 10px; font-size: 17px; }
.layer { padding: 5px 8px; }
.layer .layer-opacity { margin-top: 2px; }
.layer .opacity-row:has(input:disabled) { display: none; }
.layer label { font-size: 12px; }
.sidebar { overflow-y: auto; }
.structure-section { min-height: 158px; }
.search input { font-size: 12px; }
.tabs button { white-space: normal; font-size: 12px; }
.camera-views { flex-wrap: wrap; justify-content: center; max-width: calc(100% - 12px); }
.camera-views button { font-size: 11px; padding: 5px 6px; }
#reset-view { border-color: #72aa9b; }
.camera-label-switch { align-items: center; gap: 5px; padding: 3px 6px; color: #e5f3ef; font-size: 11px; white-space: nowrap; }
.camera-label-switch span { width: 26px; height: 15px; padding: 2px; background: #647985; }
.camera-label-switch span::after { width: 11px; height: 11px; }
.camera-label-switch input:checked + span { background: #23846f; }
.camera-label-switch input:checked + span::after { transform: translateX(11px); }
.viewport-heading h2 { font-size: clamp(12px, 1.2vw, 17px); letter-spacing: .01em; }
.scene-status { white-space: normal; text-align: center; }
.label-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.leader-outline { stroke: var(--leader-outline); stroke-width: 3.5; }
.leader-ink { stroke: var(--leader-ink); stroke-width: 1.2; }
.label-lines circle { fill: var(--leader-ink); stroke: var(--leader-outline); stroke-width: 1.2; }
.scene-label, .scene-label[aria-pressed="true"] {
  position: absolute; display: block; height: 29px; text-align: start; padding: 1px 5px;
  pointer-events: auto; cursor: grab; touch-action: none; user-select: none;
  line-height: 12px; border: 1px solid #ffdcba9c; border-radius: 4px;
  background: var(--label-bg); color: var(--label-ink); box-shadow: 0 1px 2px #0008;
}

.scene-label:hover:not(:disabled) { background: var(--label-bg); border-color: #ffe2bf; z-index: 1; }
.scene-label[aria-pressed="true"],
.scene-label[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--label-selected-bg); color: var(--label-selected-ink); border-color: #bd5b2f;
  box-shadow: 0 0 0 1px var(--leader-outline);
}
.scene-label.dragging { cursor: grabbing; z-index: 2; }
.scene-label span, .scene-label small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-label span { font: 600 11px/12px system-ui; }
.scene-label small { font: 400 10px/12px system-ui; }
.hint a { color: var(--accent); }
@media (max-width: 430px) {
  .canvas-controls p { font-size: 9px; }
  .top-actions button { line-height: 1.1; }
}
