:root {
  color-scheme: dark;
  --bg: #090c10;
  --card: #111820;
  --panel: #1a232d;
  --line: #283543;
  --line-bright: #415867;
  --text: #e7edf3;
  --muted: #7a8590;
  --muted-2: #a0a9b1;
  --mint: #31b9a9;
  --mint-bright: #76e3d6;
  --mint-soft: rgba(49, 185, 169, 0.12);
  --amber: #f0b74c;
  --danger: #ff6f61;
  --shadow: 0 24px 72px rgba(0, 0, 0, 0.44);
  --sans: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  font: 14px/1.5 var(--sans);
  background-image:
    linear-gradient(rgba(91, 111, 132, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 111, 132, 0.1) 1px, transparent 1px);
  background-size: 32px 32px;
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--mint-bright);
  outline-offset: 4px;
}

button:active:not(:disabled) {
  transform: translateY(2px) scale(0.99);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font: 11px/1.4 var(--mono);
  letter-spacing: 0.09em;
}

.site-title {
  position: absolute;
  z-index: 20;
  top: clamp(16px, 2.5vw, 28px);
  left: 50%;
  padding: 5px 18px 7px;
  border-bottom: 1px solid rgba(240, 183, 76, 0.48);
  color: #e7edf3;
  font-size: clamp(20px, 2.5vw, 28px);
  font-weight: 900;
  letter-spacing: 0.18em;
  line-height: 1;
  text-shadow: 0 0 18px rgba(240, 183, 76, 0.15);
  transform: translateX(-50%);
  white-space: nowrap;
}

/* Home */
.home-screen {
  position: relative;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(390px, 0.8fr) minmax(590px, 1.2fr);
  background: rgba(9, 12, 16, 0.7);
  animation: screenIn 420ms ease both;
}

.scanner-bay {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-right: 1px solid var(--line);
}

.scanner-bay::before,
.scan-room::before,
.ct-viewport::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(49, 185, 169, 0.035), transparent 32%, transparent 68%, rgba(49, 185, 169, 0.035)),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(75, 102, 124, 0.08) 32px),
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(75, 102, 124, 0.08) 32px);
  content: "";
}

.gantry-wrap {
  position: relative;
  width: min(70%, 360px);
  aspect-ratio: 1;
  margin-top: -40px;
}

