/* ============================================================
   体感游泳互动页 · 横屏 H5
   设计基准 1280×720：左 35% 相机区 / 右 65% 泳道区
   ============================================================ */

:root {
  --bg-deep: #071F2E;
  --accent: #FFC94A;
  --skel: #7CF5C8;
  --ink: #FFFFFF;
  --ink-dim: rgba(255, 255, 255, 0.75);
  --ink-faint: rgba(255, 255, 255, 0.45);
  --divider: rgba(255, 255, 255, 0.12);
  --pad-l: env(safe-area-inset-left, 0px);
  --pad-r: env(safe-area-inset-right, 0px);
  --pad-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

/* ---------------- 布局 ---------------- */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  padding-left: var(--pad-l);
  padding-right: var(--pad-r);
  padding-bottom: var(--pad-b);
}

#stage-camera {
  flex: 0 0 35%;
  position: relative;
  background: var(--bg-deep);
  border-right: 2px solid var(--divider);
  display: flex;
  flex-direction: column;
  padding: 8px 10px 10px;
  gap: 6px;
  min-width: 0;
}

#stage-pool {
  flex: 1 1 65%;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------------- 相机区 ---------------- */

#cam-wrap { flex: 1 1 auto; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }

/* 前置摄像头镜像：video + 骨架 canvas 一起翻转 */
#cam-mirror { position: relative; transform: scaleX(-1); }
/* ?cam=back（后置）：不做镜像，画面方向与实际一致 */
body.no-mirror #cam-mirror { transform: none; }

#cam {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;          /* 必须完整显示，禁止裁切 —— 全身入镜是识别前提 */
  background: #04141F;
  border-radius: 8px;
}

#overlay {
  position: absolute;
  left: 0; top: 0;
  pointer-events: none;
  border-radius: 8px;
}

#cam-mask {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 20, 31, 0.62);
  border-radius: 8px;
  font-size: 14px;
  letter-spacing: .5px;
  color: var(--ink);
}
#cam-mask span {
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 999px;
  background: rgba(7, 31, 46, .7);
  /* 英文文案比中文长，限宽换行避免撑出相机区 */
  max-width: 88%;
  text-align: center;
  line-height: 1.45;
  /* 父层 #cam-mirror 整体 scaleX(-1) 做画面镜像，文字要反向翻回来，否则是镜像字 */
  transform: scaleX(-1);
}
/* ?cam=back（后置）时父层不镜像，这里也不能翻 */
body.no-mirror #cam-mask span { transform: none; }

.hidden { display: none !important; }

/* 状态行 */
#cam-status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  font-size: 11px;
  line-height: 1;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}
#cam-status .sep { width: 1px; height: 11px; background: var(--divider); }
#cam-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #5A6B78; flex: 0 0 auto;
  transition: background .2s, box-shadow .2s;
}
#cam-status .dot.on { background: var(--skel); box-shadow: 0 0 6px rgba(124, 245, 200, .7); }
#cam-status .dot.off { background: #FF5C5C; }

/* 调试信息默认关闭，?debug=1 打开 */
.debug-only { display: none; }
body.debug .debug-only { display: inline; }

/* 控制行 */
#cam-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .07);
  color: var(--ink);
  font-size: 13px;
  line-height: 1;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .08s;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .38; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #23303A; font-weight: 600; }
.btn.big { font-size: 17px; padding: 13px 40px; border-radius: 10px; }

#sens-group { display: flex; margin-left: auto; border: 1px solid rgba(255, 255, 255, .18); border-radius: 8px; overflow: hidden; }
.sens {
  appearance: none; border: 0; background: transparent;
  color: var(--ink-faint); font-size: 12px; padding: 7px 10px; cursor: pointer; line-height: 1;
}
.sens + .sens { border-left: 1px solid rgba(255, 255, 255, .14); }
.sens.is-on { background: rgba(255, 201, 74, .18); color: var(--accent); }

/* ---------------- 泳道区 HUD ---------------- */

#hint-pill {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  padding: 5px 18px;
  border-radius: 999px;
  background: rgba(7, 31, 46, .5);
  border: 1.5px solid rgba(255, 255, 255, .3);
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ink);
  transition: background .2s, color .2s;
  white-space: nowrap;
}
#hint-pill.active { background: rgba(255, 201, 74, .9); border-color: var(--accent); color: #23303A; font-weight: 600; }

