:root {
  --color-primary: #c47ad2;
  --color-primary-hover: #b46bc2;
  --color-success: #9ff168;
  --color-success-hover: #8ce055;
  --color-bg: #f5f6ec;
  --color-surface: #ffffff;
  --color-text: #171717;
  --color-text-muted: #5d5d5d;
  --color-border: #d8ddd0;
  --color-tight: #f28787;
  --color-loose: #99c8ff;
  --radius-sm: 14px;
  --radius-md: 22px;
  --radius-lg: 30px;
  --shadow-sm: 0 3px 10px rgba(0,0,0,0.06);
  --shadow-md: 0 10px 24px rgba(0,0,0,0.08);
  --shadow-lg: 0 16px 44px rgba(0,0,0,0.1);
  --btn-radius: 999px;
  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'SF Mono', 'Consolas', monospace;
  --demo-topbar-h: 56px;
  /* Vertical stack gap in #left-panel (e.g. disclaimer ↔ Одежда) */
  --demo-panel-stack-gap: 12px;
  /* Space from bottom of fixed demo topbar to top of side panels (desktop); larger than stack gap reads better against full-width bar */
  --demo-below-topbar-gap: 20px;
}

/* --- БАЗОВЫЕ СТИЛИ --- */
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  color: var(--color-text);
  position: fixed;
}

#canvas-container {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 84% 18%, #f3d8f7 0, #f3d8f7 14%, transparent 15%),
    radial-gradient(circle at 14% 78%, #ddf3c7 0, #ddf3c7 16%, transparent 17%),
    linear-gradient(180deg, #fdfdf8 0%, #ecefdf 100%);
}

#canvas-container canvas {
  max-height: none;
  height: 100% !important;
  width: 100% !important;
  display: block;
  outline: none;
}

/* --- ЛЕВАЯ ПАНЕЛЬ --- */
#left-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 342px;
  max-height: 95vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--demo-panel-stack-gap);
  z-index: 100;
}

.btn-exit-demo {
  display: inline-block;
  align-self: flex-start;
  padding: 8px 14px;
  font-size: 16px;
  font-weight: 800;
  color: var(--color-primary);
  text-decoration: none;
  border: 1px solid #d8e2c8;
  border-radius: var(--btn-radius);
  background: #eef4dd;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.btn-exit-demo:hover {
  background: #eef4dd;
  border-color: #d8e2c8;
}

#left-panel #disclaimer-box {
  position: static;
  margin: 0;
  flex-shrink: 0;
}

#left-panel .accordion-section,
#ui-panel .accordion-section {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
}

#ui-panel {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 342px;
  max-height: 95vh;
  overflow-y: auto;
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  z-index: 100;
}

.accordion-section {
  margin-bottom: 8px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid #cfd5c4;
  background: #ffffff;
}

#ui-panel .accordion-section[data-accordion="body"] {
  border-top: none;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: linear-gradient(180deg, #fdfdf9 0%, #f4f7e8 100%);
  gap: 12px;
  border-bottom: 1px dashed #d7dcca;
}

.accordion-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
  padding: 4px 0;
  margin: -4px 0;
  border-radius: var(--radius-sm);
}

.accordion-toggle:hover {
  background: #f2f2e8;
}

.accordion-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  text-transform: none;
  letter-spacing: 0;
  border: none;
}

.accordion-header .accordion-icon {
  font-size: 10px;
  color: var(--color-text-muted);
  transition: transform 0.2s;
}

.accordion-section.expanded .accordion-icon {
  transform: rotate(180deg);
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.accordion-section.expanded .accordion-content {
  max-height: 800px;
}

.accordion-inner {
  padding: 12px 14px;
  background: #fbfcf6;
  border-top: 1px solid var(--color-border);
}

.control-item {
  margin-bottom: 14px;
}

.control-item:last-child {
  margin-bottom: 0;
}

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

input[type=number] {
  width: 56px;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-align: right;
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
}

input[type=number]:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

input[type=range] {
  display: block;
  width: 100%;
  cursor: pointer;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 999px;
  background: transparent;
}

input[type=range]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--color-primary) 0%,
    var(--color-primary) var(--range-progress, 50%),
    #d9dfcc var(--range-progress, 50%),
    #d9dfcc 100%
  );
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #ffffff;
  background: var(--color-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input[type=range]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: #d9dfcc;
}

