:root {
  /* Nord-inspired dark workstation palette; image pixels remain untouched. */
  --bg: #171b24;
  --surface: #252c3a;
  --border: #414b5e;
  --text: #eceff4;
  --muted: #b5bfd0;
  --accent: #88c0d0;
  --accent-hover: #8fbcbb;
  --accent-ink: #17202b;
  --image-bg: #10141c;
  --overlay-line: #88c0d0;
  --warn-border: #d08770;
  --warn-text: #ebcb8b;
  --warn-bg: #3a2d2a;
  --focus: #88c0d0;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

.chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem clamp(1.25rem, 4vw, 3rem);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.chrome-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.steps {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: color 200ms ease;
}

.step-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  transition: background-color 200ms ease, box-shadow 200ms ease;
}

.step.done { color: var(--text); }
.step.done .step-dot { background: var(--accent-hover); }

.step.active { color: var(--accent); }
.step.active .step-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(94, 129, 172, 0.18);
}

.badge {
  margin: 0;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--warn-border);
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3rem);
}

.state { display: none; }
body[data-state="inspect"] #state-inspect,
body[data-state="analyzing"] #state-analyzing,
body[data-state="reveal"] #state-reveal,
body[data-state="explore"] #state-explore,
body[data-state="report"] #state-report { display: flex; }

@keyframes state-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

body[data-state="inspect"] #state-inspect,
body[data-state="analyzing"] #state-analyzing,
body[data-state="reveal"] #state-reveal,
body[data-state="explore"] #state-explore,
body[data-state="report"] #state-report { animation: state-in 350ms ease both; }

#state-inspect,
#state-analyzing,
#state-reveal,
#state-explore {
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.prompt {
  margin: 0;
  font-size: clamp(1.5rem, 3.2vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
}

.prompt:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 6px; }

.stage,
.stack {
  position: relative;
  width: min(70vmin, 580px);
  aspect-ratio: 1 / 1;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(46, 52, 64, 0.14);
}

.slice-img,
.overlay-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.stage::after,
.stack::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 48px rgba(0, 0, 0, 0.45);
  border-radius: inherit;
}

