:root {
  color-scheme: light;
  --bg: #eef4f3;
  --ink: #1e2a2f;
  --muted: #667276;
  --line: #d3dfdc;
  --panel: #ffffff;
  --teal: #0b7285;
  --teal-dark: #075c69;
  --clay: #c95032;
  --gold: #b78222;
  --green: #477c58;
  --graphite: #263238;
  --shadow: 0 18px 45px rgba(19, 47, 51, 0.10);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 30px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  min-height: 76px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.02;
  letter-spacing: 0;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.mode-tab,
.icon-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border 160ms ease, transform 160ms ease;
}

.mode-tab {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  font-size: 15px;
  font-weight: 750;
  white-space: nowrap;
}

.mode-tab > span[aria-hidden="true"] {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
}

.mode-tab:hover,
.mode-tab.active {
  border-color: rgba(11, 114, 133, 0.24);
  background: var(--teal);
  color: #fff;
}

.icon-button {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-color: var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.icon-button:hover {
  transform: translateY(-1px);
  border-color: rgba(11, 114, 133, 0.30);
}

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: var(--teal-dark);
}

.simulation-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
  margin-top: 14px;
}

.view-panel,
.scene-panel,
.scene3d-panel,
.side-panel,
.chart-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.view-panel {
  position: relative;
  min-height: 460px;
  overflow: hidden;
}

.panel-label {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 2;
  padding: 5px 8px;
  border: 1px solid rgba(211, 223, 220, 0.85);
  background: rgba(255, 255, 255, 0.72);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 850;
}

canvas {
  display: block;
  width: 100%;
}

#scene,
#scene3d {
  height: min(52vh, 560px);
  min-height: 450px;
}

#scene3d {
  cursor: grab;
  touch-action: none;
}

#scene3d.dragging {
  cursor: grabbing;
}

.side-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.86fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
  padding: 22px;
}

.mode-kicker {
  margin-bottom: 9px;
  color: var(--clay);
  font-size: 13px;
  font-weight: 850;
}

h2 {
  margin-bottom: 12px;
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: 0;
}

#modeDescription {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.facts {
  display: grid;
  gap: 12px;
  margin: 18px 0 0;
}

.facts div {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

dt {
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 850;
}

dd {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px 20px;
}

.controls label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.controls output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--teal);
}

.charts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
  margin-top: 18px;
}

.chart-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  padding: 16px 16px 10px;
}

.spot-chart-panel {
  grid-column: auto;
}

.chart-panel > canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.chart-heading {
  display: flex;
  min-height: 32px;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

h3 {
  margin-bottom: 8px;
  font-size: 17px;
  letter-spacing: 0;
}

.chart-heading > span {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.scan-imaging {
  margin-top: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scan-imaging-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.scan-imaging-heading .mode-kicker {
  margin-bottom: 7px;
}

.scan-imaging-heading h2 {
  margin-bottom: 7px;
}

.scan-imaging-description {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.scan-status {
  display: grid;
  min-width: 220px;
  gap: 5px;
  justify-items: end;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.scan-status strong {
  color: var(--teal-dark);
  font-size: 15px;
}

.scan-result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.scan-image-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  background: #f8fbfa;
}

.scan-image-toolbar {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.scan-image-toolbar > div {
  display: grid;
  gap: 2px;
}

.scan-image-toolbar strong {
  color: var(--ink);
  font-size: 15px;
}

.scan-image-label {
  color: var(--teal-dark);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#scanImage,
#scanImage3d {
  height: clamp(320px, 32vw, 500px);
  background: #edf3f1;
}

#scanImage3d {
  background: #f8fbfa;
}

.scan-image-footer {
  display: grid;
  grid-template-columns: auto minmax(120px, 260px) auto auto 1fr;
  gap: 9px;
  align-items: center;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.height-legend {
  height: 9px;
  border: 1px solid rgba(30, 42, 47, 0.16);
  background: linear-gradient(90deg, #000000 0%, #220000 14%, #580400 29%, #941f00 43%, #c45b00 58%, #e29d22 73%, #f2d37e 87%, #fffdef 100%);
}

.fast-axis-label {
  justify-self: end;
}

.scan-3d-footer {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.scan-3d-footer > span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.scan-path-key,
.scan-probe-key {
  display: inline-block;
  flex: 0 0 auto;
}

.scan-path-key {
  width: 22px;
  height: 0;
  border-top: 2px solid var(--teal);
}

.scan-probe-key {
  width: 9px;
  height: 9px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--clay);
  box-shadow: 0 0 0 1px rgba(30, 42, 47, 0.25);
}

@media (max-width: 1050px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .mode-tabs {
    grid-column: 1 / -1;
    order: 3;
  }

  .simulation-split {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: 1.2fr 1fr;
    grid-template-rows: auto;
  }

  .scan-imaging-heading {
    align-items: flex-start;
  }

  .scan-result-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100vw - 18px, 1480px);
    padding-top: 12px;
  }

  .topbar {
    gap: 10px;
  }

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

  h1 {
    font-size: 30px;
  }

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

  .mode-tab {
    justify-content: flex-start;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

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

  .scan-imaging {
    padding: 16px;
  }

  .scan-imaging-heading {
    display: grid;
    gap: 14px;
  }

  .scan-status {
    min-width: 0;
    justify-items: start;
  }

  .scan-image-footer {
    grid-template-columns: auto 1fr auto auto;
  }

  .fast-axis-label {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .scan-3d-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  #scene,
  #scene3d {
    min-height: 390px;
  }
}
