/* ================================================================
   style.css — 乡村运营师（游戏主界面样式）
   ================================================================ */

:root {
  --primary: #ff9a9e;
  --secondary: #fad0c4;
  --text-dark: #4a4a4a;
  --glass-bg: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(255, 255, 255, 0.8);
  --shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
  --font-main: "Microsoft YaHei", "PingFang SC", sans-serif;
}

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

html { height: 100%; }

body {
  width: 100%; height: 100vh; height: 100dvh; overflow: hidden;
  font-family: var(--font-main);
  background-color: #333;
  color: var(--text-dark);
  -webkit-text-size-adjust: 100%; /* 防止 iOS 在聚焦输入框时自动放大字号 */
}

/* --- 游戏层容器 --- */
#game-stage {
  position: relative; width: 100%; height: 100%;
  background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
  transition: background 0.5s ease-in-out;
}

/* --- 背景装饰 --- */
.bg-deco {
  position: absolute; inset: 0; z-index: 0; overflow: hidden;
}
.mountain {
  position: absolute; bottom: 0; left: 0; width: 100%; height: 40%;
  background: linear-gradient(to top, #a8edea 0%, transparent 100%);
  clip-path: polygon(0% 100%, 20% 60%, 40% 90%, 60% 50%, 80% 80%, 100% 100%);
  opacity: 0.6;
}
.sun {
  position: absolute; top: 10%; right: 15%; width: 80px; height: 80px;
  background: #ffecd2; border-radius: 50%;
  box-shadow: 0 0 40px #fcb69f;
  animation: sunPulse 4s infinite alternate;
}
@keyframes sunPulse { from { transform: scale(1); opacity: 0.8; } to { transform: scale(1.1); opacity: 1; } }

/* --- 立绘层 --- */
.char-container {
  position: absolute; bottom: 0; left: 50%;
  transform: translateX(-50%);
  height: 85%; width: auto; z-index: 1;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.27), filter 0.3s;
  filter: drop-shadow(0 0 15px rgba(255,255,255,0.5));
}

.char-container.speaking-active {
  transform: translateX(-50%) scale(1.03) translateY(-5px);
  filter: drop-shadow(0 0 25px rgba(255, 154, 158, 0.4));
}

.char-img-layer {
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  height: 100%; width: auto;
  max-width: 100vw;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
}
.char-img-layer.active { opacity: 1; z-index: 2; }

/* --- UI 层 --- */
.ui-layer {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}
.pointer-events-auto { pointer-events: auto; }

