:root {
  --paper: #ffffff;
  --paper-deep: #ffffff;
  --ink: #17323a;
  --ink-soft: #5b6d74;
  --navy: #102932;
  --navy-deep: #071c24;
  --rule: rgba(28, 68, 82, 0.11);
  --rule-dark: rgba(236, 232, 219, 0.2);
  --card: #ffffff;
  --orange: #d65f2e;
  --orange-soft: #ef9e61;
  --cyan: #71c6c4;
  --yellow: #e5c45f;
  --good: #247a68;
  --warn: #bb4c2e;
  --shadow: 0 2px 12px rgba(17, 48, 58, 0.07);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

html {
  min-width: 0;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font);
  font-variant-numeric: lining-nums tabular-nums;
}

button,
input,
select,
output {
  font: inherit;
}

button,
select,
input[type="range"] {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--rule);
}

.brand-block h1 {
  margin: 0;
  font-size: clamp(24px, 2.2vw, 34px);
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--rule);
  background: var(--paper-deep);
}

.language-switch button {
  min-width: 38px;
  padding: 5px 8px;
  border: 0;
  border-radius: 0;
  color: var(--ink-soft);
  background: transparent;
  font-size: 11px;
  line-height: 1;
}

.language-switch button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--navy);
}

.language-switch button:hover:not([aria-pressed="true"]) {
  color: var(--ink);
  background: rgba(23, 36, 42, 0.06);
}

.instrument-grid {
  display: grid;
  grid-template-columns: 276px minmax(540px, 1fr) 324px;
  gap: 12px;
  width: min(1920px, 100%);
  margin: 0 auto;
  padding: 12px;
}

.panel-light,
.metric-card,
.detail-card,
.regional-card,
.primary-result {
  border: 1px solid var(--rule);
  background: var(--card);
  box-shadow: var(--shadow);
}

.control-rail {
  padding: 17px 16px 16px;
}

.section-heading,
.card-heading > div:first-child {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.section-heading > span,
.panel-index {
  flex: 0 0 auto;
  color: var(--orange);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.section-heading h2,
.card-heading h2,
.detail-heading h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.section-heading p,
.card-heading p {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.3;
}

.section-heading.compact {
  margin-bottom: 2px;
}

.section-rule {
  height: 1px;
  margin: 17px 0 15px;
  background: var(--rule);
}

.field-select,
.slider-field {
  display: grid;
  gap: 7px;
  margin-top: 15px;
}

.field-select > span,
.field-line label,
.dual-field label > span {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.field-select select {
  width: 100%;
  height: 36px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink);
  background: #ffffff;
  outline: none;
  font-size: 12px;
}

.field-select select:focus-visible,
.dual-field input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

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

.field-line label i {
  color: var(--ink);
}

.field-line output {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  height: 17px;
  margin: 0;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: rgba(35, 91, 96, 0.24);
}

input[type="range"]::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: -5px;
  appearance: none;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

input[type="range"]::-moz-range-track {
  height: 2px;
  background: rgba(35, 91, 96, 0.24);
}

input[type="range"]::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

.accent-slider input[type="range"]::-webkit-slider-thumb {
  background: var(--orange);
  box-shadow: 0 0 0 1px var(--orange);
}

.accent-slider input[type="range"]::-moz-range-thumb {
  background: var(--orange);
  box-shadow: 0 0 0 1px var(--orange);
}

input[type="range"]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.range-notes {
  display: flex;
  justify-content: space-between;
  margin-top: -5px;
  color: rgba(56, 91, 96, 0.58);
  font-size: 9px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 11px;
}

.preset-row button,
.view-actions button {
  padding: 5px 7px;
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  font-size: 10px;
  transition: 150ms ease;
}

.preset-row button:hover,
.view-actions button:hover {
  border-color: var(--orange);
  color: var(--orange);
  background: rgba(214, 95, 46, 0.06);
}

.dual-field {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 15px;
}

.dual-field label {
  position: relative;
  display: grid;
  gap: 5px;
}

.dual-field input {
  width: 100%;
  height: 34px;
  padding: 0 26px 0 8px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: #ffffff;
}

.dual-field label i {
  position: absolute;
  right: 7px;
  bottom: 10px;
  color: var(--ink-soft);
  font-size: 9px;
  font-style: normal;
}

.small-select {
  grid-template-columns: 1fr;
}

.surface-control {
  padding: 10px;
  border: 1px solid rgba(113, 198, 196, 0.32);
  background: rgba(113, 198, 196, 0.055);
}

.surface-control small {
  color: var(--ink-soft);
  font-size: 9px;
  line-height: 1.35;
}

.threshold-presets {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: -2px;
}

.threshold-presets button {
  padding: 2px 6px;
  color: var(--orange);
  border: 1px solid rgba(214, 95, 46, 0.36);
  border-radius: 0;
  background: rgba(214, 95, 46, 0.04);
  font-size: 9px;
}

.threshold-presets button:hover {
  color: var(--paper);
  background: var(--orange);
}

.threshold-presets span {
  margin-left: auto;
  color: rgba(76, 90, 94, 0.72);
  font-size: 8.5px;
}

.toggle-field {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.toggle-field > input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.toggle-field > span {
  position: relative;
  width: 28px;
  height: 14px;
  border: 1px solid rgba(35, 91, 96, 0.32);
  background: rgba(35, 91, 96, 0.08);
  transition: 150ms ease;
}

.toggle-field > span i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-soft);
  transition: 150ms ease;
}

.toggle-field > input:checked + span {
  border-color: var(--good);
  background: rgba(36, 122, 104, 0.18);
}

.toggle-field > input:checked + span i {
  left: 16px;
  background: var(--good);
}

.toggle-field > input:focus-visible + span {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

.toggle-field b {
  font-size: 10px;
}

.reset-button {
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  border: 1px solid var(--ink);
  border-radius: 0;
  color: var(--paper);
  background: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: 150ms ease;
}

.reset-button:hover {
  border-color: var(--orange);
  background: var(--orange);
}

.visual-column {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.stage-card {
  overflow: hidden;
  color: #efeadd;
  border: 1px solid rgba(7, 28, 36, 0.8);
  background: var(--navy);
  box-shadow: 0 18px 46px rgba(7, 28, 36, 0.22);
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--rule);
}

.card-heading.on-dark {
  border-bottom-color: var(--rule-dark);
}

.card-heading.on-dark h2 {
  color: #f6f0e2;
}

.card-heading.on-dark p {
  color: rgba(239, 234, 221, 0.65);
}

.view-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 5px;
}

.view-actions button {
  color: rgba(239, 234, 221, 0.78);
  border-color: var(--rule-dark);
}

.stage-wrap {
  position: relative;
  height: clamp(390px, 46vh, 560px);
  min-height: 380px;
}

#sceneCanvas,
#heatmapCanvas,
#profileCanvas {
  display: block;
  width: 100%;
}

