/* =========================================================
   青少年基础运动能力测评 — 移动优先样式
   设计基准：375px 宽（iPhone SE/13 mini 等），最大宽度 520px 居中
   ========================================================= */

:root {
  --c-bg: #f4f7f4;
  --c-surface: #ffffff;
  --c-ink: #16211d;
  --c-ink-2: #4a5c55;
  --c-ink-3: #85958f;
  --c-line: #e3eae5;
  --c-primary: #0e7c66;
  --c-primary-d: #0a5f4e;
  --c-primary-l: #e6f4f0;
  --c-accent: #f08c3c;
  --c-accent-l: #fdf0e4;
  --c-danger: #d9534f;
  --c-good: #2fa36b;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 6px 24px rgba(20, 50, 40, .07);
  --shadow-lg: 0 12px 40px rgba(20, 50, 40, .14);
  --tap: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 统一处理 hidden：避免被 display:flex 等规则覆盖导致「隐藏元素仍拦截点击」 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

#app {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b));
}

/* ---------------- 屏幕切换 ---------------- */
.screen { display: none; animation: fade .28s ease both; }
.screen.is-active { display: block; }
.screen--center.is-active { display: flex; align-items: center; justify-content: center; min-height: 70dvh; }
.screen--capture.is-active { display: flex; flex-direction: column; }

@keyframes fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------------- 通用元件 ---------------- */
.hl { color: var(--c-primary); font-weight: 600; }
.hidden-file { display: none; }

