﻿/* EmmaChinese PWA 样式 - 极简 kid + 实用 parent */
/* C 方案: 画框式布局 - 配图 contain 完整 + 装饰背景 + 居中并排 UI */
/* 横竖屏 0 适配, 整幅画永远完整可见 */

/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  /* 中国风画框背景: 顶部底部深棕朱红, 中间深黑, 营造挂画氛围 */
  background:
    radial-gradient(ellipse at center top, rgba(120, 50, 30, 0.4) 0%, transparent 50%),
    radial-gradient(ellipse at center bottom, rgba(120, 50, 30, 0.4) 0%, transparent 50%),
    linear-gradient(180deg, #1a0e08 0%, #0d0604 50%, #1a0e08 100%);
  color: #333;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }

/* === View 切换 === */
.view { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: none; }
.view.active { display: block; }

/* ============================================================ */
/* KID VIEW - 画框式: 图完整 + 装饰背景 + 居中并排 UI            */
/* ============================================================ */
.kid-view {
  overflow: hidden;
}

/* 配图 contain 完整居中 (整幅画永远完整可见) */
.kid-image-wrap {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  /* 留出顶部 🐣 状态 + 底部按钮 + 左右边距的空间, 让图不跟 UI 重叠 */
  padding: max(90px, env(safe-area-inset-top, 90px) + 30px) 12px max(180px, env(safe-area-inset-bottom, 90px) + 100px) 12px;
  box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.kid-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;  /* 完整显示, 不裁剪 */
  object-position: center center;
  border-radius: 6px;
  filter: drop-shadow(0 0 32px rgba(0, 0, 0, 0.6));  /* 微微的画框阴影 */
  pointer-events: none;
}

/* 顶部状态 emoji (💭 想着 / 🔊 念着 / 👂 听着 / 😅 出错) - 浮在画框装饰带 */
.kid-state {
  position: fixed;
  top: max(20px, env(safe-area-inset-top, 20px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 56px;
  line-height: 1;
  z-index: 10;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.8);
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}
.kid-state.thinking { animation: pulse 1.5s ease-in-out infinite; }
.kid-state.speaking { animation: bounce 0.6s ease-in-out infinite; }
.kid-state.listening { animation: glow 1.2s ease-in-out infinite; }
.kid-state.error { animation: shake 0.4s ease-in-out; }
@keyframes pulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.15); }
}
@keyframes bounce {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.1) translateY(-8px); }
}
@keyframes glow {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(255, 200, 100, 0.7)); }
  50% { filter: drop-shadow(0 0 24px rgba(255, 200, 100, 1)); }
}
@keyframes shake {
  0%, 100% { transform: translateX(-50%) translateX(0); }
  25% { transform: translateX(-50%) translateX(-12px); }
  75% { transform: translateX(-50%) translateX(12px); }
}

/* 教我进度点 (fix84): 5 个小圆点, 按比例亮起 */
.kid-progress {
  position: fixed;
  top: max(100px, env(safe-area-inset-top, 100px) + 50px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
}
.kid-progress .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 200, 100, 0.25);
  border: 1.5px solid rgba(255, 180, 60, 0.5);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
  transition: all 0.3s ease;
}
.kid-progress .dot.active {
  background: rgba(255, 180, 60, 0.95);
  border-color: rgba(255, 220, 100, 1);
  box-shadow: 0 0 12px rgba(255, 200, 100, 0.8);
  transform: scale(1.15);
}

/* 顶部右侧 🔒 家长入口 (长按 3 秒进 PIN) - 玻璃态深色 */
.kid-parent-icon {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 16px));
  right: max(16px, env(safe-area-inset-right, 16px));
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  z-index: 20;
  border: 1px solid rgba(255, 255, 255, 0.15);
  opacity: 0.6;
  transition: opacity 0.2s ease, background 0.2s ease, transform 0.1s ease;
}
.kid-parent-icon:active { opacity: 1; background: rgba(20, 20, 20, 0.7); transform: scale(0.95); }
.kid-parent-icon:hover { opacity: 0.85; }