#sceneCanvas {
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

#heatmapCanvas,
#profileCanvas {
  height: 250px;
}

.scene-readout {
  position: absolute;
  top: 14px;
  left: 14px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 8px;
  padding: 8px 10px;
  border-left: 2px solid var(--orange);
  background: rgba(4, 19, 25, 0.58);
  backdrop-filter: blur(8px);
}

.scene-readout span {
  color: var(--cyan);
  font-size: 9px;
  font-style: italic;
}

.scene-readout b {
  color: #f4efdf;
  font-size: 10px;
  font-weight: 400;
}

.drag-legend {
  position: absolute;
  right: 53px;
  bottom: 14px;
  display: flex;
  gap: 12px;
  padding: 6px 8px;
  color: rgba(239, 234, 221, 0.68);
  background: rgba(4, 19, 25, 0.55);
  font-size: 9px;
}

.drag-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.drag-legend i {
  display: inline-block;
}

.magnet-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
}

.drag-legend .line {
  width: 10px;
  height: 2px;
}

.direction-line { background: var(--orange-soft); }
.height-line { background: var(--cyan); }

.pose-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  border-top: 1px solid var(--rule-dark);
  background: var(--rule-dark);
}

.mini-slider {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 9px 10px 7px;
  background: var(--navy);
}

.mini-slider label {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--cyan);
  font-size: 10px;
}

.mini-slider output {
  color: #f4efdf;
  font-size: 10px;
}

.mini-slider input[type="range"]::-webkit-slider-runnable-track {
  background: rgba(239, 234, 221, 0.28);
}

.mini-slider input[type="range"]::-webkit-slider-thumb {
  border-color: var(--navy);
  background: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan);
}

.mini-slider input[type="range"]::-moz-range-track {
  background: rgba(239, 234, 221, 0.28);
}

.mini-slider input[type="range"]::-moz-range-thumb {
  border-color: var(--navy);
  background: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan);
}

.mini-slider.accent-slider label {
  color: var(--orange-soft);
}

.plot-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(0, 0.96fr);
  gap: 12px;
}

.plot-card {
  min-width: 0;
  overflow: hidden;
}

.sampling-chip {
  flex: 0 0 auto;
  padding: 3px 6px;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  font-size: 9px;
}

.result-rail {
  display: grid;
  align-content: start;
  gap: 10px;
}

.primary-result {
  padding: 17px 16px 15px;
  color: #f4efdf;
  border-color: var(--navy);
  background: var(--navy-deep);
}