.overlay-img {
  filter: drop-shadow(0 0 6px rgba(136, 192, 208, 0.55));
  animation: overlay-in 600ms ease both;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-img[hidden] { display: none; }

.caption {
  margin: 0;
  max-width: 56ch;
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn {
  min-height: 58px;
  padding: 0 1.9rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

@keyframes cta-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(94, 129, 172, 0.45); }
  50% { box-shadow: 0 0 0 14px rgba(94, 129, 172, 0); }
}

body.is-idle .btn-primary:not(:disabled) {
  animation: cta-pulse 1.8s ease-out infinite;
}

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-quiet {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
}
.btn-quiet:hover { color: var(--accent); }

.btn:disabled { opacity: 0.45; cursor: default; text-decoration: none; }

.btn.is-loading::after {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-left: 0.55rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: viewer-spin 800ms linear infinite;
  vertical-align: -0.1em;
}

.btn:focus-visible,
button:focus-visible,
input:focus-visible,
dialog:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* ---------- analyzing state: neural net animation ---------- */

.nn-stage {
  width: min(92vw, 620px);
  height: clamp(220px, 38vmin, 340px);
  background: var(--image-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(46, 52, 64, 0.14);
}

.nn-edge {
  stroke: #434c5e;
  stroke-width: 1.5;
  stroke-dasharray: 5 9;
  animation: nn-flow 1.1s linear infinite;
}

.nn-node {
  fill: #3b4252;
  stroke: var(--overlay-line);
  stroke-width: 2.5;
  transform-box: fill-box;
  transform-origin: center;
  animation: nn-pulse 1.7s ease-in-out infinite;
}

.nn-node.nn-out { stroke: #b48ead; fill: #434c5e; }

@keyframes nn-flow { to { stroke-dashoffset: -28; } }

@keyframes nn-pulse {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  50% { transform: scale(1.28); opacity: 1; }
}

.analyzing-status {
  margin: 0;
  min-height: 1.6em;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
}

.progress {
  width: min(420px, 80vw);
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
}

.analyzing-sub { margin: 0; color: var(--muted); text-align: center; max-width: 52ch; }

/* ---------- explore: slice browser ---------- */

.explore-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.slice-controls {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: min(70vmin, 580px);
  margin-top: 0.75rem;
}

.btn-step {
  min-width: 56px;
  min-height: 52px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  border-radius: 8px;
  font-size: 1.6rem;
  line-height: 1;
}
.btn-step:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-step:active:not(:disabled) { transform: translateY(1px); }

#slice-slider {
  flex: 1 1 auto;
  accent-color: var(--accent);
  height: 40px;
  cursor: ew-resize;
}

#slice-slider::-webkit-slider-thumb { cursor: grab; }

.slice-label {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}


.actions-explore { margin-top: 0.75rem; }

.note {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 52ch;
  text-align: center;
}

/* ---------- 3D dialog ---------- */

#viewer-dialog {
  width: min(92vw, 640px);
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(46, 52, 64, 0.3);
}

#viewer-dialog::backdrop {
  background: rgba(46, 52, 64, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.dialog-head h2 { margin: 0; font-size: 1.3rem; font-weight: 600; }

.btn-close {
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.btn-close:hover { border-color: var(--accent); color: var(--accent); }

.viewer-box {
  position: relative;
  width: 100%;
  height: clamp(280px, 48vmin, 440px);
  background: var(--image-bg);
  border-radius: var(--radius);
  overflow: hidden;
}

.viewer-mount { width: 100%; height: 100%; }

.viewer-loading {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.viewer-loading::after {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-left: 0.55rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: viewer-spin 800ms linear infinite;
  vertical-align: -0.1em;
}

@keyframes viewer-spin { to { transform: rotate(360deg); } }

model-viewer {
  width: 100%;
  height: 100%;
  --poster-color: transparent;
  background-color: transparent;
}

.volume-line {
  margin: 1.1rem 0 0;
  font-size: 1.25rem;
  font-weight: 650;
}

/* ---------- report ---------- */

#state-report { align-items: center; }

.report-panel {
  width: min(100%, 900px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: 0 8px 28px rgba(46, 52, 64, 0.1);
}

.report-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 400;
  font-style: italic;
  color: var(--muted);
  text-align: center;
}

.report-title:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 6px; }

.report-body p { margin: 0 0 0.75rem; }
.report-body p:last-child { margin-bottom: 0; }
.report-body .report-sub { font-weight: 700; color: var(--accent); margin-bottom: 0.3rem; }

.report-basis {
  margin: 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.patient-info {
  margin-top: 0.25rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  color: var(--muted);
  font-size: 1.05rem;
}

.patient-info summary {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}

.patient-info p { margin: 0.75rem 0 0; }
.patient-info a { color: var(--accent); overflow-wrap: anywhere; }
.patient-info p:last-child { font-style: italic; }

.report-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: clamp(1.25rem, 4vw, 2.5rem);
  align-items: center;
}

.report-visual .stage { width: 100%; }
.overlay-toggle { align-self: center; }

.actions-explore { flex-wrap: nowrap; justify-content: center; gap: 0.65rem; width: 100%; }
.actions-explore .btn { min-width: 0; padding-left: 1.1rem; padding-right: 1.1rem; white-space: nowrap; }

.report-volume { display: none; margin-top: 1rem; }
.report-volume model-viewer {
  display: block;
  width: 100%;
  height: 250px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--image-bg);
}

@media (max-width: 900px) {
  .actions-explore { flex-wrap: wrap; }
  .report-layout { grid-template-columns: 1fr; }
  .report-visual { max-width: 320px; }
}

@media (min-width: 900px) {
  .report-volume { display: block; }
}

.provenance {
  margin: 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  color: var(--warn-text);
  font-size: 0.95rem;
}

.fallback {
  position: absolute;
  inset: auto 0 0 0;
  margin: 0;
  padding: 0.85rem 1rem;
  background: rgba(46, 52, 64, 0.92);
  border-top: 1px solid var(--border);
  color: #ebcb8b;
  font-size: 1rem;
}

.fallback[hidden] { display: none; }

.load-error {
  margin: 2rem auto;
  padding: 1rem 1.25rem;
  max-width: 46ch;
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 1.1rem;
  text-align: center;
}

.load-error[hidden] { display: none; }
body.load-failed .main { display: none; }

@media (max-width: 640px) {
  .stage, .stack, .slice-controls { width: min(92vw, 560px); }
  .actions .btn { flex: 1 1 auto; }
  .steps { display: none; }
}

/* Keep the complete experience visible on shorter kiosk displays. */
@media (min-width: 641px) and (max-height: 850px) {
  .main { padding: 1rem 2rem; }
  #state-inspect, #state-analyzing, #state-reveal, #state-explore { gap: 0.75rem; }
  .prompt { font-size: clamp(1.3rem, 2.8vw, 1.8rem); }
  .stage, .stack { width: min(58vmin, 460px); }
  .btn { min-height: 48px; padding: 0 1.35rem; font-size: 0.98rem; }
  .slice-controls { margin-top: 0.25rem; }
  .btn-step { min-width: 48px; min-height: 44px; }
  .report-panel { padding: 1.25rem 1.5rem; gap: 0.65rem; }
  .report-volume model-viewer { height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
  .btn:active { transform: none; }
  .nn-edge { stroke-dasharray: none; }
}
