/* ============================================================
   糖果跑跑 · 儿童友好 UI 样式
   配色：橙红 / 黄绿 / 天蓝 明亮糖果色，大号圆润字体、圆形大按钮
   ============================================================ */

:root {
  --c-orange: #FF7B54;
  --c-red: #FF5E5B;
  --c-yellow: #FFD93D;
  --c-green: #8DE96D;
  --c-blue: #5BD1FF;
  --c-pink: #FF9BD2;
  --c-purple: #B79CFF;
  --c-cream: #FFF9EC;
  --c-ink: #5B4636;
  --shadow: 0 6px 0 rgba(0,0,0,.14);
  --font: 'ZCOOL KuaiLe', 'YouYuan', '幼圆', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: #A8E4FF;
  color: var(--c-ink);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  position: fixed; /* 防止 iOS 橡皮筋滚动 */
}

#game-canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 0;
}

#cam-video {
  position: fixed;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

#app { position: fixed; inset: 0; z-index: 10; }

/* ---------- 屏幕切换 ---------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.screen.show { display: flex; }
.screen.transparent { background: transparent; pointer-events: none; }
#screen-loading, #screen-home, #screen-calib, #screen-pause {
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,.42), rgba(168,228,255,.30) 55%, rgba(255,155,210,.30));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ---------- 加载屏 ---------- */
.loading-card { text-align: center; }
.loading-candy { font-size: 76px; animation: swing 1.6s ease-in-out infinite; }
@keyframes swing { 0%,100% { transform: rotate(-12deg);} 50% { transform: rotate(12deg);} }
.logo-mini { font-size: 34px; margin: 8px 0 22px; }
.progress-track {
  width: min(320px, 72vw); height: 22px;
  background: rgba(255,255,255,.65);
  border-radius: 12px; overflow: hidden;
  border: 3px solid #fff;
  margin: 0 auto;
}
.progress-track.slim { height: 16px; width: min(280px, 70vw); }
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--c-orange), var(--c-yellow), var(--c-green), var(--c-blue));
  border-radius: 12px;
  transition: width .3s ease;
}
.load-text { margin-top: 12px; font-size: 17px; color: var(--c-ink); }

/* ---------- 主页 ---------- */
#screen-home { justify-content: space-between; }

.logo {
  font-size: clamp(52px, 15vw, 92px);
  letter-spacing: .06em;
  background: linear-gradient(180deg, #FF5E5B 8%, #FF9BD2 30%, #B79CFF 50%, #5BD1FF 72%, #8DE96D 95%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 rgba(255,255,255,.9)) drop-shadow(0 8px 14px rgba(91,146,255,.35));
  margin-top: 4px;
}
.slogan {
  font-size: clamp(16px, 4.5vw, 22px);
  color: #fff;
  background: var(--c-orange);
  padding: 6px 22px; border-radius: 999px;
  box-shadow: var(--shadow);
  margin-top: 10px;
}

/* 角色选择 */
.char-picker {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px;
}
.arrow-btn {
  width: 62px; height: 62px; border-radius: 50%;
  border: 4px solid #fff;
  background: var(--c-blue);
  color: #fff; font-size: 24px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.arrow-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.14); }
.char-card {
  width: clamp(180px, 48vw, 240px);
  background: var(--c-cream);
  border: 5px solid #fff;
  border-radius: 34px;
  padding: 14px 10px 16px;
  text-align: center;
  box-shadow: 0 10px 24px rgba(120,90,200,.22);
}
.char-emoji { font-size: clamp(72px, 22vw, 104px); line-height: 1.1; animation: bounce 1.4s ease-in-out infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-10px);} }
.char-name { font-size: clamp(24px, 7vw, 32px); color: var(--c-orange); margin-top: 4px; }