.card {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card__title { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.card__note { font-size: 12px; color: var(--c-ink-3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform .12s ease, background .18s ease, opacity .18s ease;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary { background: var(--c-primary); color: #fff; box-shadow: 0 8px 20px rgba(14, 124, 102, .24); }
.btn--primary:active:not(:disabled) { background: var(--c-primary-d); }

.btn--ghost {
  background: #fff;
  color: var(--c-primary);
  border: 1.5px solid var(--c-primary);
}
.btn--text { background: transparent; color: var(--c-ink-2); font-weight: 500; }

.btn--lg { min-height: 60px; font-size: 18px; border-radius: 16px; }
.btn--sm { min-height: 44px; font-size: 15px; width: auto; padding: 0 18px; }

.link-btn {
  background: none; border: 0; padding: 10px 6px;
  color: var(--c-primary); font-size: 14px; font-family: inherit;
  cursor: pointer; min-height: 44px;
}
.link-btn__sep { color: var(--c-line); }

.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: #fff; color: var(--c-ink); font-size: 24px; line-height: 1;
  box-shadow: var(--shadow); cursor: pointer; padding: 0 0 3px;
}

/* ---------------- 1. 信息登记 ---------------- */
.hero { padding: 8px 2px 18px; }
.hero__badge {
  display: inline-block; margin: 0 0 10px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--c-primary-l); color: var(--c-primary);
  font-size: 12px; font-weight: 700; letter-spacing: .5px;
}
.hero__title { margin: 0 0 6px; font-size: 26px; line-height: 1.25; letter-spacing: -.4px; }
.hero__desc { margin: 0; font-size: 14px; color: var(--c-ink-2); }

.form { padding: 18px 16px 16px; }
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; margin-bottom: 16px; }

.field__label {
  display: block; margin-bottom: 7px;
  font-size: 14px; font-weight: 600; color: var(--c-ink-2);
}
.unit { margin-left: 4px; font-size: 12px; color: var(--c-ink-3); font-weight: 400; }

.input {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1.5px solid var(--c-line);
  border-radius: 12px;
  background: #fbfdfc;
  font-size: 17px;
  font-family: inherit;
  color: var(--c-ink);
  transition: border-color .16s ease, background .16s ease;
  appearance: none;
}
.input::placeholder { color: #b3c0ba; font-size: 15px; }
.input:focus { outline: none; border-color: var(--c-primary); background: #fff; }
.input.is-error { border-color: var(--c-danger); background: #fff7f7; }

.field__hint {
  margin: 6px 0 0; font-size: 11.5px; color: var(--c-ink-3); line-height: 1.4;
}

.field__err {
  margin: 6px 0 0; min-height: 0; font-size: 12.5px; color: var(--c-danger);
}
.field__err:empty { display: none; }

.segment { display: flex; gap: 8px; }
.segment__item {
  flex: 1; min-height: 52px;
  border: 1.5px solid var(--c-line);
  border-radius: 12px;
  background: #fbfdfc;
  font-size: 16px; font-family: inherit; font-weight: 600;
  color: var(--c-ink-2);
  cursor: pointer;
  transition: all .16s ease;
}
.segment__item.is-active {
  border-color: var(--c-primary);
  background: var(--c-primary-l);
  color: var(--c-primary-d);
}

.form .btn--primary { margin-top: 4px; }

.privacy {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 12px 0 0; font-size: 12.5px; color: var(--c-ink-3);
}
.privacy__dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--c-good); flex: none;
}

/* 模型下载状态 */
.model-chip {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 4px auto 18px;
  padding: 7px 14px;
  width: fit-content; max-width: 100%;
  border-radius: 999px;
  background: #fff; color: var(--c-ink-2);
  font-size: 12.5px;
  box-shadow: 0 2px 10px rgba(20, 50, 40, .05);
  transition: opacity .3s ease;
}
.model-chip[data-state="ready"] { color: var(--c-good); }
.model-chip[data-state="error"] { color: var(--c-accent); }
.model-chip__spinner {
  width: 12px; height: 12px; flex: none;
  border: 2px solid var(--c-line); border-top-color: var(--c-primary);
  border-radius: 50%; animation: spin 1s linear infinite;
}
.model-chip[data-state="ready"] .model-chip__spinner { display: none; }
.model-chip[data-state="error"] .model-chip__spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.tips { padding: 0 4px 8px; }
.tips__title { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--c-ink-3); letter-spacing: .5px; }
.tips__list { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--c-ink-2); }
.tips__list li { margin-bottom: 6px; }

/* ---------------- 2/3. 拍摄页 ---------------- */
.capture__top {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.capture__step { flex: 1; text-align: center; font-size: 13px; color: var(--c-ink-3); }
.capture__step b { color: var(--c-primary); }
.capture__spacer { width: 40px; }

.capture__head { margin-bottom: 12px; }
.capture__title {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 6px; font-size: 22px; font-weight: 700;
}
.tag {
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .3px;
}
.tag--side { background: var(--c-accent-l); color: #b8621b; }
.tag--front { background: var(--c-primary-l); color: var(--c-primary); }

.capture__hint { margin: 0; font-size: 13.5px; color: var(--c-ink-2); line-height: 1.5; }

.stage {
  position: relative;
  width: 100%;
  /* 宽高比由 JS 按摄像头实际输出动态设置（--stage-ar），
     比例一致 + object-fit: contain，才能保证画面不被裁切放大。
     兜底 0.75（3:4），与手机 4:3 传感器竖屏一致。 */
  aspect-ratio: var(--stage-ar, 0.75);
  max-width: calc(58dvh * var(--stage-ar, 0.75));
  margin-inline: auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0b100e;
  box-shadow: var(--shadow-lg);
}
@supports not (aspect-ratio: 1) {
  .stage { height: 58dvh; }
}

.stage__video, .stage__canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  /* contain：完整显示摄像头画面，绝不裁切（裁切 = 视觉上的数码变焦） */
  object-fit: contain;
  display: block;
}
.stage__video { transform: scaleX(-1); }          /* 前置摄像头镜像，符合用户直觉 */
.stage[data-mirror="off"] .stage__video { transform: none; }

.stage__frame { position: absolute; inset: 10% 12%; pointer-events: none; }
.stage__frame span {
  position: absolute; width: 26px; height: 26px;
  border: 2.5px solid rgba(255, 255, 255, .55);
}
.stage__frame span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.stage__frame span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.stage__frame span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.stage__frame span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

.stage__status {
  position: absolute; left: 10px; top: 10px;
  display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 20px);
  padding: 6px 11px; border-radius: 999px;
  background: rgba(10, 20, 16, .58);
  backdrop-filter: blur(6px);
  color: #fff; font-size: 12px;
  transition: background .2s;
}
.stage__status[data-ok="1"] { background: rgba(14, 124, 102, .82); }
.stage__status[data-ok="0"] { background: rgba(190, 96, 20, .82); }
.dot {
  width: 7px; height: 7px; border-radius: 50%; background: #ffd166; flex: none;
  box-shadow: 0 0 0 0 rgba(255, 209, 102, .6);
  animation: pulse 1.6s infinite;
}
.stage__status[data-ok="1"] .dot { background: #7ef0c9; animation: none; }
.stage__status[data-ok="0"] .dot { background: #ffd8b0; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 209, 102, .55); }
  70%  { box-shadow: 0 0 0 7px rgba(255, 209, 102, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0); }
}

.stage__counter {
  position: absolute; right: 10px; bottom: 10px;
  display: flex; align-items: baseline; gap: 2px;
  padding: 6px 11px; border-radius: 999px;
  background: rgba(10, 20, 16, .58);
  backdrop-filter: blur(6px);
  color: #fff; font-variant-numeric: tabular-nums;
}
.stage__counter b { font-size: 15px; }
.stage__counter span { font-size: 11px; opacity: .7; }
.stage__counter em { margin-left: 8px; font-size: 11px; font-style: normal; opacity: .65; }

.stage__fallback {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 24px; text-align: center;
  background: linear-gradient(180deg, #1b2422, #131a18);
  color: #fff;
}
.stage__fallback-icon { font-size: 34px; opacity: .85; }
.stage__fallback-title { margin: 4px 0 0; font-size: 16px; font-weight: 700; }
.stage__fallback-desc { margin: 0 0 12px; font-size: 13px; color: rgba(255, 255, 255, .68); line-height: 1.5; }
.stage__fallback .btn--ghost { background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .45); }

.capture__actions { padding: 16px 0 4px; }
.capture__sub-actions {
  display: flex; align-items: center; justify-content: center; gap: 2px;
  margin-top: 6px;
}

/* ---------------- 4. 分析中 ---------------- */
.analyzing { width: 100%; text-align: center; padding: 20px 4px; }
.analyzing__ring {
  position: relative; width: 86px; height: 86px; margin: 0 auto 22px;
  border-radius: 50%;
  border: 3px solid var(--c-primary-l);
}
.analyzing__ring::after {
  content: ""; position: absolute; inset: -3px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--c-primary);
  animation: spin 1.05s linear infinite;
}
.analyzing__pulse {
  position: absolute; inset: 22px; border-radius: 50%;
  background: var(--c-primary-l);
  animation: breathe 1.6s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(.72); opacity: .55; }
  50%      { transform: scale(1); opacity: 1; }
}
.analyzing__title { margin: 0 0 22px; font-size: 17px; font-weight: 600; }
.progress {
  height: 10px; border-radius: 99px; background: #e6ece8; overflow: hidden;
  max-width: 300px; margin: 0 auto 12px;
}
.progress__bar {
  height: 100%; width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #17a184, #0e7c66);
  transition: width .45s cubic-bezier(.3, .8, .3, 1);
}
.analyzing__step { margin: 0; font-size: 13px; color: var(--c-ink-3); min-height: 20px; }