input[type=range]::-moz-range-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--color-primary);
}

input[type=range]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #ffffff;
  background: var(--color-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
}

#body-scan-calib-which {
  width: auto;
  min-width: 90px;
}

.gender-select-row {
  margin-bottom: 12px;
  display: flex;
  justify-content: center;
}

.gender-radio-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #eef2e3;
  border: 1px solid #d6dcc7;
  border-radius: 12px;
  width: min(100%, 260px);
  box-sizing: border-box;
  overflow: hidden;
}

.gender-radio-label {
  display: block;
  cursor: pointer;
}

.gender-radio-label span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: 8px;
  background: transparent;
  color: #6a7361;
  font-size: 13px;
  font-weight: 700;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

input[name="gender-select"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

input[name="gender-select"]:checked + span {
  background: #ffffff;
  color: #2f2b35;
  box-shadow: 0 1px 2px rgba(48, 38, 59, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 700;
  border: none;
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.05s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-success);
  color: white;
  box-shadow: var(--shadow-sm);
  border: 1px solid #84d754;
}

.btn-primary:hover {
  background: var(--color-success-hover);
}

#btn-body-scan,
#btn-measure-tool {
  background: #c85bb8;
  border-color: #b44aa6;
  color: #ffffff;
}

.btn,
.primary-btn,
.secondary-btn,
.magic-btn,
.camera-controls button {
  height: 36px;
}

#btn-body-scan,
#btn-body-compute {
  font-size: 13px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
}

#btn-body-scan:hover,
#btn-measure-tool:hover {
  background: #b54ca6;
  color: #ffffff;
}

#btn-body-compute {
  background: #c85bb8 !important;
  border: 1px solid #b44aa6 !important;
  color: #ffffff !important;
  padding: 10px 18px !important;
  transition: background 0.2s, transform 0.05s !important;
}

#btn-body-compute:hover,
#btn-body-compute:focus,
#btn-body-compute:active {
  background: #b54ca6 !important;
  color: #ffffff !important;
}

#btn-body-compute:active {
  transform: scale(0.98) !important;
}

#btn-body-scan-calib,
#btn-body-scan-done {
  border: none !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  transition: background 0.2s, transform 0.05s !important;
}

#btn-body-scan-calib:hover,
#btn-body-scan-calib:focus,
#btn-body-scan-calib:active,
#btn-body-scan-done:hover,
#btn-body-scan-done:focus,
#btn-body-scan-done:active {
  transition: background 0.2s, transform 0.05s !important;
}

#btn-body-scan-calib:active,
#btn-body-scan-done:active {
  transform: scale(0.98) !important;
}

.btn-secondary {
  background: #efd2ed;
  color: var(--color-text);
}

.btn-secondary:hover {
  background: #ebc8e7;
}

.btn-accent {
  background: var(--color-primary);
  color: white;
  border: 1px solid #b46bc2;
}

.btn-accent:hover {
  background: var(--color-primary-hover);
}

.icon-btn {
  background: none;
  border: none;
  padding: 4px 8px;
  font-size: 18px;
  cursor: pointer;
  color: var(--color-text-muted);
  border-radius: var(--btn-radius);
  transition: color 0.2s, background 0.2s;
}

.icon-btn:hover {
  color: var(--color-text);
  background: #f1f5f9;
}

#bottom-ui {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 1000;
}

.legend-container {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.96);
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
}

.legend-gradient {
  width: 180px;
  height: 12px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--color-tight) 0%, #fff 50%, var(--color-loose) 100%);
  border: 1px solid var(--color-border);
}

.legend-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.camera-controls {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
}

.camera-controls button {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.camera-controls button:hover {
  background: #eef4dd;
}

#disclaimer-box {
  max-width: 280px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--color-success);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  z-index: 500;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text);
  animation: fadeIn 0.5s ease-out;
}