/* 模式选择 */
.mode-picker {
  display: flex; gap: 14px; margin-top: 10px;
}
.mode-btn {
  flex: 1; max-width: 210px;
  display: flex; flex-direction: column; align-items: center;
  background: rgba(255,255,255,.92);
  border: 4px solid #fff;
  border-radius: 26px;
  padding: 12px 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s;
}
.mode-btn .mode-icon { font-size: 40px; }
.mode-btn .mode-label { font-size: 24px; margin-top: 4px; color: var(--c-ink); }
.mode-btn .mode-sub { font-size: 15px; color: #a58b76; }
.mode-btn.selected {
  background: var(--c-green);
  border-color: #fff;
  transform: translateY(-4px) scale(1.04);
}
.mode-btn.selected .mode-label, .mode-btn.selected .mode-sub { color: #fff; }

/* 开始按钮 */
.big-start {
  width: clamp(150px, 42vw, 190px); height: clamp(150px, 42vw, 190px);
  border-radius: 50%;
  border: 8px solid #fff;
  background: radial-gradient(circle at 35% 30%, #FF9A6B, var(--c-orange) 60%, #F05B2E);
  color: #fff;
  font-family: var(--font);
  font-size: clamp(30px, 9vw, 44px);
  letter-spacing: .1em;
  box-shadow: 0 10px 0 rgba(180,60,20,.5), 0 18px 30px rgba(255,123,84,.4);
  cursor: pointer;
  animation: pulse 1.6s ease-in-out infinite;
  margin: 14px 0 6px;
}
@keyframes pulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.06);} }
.big-start:active { transform: translateY(8px) scale(.97); box-shadow: 0 3px 0 rgba(180,60,20,.5); }

.parent-tip {
  font-size: 13px; color: #6d5847;
  background: rgba(255,255,255,.72);
  border-radius: 14px;
  padding: 8px 14px;
  max-width: 460px; text-align: center;
  line-height: 1.5;
}

/* ---------- 校准屏 ---------- */
.calib-card {
  width: min(420px, 92vw);
  background: var(--c-cream);
  border: 5px solid #fff;
  border-radius: 30px;
  padding: 18px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(120,90,200,.25);
}
.calib-card h2 { font-size: 26px; margin-bottom: 12px; color: var(--c-orange); }
.calib-preview {
  position: relative;
  width: 100%; aspect-ratio: 4 / 3;
  border-radius: 20px; overflow: hidden;
  background: #123;
  border: 4px solid var(--c-blue);
}
.calib-preview video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* 镜像，像照镜子 */
}
.calib-preview canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.calib-text { margin: 12px 0; font-size: 19px; min-height: 26px; }
.ghost-btn {
  margin: 8px 6px 0;
  padding: 10px 22px;
  font-family: var(--font);
  font-size: 18px;
  color: #fff;
  background: var(--c-blue);
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.ghost-btn.hidden { display: none; }

/* ---------- 倒计时 ---------- */
.count-num {
  font-size: clamp(120px, 40vw, 240px);
  color: #fff;
  -webkit-text-stroke: 8px var(--c-orange);
  paint-order: stroke fill;
  text-shadow: 0 12px 30px rgba(255,123,84,.5);
  animation: countPop .9s ease;
}
@keyframes countPop { 0% { transform: scale(2.2); opacity: 0;} 40% { transform: scale(.95); opacity: 1;} 100% { transform: scale(1);} }

/* ---------- HUD ---------- */
#hud {
  justify-content: flex-start;
  pointer-events: none;
  background: transparent;
  backdrop-filter: none;
}
.hud-row {
  width: 100%;
  display: flex; justify-content: space-between; align-items: center;
}
.hud-coin {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.9);
  border: 4px solid var(--c-yellow);
  border-radius: 999px;
  padding: 6px 20px 6px 10px;
  font-size: 30px;
  box-shadow: var(--shadow);
}
.coin-icon {
  width: 38px; height: 38px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFE98A, #FFD23F 55%, #F5A623);
  border: 3px solid #E8940C;
  display: inline-block;
}
.hud-coin.pop { animation: coinPop .3s ease; }
@keyframes coinPop { 50% { transform: scale(1.22); } }

.pause-btn {
  pointer-events: auto;
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid #fff;
  background: var(--c-purple);
  color: #fff; font-size: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.hud-row2 {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-top: 6px;
}
.hud-dist {
  font-size: 22px; color: #fff;
  background: rgba(91,146,255,.85);
  padding: 4px 18px; border-radius: 999px;
  border: 3px solid #fff;
  box-shadow: var(--shadow);
}
.reward-badge {
  font-size: 26px; color: #fff;
  background: linear-gradient(90deg, var(--c-red), var(--c-orange), var(--c-yellow));
  padding: 8px 26px; border-radius: 999px;
  border: 4px solid #fff;
  box-shadow: 0 0 24px rgba(255,94,91,.7), var(--shadow);
  animation: pulse 1s ease-in-out infinite;
}
.hidden { display: none !important; }