/* 顶部状态栏 */
.top-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 40px;
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-left: calc(40px + env(safe-area-inset-left));
  padding-right: calc(40px + env(safe-area-inset-right));
  background: linear-gradient(to bottom, rgba(255,255,255,0.8), transparent);
}
.game-title {
  font-size: 1.5rem; font-weight: bold; color: #555; text-shadow: 0 1px 0 #fff;
  display: flex; align-items: center; gap: 10px;
}
.save-badge {
  background: var(--primary); color: white; padding: 4px 12px; border-radius: 20px; font-size: 0.8rem;
  box-shadow: 0 2px 10px rgba(255, 154, 158, 0.4);
}
.sys-menu { display: flex; gap: 15px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.6); backdrop-filter: blur(5px);
  border: 1px solid rgba(255,255,255,0.8);
  color: #555; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: 0.2s; font-size: 1.2rem;
}
.icon-btn:hover { background: #fff; transform: scale(1.1); color: var(--primary); }

/* --- 底部常驻交互区 (核心修改) --- */
.bottom-interaction-area {
  width: 100%;
  background: linear-gradient(to top, rgba(255,255,255,0.95) 80%, rgba(255,255,255,0));
  padding: 20px 0 30px 0;
  padding-bottom: calc(30px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
  z-index: 20;
}

/* 对话框主体 */
.dialogue-wrapper {
  width: 90%; max-width: 1000px;
  position: relative;
  margin-bottom: 15px;
}

.name-tag {
  position: absolute; top: -15px; left: 10px;
  background: var(--primary); color: white;
  padding: 5px 20px; border-radius: 12px 12px 0 0;
  font-weight: bold; font-size: 1rem;
  box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
  z-index: 2;
}

.textbox {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 0 12px 12px 12px;
  padding: 20px 25px;
  min-height: 120px;
  box-shadow: var(--shadow);
  position: relative;
  cursor: pointer;
}

.text-content {
  font-size: 1.1rem; line-height: 1.6; color: #333;
  white-space: pre-wrap;
}

.cursor-blink::after {
  content: '|'; display: inline-block; margin-left: 2px;
  animation: blink 1s infinite; color: var(--primary);
  font-weight: bold;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* --- 推荐问题/选项区域 (样式统一) --- */
.suggestions-container {
  display: flex;
  gap: 10px;
  width: 90%; max-width: 1000px;
  overflow-x: auto;
  padding: 5px 5px 15px 5px; /* 底部padding给阴影留空间 */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE */
}
.suggestions-container::-webkit-scrollbar { display: none; } /* Chrome/Safari */

.suggestion-chip {
  background: white;
  border: 1px solid rgba(255, 154, 158, 0.3);
  color: #555;
  padding: 10px 20px;
  border-radius: 25px;
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.suggestion-chip:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 154, 158, 0.3);
}

.suggestion-chip small {
  font-size: 0.75rem;
  opacity: 0.8;
  background: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: 4px;
}
.suggestion-chip:hover small {
  background: rgba(255,255,255,0.2);
}

/* --- 输入控制栏 (常驻) --- */
.input-control-bar {
  display: flex;
  gap: 10px;
  width: 90%; max-width: 1000px;
  background: white;
  padding: 8px;
  border-radius: 30px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
  align-items: center;
}

.voice-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: #f0f2f5;
  color: #666;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  transition: 0.2s;
  flex-shrink: 0;
  position: relative;
}

/* 语音激活时的波纹效果 */
.voice-btn.listening {
  background: #ff5252;
  color: white;
  animation: pulse-red 1.5s infinite;
}
@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(255, 82, 82, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0); }
}

.main-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0 10px;
  font-size: 1rem;
  outline: none;
  color: #333;
}

