:root {
  --bg: #FFF8F0;
  --bg-2: #FFF1E0;
  --ink: #2B2620;
  --muted: #8A7E70;
  --primary: #F59E0B;     /* 暖橙 */
  --primary-d: #D97706;
  --coral: #FF6B6B;       /* 珊瑚红 */
  --green: #22C55E;       /* 成功绿 */
  --purple: #8B5CF6;      /* 强调紫（非冷蓝） */
  --card: #FFFFFF;
  --shadow: 0 10px 30px rgba(120, 80, 20, 0.15);
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-2) 0%, var(--bg) 60%);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}

.hidden { display: none !important; }

/* 顶栏 */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 64px; z-index: 30;
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.topbar-title { font-weight: 800; font-size: 18px; }
.icon-btn {
  border: none; background: var(--bg-2); color: var(--ink);
  font-size: 16px; font-weight: 700; padding: 10px 14px; border-radius: 14px; cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }
.privacy-badge {
  margin-left: auto; font-size: 13px; font-weight: 700; color: var(--green);
  background: rgba(34,197,94,0.12); padding: 8px 12px; border-radius: 12px;
}

/* 舞台 */
#stage { position: relative; height: 100%; width: 100%; }

/* 摄像头层 */
.cam-wrap {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  background: #1c1a17;
}
#video {
  width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); /* 镜像 */
}
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.live-label {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%);
  background: rgba(0,0,0,0.55); color: #fff; font-size: 28px; font-weight: 800;
  padding: 10px 22px; border-radius: 16px; letter-spacing: 2px;
}

/* 物品/手势模式：摄像头缩成居中方块（只取一部分），周围是正常界面 */
.cam-wrap.square-mode { background: transparent; padding: 150px 0 150px; }
.cam-wrap.square-mode #video {
  width: min(50vmin, 340px); height: min(50vmin, 340px);
  object-fit: cover; border-radius: 26px;
  border: 5px solid var(--primary); box-shadow: var(--shadow);
}

/* 屏幕通用 */
.screen {
  position: absolute; inset: 0; z-index: 10; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 24px 40px; text-align: center; gap: 18px;
}
.screen.active { display: flex; }

/* 吸引屏 */
.attract-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.float-emoji {
  position: absolute; font-size: 64px; opacity: 0.25;
  top: calc(20% + var(--i, 0) * 12%); left: calc(10% + var(--d, 0) * 18%);
  animation: floatY 6s ease-in-out infinite; animation-delay: var(--d);
}
.float-emoji:nth-child(1){ --i:0; left:12%; }
.float-emoji:nth-child(2){ --i:1; left:78%; }
.float-emoji:nth-child(3){ --i:2; left:30%; }
.float-emoji:nth-child(4){ --i:0; left:60%; }
.float-emoji:nth-child(5){ --i:1; left:46%; }
.float-emoji:nth-child(6){ --i:2; left:88%; }
@keyframes floatY { 0%,100%{ transform: translateY(0) rotate(-6deg);} 50%{ transform: translateY(-22px) rotate(6deg);} }
.attract-title { font-size: clamp(34px, 7vw, 64px); font-weight: 900; margin: 0; color: var(--primary-d); text-shadow: 0 3px 0 #fff; }
.attract-sub { font-size: clamp(16px, 3vw, 24px); color: var(--muted); margin: 0; }
.attract-hint { font-size: 14px; color: var(--muted); margin-top: 8px; }

/* 大按钮 */
.big-btn {
  border: none; border-radius: 18px; font-size: 22px; font-weight: 800;
  padding: 18px 40px; cursor: pointer; box-shadow: var(--shadow); transition: transform .08s;
}
.big-btn:active { transform: scale(0.96); }
.big-btn.primary { background: linear-gradient(180deg, var(--primary), var(--primary-d)); color: #fff; }
.big-btn.ghost { background: #fff; color: var(--primary-d); border: 3px solid var(--primary); }

/* 菜单 */
.menu-title { font-size: 30px; font-weight: 900; margin: 0 0 10px; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 22px; width: min(880px, 92vw); }
.mode-card {
  background: var(--card); border: none; border-radius: var(--radius); padding: 28px 18px;
  box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: transform .1s;
}
.mode-card:active { transform: scale(0.97); }
.mode-emoji { font-size: 56px; }
.mode-name { font-size: 22px; font-weight: 800; }
.mode-desc { font-size: 14px; color: var(--muted); }

/* 模式内通用头 */
.mode-head { position: absolute; top: 76px; left: 0; right: 0; padding: 0 24px; }
.mode-head h2 { font-size: 28px; margin: 0; }
.mode-head .mode-tip { color: var(--muted); font-size: 14px; margin: 4px 0 0; }

/* 结果横幅（覆盖在摄像头上的卡片） */
.result-banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.95); border-radius: 24px; padding: 26px 36px;
  box-shadow: var(--shadow); text-align: center; z-index: 20; min-width: 240px;
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: translate(-50%,-50%) scale(.6); opacity: 0; } to { transform: translate(-50%,-50%) scale(1); opacity: 1; } }
.result-banner .rb-emoji { font-size: 72px; line-height: 1; }
.result-banner .rb-name { font-size: 34px; font-weight: 900; margin-top: 6px; }
.result-banner .rb-sub { font-size: 15px; color: var(--muted); margin-top: 4px; }