#telemetry {
  position: absolute;
  top: 14px; left: 18px;
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  line-height: 1.55;
  text-shadow: 0 1px 3px rgba(0, 30, 50, .5);
}
#telemetry .tel-row { display: flex; align-items: baseline; gap: 5px; }
#telemetry .tel-k { color: rgba(255, 255, 255, .6); min-width: 26px; }
#telemetry .tel-v { font-size: 15px; font-weight: 600; color: var(--ink); }
#telemetry .tel-u { font-size: 10px; color: var(--ink-faint); }
#telemetry .best .tel-v { color: var(--accent); }

/* 泳道尽头双计数器 */
.counter {
  position: absolute;
  right: 40px;
  width: 140px;
  height: 96px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(7, 31, 46, .55);
  border: 1.5px solid rgba(255, 255, 255, .35);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  will-change: transform;
}
#counter-squat { top: 32%; margin-top: -48px; }
#counter-knee  { top: 52%; margin-top: -48px; }

.counter .c-head { display: flex; align-items: center; gap: 6px; color: var(--ink-dim); }
.counter .c-icon { width: 24px; height: 24px; flex: 0 0 auto; }
.counter .c-label { font-size: 12px; letter-spacing: .5px; }
.counter .c-value {
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  transition: color .18s;
}
.counter.bump { animation: bump .2s ease-out; }
.counter.bump .c-value { color: var(--accent); }

@keyframes bump {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---------------- 覆盖层 ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4, 18, 28, .88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  padding: 24px;
}
.overlay.is-on { display: flex; }

/* 校准倒计时不遮挡画面，让用户能看着自己调整站位 */
#guide-countdown { background: rgba(4, 18, 28, .5); }

.panel {
  width: min(520px, 100%);
  padding: 28px 30px;
  border-radius: 16px;
  background: rgba(9, 38, 56, .92);
  border: 1px solid rgba(255, 255, 255, .14);
  text-align: center;
}
.panel.tight { padding: 22px 34px; }
.panel h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: 2px; }
.panel h2 { margin: 0 0 14px; font-size: 20px; font-weight: 600; }
.panel .sub { margin: 0 0 16px; font-size: 13px; color: var(--ink-dim); line-height: 1.6; }
.panel .tips { margin: 0 0 22px; padding: 0; list-style: none; text-align: left; }
.panel .tips li { font-size: 13px; color: var(--ink-dim); line-height: 1.9; padding-left: 16px; position: relative; }
.panel .tips li::before { content: ""; position: absolute; left: 3px; top: 11px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.panel .tips b { color: var(--ink); }
.panel .err { min-height: 18px; margin: 12px 0 0; font-size: 12px; color: #FF8A8A; }

.progress { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .12); overflow: hidden; margin-bottom: 10px; }
.progress .bar { height: 100%; width: 0%; border-radius: 3px; background: var(--accent); transition: width .18s linear; }

.count { font-size: 64px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }

/* 竖屏引导 */
#guide-rotate {
  position: fixed; inset: 0; z-index: 90;
  display: none;
  align-items: center; justify-content: center;
  background: var(--bg-deep);
  text-align: center;
}
#guide-rotate .rot-inner p { margin: 16px 0 0; font-size: 15px; color: var(--ink-dim); }
#guide-rotate svg { animation: rot 2.2s ease-in-out infinite; }
@keyframes rot { 0%, 60% { transform: rotate(0); } 80%, 100% { transform: rotate(-90deg); } }

@media (orientation: portrait) {
  /* 仅游戏进行中提示横屏；落地屏/加载/错误页在竖屏下正常展示 */
  body.game-on #guide-rotate { display: flex; }
}

/* 竖屏下仍保留 counter 定位（横屏容器宽度），避免闪现错位 */

#toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translate(-50%, 12px);
  z-index: 80;
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(7, 31, 46, .92);
  border: 1px solid rgba(255, 255, 255, .2);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  max-width: 80vw;
  text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 小屏压缩 ---------------- */
@media (max-height: 430px) {
  .counter { width: 118px; height: 82px; padding: 8px 10px; }
  .counter .c-value { font-size: 32px; }
  .counter .c-icon { width: 20px; height: 20px; }
  #hint-pill { font-size: 12px; padding: 4px 14px; }
}
