* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f1eb;
  --panel: #fffdfa;
  --ink: #171717;
  --muted: #66635d;
  --line: #d8d1c8;
  --accent: #1e6f9f;
  --accent-strong: #155374;
  --focus: #c27803;
  --stage: #dfe7ea;
  --measure: #c23d2a;
  --measure-ink: #ffffff;
  --object-label: #171717;
  --object-label-ink: #ffffff;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  transition: grid-template-columns 280ms ease-in-out;
}

.shell.aside-hidden {
  grid-template-columns: minmax(0, 1fr) 0;
}

.stage {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0) 40%),
    var(--stage);
}

model-viewer {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  display: block;
  --poster-color: transparent;
  --progress-bar-color: var(--accent);
  --b2mv-viewer-cursor: default;
  cursor: default;
}

.controls {
  min-height: 100vh;
  min-width: 0;
  overflow-y: auto;
  padding: 28px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 24px;
  opacity: 1;
  transform: translateX(0);
  transition:
    opacity 180ms ease-in,
    transform 280ms ease-in-out,
    padding 280ms ease-in-out,
    border-color 280ms ease-in-out;
}

.shell.aside-hidden .controls {
  overflow: hidden;
  padding-right: 0;
  padding-left: 0;
  border-left-color: transparent;
  opacity: 0;
  transform: translateX(100%);
  pointer-events: none;
}

.aside-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 6px;
  background: rgba(23, 23, 23, 0.82);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.aside-toggle:hover {
  background: rgba(23, 23, 23, 0.94);
}

.aside-toggle img {
  display: block;
  width: 100%;
  height: 100%;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  line-height: 1.02;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

select {
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.object-panel {
  display: grid;
  gap: 14px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.object-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.object-panel h2,
.measure-panel__header h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.label-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.label-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.selected-object {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.selected-object strong {
  color: var(--ink);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.object-list {
  max-height: min(34vh, 320px);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  list-style: none;
}

.object-list li + li {
  border-top: 1px solid var(--line);
}

.object-list button {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
  overflow-wrap: anywhere;
}

.object-list button:hover,
.object-list button[aria-current="true"] {
  color: #ffffff;
  background: var(--accent-strong);
}

.measure-panel {
  display: grid;
  gap: 12px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.measure-panel__header,
.measure-panel__footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.measure-panel__header {
  justify-content: space-between;
}

.measure-panel__footer {
  min-height: 34px;
  color: var(--muted);
  font-size: 0.82rem;
}

#measurementStatus {
  min-width: 0;
  margin-right: auto;
}

.measure-value {
  color: var(--ink);
  font-size: 1.65rem;
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.unit-field select {
  width: 66px;
  min-height: 34px;
  padding: 0 8px;
}

.button-secondary,
.button-quiet {
  min-height: 34px;
  padding: 0 12px;
}

.button-secondary {
  color: var(--accent-strong);
  background: transparent;
}

.button-secondary:hover,
.button-secondary[aria-pressed="true"] {
  color: #ffffff;
  background: var(--accent-strong);
}

.button-quiet {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

.button-quiet:hover:not(:disabled) {
  color: var(--ink);
  background: transparent;
  border-color: var(--muted);
}

.button-quiet:disabled {
  opacity: 0.45;
  cursor: default;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  cursor: default;
}

button:hover {
  background: var(--accent-strong);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.progress {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 24px;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 23, 23, 0.16);
}

.progress__fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 160ms ease;
}

model-viewer.loaded .progress {
  opacity: 0;
}

.measure-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

#measurementLine {
  display: none;
  stroke: var(--measure);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 7 5;
  vector-effect: non-scaling-stroke;
}

#measurementLabel {
  display: none;
}

#measurementLabel rect {
  fill: var(--measure);
  stroke: var(--measure-ink);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

#measurementLabel text {
  fill: var(--measure-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0;
  text-anchor: middle;
  dominant-baseline: middle;
}

.measure-point {
  display: block;
  width: 32px;
  min-height: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  line-height: 0;
  pointer-events: none;
}

.measure-point img {
  display: block;
  width: 100%;
  height: 100%;
}

.object-hotspot {
  max-width: 190px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 4px;
  color: var(--object-label-ink);
  background: var(--object-label);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
  pointer-events: none;
  transform: translate3d(-50%, -100%, 0);
}

.object-anchor {
  width: 1px;
  height: 1px;
  min-height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.object-leader-line {
  display: none;
  stroke: var(--object-label);
  stroke-width: 1.5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

@media (max-width: 860px) {
  .shell {
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .shell.aside-hidden {
    grid-template-columns: 1fr;
  }

  .stage,
  model-viewer {
    min-height: 68vh;
  }

  .controls {
    min-height: auto;
    max-height: 2400px;
    border-left: 0;
    border-top: 1px solid var(--line);
    transition:
      max-height 320ms ease-in-out,
      opacity 180ms ease-in,
      transform 280ms ease-in-out,
      padding 280ms ease-in-out,
      border-color 280ms ease-in-out;
  }

  .shell.aside-hidden .controls {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-top-color: transparent;
    transform: translateY(24px);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --panel: #20201e;
    --ink: #f7f3ec;
    --muted: #b9b0a4;
    --line: #3a3834;
    --accent: #4fb0d8;
    --accent-strong: #8ccde8;
    --focus: #e0a12b;
    --stage: #253036;
    --measure: #f06d55;
  }

  select {
    color: var(--ink);
    background: #191918;
  }
}
