/* ===== 走失安全教育游戏 - UI 样式 ===== */
/* 设计目标：iPad 触屏友好、大按钮、圆润可爱、高对比 */

:root {
  --primary: #ff7eb3;
  --primary-dark: #e85a93;
  --accent: #4ecdc4;
  --warn: #ff9f43;
  --good: #2ed573;
  --bg-cream: #fff8f0;
  --text-dark: #4a3b52;
  --panel-bg: rgba(255, 252, 248, 0.97);
  --shadow: 0 8px 24px rgba(74, 59, 82, 0.18);
  --radius-lg: 24px;
  --radius-md: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a1625;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

#game-container {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

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

.hidden { display: none !important; }

/* ===== 屏幕特效 ===== */
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  transition: box-shadow 0.8s ease;
}
.vignette.lost {
  box-shadow: inset 0 0 120px 40px rgba(255, 80, 80, 0.35);
  animation: lost-pulse 2s ease-in-out infinite;
}
@keyframes lost-pulse {
  0%, 100% { box-shadow: inset 0 0 120px 40px rgba(255, 80, 80, 0.28); }
  50% { box-shadow: inset 0 0 140px 60px rgba(255, 80, 80, 0.42); }
}
.vignette.consequence {
  box-shadow: inset 0 0 200px 80px rgba(30, 30, 50, 0.55);
}

.fade-overlay {
  position: absolute;
  inset: 0;
  background: #1a1625;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 50;
}
.fade-overlay.active { opacity: 1; pointer-events: auto; }

#particles-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  overflow: hidden;
}
.particle {
  position: absolute;
  font-size: 28px;
  animation: float-up 1.6s ease-out forwards;
  will-change: transform, opacity;
}
@keyframes float-up {
  0% { transform: translateY(0) scale(0.5) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-160px) scale(1.4) rotate(40deg); opacity: 0; }
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(12px + var(--safe-top)) 16px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  z-index: 40;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

.score-display {
  background: var(--panel-bg);
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-dark);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
}
.score-star { font-size: 26px; }

.area-label {
  background: rgba(74, 59, 82, 0.75);
  color: #fff;
  border-radius: 999px;
  padding: 8px 22px;
  font-size: 18px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

.round-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--panel-bg);
  font-size: 24px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.round-btn:active { transform: scale(0.92); }

#hud .pause-btn { margin-left: auto; margin-right: 10px; }
#hud .tts-btn { margin-right: 0; }

/* ===== 触屏控制 ===== */
#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

#joystick-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 45%;
  height: 55%;
  pointer-events: auto;
}

#joystick-base {
  position: absolute;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  border: 3px solid rgba(255, 255, 255, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
#joystick-base.active { display: flex; }

#joystick-stick {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

#action-buttons {
  position: absolute;
  right: 24px;
  bottom: calc(32px + var(--safe-bottom));
  display: flex;
  flex-direction: column-reverse;
  gap: 16px;
  align-items: flex-end;
  pointer-events: auto;
}

.action-btn {
  min-width: 120px;
  height: 88px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font-family: inherit;
}
.action-btn:active { transform: scale(0.93); }
.action-btn .btn-icon { font-size: 32px; }
.action-btn .btn-label { font-size: 18px; font-weight: 700; color: var(--text-dark); }