/* ---------------- 5. 结果 ---------------- */
.result-head { text-align: center; padding: 6px 0 20px; }
.result-head__label {
  margin: 0 0 12px; font-size: 12px; font-weight: 700; letter-spacing: 2px;
  color: var(--c-ink-3); text-transform: uppercase;
}
.grade {
  display: inline-flex; flex-direction: column; align-items: center;
  padding: 16px 34px; border-radius: 24px;
  background: #fff; box-shadow: var(--shadow);
  border: 2px solid var(--c-line);
}
.grade__score {
  font-size: 42px; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -1px;
}
.grade__label {
  margin-top: 6px; font-size: 15px; font-weight: 700; letter-spacing: 2px;
}
.grade[data-level="excellent"] { border-color: #bfe8d4; }
.grade[data-level="excellent"] .grade__score,
.grade[data-level="excellent"] .grade__label { color: #12805a; }
.grade[data-level="good"] { border-color: #f8ddc0; }
.grade[data-level="good"] .grade__score,
.grade[data-level="good"] .grade__label { color: #b8621b; }
.grade[data-level="fair"] { border-color: #d8e2dd; }
.grade[data-level="fair"] .grade__score,
.grade[data-level="fair"] .grade__label { color: #3d554c; }
.result-head__sub { margin: 12px 0 0; font-size: 13px; color: var(--c-ink-3); }
.result-head__basis {
  display: inline-block; margin: 8px 0 0; padding: 4px 10px;
  font-size: 11.5px; color: var(--c-primary); line-height: 1.4;
  background: var(--c-primary-l); border-radius: 999px;
}
.result-head__basis:empty { display: none; }

.pill {
  padding: 4px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
  background: var(--c-primary-l); color: var(--c-primary-d);
}
.pill[data-cat="thin"] { background: #eaf3fb; color: #2a6ea6; }
.pill[data-cat="normal"] { background: #e6f4ee; color: #12805a; }
.pill[data-cat="over"] { background: var(--c-accent-l); color: #b8621b; }
.pill[data-cat="obese"] { background: #fdecec; color: #c0453f; }

.bmi { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.bmi__value { font-size: 34px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.bmi__advice { margin: 0; font-size: 13.5px; color: var(--c-ink-2); line-height: 1.5; }
.bmi__basis { margin: 10px 0 0; font-size: 11.5px; color: var(--c-ink-3); }
.bmi__basis:empty { display: none; }

.bmi-bar__track {
  position: relative; display: flex; height: 8px; border-radius: 99px;
  overflow: hidden; background: #eef2ef;
}
.bmi-bar__zone { height: 100%; }
.bmi-bar__zone--thin   { flex: 21.5; background: #bcd8ee; }
.bmi-bar__zone--normal { flex: 30.5; background: #9fd9bf; }
.bmi-bar__zone--over   { flex: 22;   background: #f6c99a; }
.bmi-bar__zone--obese  { flex: 26;   background: #eda4a1; }
.bmi-bar__marker {
  position: absolute; top: -3px; left: 0;
  width: 4px; height: 14px; border-radius: 3px;
  background: #16211d; box-shadow: 0 0 0 2px #fff;
  transform: translateX(-2px);
  transition: left .5s cubic-bezier(.3, .8, .3, 1);
}
.bmi-bar__labels {
  display: flex; margin-top: 6px;
  font-size: 11px; color: var(--c-ink-3);
}
.bmi-bar__labels span { flex: 1; text-align: center; }

.radar { width: 100%; height: 300px; }
.dims { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 8px; }
.dim {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--c-ink-2);
}
.dim__name { flex: none; width: 5.4em; }
.dim__track { flex: 1; height: 6px; border-radius: 99px; background: #eef2ef; overflow: hidden; }
.dim__fill { height: 100%; border-radius: 99px; background: var(--c-primary); transition: width .6s ease; }
.dim__num { flex: none; width: 2.2em; text-align: right; font-weight: 700; color: var(--c-ink); font-variant-numeric: tabular-nums; }

.report { margin: 0; padding: 0; list-style: none; }
.report li {
  position: relative;
  padding: 0 0 12px 22px;
  font-size: 14px; color: var(--c-ink-2); line-height: 1.6;
}
.report li:last-child { padding-bottom: 0; }
.report li::before {
  content: ""; position: absolute; left: 4px; top: 8px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--c-primary); opacity: .55;
}
.report li b { color: var(--c-ink); }

.result-actions { padding: 6px 0 10px; }
.result-actions__note {
  margin: 12px 0 0; text-align: center; font-size: 11.5px; color: var(--c-ink-3);
}

/* ---------------- 遮罩 & 提示 ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(12, 22, 19, .45);
  backdrop-filter: blur(3px);
  animation: fade .2s ease both;
}
.overlay__card {
  width: 100%; max-width: 320px;
  padding: 26px 22px;
  border-radius: 20px; background: #fff;
  text-align: center; box-shadow: var(--shadow-lg);
}
.overlay__spinner {
  width: 34px; height: 34px; margin: 0 auto 16px;
  border: 3px solid #eef2ef; border-top-color: var(--c-primary);
  border-radius: 50%; animation: spin .9s linear infinite;
}
.overlay__title { margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.overlay__desc { margin: 0; font-size: 13px; color: var(--c-ink-3); line-height: 1.5; }
.overlay__actions { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.overlay__actions .btn { width: 100%; }

.toast {
  /* 顶部提示：避免遮住底部主按钮 */
  position: fixed; left: 50%; top: calc(14px + var(--safe-t));
  transform: translate(-50%, -14px);
  max-width: calc(100% - 48px);
  padding: 11px 18px; border-radius: 12px;
  background: rgba(20, 32, 28, .92); color: #fff;
  font-size: 13.5px; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .24s ease, transform .24s ease;
  z-index: 60;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 大屏微调 ---------------- */
@media (min-width: 480px) {
  .hero__title { font-size: 30px; }
  .radar { height: 340px; }
  .dims { grid-template-columns: 1fr 1fr 1fr; }
}

@media (max-width: 340px) {
  .hero__title { font-size: 22px; }
  .capture__title { font-size: 19px; }
  .bmi__value { font-size: 29px; }
  .grade__score { font-size: 36px; }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