.disclaimer-icon { font-size: 20px; }
.disclaimer-content strong { color: var(--color-text); font-weight: 700; }

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

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(25, 25, 25, 0.55);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  backdrop-filter: blur(4px);
}

.modal-content.large-modal {
  width: 95%;
  max-width: 760px;
  max-height: 90vh;
  background: #f8faef;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 60px -12px rgba(0,0,0,0.3);
}

#body-scan-modal .modal-content.large-modal {
  max-width: 840px;
}

#body-scan-modal .modal-header {
  align-items: flex-start;
}

#body-scan-modal .body-scan-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

#body-scan-modal .body-scan-header h4 {
  line-height: 1.2;
}

#body-scan-modal .body-scan-header-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#body-scan-modal .body-scan-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

#body-scan-modal .body-scan-header-row--metrics {
  gap: 16px;
}

#measure-modal .modal-header {
  align-items: flex-start;
}

#measure-modal .modal-header h4 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.measure-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  min-width: 0;
}

.measure-header-title {
  white-space: nowrap;
  flex: 0 0 auto;
}

.measure-select {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: #fffefb;
  font-weight: 700;
  color: var(--color-text);
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.05);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
  flex: 0 1 auto;
  min-width: 0;
}

.measure-select:hover {
  border-color: rgba(194, 122, 210, 0.55);
}

.measure-select:focus-visible {
  outline: none;
  border-color: rgba(194, 122, 210, 0.85);
  box-shadow: 0 0 0 3px rgba(194, 122, 210, 0.18), 0 8px 18px rgba(0,0,0,0.06);
}

.measure-select:active {
  transform: scale(0.99);
}

#close-body-scan {
  align-self: flex-start;
  margin-top: -2px;
}

.modal-header {
  padding: 16px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.modal-body {
  flex-grow: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.body-scan-upload-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: flex-start;
  align-items: stretch;
  position: relative;
}

.body-scan-select-wrap {
  position: relative;
  min-width: 150px;
}

.body-scan-select--native {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.body-scan-select-trigger {
  width: 100%;
  min-height: 34px;
  padding: 6px 36px 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: #fffefb;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.05);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
  text-align: left;
}

.body-scan-select-trigger:hover {
  border-color: rgba(194, 122, 210, 0.55);
}

.body-scan-select-trigger:focus-visible {
  outline: none;
  border-color: rgba(194, 122, 210, 0.85);
  box-shadow: 0 0 0 3px rgba(194, 122, 210, 0.18), 0 8px 18px rgba(0,0,0,0.06);
}

.body-scan-select-trigger:active {
  transform: scale(0.99);
}

.body-scan-select-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.body-scan-select-chevron {
  position: absolute;
  right: 10px;
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath fill='%23555555' d='M5.3 7.7a1 1 0 0 1 1.4 0L10 11l3.3-3.3a1 1 0 1 1 1.4 1.4l-4 4a1 1 0 0 1-1.4 0l-4-4a1 1 0 0 1 0-1.4Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
  pointer-events: none;
}

.body-scan-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  border-radius: 14px;
  border: 1px solid rgba(216, 221, 208, 1);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 40px rgba(0,0,0,0.14);
  backdrop-filter: blur(12px);
  padding: 6px;
  max-height: 220px;
  overflow: auto;
  z-index: 2500;
}

.body-scan-select-option {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.body-scan-select-option:hover {
  background: rgba(194, 122, 210, 0.1);
}

.body-scan-select-option[aria-selected="true"] {
  background: rgba(159, 241, 104, 0.22);
}

.body-scan-modal-body {
  overflow-y: auto;
}

.body-scan-upload-zone {
  flex: 1;
  min-width: 200px;
  min-height: 140px;
  padding: 28px 24px !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  box-sizing: border-box;
}

.body-scan-zone-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  color: var(--color-text);
  font-family: var(--font-sans);
}

.body-scan-zone-placeholder p {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.body-scan-zone-placeholder p strong {
  font-size: 13px;
  font-weight: 600;
}

.body-scan-zone-placeholder small {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

#body-scan-front-placeholder > span,
#body-scan-side-placeholder > span {
  font-size: 26px !important;
}

.body-scan-zone-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
}

.body-scan-zone-preview canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 280px;
  max-height: 240px;
  border-radius: 4px;
  background: transparent;
}