.gantry {
  position: absolute;
  inset: 0;
  border: 34px solid #202a35;
  border-radius: 50%;
  background: radial-gradient(circle, #07090d 0 46%, #101721 47% 58%, transparent 59%);
  box-shadow:
    inset 0 0 0 2px #35414e,
    inset 0 0 45px rgba(0, 0, 0, 0.65),
    0 28px 55px rgba(0, 0, 0, 0.36);
}

.gantry::before {
  position: absolute;
  inset: -21px;
  border: 1px dashed rgba(74, 198, 183, 0.55);
  border-radius: 50%;
  content: "";
  animation: slowSpin 18s linear infinite;
}

.gantry::after {
  position: absolute;
  inset: 15%;
  border: 1px solid #0c1117;
  border-radius: 50%;
  content: "";
}

.focus-corners {
  position: absolute;
  z-index: 2;
  inset: 43%;
  filter: drop-shadow(0 0 6px rgba(49, 185, 169, 0.55));
}

.focus-corners::before,
.focus-corners::after {
  position: absolute;
  inset: 0;
  border: 4px solid var(--mint);
  content: "";
}

.focus-corners::before {
  clip-path: polygon(0 0, 42% 0, 42% 12%, 12% 12%, 12% 42%, 0 42%, 0 0, 100% 0, 100% 42%, 88% 42%, 88% 12%, 58% 12%, 58% 0);
}

.focus-corners::after {
  clip-path: polygon(0 100%, 0 58%, 12% 58%, 12% 88%, 42% 88%, 42% 100%, 100% 100%, 100% 58%, 88% 58%, 88% 88%, 58% 88%, 58% 100%);
}

.bay-status {
  position: absolute;
  right: 0;
  bottom: 56px;
  left: 0;
  text-align: center;
}

.bay-status .eyebrow {
  color: var(--amber);
  font-size: 12px;
  letter-spacing: 0.17em;
}

.bay-status p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.form-zone {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px clamp(28px, 5vw, 78px);
}

.form-panel {
  width: min(100%, 640px);
  padding: clamp(26px, 4vw, 38px);
  border: 1px solid var(--line);
  background: rgba(17, 24, 32, 0.97);
  box-shadow: var(--shadow);
}

.form-panel h1 {
  margin: 10px 0 5px;
  font-size: clamp(29px, 3vw, 38px);
  line-height: 1.16;
  letter-spacing: 0.04em;
}

.lede {
  margin: 0 0 28px;
  color: var(--muted-2);
  line-height: 1.8;
}

.section-label {
  margin: 0 0 10px;
  color: var(--muted);
  font: 11px/1.3 var(--mono);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.mode-card {
  position: relative;
  display: block;
  min-height: 82px;
  padding: 15px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
  transition: 160ms ease;
}

.mode-card:hover {
  border-color: var(--line-bright);
  background: #202b36;
}

.mode-card:has(input:checked) {
  border-color: var(--mint);
  color: var(--mint);
  background: var(--mint-soft);
  box-shadow: inset 4px 0 var(--mint);
}

.mode-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-card strong,
.mode-card small {
  display: block;
}

.mode-card strong {
  font-size: 16px;
}

.mode-card small {
  margin-top: 6px;
  color: var(--muted-2);
  font-size: 11px;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  margin-top: 16px;
  border: 1px solid #8af0e3;
  border-radius: 0;
  color: #06110f;
  font-weight: 800;
  background: var(--mint);
  box-shadow: 5px 5px 0 #0a3531;
  cursor: pointer;
  transition: 160ms ease;
}

.primary-button:hover {
  filter: brightness(1.08);
  box-shadow: 2px 2px 0 #0a3531;
  transform: translate(3px, 3px);
}

/* Preparation and scan */
.scan-room {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  overflow: hidden;
  animation: screenIn 420ms ease both;
}

.scan-meta {
  position: absolute;
  z-index: 2;
  top: 28px;
  left: 32px;
  display: grid;
  gap: 8px;
  color: var(--amber);
  font: 12px/1 var(--mono);
  letter-spacing: 0.03em;
}

.scan-center {
  position: relative;
  z-index: 2;
  width: min(92vw, 720px);
  display: grid;
  justify-items: center;
  padding: 32px 0;
  text-align: center;
}

.machine {
  position: relative;
  width: min(43vw, 330px);
  min-width: 245px;
  aspect-ratio: 1;
}

.machine .gantry {
  border-width: 30px;
}

.bed {
  position: absolute;
  z-index: 4;
  right: -13%;
  bottom: 1%;
  left: -13%;
  height: 25px;
  border: 1px solid #394655;
  background: #202a35;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
}

.bed::before {
  position: absolute;
  right: 28%;
  bottom: 21px;
  left: 22%;
  height: 25px;
  border-radius: 45% 50% 10% 10%;
  background: #2b3642;
  content: "";
}

.countdown-title {
  margin: 28px 0 0;
  color: var(--muted-2);
  font: 13px/1.3 var(--mono);
}

.countdown-number {
  margin: 8px 0;
  color: var(--amber);
  font: 800 clamp(68px, 10vw, 94px)/1 var(--mono);
  text-shadow: 0 0 28px rgba(240, 183, 76, 0.2);
  animation: countPop 900ms ease both;
}

.scan-instruction {
  margin: 5px 0;
  color: var(--muted-2);
  font-size: clamp(15px, 2vw, 19px);
}

.scan-auto {
  margin: 18px 0 0;
  color: var(--mint);
  font: 11px/1.5 var(--mono);
}

.scan-canvas-wrap {
  position: relative;
  width: min(82vw, 680px);
  aspect-ratio: 16 / 8.2;
  overflow: hidden;
  border: 1px solid #284049;
  background: rgba(4, 7, 10, 0.9);
  box-shadow: 0 0 55px rgba(49, 185, 169, 0.08);
}

#scan-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.scan-beam {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #9ffcef;
  box-shadow: -12px 0 28px 9px rgba(49, 185, 169, 0.18), 0 0 15px var(--mint);
  animation: horizontalSweep 1.4s linear infinite;
}

.scan-frame-corner {
  position: absolute;
  z-index: 4;
  width: 35px;
  height: 35px;
  border-color: var(--mint);
  opacity: 0.8;
}

.corner-tl { top: 12px; left: 12px; border-top: 2px solid; border-left: 2px solid; }
.corner-tr { top: 12px; right: 12px; border-top: 2px solid; border-right: 2px solid; }
.corner-bl { bottom: 12px; left: 12px; border-bottom: 2px solid; border-left: 2px solid; }
.corner-br { right: 12px; bottom: 12px; border-right: 2px solid; border-bottom: 2px solid; }

.scan-progress-box {
  width: min(82vw, 680px);
  margin-top: 24px;
}

.scan-progress-copy {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--muted-2);
  font: 12px/1 var(--mono);
}