.result-label,
.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-label > span {
  color: var(--cyan);
  font-size: 11px;
  font-weight: 700;
}

.result-label i {
  padding: 3px 5px;
  color: rgba(244, 239, 223, 0.72);
  border: 1px solid var(--rule-dark);
  font-size: 9px;
  font-style: normal;
}

.metric-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 6px;
}

.metric-main strong {
  color: #f8f2e1;
  font-size: clamp(50px, 4.2vw, 72px);
  line-height: 0.94;
  font-weight: 400;
  letter-spacing: -0.055em;
}

.metric-main span {
  color: var(--orange-soft);
  font-size: 15px;
  font-style: italic;
}

.primary-result > p {
  margin: 8px 0 15px;
  color: rgba(244, 239, 223, 0.58);
  font-size: 10px;
  line-height: 1.35;
}

.threshold-track {
  position: relative;
  height: 4px;
  background: rgba(244, 239, 223, 0.14);
}

.threshold-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--cyan);
  transition: width 180ms ease, background 180ms ease;
}

.threshold-track i {
  position: absolute;
  top: -4px;
  left: 50%;
  width: 1px;
  height: 12px;
  background: var(--orange-soft);
}

.threshold-caption {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  color: rgba(244, 239, 223, 0.48);
  font-size: 9px;
}

.threshold-caption b {
  color: var(--cyan);
  font-weight: 700;
}

.result-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card {
  position: relative;
  min-height: 112px;
  padding: 13px;
  overflow: hidden;
}

.metric-card > span,
.regional-score span {
  display: block;
  min-height: 26px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.3;
}

.metric-card strong {
  display: inline-block;
  margin-top: 7px;
  font-size: 27px;
  font-weight: 400;
  letter-spacing: -0.035em;
}

.metric-card small {
  color: var(--orange);
  font-size: 9px;
}

.detail-card,
.regional-card {
  padding: 13px 14px;
}

.detail-heading {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}

.detail-heading > span {
  color: var(--orange);
  font-size: 9px;
  font-weight: 700;
}

.comparison-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 10px;
}

.comparison-row div {
  display: grid;
  gap: 3px;
}

.comparison-row span,
.envelope-row span,
.regional-grid span {
  color: var(--ink-soft);
  font-size: 9px;
}

.comparison-row b,
.envelope-row b,
.regional-grid b {
  font-size: 12px;
}

.detail-card > p,
.regional-card > p {
  margin: 9px 0 0;
  color: var(--ink-soft);
  font-size: 9.5px;
  line-height: 1.38;
}

.envelope-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dotted var(--rule);
}

.envelope-row b {
  max-width: 68%;
  text-align: right;
  font-weight: 700;
}

.axis-bars {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.axis-bars > div {
  display: grid;
  grid-template-columns: 20px 1fr 56px;
  align-items: center;
  gap: 7px;
  font-size: 9px;
}

.axis-bars i {
  height: 4px;
  background: rgba(35, 91, 96, 0.10);
}

.axis-bars i b {
  display: block;
  width: 0;
  height: 100%;
  background: var(--orange);
  transition: width 180ms ease;
}

.axis-bars em {
  color: var(--ink-soft);
  text-align: right;
  font-style: normal;
}

.regional-card {
  background: var(--card);
}

.regional-score {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0 8px;
}

.regional-score span {
  min-height: 0;
}

.regional-score strong {
  color: var(--orange);
  font-size: 20px;
  font-weight: 400;
}

.regional-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.regional-grid > div {
  display: grid;
  gap: 4px;
  padding: 9px;
  background: #ffffff;
}

@media (max-width: 1280px) {
  .instrument-grid {
    grid-template-columns: 260px minmax(500px, 1fr);
  }

  .result-rail {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .primary-result {
    grid-column: span 2;
  }

  .result-pair {
    grid-column: span 2;
  }

}

@media (max-width: 900px) {
  .instrument-grid {
    grid-template-columns: 1fr;
  }

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

  .control-rail > .section-heading,
  .control-rail > .section-rule,
  .control-rail > .reset-button {
    grid-column: 1 / -1;
  }

  .result-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-result,
  .result-pair {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    padding: 18px 14px 13px;
  }

  .instrument-grid {
    padding: 8px;
  }

  .control-rail,
  .plot-grid,
  .result-rail {
    grid-template-columns: 1fr;
  }

  .control-rail > *,
  .primary-result,
  .result-pair {
    grid-column: 1;
  }

  .stage-wrap {
    height: 390px;
  }

  .pose-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mini-slider:last-child {
    grid-column: span 2;
  }

  .view-actions,
  .drag-legend {
    display: none;
  }

  #heatmapCanvas,
  #profileCanvas {
    height: 270px;
  }

}

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