.body-scan-processing {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 140px;
  border-radius: var(--radius-md);
  background: rgba(251, 252, 247, 0.88);
  backdrop-filter: blur(3px);
  color: var(--color-text);
  text-align: center;
  pointer-events: auto;
}

.body-scan-processing[hidden] {
  display: none;
}

.body-scan-processing .loading-spinner {
  width: 34px;
  height: 34px;
  border-width: 3px;
}

.body-scan-processing span {
  max-width: 220px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.body-scan-replace-link {
  font-size: 11px;
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
}

.body-scan-replace-link:hover { opacity: 0.8; }

.body-scan-toolbar {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.measure-upload-zone {
  min-height: 140px;
  padding: 28px 24px !important;
}

.body-scan-canvas-row {
  flex-direction: row !important;
}

.body-scan-preview-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  width: 100%;
}

.body-scan-preview-box {
  padding: 16px 20px;
  background: #30333c;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.body-scan-preview-label {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 4px;
}

.body-scan-side-upload {
  min-height: 100px !important;
  padding: 24px 20px !important;
}

#body-scan-side-area {
  min-width: 180px;
}

.body-scan-tips {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: #f3f7e8;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--color-text);
}

.body-scan-tips-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.body-scan-tips ul {
  margin: 10px 0 0 0;
  padding-left: 20px;
  line-height: 1.6;
}

.body-scan-tips li { margin-bottom: 4px; }

.body-scan-tips-compact {
  margin-bottom: 10px;
}

.body-scan-tips-compact ul { margin-top: 6px; }

.body-scan-tips-compact li { margin-bottom: 0; list-style: none; }

#body-scan-summary {
  white-space: pre-line;
  line-height: 1.4;
}

.upload-zone {
  border: 1px dashed #c5cfb8;
  border-radius: var(--radius-md);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #fbfcf7;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}

.upload-zone:hover {
  border-color: var(--color-primary);
  background: #f2e9f6;
}

.upload-zone input {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.canvas-wrapper {
  flex-grow: 1;
  background: linear-gradient(180deg, #2f3441 0%, #22252d 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 12px;
}

#measure-canvas {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 4px;
  cursor: crosshair;
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--color-surface);
  padding: 12px 14px;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid #d6dcc8;
}

.calib-block {
  background: #f1f6e5;
  border: 1px solid var(--color-border);
}

.instruction-badge {
  background: #f5f0fa;
  color: var(--color-text);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  border-left: 4px solid var(--color-primary);
}

.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(247, 249, 239, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#init-overlay {
  opacity: 1;
  pointer-events: auto;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay span {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
}

.primary-btn {
  background: var(--color-success) !important;
  color: white !important;
  padding: 10px 20px !important;
  font-weight: 600 !important;
  border-radius: var(--btn-radius) !important;
  cursor: pointer !important;
}

.primary-btn:disabled {
  opacity: 0.68;
  cursor: wait !important;
}

.secondary-btn {
  background: #f3d9f0 !important;
  color: var(--color-text) !important;
  font-weight: 500 !important;
  border-radius: var(--btn-radius) !important;
  cursor: pointer !important;
}

.magic-btn {
  background: linear-gradient(135deg, var(--color-primary), #8cb7ff) !important;
  color: white !important;
  font-weight: 600 !important;
  border-radius: var(--btn-radius) !important;
  cursor: pointer !important;
}

#toast-notification {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: #252525;
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 2100;
}

#toast-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.spinning::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  animation: button-spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes button-spin {
  to { transform: rotate(360deg); }
}

.mobile-topbar-title-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: calc(100% - 112px);
  padding: 0 56px;
}

.mobile-topbar-title-wrap .mobile-topbar-title {
  padding: 0;
  min-width: 0;
}