.scan-progress-track {
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(122, 133, 144, 0.16);
}

.scan-progress-bar {
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--mint) 0 10px, #6ce1d3 10px 12px);
  box-shadow: 0 0 18px rgba(49, 185, 169, 0.5);
}

.scan-stage-labels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 12px;
  color: #56616d;
  font: 10px/1 var(--mono);
}

.scan-stage-labels span.is-current {
  color: var(--mint);
}

/* Simplified CT result */
.result-screen {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(12px, 2vw, 24px);
  background:
    radial-gradient(circle at 50% 42%, rgba(49, 185, 169, 0.07), transparent 48%),
    rgba(5, 8, 11, 0.88);
  animation: screenIn 480ms ease both;
}

.result-layout {
  width: min(100%, 900px);
  display: grid;
  justify-items: center;
  gap: 20px;
  padding-top: 54px;
}

.ct-viewport {
  position: relative;
  isolation: isolate;
  width: min(90vw, 720px);
  aspect-ratio: 1.55 / 1;
  overflow: hidden;
  border: 1px solid #2b3f48;
  background: #020304;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.56), 0 0 42px rgba(49, 185, 169, 0.06);
}

.ct-image {
  position: absolute;
  z-index: 1;
  inset: 1.5%;
  width: 97%;
  height: 97%;
  object-fit: contain;
  filter: saturate(0.92) brightness(0.96);
  opacity: 0;
  transform: scale(0.96);
  animation: imageReveal 900ms 100ms ease forwards;
}

.ct-viewport::before {
  z-index: 2;
}

.ct-crosshair::before,
.ct-crosshair::after {
  position: absolute;
  z-index: 3;
  background: rgba(49, 185, 169, 0.4);
  content: "";
  pointer-events: none;
}

.ct-crosshair::before {
  top: 50%;
  right: 0;
  left: 0;
  height: 1px;
}

.ct-crosshair::after {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
}

.worm-cluster {
  position: absolute;
  z-index: 6;
  top: 58%;
  left: 52%;
  width: 160px;
  height: 138px;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.72);
  animation: wormsAppear 900ms 620ms cubic-bezier(0.2, 1.3, 0.4, 1) forwards;
  pointer-events: none;
}

.worm {
  position: absolute;
  width: 70px;
  height: 28px;
  border: 6px solid #ffe071;
  border-top-color: transparent;
  border-left-color: transparent;
  border-radius: 50%;
  filter:
    drop-shadow(0 1px 2px rgba(5, 17, 23, 0.95))
    drop-shadow(0 0 9px rgba(255, 216, 84, 0.9));
  animation: wormWiggle 1.1s ease-in-out infinite alternate;
}

