*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --red: #dc2626;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.10);
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--gray-800);
  background: var(--gray-50);
}

/* ── Screens ── */
.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.screen.hidden { display: none; }

/* ── Cards ── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 720px;
}
.card--narrow { max-width: 400px; }
.card--wide   { max-width: 960px; }

/* ── Logo / brand ── */
.logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
}
.logo h1 { font-size: 1.25rem; font-weight: 700; }
.subtitle { color: var(--gray-600); font-size: .9rem; margin-bottom: 1.5rem; }

/* ── Form fields ── */
.field { margin-bottom: 1.25rem; }
.field label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  margin-bottom: .4rem;
  color: var(--gray-800);
}
input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--blue); }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

.input-group { position: relative; }
.input-group input { padding-right: 2.8rem; }
.input-suffix {
  position: absolute; right: .9rem; top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400); font-size: .9rem; pointer-events: none;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; font-size: .95rem; font-weight: 600;
  padding: .65rem 1.25rem; border-radius: 8px;
  border: none; cursor: pointer; text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary  { background: var(--blue); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn--secondary { background: var(--gray-100); color: var(--gray-800); border: 1.5px solid var(--gray-200); }
.btn--secondary:hover:not(:disabled) { background: var(--gray-200); }
.btn--ghost { background: transparent; color: var(--gray-600); }
.btn--ghost:hover { color: var(--gray-800); background: var(--gray-100); }
.btn--full { width: 100%; }
.btn--sm { font-size: .8rem; padding: .4rem .85rem; }

/* ── Error ── */
.error {
  color: var(--red); font-size: .875rem;
  background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 6px; padding: .6rem .85rem;
  margin-bottom: 1rem;
}
.error.hidden { display: none; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 1.25rem;
  overflow: hidden;
  transition: border-color .15s;
}
.upload-zone:hover { border-color: var(--blue); }

.upload-placeholder {
  display: flex; flex-direction: column; align-items: center;
  gap: .5rem; padding: 2rem 1rem; color: var(--gray-600);
  font-size: .95rem; font-weight: 500;
}
.upload-hint { font-size: .8rem; color: var(--gray-400); font-weight: 400; }

.image-preview {
  position: relative;
}
.image-preview img {
  width: 100%; max-height: 320px;
  object-fit: cover; display: block;
}
.image-preview .btn {
  position: absolute; top: .6rem; right: .6rem;
  background: rgba(255,255,255,.85); backdrop-filter: blur(4px);
}
.image-preview.hidden { display: none; }

/* ── Capture header ── */
.capture-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.capture-header h2 { font-size: 1.15rem; font-weight: 700; }

/* ── Results layout ── */
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .75rem;
  margin-bottom: 1.5rem;
}
.meta-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--gray-100); border-radius: 99px;
  padding: .3rem .85rem; font-size: .875rem;
}

.results-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ── SVG silhouette ── */
.silhouette-wrap {
  background: var(--gray-50);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex; align-items: center; justify-content: center;
}
#body-svg {
  width: 100%;
  max-height: 480px;
}

/* ── Measurement panel ── */
.panel-title {
  font-size: .95rem; font-weight: 700;
  color: var(--gray-600); text-transform: uppercase;
  letter-spacing: .05em; margin-bottom: .75rem;
}

.m-list { display: flex; flex-direction: column; gap: .1rem; }
.m-list--compact { margin-top: .5rem; gap: .05rem; }

.m-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .75rem; border-radius: 8px;
  cursor: default; transition: background .12s;
}
.m-item:hover { background: var(--gray-50); }
.m-item.highlighted { background: #fef2f2; }

.m-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0; opacity: 0.35;
  transition: opacity .15s;
}
.m-item:hover .m-dot, .m-item.highlighted .m-dot { opacity: 1; }

.m-name { flex: 1; font-size: .9rem; color: var(--gray-600); }
.m-val  { font-size: .95rem; font-weight: 700; color: var(--gray-800); min-width: 4rem; text-align: right; }

/* ── Alts ── */
.alts-toggle-btn { margin-top: 1rem; width: 100%; justify-content: center; }
.alts-content { margin-top: .75rem; }
.alts-set { margin-bottom: 1rem; }
.alts-set h4 {
  font-size: .8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--gray-400); margin-bottom: .35rem;
}
.alts-content.hidden { display: none; }

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(255,255,255,.85); backdrop-filter: blur(4px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1rem;
  font-weight: 600; color: var(--gray-600);
}
.loading-overlay.hidden { display: none; }

.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ── */
.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;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .card { padding: 1.25rem; border-radius: 0; box-shadow: none; min-height: 100dvh; }
  .card--wide { padding: 1rem; }
  .results-body { grid-template-columns: 1fr; }
  .silhouette-wrap { padding: .5rem; }
  #body-svg { max-height: 320px; }
  .screen { padding: 0; align-items: flex-start; }
}