.mobile-topbar-title-wrap .ui-onboarding-help {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

@media (min-width: 1025px) {
  .mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--demo-topbar-h);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    z-index: 1900;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(216, 221, 208, 1);
    backdrop-filter: blur(12px);
  }

  .mobile-topbar-back {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 900;
    color: var(--color-primary);
    border: 1px solid #d8e2c8;
    background: #eef4dd;
    border-radius: var(--btn-radius);
  }

  .mobile-topbar-title {
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0;
    font-size: 16px;
    line-height: 1.1;
    color: var(--color-text);
    padding: 0 56px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #canvas-container {
    top: var(--demo-topbar-h);
  }

  #left-panel,
  #ui-panel {
    top: calc(var(--demo-topbar-h) + var(--demo-below-topbar-gap));
  }

  .btn-exit-demo {
    display: none;
  }
}


@media (max-width: 1024px) {
  :root {
    --mobile-sheet-peek: 124px;
  }

  body:not(.mobile-ui-ready) #left-panel,
  body:not(.mobile-ui-ready) #ui-panel {
    display: none !important;
  }

  html.mobile-ui-pending #left-panel,
  html.mobile-ui-pending #ui-panel {
    display: none !important;
  }

  #init-overlay {
    display: none;
  }

  html.mobile-ui-pending #init-overlay {
    display: flex;
    opacity: 1;
    pointer-events: auto;
  }

  html.mobile-ui-ready #init-overlay {
    display: none;
  }

  .mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--demo-topbar-h) + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    z-index: 1900;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(216, 221, 208, 1);
    backdrop-filter: blur(12px);
  }

  .mobile-topbar-back {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 900;
    color: var(--color-primary);
    border: 1px solid #d8e2c8;
    background: #eef4dd;
    border-radius: var(--btn-radius);
  }

  .mobile-topbar-title {
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0;
    font-size: 16px;
    line-height: 1.1;
    color: var(--color-text);
    padding: 0 56px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #canvas-container {
    top: calc(var(--demo-topbar-h) + env(safe-area-inset-top));
  }

  #left-panel {
    width: calc(100% - 16px);
    max-width: 340px;
    left: 8px;
  }

  #ui-panel {
    width: calc(100% - 16px);
    max-width: 340px;
    right: 8px;
  }

  #disclaimer-box {
    max-width: none;
    font-size: 12px;
  }

  #bottom-ui {
    bottom: calc(var(--mobile-sheet-peek) + 16px);
  }

  .legend-container {
    padding: 8px 14px;
  }

  .camera-controls button {
    padding: 10px 14px;
    min-height: 44px;
  }

  .mobile-sheet[hidden] {
    display: none !important;
  }

  .mobile-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 85vh;
    transform: translateY(calc(100% - var(--mobile-sheet-peek)));
    transition: transform 0.22s ease;
    z-index: 1500;
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
    background: rgba(255, 255, 255, 0.92);
    border-top: 1px solid rgba(216, 221, 208, 1);
    box-shadow: 0 -14px 34px rgba(0,0,0,0.18);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mobile-sheet.is-expanded {
    transform: translateY(0);
  }

  .mobile-sheet-handle {
    appearance: none;
    border: none;
    background: transparent;
    padding: 10px 0 2px;
    cursor: pointer;
    touch-action: none;
  }

  .mobile-sheet-grabber {
    display: block;
    width: 46px;
    height: 5px;
    margin: 0 auto;
    border-radius: 999px;
    background: rgba(93, 93, 93, 0.32);
  }

  .mobile-sheet-header {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 12px;
    border-bottom: 1px solid rgba(216, 221, 208, 1);
    background: rgba(255, 255, 255, 0.86);
  }

  .mobile-sheet-back,
  .mobile-sheet-header-spacer {
    display: none;
  }

  .mobile-sheet-header {
    grid-template-columns: 1fr;
  }

  .mobile-sheet-back {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 900;
    color: var(--color-primary);
    border: 1px solid #d8e2c8;
    background: #eef4dd;
    border-radius: var(--btn-radius);
  }

  .mobile-sheet-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: rgba(238, 242, 227, 0.9);
    border: 1px solid #d6dcc7;
    border-radius: 14px;
    padding: 4px;
  }

  .mobile-sheet-tab {
    border: none;
    background: transparent;
    border-radius: 10px;
    min-height: 36px;
    font-size: 13px;
    font-weight: 800;
    color: #6a7361;
    cursor: pointer;
  }

  .mobile-sheet-tab.is-active {
    background: #ffffff;
    color: #2f2b35;
    box-shadow: 0 1px 2px rgba(48, 38, 59, 0.12);
  }

  .mobile-sheet-header-spacer {
    width: 40px;
    height: 40px;
  }

  .mobile-sheet-body {
    padding: 12px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
  }

  #left-panel,
  #ui-panel {
    position: static;
    width: 100%;
    max-width: none;
    max-height: none;
    overflow: visible;
    left: auto;
    right: auto;
    top: auto;
  }

  .btn-exit-demo {
    display: none;
  }

  body.mobile-sheet-expanded #bottom-ui {
    opacity: 0;
    pointer-events: none;
  }
}

