:root {
  --bg: var(--tg-theme-bg-color, #f7f5f8);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #222);
  --hint: var(--tg-theme-hint-color, #888);
  --accent: var(--tg-theme-button-color, #c2528b);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --ref: #e53935;
  --good: #2e7d32;
  --bad: #e65100;
  --body-fill: rgba(194, 82, 139, 0.15);
  --body-stroke: #c2528b;
  --skin: #f2d7c2;
  --hair: #7a4a33;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: 70px;
}
header { padding: 14px 16px 8px; }
header h1 { font-size: 1.15rem; }
main { padding: 0 12px; }
.card {
  background: var(--card); border-radius: 14px; padding: 14px;
  margin: 10px 0; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h2 { font-size: .95rem; margin-bottom: 10px; }
.hint { color: var(--hint); font-size: .8rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label.field { display: block; font-size: .8rem; color: var(--hint); }
label.field input[type=number] {
  width: 100%; padding: 8px; margin-top: 3px; border: 1px solid #d8d3dc;
  border-radius: 9px; font-size: 1rem; background: transparent; color: var(--text);
}
button.primary {
  background: var(--accent); color: var(--accent-text); border: 0;
  padding: 10px 16px; border-radius: 10px; font-size: .95rem; margin-top: 10px;
}
button.ghost {
  background: transparent; border: 1px solid var(--accent); color: var(--accent);
  padding: 8px 14px; border-radius: 10px; font-size: .9rem;
}
button:disabled { opacity: .5; }
nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--card); border-top: 1px solid rgba(0,0,0,.08);
}
nav button {
  flex: 1; background: none; border: 0; padding: 10px 4px 12px;
  font-size: .8rem; color: var(--hint);
}
nav button.active { color: var(--accent); font-weight: 600; }
section.tab { display: none; }
section.tab.active { display: block; }
.toggle-group { display: flex; gap: 6px; margin: 8px 0; }
.toggle-group button { flex: 1; }
.toggle-group button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.legend { display: flex; gap: 14px; font-size: .75rem; color: var(--hint); margin-top: 6px; }
.legend .swatch { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; }
.ok-note { color: var(--good); font-size: .85rem; margin-left: 8px; }
.photo-thumb { width: 84px; height: 112px; object-fit: cover; border-radius: 8px; background: #ddd; }
.photo-date-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid rgba(0,0,0,.06); }
.switch { margin-left: auto; font-size: .8rem; color: var(--hint); display: flex; align-items: center; gap: 6px; }
#consent-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none;
  align-items: flex-end; justify-content: center; z-index: 50;
}
#consent-modal.open { display: flex; }
#consent-modal .sheet {
  background: var(--card); border-radius: 16px 16px 0 0; padding: 18px;
  max-height: 85vh; overflow-y: auto; width: 100%; max-width: 560px;
}
#consent-modal p { white-space: pre-line; font-size: .9rem; margin: 10px 0; }
#fatal {
  position: fixed; inset: 0; background: var(--bg); z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 24px; text-align: center;
}
#fatal.open { display: flex; }
#movie-overlay {
  position: fixed; inset: 0; background: #000; z-index: 60; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
#movie-overlay.open { display: flex; }
#movie-canvas { max-width: 100%; max-height: 78vh; border-radius: 8px; }
#movie-overlay .row { justify-content: center; }
svg.chart { width: 100%; height: auto; }
#body-svg { display: block; max-width: 460px; margin: 0 auto; }
.chart-wrap { position: relative; max-width: 590px; margin: 0 auto; }
.chart-wrap img { display: block; width: 100%; height: auto; border-radius: 8px; }
.chart-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; }
table.meas { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.meas td, table.meas th { padding: 6px 4px; text-align: right; border-top: 1px solid rgba(0,0,0,.06); }
table.meas th:first-child, table.meas td:first-child { text-align: left; }
.delta-neg { color: var(--good); font-weight: 600; }
.delta-pos { color: var(--bad); font-weight: 600; }
.wizard-preview { width: 100%; max-height: 320px; object-fit: contain; border-radius: 10px; margin-top: 8px; }
.feedback { background: rgba(194,82,139,.08); border-radius: 10px; padding: 10px; font-size: .85rem; margin-top: 8px; }
.warn { background: rgba(230,81,0,.1); color: var(--bad); border-radius: 10px; padding: 10px; font-size: .85rem; margin-top: 8px; }