.worm::after {
  position: absolute;
  right: -9px;
  bottom: -4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff3ac;
  box-shadow:
    inset -2px -1px #d89f2b,
    0 0 0 1px rgba(68, 47, 11, 0.45);
  content: "";
}

.worm:nth-of-type(2) { top: 14px; left: 18px; transform: rotate(18deg); }
.worm:nth-of-type(3) { top: 63px; left: 68px; transform: rotate(210deg) scale(0.84); animation-delay: -0.4s; }
.worm:nth-of-type(4) { top: 91px; left: 12px; transform: rotate(122deg) scale(0.7); animation-delay: -0.7s; }

.finding-ring {
  position: absolute;
  inset: 0;
  border: 2px solid #ffd45d;
  border-radius: 50%;
  box-shadow:
    0 0 0 7px rgba(255, 212, 93, 0.12),
    0 0 28px rgba(255, 212, 93, 0.48);
  animation: findingPulse 1.3s ease-in-out infinite;
}

.result-badge {
  position: absolute;
  z-index: 9;
  top: 22px;
  left: 50%;
  padding: 10px 18px;
  border: 1px solid transparent;
  font: 700 14px/1 var(--mono);
  opacity: 1;
  transform: translate(-50%, 0);
  animation: badgeIn 520ms 500ms ease both;
}

.result-badge.is-warning {
  border-color: #f2c653;
  color: #fff2bd;
  background: rgba(102, 70, 13, 0.92);
}

.result-badge.is-clear {
  border-color: var(--mint);
  color: #c7fff7;
  background: rgba(10, 76, 67, 0.9);
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 4vw, 34px);
}

.result-circle-button {
  position: relative;
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  border: 2px solid var(--mint-bright);
  border-radius: 50%;
  color: #06110f;
  background:
    radial-gradient(circle at 38% 30%, #8df2e6, var(--mint) 58%, #218b80);
  box-shadow:
    inset 0 0 0 7px rgba(7, 56, 51, 0.18),
    0 0 0 8px rgba(49, 185, 169, 0.08),
    0 18px 40px rgba(0, 0, 0, 0.42);
  cursor: pointer;
  transition: 180ms ease;
}

.result-circle-button:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow:
    inset 0 0 0 7px rgba(7, 56, 51, 0.18),
    0 0 0 12px rgba(49, 185, 169, 0.08),
    0 22px 46px rgba(0, 0, 0, 0.48);
}

.replay-icon {
  position: relative;
  width: 38px;
  height: 30px;
}

.replay-icon::before {
  position: absolute;
  inset: 0;
  background: currentColor;
  clip-path: polygon(0 34%, 24% 34%, 57% 4%, 57% 96%, 24% 66%, 0 66%);
  content: "";
}

.replay-icon::after {
  position: absolute;
  top: 3px;
  right: 0;
  width: 19px;
  height: 24px;
  border: 3px solid currentColor;
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-left-color: transparent;
  border-radius: 50%;
  content: "";
}

.result-circle-button strong {
  font-size: 14px;
}

.share-icon {
  position: relative;
  width: 34px;
  height: 28px;
  margin-top: 6px;
  border: 3px solid currentColor;
  border-top: 0;
  border-radius: 3px;
}

.share-icon::before {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 3px;
  height: 24px;
  background: currentColor;
  content: "";
  transform: translateX(-50%);
}

.share-icon::after {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 12px;
  height: 12px;
  border-top: 3px solid currentColor;
  border-left: 3px solid currentColor;
  content: "";
  transform: translateX(-50%) rotate(45deg);
}

/* Poster */
.poster-modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  overflow-y: auto;
  padding: 24px;
  background: rgba(2, 4, 6, 0.86);
  backdrop-filter: blur(10px);
}