html.ui-pending #init-overlay {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

html.ui-ready #init-overlay {
  display: none;
}

@media (max-width: 820px) {
  #body-scan-modal .modal-content.large-modal {
    width: calc(100% - 16px);
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 22px;
  }

  #body-scan-modal .modal-header {
    padding: 12px 14px;
  }


  #body-scan-modal .body-scan-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
  }

  #body-scan-modal .body-scan-header-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  #body-scan-modal .body-scan-header-row {
    flex-wrap: wrap;
    gap: 10px;
  }

  #body-scan-modal .body-scan-select-wrap {
    min-width: 132px;
  }

  .body-scan-select-trigger {
    font-size: 14px;
  }

  #body-scan-modal .modal-body {
    padding: 14px;
  }

  .body-scan-tips {
    font-size: 12px;
  }

  .body-scan-tips ul {
    padding-left: 18px;
  }

  .body-scan-upload-row {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 12px;
  }

  .body-scan-upload-zone {
    min-width: 0;
    width: 100%;
    padding: 18px 14px !important;
  }

  .body-scan-side-upload {
    min-height: 120px !important;
    padding: 18px 14px !important;
  }

  .body-scan-zone-preview {
    width: 100%;
  }

  .body-scan-zone-preview canvas {
    max-height: 34vh;
    max-width: 160px;
    width: auto;
    height: auto;
  }

  #body-scan-summary {
    font-size: 12px;
  }

  #body-scan-params {
    flex-wrap: wrap !important;
    gap: 10px !important;
    align-items: flex-end;
  }

  #body-scan-params > div {
    flex: 1 1 140px;
    min-width: 140px;
  }
}

@media (max-width: 420px) {
  #body-scan-modal {
    padding-left: 0;
    padding-right: 0;
  }

  #body-scan-modal .modal-content.large-modal {
    width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 0;
  }

  #body-scan-modal .body-scan-header-controls {
    gap: 8px;
  }

  #body-scan-modal .body-scan-select-wrap {
    min-width: 120px;
  }
}

@media (hover: none) {
  .upload-zone:hover {
    border-color: #c5cfb8;
    background: #fbfcf7;
  }
}

@media (max-width: 1024px) and (min-width: 821px) {
  #body-scan-params {
    flex-wrap: wrap !important;
    gap: 10px !important;
    align-items: flex-end;
  }

  #body-scan-params > div {
    flex: 1 1 160px;
    min-width: 160px;
  }
}
.clothing-type-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto;
}

.type-card-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: #ffffff;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.type-card-btn:hover {
  border-color: var(--color-primary);
  background: #fdfafc;
  transform: translateY(-2px);
}

.type-card-btn .type-icon {
  font-size: 32px;
}

.type-card-btn .type-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
  display: block;
}

.type-card-btn .type-desc {
  font-size: 13px;
  color: var(--color-text-muted);
}

.magic-btn {
  color: #171717 !important;
}

button:disabled,
.btn:disabled,
.secondary-btn:disabled,
.primary-btn:disabled,
.icon-btn:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
  filter: grayscale(100%);
}