/* 底部 2 个大圆按钮: 教我 + 麦克风 - 玻璃态深色胶囊, 居中并排 */
.kid-buttons {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom, 28px));
  left: 0; right: 0;
  display: flex;
  justify-content: center;  /* 居中并排, 不浪费两端 */
  align-items: center;
  gap: 32px;  /* 间距 32px, 3 岁不误触 */
  z-index: 10;
  pointer-events: none;  /* 容器不拦截, 子按钮自己拦截 */
}
.kid-btn {
  pointer-events: auto;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.kid-btn:active { transform: scale(0.92); background: rgba(40, 40, 40, 0.8); }
.kid-btn:disabled { opacity: 0.4; pointer-events: none; }

/* 教我按钮: 暖黄光晕 (念诗主题色) */
.kid-btn.teach {
  background: rgba(255, 180, 60, 0.22);
  border-color: rgba(255, 200, 100, 0.5);
  box-shadow: 0 8px 28px rgba(255, 180, 60, 0.35), inset 0 0 20px rgba(255, 200, 100, 0.2);
}
.kid-btn.teach:active { background: rgba(255, 180, 60, 0.4); }

/* 麦克风按钮: 暖粉光晕 (说话主题色) */
.kid-btn.mic {
  background: rgba(255, 120, 170, 0.22);
  border-color: rgba(255, 150, 190, 0.5);
  box-shadow: 0 8px 28px rgba(255, 120, 170, 0.35), inset 0 0 20px rgba(255, 150, 190, 0.2);
}
.kid-btn.mic:active { background: rgba(255, 120, 170, 0.4); }
/* 录音中: 红色脉冲, 3 岁娃明显能看到在录 */
.kid-btn.mic.recording {
  background: rgba(255, 60, 80, 0.45);
  border-color: rgba(255, 100, 120, 0.9);
  animation: mic-pulse 0.9s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 8px 28px rgba(255, 60, 80, 0.5), 0 0 0 0 rgba(255, 60, 80, 0.6); }
  50% { transform: scale(1.08); box-shadow: 0 8px 28px rgba(255, 60, 80, 0.7), 0 0 0 18px rgba(255, 60, 80, 0); }
}
.kid-btn-icon { font-size: 60px; line-height: 1; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5)); }

/* fix388: 麦克风 emoji 视觉比教我小, 单独放大 1.33x 补偿 */
.kid-btn.mic .kid-btn-icon { font-size: 80px; }

/* === C 方案完成: 画框式, 整幅画永远完整可见, 横竖屏 0 适配 === */