/* 物品识别：前三结果列表 */
.result-banner .or-title { font-size: 17px; font-weight: 800; color: var(--muted); margin-bottom: 8px; }
.or-row { display: flex; align-items: center; gap: 10px; margin: 9px 0; min-width: 320px; }
.or-rank { width: 26px; height: 26px; border-radius: 50%; background: var(--bg-2); color: var(--muted); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 14px; flex: none; }
.or-row.top .or-rank { background: var(--primary); color: #fff; }
.or-name { font-size: 20px; font-weight: 800; flex: none; min-width: 92px; text-align: left; }
.or-row.top .or-name { color: var(--primary-d); font-size: 25px; }
.or-bar { flex: 1; height: 14px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.or-bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--coral)); border-radius: 999px; }
.or-pct { font-size: 15px; font-weight: 800; color: var(--muted); width: 48px; text-align: right; flex: none; }

/* 手势识别结果：底部紧凑 pill，不挡摄像头方块 */
#gesture-result {
  top: auto; bottom: 32px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: row; align-items: center; gap: 12px;
  padding: 10px 22px; border-radius: 999px; min-width: 0; text-align: left;
  animation: riseIn .3s ease;
}
#gesture-result .rb-emoji { font-size: 38px; line-height: 1; }
#gesture-result .rb-name { font-size: 24px; margin: 0; }
#gesture-result .rb-sub { font-size: 14px; margin: 0; }
@keyframes riseIn { from { transform: translateX(-50%) translateY(14px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }

/* RPS：左「你」右「电脑」两侧展示，中间留给摄像头方块 */
.rps-panel { position: absolute; inset: 0; z-index: 18; pointer-events: none; }
.rps-side {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.95); border-radius: 22px; padding: 16px 20px;
  text-align: center; box-shadow: var(--shadow); min-width: 116px;
}
.rps-side.you { left: 3vw; }
.rps-side.cpu { right: 3vw; }
.rps-who { font-size: 18px; color: var(--muted); font-weight: 800; }
.rps-hand { font-size: 88px; line-height: 1.15; }
.rps-outcome {
  position: absolute; top: 132px; left: 50%; transform: translateX(-50%);
  font-size: 40px; font-weight: 900; color: var(--primary-d); text-align: center;
  background: rgba(255,255,255,0.94); padding: 8px 26px; border-radius: 999px;
  box-shadow: var(--shadow); white-space: nowrap;
}
.rps-controls { position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; pointer-events: auto; z-index: 19; }
.rps-controls .big-btn { pointer-events: auto; }
/* 暂停蓄势：电脑手势抖动 */
.rps-panel.thinking #rps-cpu { display: inline-block; transform-origin: 50% 70%; animation: cpuShake .34s infinite ease-in-out; }
@keyframes cpuShake {
  0%,100% { transform: rotate(-9deg) translateY(0); }
  50% { transform: rotate(9deg) translateY(-9px); }
}
/* 比分牌（右上角，不挡中间摄像头方块） */
.rps-score {
  position: absolute; top: 76px; right: 3vw; z-index: 19;
  font-size: 20px; font-weight: 800; color: var(--primary-d);
  background: rgba(255,255,255,0.92); padding: 8px 18px; border-radius: 999px;
  box-shadow: var(--shadow); white-space: nowrap;
}
/* 倒计时数字脉冲（保持 translateX(-50%) 居中，避免动画覆盖定位） */
.rps-panel.thinking #rps-outcome { animation: countPulse .55s ease-in-out infinite; }
@keyframes countPulse {
  0%,100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.14); }
}

