/* RenalSeg 3 -- one stylesheet, no framework, no web fonts (nothing is fetched from a third party). */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #131c27;
  --mute: #5a6878;
  --faint: #8794a3;
  --line: #dde3ea;
  --line-strong: #c6cfd9;
  --accent: #0b6bcb;
  --accent-ink: #ffffff;
  --accent-soft: #e8f1fc;
  --ok: #12804a;
  --ok-soft: #e7f6ee;
  --warn: #9a5700;
  --warn-soft: #fff4e2;
  --danger: #b3261e;
  --viewer: #0b0e13;
  --viewer-line: #222a35;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans Thai", "Leelawadee UI", Thonburi, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand svg { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-tag { color: var(--faint); font-size: 13px; padding-left: 10px; border-left: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.chip svg { width: 13px; height: 13px; }
.chip-local { color: var(--ok); border-color: #b9e2c9; background: var(--ok-soft); }
.chip-research { color: var(--warn); border-color: #f0d3a3; background: var(--warn-soft); }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-btn { border: 0; background: transparent; padding: 4px 10px; font-size: 12.5px; cursor: pointer; color: var(--mute); }
.lang-btn.active { background: var(--ink); color: #fff; }
.top-link { font-size: 13px; color: var(--mute); text-decoration: none; }
.top-link:hover { color: var(--accent); text-decoration: underline; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--card);
  font-weight: 600; font-size: 14px; cursor: pointer; transition: border-color .12s, background .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex: none; }
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible, .link-btn:focus-visible, .drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #095bae; border-color: #095bae; color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover:not(:disabled) { background: #0e6b3e; border-color: #0e6b3e; color: #fff; }
.btn.ok.done { background: var(--ok-soft); color: var(--ok); border-color: #b9e2c9; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.block { width: 100%; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 13.5px; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: #095bae; }
.select { border: 1px solid var(--line-strong); border-radius: 7px; background: var(--card); padding: 5px 8px; }
.select.small { font-size: 12.5px; padding: 4px 6px; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: transparent; padding: 8px 16px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--mute); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--ink); color: #fff; }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }
.seg.small button { padding: 4px 10px; font-size: 12.5px; }
.seg .sub { font-weight: 400; opacity: 0.75; margin-left: 6px; font-size: 12.5px; }

/* ---------- stages ---------- */
.stage { flex: 1; min-height: 0; }
.stage-drop, .stage-run { display: grid; place-items: start center; padding: 40px 20px 32px; }
.hero { width: min(820px, 100%); text-align: center; }
.hero h1 { font-size: clamp(26px, 3.4vw, 36px); line-height: 1.15; letter-spacing: -0.02em; }
.lead { color: var(--mute); font-size: 16.5px; margin: 14px auto 28px; max-width: 660px; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 36px 24px 28px; border: 2px dashed var(--line-strong); border-radius: 18px; background: var(--card);
  transition: border-color .15s, background .15s, transform .15s; box-shadow: var(--shadow);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.01); }
.drop-icon { width: 46px; height: 46px; color: var(--accent); }
.drop-title { font-size: 20px; letter-spacing: -0.01em; }
.drop-sub { color: var(--mute); max-width: 520px; }
.drop-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
.drop-formats { color: var(--faint); font-size: 12.5px; margin-top: 8px; }
.under-drop { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 14px 4px 0; flex-wrap: wrap; }
.model-status { display: inline-flex; align-items: center; gap: 8px; color: var(--mute); font-size: 13px; }
.model-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #e0a100; animation: pulse 1.2s ease-in-out infinite; }
.model-status.ready .dot { background: var(--ok); animation: none; }
.model-status.failed { color: var(--danger); }
.model-status.failed .dot { background: var(--danger); animation: none; }
@keyframes pulse { 50% { opacity: 0.3; } }

.how { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 0; margin: 34px 0 0; text-align: left; }
.how li { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.how-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 13px; }
.how strong { display: block; font-size: 14.5px; }
.how span { color: var(--mute); font-size: 13.5px; }

/* ---------- running ---------- */
.run-card { width: min(620px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.run-card h2 { font-size: 22px; letter-spacing: -0.01em; }
.run-sub { color: var(--mute); margin-top: 4px; }
.series-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 4px; min-height: 28px; }
.series-chips.compact { margin: 0; min-height: 0; }
.s-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: #f8fafc; color: var(--mute); }
.s-chip b { color: var(--ink); font-weight: 600; }
.s-chip.native { border-color: #cfd6de; }
.s-chip.arterial { border-color: #f3b4b0; background: #fdeeed; }
.s-chip.venous { border-color: #aac6f3; background: #ecf3fe; }
.s-chip.excretory { border-color: #ecd98a; background: #fdf8e1; }
.run-steps { list-style: none; padding: 0; margin: 18px 0 20px; display: grid; gap: 12px; }
.run-steps li { display: flex; gap: 12px; align-items: flex-start; color: var(--faint); }
.run-steps li strong { font-weight: 600; display: block; }
.run-steps .detail { font-size: 13px; color: var(--mute); }
.tick { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); margin-top: 1px; position: relative; }
.run-steps li.active { color: var(--ink); }
.run-steps li.active .tick { border-color: var(--accent); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.run-steps li.done { color: var(--ink); }
.run-steps li.done .tick { border-color: var(--ok); background: var(--ok); }
.run-steps li.done .tick::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 8px; border-radius: 4px; background: #e6ebf1; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.4s ease; }
.run-foot { display: flex; justify-content: space-between; margin-top: 10px; color: var(--mute); font-size: 13px; min-height: 20px; }
.error-card h2 { color: var(--danger); }
.error-text { margin: 12px 0 20px; color: var(--ink); white-space: pre-wrap; }

/* ---------- result ---------- */
.stage-result { display: flex; flex-direction: column; padding: 14px 16px 12px; gap: 12px; min-height: 0; }
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.case { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.case-meta { display: flex; flex-direction: column; gap: 4px; color: var(--mute); font-size: 13px; }
.head-actions { display: flex; gap: 10px; }
.workspace {
  flex: 1; min-height: 0; display: grid; gap: 12px;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) 340px;
  height: calc(100vh - 176px); min-height: 520px;
}
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--viewer); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--viewer-line); color: #d9e1ea; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--viewer-line); min-height: 44px; flex-wrap: wrap; }
.pane-head h3 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.pane-n { width: 20px; height: 20px; border-radius: 50%; background: #2a3442; display: inline-grid; place-items: center; font-size: 12px; }
.pane-meta { font-size: 12.5px; color: #93a0af; }
.viewer { position: relative; flex: 1; min-height: 0; }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
#modelCanvas { cursor: grab; }
#modelCanvas:active { cursor: grabbing; }
#sliceCanvas.painting { cursor: crosshair; }
.pane-foot { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--viewer-line); flex-wrap: wrap; font-size: 12.5px; }
.pane .seg { background: transparent; border-color: #313b49; }
.pane .seg button { color: #9aa7b6; border-right-color: #313b49; }
.pane .seg button.active { background: #e6ecf3; color: #0b0e13; }
.pane .select, .pane .btn { background: #151b24; border-color: #313b49; color: #d9e1ea; }
.pane .btn:hover:not(:disabled) { border-color: #6aa9f0; color: #fff; }
.pane .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.pane .btn.active { background: #e6ecf3; color: #0b0e13; border-color: #e6ecf3; }
.slider { display: inline-flex; align-items: center; gap: 8px; color: #9aa7b6; white-space: nowrap; }
.slider input[type=range] { width: 90px; accent-color: #6aa9f0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 1px solid #313b49; background: transparent; color: #9aa7b6; border-radius: 999px; padding: 3px 11px; font-size: 12.5px; cursor: pointer; }
.tabs button.active { background: #e6ecf3; color: #0b0e13; border-color: #e6ecf3; font-weight: 600; }
.anno { position: absolute; font: 11.5px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; color: #c9d4df; pointer-events: none; text-shadow: 0 1px 2px #000; }
.anno-bl { left: 10px; bottom: 8px; }
.anno-tr { right: 10px; top: 8px; text-align: right; }
.busy { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(11, 14, 19, 0.72); color: #d9e1ea; font-size: 13.5px; z-index: 3; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #3b4757; border-top-color: #6aa9f0; animation: spin 0.8s linear infinite; }
.edit-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--viewer-line); background: #10151c; flex-wrap: wrap; font-size: 12.5px; }
.edit-labels { display: flex; gap: 4px; flex-wrap: wrap; }
.edit-labels button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #313b49; background: transparent; color: #c3cdd8; border-radius: 7px; padding: 4px 9px; font-size: 12.5px; cursor: pointer; }
.edit-labels button.active { border-color: #fff; background: #222b37; color: #fff; }
.edit-labels i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.edit-hint { color: #8493a3; flex-basis: 100%; }
.legend-note { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; color: #8493a3; }

.v3d-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.v3d-label { position: absolute; left: 0; top: 0; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; background: var(--c, #555); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); }
.v3d-label.vent { min-width: 18px; height: 18px; font-size: 10px; background: #fff; color: #333; border-color: #8a96a3; }
.v3d-label.demo { position: static; transform: none; display: inline-grid; box-shadow: none; }

/* side column */
.side { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-height: 0; padding-right: 2px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--mute); margin-bottom: 10px; font-weight: 600; }
.verify-card { background: var(--warn-soft); border-color: #f0d3a3; display: flex; flex-direction: column; gap: 10px; }
.verify-card p { font-size: 13.5px; color: #6b3d00; }
.verify-card.done { background: var(--ok-soft); border-color: #b9e2c9; }
.verify-card.done p { color: #0e5a33; }
.struct-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.struct { display: grid; grid-template-columns: 22px 26px 1fr auto; align-items: center; gap: 8px; padding: 8px 6px; border-radius: 8px; }
.struct:hover { background: #f6f8fb; }
.struct.off .s-name, .struct.off .s-vol { color: var(--faint); }
.struct.missing { opacity: 0.62; }
.struct input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.struct input[type=color] { width: 24px; height: 24px; padding: 0; border: 1px solid var(--line-strong); border-radius: 6px; background: none; cursor: pointer; }
.struct input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
.struct input[type=color]::-webkit-color-swatch { border: 0; border-radius: 3px; }
.swatch-clear { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line-strong); background: linear-gradient(135deg, #fff 0 45%, #dfe8f2 45% 55%, #fff 55%); }
.s-main { min-width: 0; cursor: pointer; }
.s-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.s-port { border: 0; cursor: pointer; font-family: inherit; display: inline-grid; place-items: center; min-width: 18px; height: 18px; border-radius: 9px; font-size: 11px; font-weight: 700; color: #fff; padding: 0 4px; }
.s-note { font-size: 12.5px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-vol { text-align: right; font-variant-numeric: tabular-nums; font-size: 13.5px; white-space: nowrap; }
.s-vol b { display: block; font-size: 14.5px; }
.s-vol span { color: var(--mute); font-size: 12px; }
.settings summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--mute); font-weight: 600; }
.settings[open] summary { margin-bottom: 10px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; font-size: 13.5px; }
.setting .num { color: var(--mute); white-space: nowrap; }
.setting input[type=number] { width: 66px; padding: 4px 6px; border: 1px solid var(--line-strong); border-radius: 6px; text-align: right; }
.switch { appearance: none; -webkit-appearance: none; width: 36px; height: 20px; border-radius: 10px; background: #c8d0da; position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.switch::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
.hint { font-size: 12.5px; color: var(--mute); margin: 2px 0 6px; }
.downloads .hint { margin: 6px 0 10px; }
.dl-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.dl-row .btn { font-size: 12.5px; padding: 8px 6px; white-space: normal; }

/* ---------- footer ---------- */
.foot { display: flex; align-items: center; gap: 16px; padding: 8px 20px; border-top: 1px solid var(--line); background: var(--card); font-size: 12.5px; color: var(--mute); flex-wrap: wrap; }
.foot strong { color: var(--danger); letter-spacing: 0.04em; font-size: 11.5px; }
.foot-right { margin-left: auto; }
.foot .link-btn { font-size: 12.5px; }

/* ---------- modals ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(10, 16, 24, 0.62); display: grid; place-items: center; padding: 20px; z-index: 50; overflow-y: auto; }
.modal-card { background: var(--card); border-radius: 16px; width: min(560px, 100%); padding: 0 26px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); max-height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; }
.modal-card.wide { width: min(760px, 100%); padding-top: 22px; }
.modal-band { background: var(--danger); color: #fff; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 12px; text-align: center; padding: 8px; margin: 0 -26px 18px; }
.modal-card h2 { font-size: 20px; margin-bottom: 10px; }
.modal-card p { margin-bottom: 10px; }
.modal-list { margin: 0 0 12px; padding-left: 20px; }
.modal-list li { margin-bottom: 4px; }
.modal-ai { background: var(--warn-soft); border: 1px solid #f0d3a3; border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }
.modal-privacy { color: var(--mute); font-size: 13.5px; }
.modal-remember { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin: 4px 0 14px; color: var(--mute); }
.modal-body { overflow-y: auto; padding-right: 6px; margin-bottom: 16px; font-size: 14px; }
.modal-body h3 { font-size: 14px; margin: 16px 0 6px; }
.modal-body ul { margin: 0 0 8px; padding-left: 20px; }
.modal-body li { margin-bottom: 6px; }
.modal-body code { font-size: 12.5px; background: #f1f4f7; padding: 1px 5px; border-radius: 4px; }
.modal-note { color: var(--mute); font-size: 13px; }
.modal-close { align-self: flex-end; }
body.modal-open { overflow: hidden; }

/* ---------- narrower screens ---------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: auto; }
  .pane { height: 62vh; min-height: 420px; }
  .side { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); overflow: visible; }
}
@media (max-width: 760px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .how { grid-template-columns: 1fr; }
  .brand-tag, .chip-research { display: none; }
  .stage-drop, .stage-run { padding: 24px 14px; }
}