/* ============================================================ */
/* PARENT VIEW - 实用面板                                          */
/* ============================================================ */
.parent-view {
  background: #f8f5f0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* PIN 锁屏 */
.pin-lock {
  max-width: 400px; margin: 15vh auto 0;
  padding: 32px 24px;
  text-align: center;
}
.pin-lock h1 { font-size: 24px; margin-bottom: 8px; color: #2c5282; }
.pin-lock p { color: #718096; margin: 12px 0 4px; }
.pin-lock input {
  width: 100%; padding: 12px 16px;
  font-size: 24px; text-align: center; letter-spacing: 8px;
  border: 2px solid #cbd5e0; border-radius: 8px;
  background: white;
}
.pin-lock input:focus { border-color: #4a90e2; outline: none; }
.pin-lock button {
  width: 100%; margin-top: 16px;
  padding: 12px;
  font-size: 16px; font-weight: bold;
  background: #4a90e2; color: white;
  border-radius: 8px;
}
.pin-error { color: #e53e3e; min-height: 20px; }
.link-btn { color: #4a90e2; background: none; padding: 8px 12px; font-size: 14px; }

/* 家长面板 */
.parent-panel { max-width: 720px; margin: 0 auto; padding: 16px; }
.parent-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0 16px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 16px;
}
.parent-header h1 { font-size: 22px; color: #2c5282; }
.parent-header-btns { display: flex; gap: 8px; }

.parent-section {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}
.parent-section h2 { font-size: 16px; color: #2d3748; margin-bottom: 12px; }

/* 场景网格 */
.scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.scene-btn {
  padding: 16px 8px;
  background: #edf2f7;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  transition: background 0.2s ease;
}
.scene-btn.active { background: #fef3c7; border: 2px solid #f59e0b; }
.scene-btn:active { background: #cbd5e0; }
.scene-btn .emoji { display: block; font-size: 32px; margin-bottom: 4px; }

/* Toggle switch */
.toggle-row {
  display: flex; align-items: center; gap: 12px;
  font-size: 14px;
}
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background: #cbd5e0; border-radius: 28px;
  transition: background 0.2s ease;
}
.slider::before {
  position: absolute; content: ""; height: 22px; width: 22px;
  left: 3px; bottom: 3px;
  background: white; border-radius: 50%;
  transition: transform 0.2s ease;
}
input:checked + .slider { background: #4a90e2; }
input:checked + .slider::before { transform: translateX(22px); }

/* 档位按钮组 (语速 / 使用时间) - fix83 */
.time-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 4px;
}
.time-btn {
  padding: 10px 8px;
  background: #edf2f7;
  border: 2px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  transition: all 0.15s ease;
  color: #2d3748;
}
.time-btn:active { transform: scale(0.96); }
.time-btn.active {
  background: #fef3c7;
  border-color: #f59e0b;
  font-weight: bold;
  color: #2c5282;
}
.hint {
  margin-top: 8px;
  font-size: 12px;
  color: #718096;
  line-height: 1.5;
}

/* 时间到啦锁定界面 - fix83 */
.time-up-lock {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  animation: fadeIn 0.4s ease;
}
.time-up-content {
  text-align: center;
  color: white;
  padding: 32px 24px;
  max-width: 360px;
}
.time-up-emoji { font-size: 96px; margin-bottom: 16px; animation: ring 2s ease-in-out infinite; }
.time-up-title { font-size: 24px; font-weight: bold; margin-bottom: 8px; }
.time-up-subtitle { font-size: 16px; opacity: 0.8; margin-bottom: 24px; }
.time-up-btn {
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  border-radius: 24px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.time-up-btn:active { background: rgba(255, 255, 255, 0.25); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes ring { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-15deg); } 75% { transform: rotate(15deg); } }

/* 统计 */
.stats { display: flex; gap: 24px; font-size: 14px; color: #4a5568; }
.stats span { font-weight: bold; color: #2c5282; font-size: 18px; }

/* 当前讲解文字 */
.current-text {
  padding: 12px;
  background: #f7fafc;
  border-radius: 8px;
  min-height: 60px;
  font-size: 14px; line-height: 1.6;
  color: #2d3748;
  max-height: 200px; overflow-y: auto;
}
.current-text .line { padding: 4px 0; border-bottom: 1px solid #edf2f7; }
.current-text .line.active { background: #fef3c7; padding: 4px 8px; margin: 0 -8px; border-radius: 4px; border-bottom: 0; }

/* D5: 对话历史 */
.chat-today-badge { font-size: 12px; font-weight: normal; color: #6b7280; background: rgba(255,255,255,0.5); padding: 2px 8px; border-radius: 10px; margin-left: 8px; }
.chat-history { max-height: 320px; overflow-y: auto; padding: 4px 0; }
.chat-empty { color: #9ca3af; font-size: 13px; padding: 8px 0; text-align: center; }
.chat-item { padding: 8px 10px; margin-bottom: 6px; background: rgba(255,255,255,0.5); border-radius: 6px; border-left: 3px solid #fbbf24; }
.chat-sensitive { border-left-color: #ef4444; background: rgba(254,226,226,0.5); }
.chat-time { font-size: 11px; color: #9ca3af; margin-bottom: 4px; }
.chat-kid { font-size: 14px; color: #1f2937; margin-bottom: 2px; word-break: break-word; }
.chat-reply { font-size: 14px; color: #4b5563; word-break: break-word; }

/* PIN 弹窗 */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-content {
  background: white;
  border-radius: 12px;
  padding: 24px;
  width: 90%; max-width: 360px;
  text-align: center;
}
.modal-content h2 { color: #2c5282; margin-bottom: 12px; }
.modal-content input {
  width: 100%; padding: 12px;
  font-size: 24px; text-align: center; letter-spacing: 8px;
  border: 2px solid #cbd5e0; border-radius: 8px;
  margin: 12px 0;
}
.modal-content input:focus { border-color: #4a90e2; outline: none; }
.modal-buttons {
  display: flex; gap: 8px; margin-top: 12px;
}
.modal-buttons button {
  flex: 1; padding: 10px;
  border-radius: 8px; font-size: 14px;
}
.modal-buttons .primary { background: #4a90e2; color: white; font-weight: bold; }

/* Toast 提示 (3-4 岁娃也看得懂的 emoji 提示) */
.toast {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75); color: white;
  padding: 12px 24px; border-radius: 24px;
  font-size: 16px; z-index: 200;
  opacity: 0; transition: opacity 0.3s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* fix456 (8/11 8:35): 删 .pwa-install-banner / .pwa-banner-* / .pwa-ios-guide / @keyframes slideUp 整块 (PWA banner 删, 6 个 CSS 规则 + 1 个 keyframe 都没用了) */


/* fix106: 麦克风调试 overlay (右下角小框) */
.mic-debug {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 11px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 6px;
  font-family: 'SF Mono', Consolas, monospace;
  white-space: pre;
  pointer-events: none;
  max-width: 240px;
}




/* fix419 (8/7 10:55): kidView 顶部左侧 kid name badge */
.kid-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  padding: 6px 12px;
  background: rgba(255, 217, 122, 0.85);
  color: #5a3818;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kid-badge--fallback {
  background: rgba(180, 180, 180, 0.7);
  color: #2a2a2a;
  font-weight: 500;
  font-size: 12px;
}

/* ===== fix455 (8/8 19:50): JS 错误降级 overlay (跟 EN 端 fix72/fix217 同步) ===== */
.emma-error-overlay {
  position: fixed; inset: 0; z-index: 99999;
  background: linear-gradient(135deg, #1e3a8a, #3b82f6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.emma-error-overlay.hidden { display: none; }
.emma-error-box { text-align: center; padding: 24px; max-width: 380px; }
.emma-error-emoji { font-size: 88px; margin-bottom: 18px; }
.emma-error-text { font-size: 26px; font-weight: 700; margin-bottom: 14px; }
.emma-error-detail { font-size: 14px; opacity: 0.85; margin-bottom: 24px; word-break: break-all; line-height: 1.5; }
.emma-error-reload {
  background: #fff; color: #1e3a8a; border: 0;
  padding: 14px 36px; font-size: 18px; font-weight: 700;
  border-radius: 12px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  -webkit-tap-highlight-color: transparent;
}
.emma-error-reload:active { transform: scale(0.96); }