.interact-btn {
  background: linear-gradient(145deg, #ffd93d, #ffb142);
  animation: btn-breathe 1.6s ease-in-out infinite;
}
.interact-btn .btn-label { color: #6b4400; }

.shout-btn {
  background: linear-gradient(145deg, #ff9ff3, #f368e0);
  animation: btn-breathe 1.6s ease-in-out infinite;
}
.shout-btn .btn-label { color: #6b0058; }

@keyframes btn-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ===== 字幕 ===== */
.subtitle-bar {
  position: absolute;
  left: 50%;
  bottom: calc(170px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: 80%;
  background: rgba(30, 25, 40, 0.85);
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: var(--radius-md);
  z-index: 45;
  text-align: center;
  backdrop-filter: blur(6px);
}

/* ===== 对话框 ===== */
.dialog-box {
  position: absolute;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(720px, 92%);
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 24px 22px;
  z-index: 60;
}

.dialog-speaker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.dialog-avatar { font-size: 34px; }
.dialog-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary-dark);
}

.dialog-text {
  font-size: 22px;
  line-height: 1.55;
  color: var(--text-dark);
  margin-bottom: 16px;
  min-height: 34px;
}

.dialog-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.dialog-option-btn {
  flex: 1 1 40%;
  min-height: 64px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 20px;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 0 rgba(0,0,0,0.12);
  cursor: pointer;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.dialog-option-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.12); }
.dialog-option-btn.opt-pink { background: var(--primary); }
.dialog-option-btn.opt-green { background: var(--good); }
.dialog-option-btn.opt-orange { background: var(--warn); }
.dialog-option-btn.opt-gray { background: #95a5a6; }
.dialog-option-btn .opt-icon { font-size: 24px; }

/* ===== 通用覆盖面板 ===== */
.overlay-panel {
  position: absolute;
  inset: 0;
  background: rgba(30, 25, 40, 0.55);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 20px;
}

.menu-panel {
  background: var(--panel-bg);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 40px 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.game-title {
  font-size: 52px;
  line-height: 1.25;
  color: var(--primary-dark);
  text-align: center;
  letter-spacing: 2px;
}
.game-subtitle {
  font-size: 20px;
  color: #8a7a94;
  margin-bottom: 8px;
}

.big-btn {
  min-width: 260px;
  min-height: 72px;
  border: none;
  border-radius: 999px;
  font-size: 26px;
  font-weight: 800;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(145deg, var(--primary), var(--primary-dark));
  box-shadow: 0 6px 0 rgba(0,0,0,0.14);
  cursor: pointer;
  padding: 14px 32px;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.14); }
.big-btn.secondary {
  background: linear-gradient(145deg, #7ed6ff, #4ea8de);
}
.start-btn { font-size: 30px; min-height: 84px; }

/* ===== 家长设置 ===== */
.settings-panel { align-items: stretch; }
.settings-panel h2 { text-align: center; color: var(--text-dark); }

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
}
.setting-row input, .setting-row select {
  height: 56px;
  border: 2px solid #e8dff0;
  border-radius: var(--radius-md);
  font-size: 20px;
  font-family: inherit;
  padding: 0 16px;
  background: #fff;
  color: var(--text-dark);
  user-select: text;
  -webkit-user-select: text;
}
.setting-row input:focus, .setting-row select:focus {
  outline: none;
  border-color: var(--primary);
}

.settings-stats {
  background: #f6f0fa;
  border-radius: var(--radius-md);
  padding: 16px 20px;
}
.settings-stats h3 { font-size: 18px; color: var(--text-dark); margin-bottom: 8px; }
#stats-content { font-size: 16px; color: #6b5b75; line-height: 1.7; }

.small-btn {
  margin-top: 10px;
  border: none;
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  background: #e0d5ea;
  color: var(--text-dark);
}
.small-btn.danger { background: #ffd6d6; color: #c0392b; }

/* ===== 拨号盘 ===== */
.dialpad-panel {
  background: var(--panel-bg);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.dialpad-title { font-size: 26px; font-weight: 800; color: var(--text-dark); }

.dial-display {
  width: 320px;
  height: 64px;
  background: #fff;
  border: 3px solid #e8dff0;
  border-radius: var(--radius-md);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dark);
}
.dial-display.error { border-color: #e74c3c; animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.dialpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 92px);
  gap: 12px;
}
.dial-key {
  height: 72px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 30px;
  font-weight: 700;
  font-family: inherit;
  background: #f0e8f5;
  color: var(--text-dark);
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
  cursor: pointer;
}
.dial-key:active { transform: translateY(3px); box-shadow: none; background: #e2d5ec; }

.dialpad-actions { display: flex; gap: 16px; }
.dial-action-btn {
  min-width: 140px;
  height: 60px;
  border: none;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 700;
  font-family: inherit;
  background: #e0d5ea;
  color: var(--text-dark);
  cursor: pointer;
}
.dial-call-btn { background: var(--good); color: #fff; }
.dial-cancel {
  border: none;
  background: none;
  font-size: 18px;
  color: #8a7a94;
  font-family: inherit;
  cursor: pointer;
  padding: 8px;
}

/* ===== 后果反馈 ===== */
.feedback-panel {
  background: var(--panel-bg);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 36px 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 520px;
  text-align: center;
}
.feedback-icon { font-size: 64px; }
.feedback-text {
  font-size: 22px;
  line-height: 1.6;
  color: var(--text-dark);
  font-weight: 600;
}

/* ===== 加载画面 ===== */
#loading-screen { background: linear-gradient(160deg, #ffd6e8, #c9f0ff); z-index: 100; }
.loading-panel { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.loading-spinner {
  font-size: 64px;
  animation: bounce 1s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-24px); }
}
.loading-text { font-size: 24px; font-weight: 700; color: var(--text-dark); }

/* ===== 触屏设备适配 ===== */
@media (max-width: 820px) {
  .game-title { font-size: 40px; }
  .dialog-text { font-size: 20px; }
  .dialog-option-btn { font-size: 18px; min-height: 58px; }
  .dialpad-grid { grid-template-columns: repeat(3, 80px); }
  .dial-key { height: 62px; font-size: 26px; }
  .dial-display { width: 280px; }
  .subtitle-bar { font-size: 19px; bottom: calc(150px + var(--safe-bottom)); }
}
