:root {
  --bg: #0b0e13;
  --panel: #131820;
  --panel-2: #1a2029;
  --line: #262e3a;
  --text: #e6e9ee;
  --muted: #8b95a5;
  --accent: #5bc0eb;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; min-height: 100vh; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: 0.2px; }
.subtitle { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.presets { display: flex; gap: 4px; background: var(--panel); padding: 3px; border-radius: 8px; border: 1px solid var(--line); }
.btn, .presets button { background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 6px; padding: 6px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.presets button[aria-pressed="true"] { background: var(--panel-2); border-color: var(--line); color: var(--accent); }
.btn { border-color: var(--line); background: var(--panel); }
.btn:hover, .presets button:hover { border-color: var(--accent); }

.progress { position: relative; height: 22px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #2a6f97, var(--accent)); transition: width .15s; }
.progress span { position: relative; padding: 0 12px; line-height: 22px; }
.progress[hidden] { display: none; }

.layout { flex: 1; display: grid; grid-template-columns: 3fr 2fr; gap: 12px; padding: 12px 16px; min-height: 0; }
.pane { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.pane-title { position: absolute; top: 8px; left: 10px; font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); z-index: 2; pointer-events: none; }

.pane-3d { min-height: 420px; flex-direction: row; }
.view3d { flex: 1 1 0; min-width: 0; min-height: 0; overflow: hidden; position: relative; cursor: grab; }
.view3d:active { cursor: grabbing; }
/* The canvas must never dictate layout size, or renderer.setSize and the
   ResizeObserver feed back on each other until the canvas is gigantic. */
.view3d canvas { display: block; position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

.organs { flex: none; width: 170px; margin: 8px; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px; font-size: 13px; }
.organs label { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.organs label:hover { background: var(--panel-2); }
.organs label.selected { background: var(--panel-2); outline: 1px solid var(--accent); }
.organs input { margin: 0; accent-color: var(--accent); }
.organs .name { flex: 1; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }

.grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 12px; min-height: 0; }
.slice canvas { width: 100%; flex: 1; min-height: 0; display: block; background: #000; cursor: crosshair; touch-action: none; image-rendering: pixelated; }
.slice input[type=range] { width: 100%; margin: 0; padding: 6px 10px; accent-color: var(--accent); background: var(--panel-2); border-top: 1px solid var(--line); }

.card-body { padding: 34px 14px 14px; flex: 1; overflow: auto; }
.card-empty { color: var(--muted); font-size: 14px; line-height: 1.5; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin: 0; font-size: 18px; }
.card-head .swatch { width: 16px; height: 16px; }
#card-blurb { color: var(--text); line-height: 1.5; font-size: 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 0; }
.stats div { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.stats dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.stats dd { margin: 2px 0 0; font-size: 15px; font-variant-numeric: tabular-nums; }

.banner { position: absolute; left: 10px; right: 10px; bottom: 10px; background: #3a1f24; color: #ffd7dc; border: 1px solid #7a2f3a; padding: 8px 10px; border-radius: 8px; font-size: 13px; z-index: 3; }
.banner[hidden] { display: none; }

.foot { padding: 8px 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.foot a { color: var(--accent); text-decoration: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .pane-3d { min-height: 360px; }
  .pane-3d { flex-direction: column; }
  .organs { width: auto; max-height: 150px; }
  .grid { grid-template-rows: auto; }
  .slice canvas { flex: none; height: auto; aspect-ratio: 1 / 1; }
  .card { grid-column: 1 / -1; min-height: 160px; }
}

/* ---- Case mode (clinic-branded, owner-facing) ------------------------- */
.brand-logo { height: 28px; width: auto; max-width: 120px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.clinic-line { color: var(--muted); font-size: 12px; }
.btn-accent { background: var(--accent); color: #041018; border-color: var(--accent); font-weight: 600; }
.btn-accent:hover { filter: brightness(1.1); }
.findings-body { padding: 34px 14px 14px; overflow: auto; flex: 1; }
#findings-summary { margin: 0 0 12px; font-size: 14px; line-height: 1.55; }
#findings-list { display: flex; flex-direction: column; gap: 6px; }
.finding { display: grid; grid-template-columns: 14px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); font: inherit; cursor: pointer; }
.finding .swatch { grid-row: 1 / span 2; width: 14px; height: 14px; }
.finding-title { font-weight: 600; font-size: 14px; }
.finding-organ { font-size: 12px; color: var(--muted); }
.finding:hover { border-color: var(--accent); }
.finding.selected { outline: 1px solid var(--accent); background: var(--panel); }
.findings-hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }
.share-dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 20px; max-width: 360px; width: calc(100vw - 32px); text-align: center; }
.share-dialog::backdrop { background: rgba(0,0,0,0.6); }
.share-dialog h3 { margin: 0 0 12px; font-size: 16px; }
.share-dialog img { width: 200px; height: 200px; background: #fff; border-radius: 8px; padding: 8px; }
.share-dialog code { display: block; margin: 12px 0; font-size: 12px; color: var(--muted); word-break: break-all; }
.share-actions { display: flex; gap: 8px; justify-content: center; }

/* Owner mode: 3D + transverse + findings + card; everything clinical hidden. */
body.owner .organs, body.owner .presets, body.owner #reset,
body.owner .slice[data-axis="x"], body.owner .slice[data-axis="y"],
body.owner .stats { display: none; }
body.owner .grid { grid-template-columns: 1fr; grid-template-rows: auto; }
body.owner .findings { order: -1; }
body.owner .slice canvas { flex: none; height: auto; aspect-ratio: 1 / 1; max-height: 320px; }
body.owner .card-body { padding-top: 34px; }
body.owner #card-blurb { font-size: 15px; }
@media (min-width: 901px) {
  body.owner .grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
  body.owner .findings { grid-row: 1 / span 2; }
}
