:root {
  color-scheme: dark;
  --bg: #20262c;
  --panel: rgba(12, 16, 20, 0.88);
  --panel-strong: rgba(20, 26, 31, 0.94);
  --line: rgba(255, 255, 255, 0.13);
  --text: #edf3f6;
  --muted: #aab8bf;
  --soft: #6f818a;
  --atlas: #e8d2b5;
  --bone: #c9c1b4;
  --nerve: #65f3ff;
  --pain: #ff465f;
  --muscle: #d86e65;
  --green: #58d68d;
  --amber: #ffc95c;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 31vw, 430px);
  width: 100vw;
  height: 100vh;
  min-height: 620px;
}

.viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #20262c;
}

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

.scene-hud {
  position: absolute;
  left: 24px;
  bottom: 24px;
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(12px);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.view-toolbar {
  position: absolute;
  top: 0;
  right: 24px;
  z-index: 4;
  display: flex;
  align-items: stretch;
  background: rgba(15, 18, 22, 0.58);
  backdrop-filter: blur(10px);
}

.view-button {
  display: grid;
  place-items: center;
  width: 56px;
  height: 40px;
  border: 0;
  border-left: 1px dotted rgba(255, 255, 255, 0.24);
  background: transparent;
  color: rgba(255, 255, 255, 0.34);
  cursor: pointer;
}

.view-button:first-child {
  border-left: 0;
}

.view-button:hover,
.view-button.active {
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
}

.view-button svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.75;
}

.measurement-label {
  position: absolute;
  z-index: 3;
  display: grid;
  gap: 6px;
  min-width: 128px;
  padding: 14px 18px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.86);
  color: #fff;
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.24);
  transform: none;
  pointer-events: none;
}

.measurement-label.is-hidden {
  display: none;
}

.measurement-label span {
  color: rgba(255, 255, 255, 0.78);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
  line-height: 1;
  text-transform: uppercase;
}

.measurement-label strong {
  font-size: 17px;
  font-weight: 500;
  line-height: 1.1;
}

.label-atlas {
  top: 11%;
  right: 13%;
}

.label-lower {
  top: 55%;
  left: 24%;
}

.label-frontal {
  right: 13%;
  bottom: 18%;
}

.label-leg {
  right: 31%;
  bottom: 6%;
  min-width: 122px;
}

.label-rotation {
  left: 15%;
  top: 14%;
}

.label-axis {
  right: 22%;
  top: 33%;
}

.label-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: -1px;
}

.label-dot.atlas {
  background: var(--atlas);
}

.label-dot.nerve {
  background: var(--nerve);
  box-shadow: 0 0 12px var(--nerve);
}

.label-dot.muscle {
  background: var(--muscle);
  box-shadow: 0 0 12px rgba(255, 70, 95, 0.55);
}

.icon-button {
  position: absolute;
  top: 52px;
  right: 24px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 12, 16, 0.72);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(12px);
}

.icon-button:hover {
  border-color: rgba(101, 243, 255, 0.52);
  color: var(--nerve);
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  height: 100vh;
  padding: 26px;
  overflow: auto;
  border-left: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(18, 22, 27, 0.98), rgba(10, 12, 15, 0.98)),
    var(--panel);
}

header {
  display: grid;
  gap: 9px;
}

.eyebrow {
  margin: 0;
  color: var(--nerve);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.03;
  letter-spacing: 0;
}

h2 {
  color: #f5f1e8;
  font-size: 15px;
  line-height: 1.2;
}

.subtle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.control-group {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.text-button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 12px;
}

.text-button:hover {
  border-color: rgba(255, 255, 255, 0.34);
}

#controls {
  display: grid;
  gap: 15px;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(94px, 1fr) 82px;
  gap: 11px;
  align-items: center;
}

.control-row label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.control-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.control-meta strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.control-meta span {
  color: var(--soft);
  font-size: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--nerve);
}

input[type="checkbox"] {
  accent-color: var(--nerve);
}

input[type="number"] {
  width: 82px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(4, 7, 9, 0.86);
  color: var(--text);
  padding: 8px 8px;
}

output {
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

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

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.toggle-row span {
  min-width: 0;
}

.slider-row {
  display: grid;
  gap: 9px;
  min-width: 0;
  padding-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.slider-row span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.slider-row strong {
  color: var(--text);
  font-size: 12px;
}

.slider-row small {
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
}

.severity-meter {
  position: relative;
  height: 11px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
}

.severity-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--pain));
  box-shadow: 0 0 24px rgba(255, 70, 95, 0.45);
  transition: width 160ms ease;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metrics-grid article {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--soft);
  font-size: 11px;
  line-height: 1.2;
  background: rgba(255, 255, 255, 0.035);
}

.metrics-grid span {
  color: var(--text);
  font-size: 20px;
  font-weight: 750;
}

.breakdown {
  display: grid;
  gap: 10px;
}

.pattern-card {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.pattern-card strong {
  color: #fff7e9;
  font-size: 13px;
}

.pattern-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(460px, 58vh) auto;
    height: auto;
    min-height: 100vh;
  }

  .control-panel {
    height: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .scene-hud {
    left: 14px;
    bottom: 14px;
    max-width: calc(100% - 28px);
  }

  .view-toolbar {
    right: 0;
  }

  .view-button {
    width: 44px;
    height: 38px;
  }

  .measurement-label {
    min-width: 105px;
    padding: 10px 12px;
  }

  .measurement-label span {
    font-size: 8px;
  }

  .measurement-label strong {
    font-size: 13px;
  }

  .label-rotation,
  .label-axis,
  .label-leg {
    display: none;
  }

  .label-atlas {
    right: 5%;
  }

  .label-lower {
    left: 7%;
  }

  .label-frontal {
    right: 7%;
    bottom: 16%;
  }

  .icon-button {
    display: none;
  }
}

@media (max-width: 430px) {
  .control-panel {
    padding: 18px;
  }

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

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

  .control-row {
    grid-template-columns: 1fr 74px;
  }

  input[type="number"] {
    width: 74px;
  }
}
