/* ============================================================
   走散安全挑战赛 — 全局样式
   儿童向：明亮配色、大字、大按钮（最小点击区 56px）
   ============================================================ */

:root {
  --c-bg: #fff7e6;
  --c-bg-grad: linear-gradient(160deg, #ffe9a8 0%, #ffd3e0 50%, #c9f0ff 100%);
  --c-primary: #ff8a3d;
  --c-primary-dark: #f06f1f;
  --c-secondary: #4ec3f7;
  --c-secondary-dark: #2ba6de;
  --c-text: #4a3728;
  --c-card: #ffffff;
  --c-danger: #ff5252;
  --c-ok: #58c95e;
  --btn-min: 56px;
  --radius: 20px;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hidden { display: none !important; }

#app {
  width: 100%;
  height: 100%;
  background: var(--c-bg-grad);
}

/* ---------------- 通用 screen ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
  overflow-y: auto;
}

/* ---------------- 大按钮 ---------------- */
.big-btn {
  min-height: var(--btn-min);
  min-width: 220px;
  padding: 14px 40px;
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.big-btn:hover { transform: translateY(-3px) scale(1.03); filter: brightness(1.06); }
.big-btn:active { transform: translateY(2px) scale(0.97); box-shadow: 0 2px 0 rgba(0,0,0,0.12); }

.btn-primary { background: linear-gradient(180deg, var(--c-primary), var(--c-primary-dark)); }
.btn-secondary { background: linear-gradient(180deg, var(--c-secondary), var(--c-secondary-dark)); }

/* ---------------- 标题页 ---------------- */
.game-title {
  font-size: clamp(36px, 6vw, 64px);
  text-shadow: 3px 3px 0 #ffffffaa;
  animation: bounce-title 2.4s ease-in-out infinite;
}
@keyframes bounce-title {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.game-subtitle { font-size: clamp(18px, 2.6vw, 26px); opacity: 0.85; }

.title-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
}

.mantra {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 20px 28px;
  box-shadow: var(--shadow);
  max-width: 860px;
  width: 100%;
  text-align: center;
}
.mantra-title { font-size: 26px; margin-bottom: 14px; }
.mantra-steps {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}
.mantra-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #fff3d6;
  border-radius: 16px;
  padding: 12px 18px;
  min-width: 110px;
  transition: transform 0.15s ease;
}
.mantra-step:hover { transform: scale(1.08) rotate(-2deg); }
.mantra-emoji { font-size: 40px; }
.mantra-text { font-size: 22px; font-weight: 700; }

/* ---------------- 家长设置页 ---------------- */
.setup-title { font-size: clamp(30px, 5vw, 48px); }
.setup-tip { font-size: 20px; opacity: 0.8; }
.setup-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: min(520px, 92vw);
}
.setup-label { font-size: 22px; font-weight: 700; }
.setup-form input {
  min-height: var(--btn-min);
  font-size: 26px;
  font-family: var(--font);
  padding: 8px 16px;
  border: 3px solid #ffd9a0;
  border-radius: 14px;
  outline: none;
}
.setup-form input:focus { border-color: var(--c-primary); }
.setup-error { color: var(--c-danger); font-size: 20px; font-weight: 700; }

/* ---------------- 选场景页 ---------------- */
.select-title { font-size: clamp(28px, 4.5vw, 44px); }
#scene-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 240px));
  gap: 24px;
  justify-content: center;
  width: 100%;
  max-width: 1100px;
}
.scene-card {
  min-height: 200px;
  background: var(--c-card);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  font-family: var(--font);
  transition: transform 0.15s ease;
}
.scene-card:hover { transform: translateY(-6px) scale(1.04); }
.scene-card:active { transform: scale(0.96); }
.scene-card .card-emoji { font-size: 64px; }
.scene-card .card-name { font-size: 28px; font-weight: 700; color: var(--c-text); }
.scene-card .card-best { font-size: 22px; color: #f5a623; letter-spacing: 2px; }

/* ---------------- 游戏页 / canvas 自适应 16:9 ---------------- */
#screen-game {
  padding: 0;
  background: #222;
  justify-content: center;
  align-items: center;
}

#canvas-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  margin: auto;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
  background: #000;
}

/* 震屏：transform 加在 canvas 容器上 */
#canvas-wrap.shaking { animation: screen-shake 0.08s linear infinite; }
@keyframes screen-shake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-8px, 5px); }
  50%  { transform: translate(6px, -6px); }
  75%  { transform: translate(-5px, -4px); }
  100% { transform: translate(7px, 4px); }
}

/* ---------------- HUD 覆盖层 ---------------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;   /* 子元素按钮自行开启 */
  z-index: 10;
  font-family: var(--font);
}
#hud button {
  pointer-events: auto;
  min-height: var(--btn-min);
  min-width: var(--btn-min);
  font-size: 26px;
  font-weight: 700;
  font-family: var(--font);
  border: none;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}
#hud button:hover { transform: scale(1.05); }
#hud button:active { transform: scale(0.94); }

/* ---------------- 对话框 ---------------- */
#dialog-box {
  position: absolute;
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
  width: min(92%, 900px);
  min-height: 96px;
  background: rgba(255, 255, 255, 0.96);
  border: 4px solid var(--c-primary);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  padding: 16px 24px;
  font-size: 26px;
  line-height: 1.5;
  z-index: 20;
}

/* ---------------- 覆盖层根（键盘/拼句/结算） ---------------- */
#overlay-root {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}
#overlay-root > * { pointer-events: auto; }
#overlay-root button {
  min-height: var(--btn-min);
  min-width: var(--btn-min);
  font-family: var(--font);
  cursor: pointer;
}

/* ---------------- 顶部常驻栏 ---------------- */
#topbar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 12px;
  z-index: 100;
}
.top-btn {
  width: var(--btn-min);
  height: var(--btn-min);
  font-size: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.top-btn:hover { transform: scale(1.1); }
.top-btn:active { transform: scale(0.9); }
.top-btn.off { opacity: 0.45; filter: grayscale(1); }

/* ---------------- 星星动画 ---------------- */
.star {
  display: inline-block;
  font-size: 34px;
  transition: transform 0.3s ease;
}
.star.lit {
  animation: star-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 0 8px #ffd700);
}
@keyframes star-pop {
  0%   { transform: scale(0) rotate(-180deg); }
  60%  { transform: scale(1.5) rotate(12deg); }
  100% { transform: scale(1) rotate(0deg); }
}
.star.dim { opacity: 0.45; }

@keyframes star-twinkle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18) rotate(6deg); }
}
.star.twinkle { animation: star-twinkle 1.2s ease-in-out infinite; }

/* ---------------- 小屏适配 ---------------- */
@media (max-width: 640px) {
  .big-btn { font-size: 22px; min-width: 180px; }
  .mantra-step { min-width: 84px; padding: 10px 12px; }
  .mantra-emoji { font-size: 30px; }
  .mantra-text { font-size: 18px; }
  #dialog-box { font-size: 20px; }
}