.send-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s;
  flex-shrink: 0;
}
.send-btn:hover { background: #ff7eb3; }

/* 新增：音色选择器样式 */
.voice-selector {
  position: relative;
  margin-left: 10px;
  flex-shrink: 0;
}
.voice-select-btn {
  background: transparent;
  border: 1px solid #eee;
  color: #666;
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: 0.2s;
}
.voice-select-btn:hover {
  background: #f9f9f9;
  border-color: var(--primary);
  color: var(--primary);
}
.voice-dropdown {
  position: absolute;
  bottom: 100%;
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  padding: 5px 0;
  width: 150px;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  margin-bottom: 5px;
  z-index: 50;
}
.voice-dropdown.show {
  display: block;
}
.voice-option {
  padding: 8px 15px;
  font-size: 0.9rem;
  color: #555;
  cursor: pointer;
  transition: 0.2s;
}
.voice-option:hover {
  background: #fff0f5;
  color: var(--primary);
}
.voice-option.active {
  background: var(--primary);
  color: white;
}

/* 功能菜单 (悬浮球) */
.floating-menu {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 15px; pointer-events: auto;
}
/* 默认（及显式）左侧放置 */
.floating-menu.side-left { right: auto; left: 20px; }
.float-btn {
  width: 50px; height: 50px; border-radius: 50%;
  background: rgba(255,255,255,0.9); backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  transition: 0.3s; position: relative;
}
.float-btn:hover { transform: scale(1.1) rotate(5deg); background: #fff; }
.float-tooltip {
  position: absolute; right: 60px; background: rgba(0,0,0,0.7); color: white;
  padding: 5px 10px; border-radius: 4px; font-size: 0.8rem;
  opacity: 0; transition: 0.2s; pointer-events: none; white-space: nowrap;
}
.float-btn:hover .float-tooltip { opacity: 1; }
/* 菜单在左侧时，提示气泡改到按钮右侧 */
.floating-menu.side-left .float-tooltip { right: auto; left: 60px; }

/* 模态框 */
.modal-screen {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(8px);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: 0.3s;
}
.modal-screen.active { opacity: 1; visibility: visible; }
.modal-content {
  width: min(800px, 92vw); max-height: 85vh; max-height: 85dvh; background: #fff;
  border-radius: 16px; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  transform: scale(0.9); transition: 0.3s;
}
.modal-screen.active .modal-content { transform: scale(1); }
.modal-header {
  background: var(--primary); color: white; padding: 15px 25px;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-body { padding: 25px; overflow-y: auto; background: #f9f9f9; }
.close-modal { background: none; border: none; color: white; font-size: 1.5rem; cursor: pointer; }

/* ============================================================
   响应式 / 自适应
   - 平板 (≤1024px)
   - 手机 (≤768px, 含 iPhone SE3 375px)
   - 小屏手机 (≤480px)
   - 手机横屏 (高度紧张)
   ============================================================ */

/* --- 平板 --- */
@media (max-width: 1024px) {
  .char-container { height: 75%; }
  .dialogue-wrapper, .suggestions-container, .input-control-bar { width: 92%; }
}

/* --- 手机（含 iPhone SE3 375px） --- */
@media (max-width: 768px) {
  .top-bar {
    padding: 14px 18px;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-left: calc(18px + env(safe-area-inset-left));
    padding-right: calc(18px + env(safe-area-inset-right));
  }
  .game-title { font-size: 1.25rem; }
  .char-container { height: 50%; }

  .dialogue-wrapper, .suggestions-container, .input-control-bar { width: 94%; }
  .textbox { min-height: 96px; padding: 16px; }
  .text-content { font-size: 1rem; }

  .suggestion-chip { padding: 8px 14px; font-size: 0.88rem; }

  /* 悬浮菜单移到顶部栏下方，避免与底部输入区重叠 */
  .floating-menu { top: 64px; bottom: auto; right: 12px; gap: 12px; transform: none; }
  .floating-menu.side-left { right: auto; left: 12px; }
  .float-btn { width: 42px; height: 42px; font-size: 1.25rem; }

  .voice-select-btn { font-size: 0.78rem; padding: 4px 8px; }
  .modal-content { width: 92vw; }
  .modal-body { padding: 18px; }
}

/* --- 小屏手机 (iPhone SE3 等 375px 及以下) --- */
@media (max-width: 480px) {
  .top-bar {
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-left: calc(14px + env(safe-area-inset-left));
    padding-right: calc(14px + env(safe-area-inset-right));
  }
  .game-title { font-size: 1.1rem; }
  .sys-menu { gap: 10px; }
  .icon-btn { width: 36px; height: 36px; font-size: 1.05rem; }

  .char-container { height: 45%; }

  .dialogue-wrapper, .suggestions-container, .input-control-bar { width: 96%; }
  .textbox { min-height: 88px; padding: 14px; }
  .text-content { font-size: 0.95rem; }

  /* 当前音色名过长时截断，避免撑爆输入栏 */
  .voice-select-btn span#currentVoiceName {
    max-width: 70px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; display: inline-block; vertical-align: middle;
  }
  .send-btn { padding: 8px 14px; }
  .floating-menu { top: 58px; gap: 10px; }
  .float-btn { width: 40px; height: 40px; font-size: 1.15rem; }
  .float-tooltip { font-size: 0.75rem; padding: 4px 8px; }
}

/* --- 手机横屏（高度紧张，立绘与输入区抢空间） --- */
@media (max-height: 500px) and (orientation: landscape) {
  .char-container { height: 82%; }
  .bottom-interaction-area { padding-top: 10px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .textbox { min-height: 60px; padding: 10px 14px; }
  .text-content { font-size: 0.95rem; }
  .floating-menu { top: 50%; bottom: auto; transform: translateY(-50%); }
}