/* ---------- 触摸控制 ---------- */
#touch-pads {
  position: fixed; z-index: 20;
  left: 0; right: 0; bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 18px;
  pointer-events: none;
}
.pad {
  pointer-events: auto;
  width: 88px; height: 88px; border-radius: 50%;
  border: 5px solid #fff;
  color: #fff; font-size: 34px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.pad:active { transform: translateY(4px) scale(.95); }
.pad-left  { background: var(--c-green); }
.pad-right { background: var(--c-blue); }
.pad-jump {
  width: 108px; height: 108px;
  font-size: 44px;
  background: radial-gradient(circle at 35% 30%, #FFB199, var(--c-red) 65%);
  box-shadow: 0 8px 0 rgba(180,40,40,.5), 0 14px 26px rgba(255,94,91,.45);
  margin-bottom: 10px;
}

/* ---------- 摄像头预览小窗 ---------- */
#cam-preview {
  position: fixed; z-index: 15;
  left: 14px; bottom: calc(14px + env(safe-area-inset-bottom));
  width: 118px; height: 118px;
  border-radius: 50%;
  overflow: hidden;
  border: 5px solid #fff;
  box-shadow: 0 0 0 4px var(--c-blue), var(--shadow);
  background: #123;
}
#cam-preview video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
#cam-preview canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}
#cam-preview.offline::after {
  content: '看不到你哦';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(40,40,60,.75);
  color: #fff; font-size: 14px; text-align: center;
}

/* ---------- 鼓励气泡 ---------- */
#bubble {
  position: fixed; z-index: 25;
  top: 22%; left: 50%;
  transform: translateX(-50%);
  font-size: clamp(26px, 8vw, 40px);
  color: #fff;
  background: linear-gradient(180deg, #FF9BD2, var(--c-purple));
  padding: 12px 34px;
  border-radius: 999px;
  border: 5px solid #fff;
  box-shadow: 0 0 30px rgba(255,155,210,.6), var(--shadow);
  white-space: nowrap;
  animation: bubbleIn .4s cubic-bezier(.2,1.6,.4,1);
  pointer-events: none;
}
@keyframes bubbleIn { 0% { transform: translateX(-50%) scale(.3); opacity: 0;} 100% { transform: translateX(-50%) scale(1); opacity: 1;} }

/* ---------- 提示条 ---------- */
#toast {
  position: fixed; z-index: 30;
  bottom: calc(140px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: rgba(60,44,36,.92);
  color: #fff; font-size: 17px;
  padding: 12px 22px; border-radius: 18px;
  max-width: 86vw; text-align: center;
  line-height: 1.5;
  pointer-events: none;
}

/* ---------- 暂停面板 ---------- */
.pause-card {
  width: min(360px, 88vw);
  background: var(--c-cream);
  border: 5px solid #fff;
  border-radius: 32px;
  padding: 24px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 14px 34px rgba(120,90,200,.3);
}
.pause-card h2 { font-size: 34px; color: var(--c-orange); }
.jelly-btn {
  width: 100%; max-width: 260px;
  padding: 14px; border-radius: 999px;
  border: 4px solid #fff;
  color: #fff; font-family: var(--font);
  font-size: 26px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.jelly-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.14); }
.jelly-btn.green { background: var(--c-green); color: #2f6b1f; }
.jelly-btn.orange { background: var(--c-orange); }
.jelly-btn.blue { background: var(--c-blue); }
.toggle-row { display: flex; gap: 10px; }
.toggle {
  padding: 10px 18px; border-radius: 999px;
  border: 3px solid #fff;
  background: #fff;
  color: var(--c-ink); font-family: var(--font);
  font-size: 17px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.toggle.off { background: #d8d2c8; color: #8a7d6d; }

/* ---------- 彩纸 ---------- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 12px; height: 18px;
  border-radius: 4px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 500px) {
  .logo { font-size: 44px; }
  .slogan { font-size: 14px; padding: 4px 16px; }
  .char-emoji { font-size: 56px; }
  .char-card { padding: 8px 8px 10px; }
  .mode-btn .mode-icon { font-size: 28px; }
  .mode-btn .mode-label { font-size: 18px; }
  .big-start { width: 110px; height: 110px; font-size: 26px; margin: 8px 0 4px; }
  .parent-tip { font-size: 11px; }
}