/* 物品控制 */
.object-controls { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); display: flex; gap: 14px; z-index: 20; }
.object-note { position: absolute; left: 0; right: 0; bottom: 86px; text-align: center; color: var(--muted); font-size: 13px; padding: 0 24px; }

/* 人脸 */
.face-counter { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 20; font-size: 22px; font-weight: 800; color: #fff; background: rgba(34,197,94,0.9); padding: 12px 22px; border-radius: 16px; }
.face-privacy { position: absolute; left: 0; right: 0; bottom: 70px; text-align: center; color: #e8e2d8; font-size: 14px; padding: 0 24px; }

/* 遮罩 */
.mask { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(28,26,23,0.78); }
.mask-box { background: #fff; border-radius: 20px; padding: 30px 40px; text-align: center; }
.mask-text { margin-top: 14px; font-weight: 700; }
.spinner { width: 42px; height: 42px; border: 5px solid var(--bg-2); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 撒花 */
.confetti { position: absolute; inset: 0; z-index: 60; pointer-events: none; }

/* 跟学手势引导 */
.gesture-guide {
  position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%);
  display: flex; gap: 14px; z-index: 20; flex-wrap: wrap; justify-content: center; max-width: 92vw;
}
.gg-item {
  background: rgba(255,255,255,0.92); border-radius: 16px; padding: 12px 14px; min-width: 84px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: var(--shadow);
}
.gg-emoji { font-size: 40px; line-height: 1; }
.gg-name { font-size: 15px; font-weight: 800; color: var(--primary-d); }

/* 加载徽标（非阻塞，顶部居中） */
.badge {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.95); border-radius: 999px; padding: 10px 18px;
  box-shadow: var(--shadow); font-weight: 700; font-size: 15px;
}
.badge-error { background: #fff1f0; color: var(--coral); }
.badge-spin {
  width: 18px; height: 18px; border: 3px solid var(--bg-2); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
.badge-back {
  border: none; background: var(--coral); color: #fff; font-weight: 800; font-size: 14px;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}

/* 适配窄屏（手机/小平板） */
@media (max-width: 560px) {
  .mode-head { top: 70px; }
  .result-banner .rb-emoji { font-size: 56px; }
  .big-btn { font-size: 19px; padding: 16px 30px; }
  .object-controls { bottom: 100px; }
  .gesture-guide { bottom: 96px; gap: 8px; }
  .gg-item { min-width: 64px; padding: 9px 10px; }
  .gg-emoji { font-size: 32px; }
  .rps-side { min-width: 80px; padding: 10px 12px; }
  .rps-side.you { left: 8px; }
  .rps-side.cpu { right: 8px; }
  .rps-hand { font-size: 58px; }
  .rps-outcome { font-size: 24px; top: 120px; padding: 6px 16px; }
  .rps-controls { bottom: 18px; gap: 10px; }
  .rps-controls .big-btn { font-size: 16px; padding: 12px 20px; }
  .rps-score { top: 70px; right: 8px; font-size: 16px; padding: 6px 12px; }
  .result-banner { width: 92vw; }
  .or-row { min-width: 0; }
  .or-name { min-width: 76px; font-size: 18px; }
  .or-row.top .or-name { font-size: 21px; }
  .cam-wrap.square-mode { padding: 96px 0 130px; }
  .cam-wrap.square-mode #video { width: min(58vmin, 280px); height: min(58vmin, 280px); }
}

/* 无障碍：用户偏好减少动效时关闭装饰性动画 */
@media (prefers-reduced-motion: reduce) {
  .float-emoji, .spinner, .badge-spin, .result-banner,
  .rps-panel.thinking #rps-cpu, .rps-panel.thinking #rps-outcome { animation: none !important; }
}