.poster-modal[hidden] {
  display: none;
}

.poster-panel {
  position: relative;
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 26px;
  border: 1px solid var(--line-bright);
  background: #111820;
  box-shadow: var(--shadow);
  animation: modalIn 320ms ease both;
}

.poster-panel h2 {
  margin: 0;
  font-size: 24px;
}

.poster-panel .poster-hospital {
  margin: 0 44px 7px 0;
  color: var(--amber);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.poster-panel > p {
  margin: 8px 36px 20px 0;
  color: var(--muted-2);
  font-size: 12px;
}

.poster-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  color: var(--muted-2);
  background: #0a0f14;
  cursor: pointer;
}

#poster-preview {
  width: min(100%, 440px);
  display: block;
  margin: 0 auto;
  border: 1px solid var(--line);
  background: #081015;
}

.poster-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 18px;
}

.download-button,
.cancel-button {
  min-height: 48px;
  padding: 0 22px;
  border-radius: 0;
  cursor: pointer;
}

.download-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--mint-bright);
  color: #07110f;
  font-weight: 800;
  background: var(--mint);
  text-decoration: none;
}

.cancel-button {
  border: 1px solid var(--line-bright);
  color: var(--text);
  background: transparent;
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes slowSpin {
  to { transform: rotate(360deg); }
}

@keyframes countPop {
  0% { opacity: 0; transform: scale(1.35); }
  28% { opacity: 1; }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes horizontalSweep {
  from { left: 4%; }
  to { left: 96%; }
}

@keyframes imageReveal {
  to { opacity: 1; transform: scale(1); }
}

@keyframes wormsAppear {
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes wormWiggle {
  from { margin: -4px 0 0 -2px; }
  to { margin: 4px 0 0 3px; }
}

@keyframes findingPulse {
  50% { opacity: 0.55; transform: scale(1.08); }
}

@keyframes badgeIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .home-screen {
    grid-template-columns: minmax(280px, 0.7fr) minmax(460px, 1.3fr);
  }

  .form-zone {
    padding: 24px;
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .home-screen {
    display: block;
  }

  .scanner-bay {
    min-height: 42svh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .gantry-wrap {
    width: 220px;
    margin-top: -22px;
  }

  .gantry {
    border-width: 23px;
  }

  .bay-status {
    bottom: 15px;
  }

  .bay-status .eyebrow {
    font-size: 10px;
  }

  .form-zone {
    min-height: 58svh;
    padding: 16px 12px 28px;
  }

  .form-panel {
    padding: 22px 17px;
  }

  .scan-meta {
    top: 16px;
    left: 14px;
    font-size: 10px;
  }

  .machine {
    width: 58vw;
    min-width: 210px;
  }

  .scan-canvas-wrap,
  .scan-progress-box {
    width: calc(100vw - 24px);
  }

  .result-screen {
    align-items: start;
    padding: 12px;
  }

  .result-layout {
    gap: 16px;
    padding-top: 58px;
  }

  .ct-viewport {
    width: 100%;
    height: clamp(410px, 58svh, 500px);
    aspect-ratio: auto;
  }

  .ct-image {
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
  }

  .worm-cluster {
    width: 132px;
    height: 116px;
  }

  .worm {
    width: 57px;
    height: 22px;
    border-width: 5px;
  }

  .worm:nth-of-type(2) { top: 12px; left: 15px; }
  .worm:nth-of-type(3) { top: 53px; left: 56px; }
  .worm:nth-of-type(4) { top: 75px; left: 10px; }

  .result-actions {
    width: 100%;
    flex-flow: row wrap;
    gap: 14px;
  }

  .result-circle-button {
    width: 98px;
    height: 98px;
  }

  .poster-modal {
    padding: 10px;
  }

  .poster-panel {
    padding: 20px 14px;
  }

  .poster-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
