/* ===== 可愛粉彩風（以手機直式為主） ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button, .option { touch-action: manipulation; } /* 取消點兩下縮放延遲，搶答更即時 */

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Baloo 2", "Huninn", "Microsoft JhengHei", sans-serif;
  background: linear-gradient(160deg, #ffe5ec 0%, #fff5e1 35%, #e0f7fa 70%, #f3e5f5 100%);
  background-attachment: fixed;
  color: #5d4a66;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* 漂浮裝飾 */
.floaties { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.floaties span {
  position: absolute;
  font-size: 28px;
  opacity: 0.5;
  animation: floaty 12s ease-in-out infinite;
}
.floaties span:nth-child(1)  { left: 5%;  top: 10%; animation-delay: 0s; }
.floaties span:nth-child(2)  { left: 85%; top: 15%; animation-delay: -2s; }
.floaties span:nth-child(3)  { left: 15%; top: 75%; animation-delay: -4s; }
.floaties span:nth-child(4)  { left: 90%; top: 70%; animation-delay: -6s; }
.floaties span:nth-child(5)  { left: 50%; top: 5%;  animation-delay: -8s; }
.floaties span:nth-child(6)  { left: 75%; top: 45%; animation-delay: -3s; }
.floaties span:nth-child(7)  { left: 8%;  top: 45%; animation-delay: -7s; }
.floaties span:nth-child(8)  { left: 40%; top: 88%; animation-delay: -5s; }
.floaties span:nth-child(9)  { left: 65%; top: 85%; animation-delay: -9s; }
.floaties span:nth-child(10) { left: 30%; top: 30%; animation-delay: -11s; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50% { transform: translateY(-24px) rotate(8deg); }
}

/* BGM 按鈕（右上）與回主目錄按鈕（左上，遠離答題區並有確認窗防誤觸） */
.bgm-toggle, .home-btn {
  position: fixed; top: 8px; z-index: 50;
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid #fff; background: #ffd6e7;
  font-size: 21px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(214, 51, 132, 0.25);
  transition: transform 0.15s;
}
.bgm-toggle { right: 10px; }
.home-btn { left: 10px; background: #e7f5ff; box-shadow: 0 4px 12px rgba(47, 134, 212, 0.25); }
.bgm-toggle:active, .home-btn:active { transform: scale(0.9); }

/* ===== 畫面與卡片 ===== */
.screen { display: none; width: 100%; max-width: 520px; padding: 16px; z-index: 1; }
.screen.active { display: block; animation: screen-in 0.4s ease; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.card {
  background: rgba(255, 255, 255, 0.88);
  border-radius: 28px;
  padding: 28px 24px;
  box-shadow: 0 10px 32px rgba(186, 104, 200, 0.18), 0 2px 0 4px rgba(255,255,255,0.6) inset;
  border: 3px solid #ffe1ef;
  text-align: center;
}

/* ===== 首頁 ===== */
.home-card { margin-top: 6vh; }
.title {
  margin: 0 0 8px;
  font-size: 42px; font-weight: 800;
  background: linear-gradient(90deg, #ff6fa5, #ffa94d, #74c0fc, #b197fc);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}
.title-sub { font-size: 20px; letter-spacing: 4px; }

/* 角色選擇 */
.char-select { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 18px 0 6px; }
.char-card {
  flex: 1; max-width: 170px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 20px 12px 16px;
  border-radius: 24px; cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
}
.char-card.laosai {
  border: 4px solid #69db7c;
  background: linear-gradient(160deg, #ebfbee, #c3fad0);
  box-shadow: 0 6px 0 #51cf66;
}
.char-card.abao {
  border: 4px solid #ffa8c5;
  background: linear-gradient(160deg, #fff0f6, #ffd6e7);
  box-shadow: 0 6px 0 #f783ac;
}
.char-card:hover { transform: translateY(-4px) scale(1.03); }
.char-card:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }
.char-img { width: 112px; height: 112px; object-fit: contain; }
.end-char { width: 150px; height: 150px; object-fit: contain; }
.end-medal { font-size: 40px; margin-top: -14px; }
.char-name { font-size: 26px; font-weight: 800; color: #5d4a66; }

/* 小頭像（等待室、計分列、拉鋸條） */
.avatar { width: 1.5em; height: 1.5em; vertical-align: -0.35em; }
.tug-face .avatar { width: 26px; height: 26px; vertical-align: middle; }
.player-chip .avatar { width: 30px; height: 30px; }

.bounce1 { animation: bounce 1.2s ease-in-out infinite; }
.bounce2 { animation: bounce 1.2s ease-in-out infinite 0.6s; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
.vs {
  font-weight: 800; font-size: 26px; color: #fff;
  background: linear-gradient(135deg, #ff8fab, #ff6fa5);
  border-radius: 50%; width: 52px; height: 52px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(255, 111, 165, 0.4);
}
.vs.small { width: 40px; height: 40px; font-size: 18px; }

.big-btn {
  flex: 1;
  padding: 16px 20px;
  border: none; border-radius: 20px;
  font-size: 20px; font-weight: 800; font-family: inherit;
  color: #fff; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.big-btn.pink { background: linear-gradient(135deg, #ff8fab, #ff6fa5); box-shadow: 0 6px 0 #e8557f; }
.big-btn.blue { background: linear-gradient(135deg, #74c0fc, #4dabf7); box-shadow: 0 6px 0 #2f86d4; }
.big-btn.purple { background: linear-gradient(135deg, #b197fc, #9775fa); box-shadow: 0 6px 0 #7c5fd3; }
.big-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.2); }
.big-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.status-text { min-height: 1.3em; color: #e8557f; font-weight: 700; margin: 12px 0 0; }
.hint { color: #9b8aa6; font-size: 15px; }
.hidden { display: none !important; }

/* ===== 等待室 ===== */
.lobby-title { margin: 0 0 6px; }
.lobby-players { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 18px 0; }
.player-chip {
  display: flex; align-items: center; gap: 8px;
  background: #fff0f6; border: 3px solid #ffd6e7;
  border-radius: 999px; padding: 10px 18px;
  font-weight: 800; font-size: 18px;
}
.player-chip span:first-child { font-size: 26px; }
.player-chip.waiting { opacity: 0.6; border-style: dashed; }

.settings { margin-top: 10px; text-align: left; }
.settings h3 { text-align: center; margin: 10px 0; }
.setting-group { margin-bottom: 14px; }
.setting-label { font-weight: 700; margin: 0 0 8px 4px; }
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  border: 3px solid #e6d9f2; background: #faf6ff;
  border-radius: 999px; padding: 9px 16px;
  font-size: 16px; font-weight: 700; font-family: inherit; color: #8a7796;
  cursor: pointer; transition: all 0.15s;
}
.pill.active {
  background: linear-gradient(135deg, #b197fc, #9775fa);
  border-color: #9775fa; color: #fff;
  box-shadow: 0 3px 8px rgba(151, 117, 250, 0.35);
}
#btn-start { width: 100%; margin-top: 6px; }

/* ===== 遊戲畫面 ===== */
.game-top { position: sticky; top: 0; z-index: 10; padding: 8px 4px 6px; }
/* 兩側留空給左上🏠/右上🔊圓鈕，分數膠囊不會被蓋到 */
.score-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; padding: 0 48px; }
.player-tag {
  display: flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 16px;
  background: rgba(255,255,255,0.85); border-radius: 999px; padding: 6px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.player-tag b { font-size: 20px; color: #ff6fa5; }
.round-info { text-align: center; font-weight: 700; font-size: 14px; line-height: 1.3; }
.stake { color: #f59f00; }

.tug-wrap { position: relative; }
.tug-bar {
  height: 30px;
  border-radius: 999px; overflow: hidden;
  border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}
.tug-fill {
  height: 100%;
  border-radius: 999px 0 0 999px;
  transition: width 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}
/* 主題色：老細＝綠色、阿寶＝粉紅色（左側永遠是自己） */
.as-laosai .tug-fill { background: linear-gradient(135deg, #b2f2bb, #51cf66); }
.as-laosai .tug-bar  { background: linear-gradient(135deg, #ffdeeb, #ffa8c5); }
.as-abao   .tug-fill { background: linear-gradient(135deg, #ffc2d9, #ff8fab); }
.as-abao   .tug-bar  { background: linear-gradient(135deg, #d3f9d8, #8ce99a); }
.as-laosai #score-me   { color: #2f9e44; }
.as-laosai #score-them { color: #e8557f; }
.as-abao   #score-me   { color: #e8557f; }
.as-abao   #score-them { color: #2f9e44; }
.as-laosai .player-chip.me   { border-color: #8ce99a; background: #ebfbee; }
.as-laosai .player-chip.them { border-color: #ffc2d9; background: #fff0f6; }
.as-abao   .player-chip.me   { border-color: #ffc2d9; background: #fff0f6; }
.as-abao   .player-chip.them { border-color: #8ce99a; background: #ebfbee; }

/* 兩個大頭固定對稱在血條左右兩端 */
.tug-face { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; line-height: 0; }
.left-face { left: 5px; }
.right-face { right: 5px; }

/* ===== 得分推進特效：火花爆裂＋血條震動＋頭像撲擊 ===== */
#fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.spark {
  position: absolute;
  font-size: 18px;
  transform: translate(-50%, -50%) scale(0.6);
  animation: spark-fly 0.75s ease-out forwards;
}
@keyframes spark-fly {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  60%  { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.5) rotate(var(--rot)); opacity: 0; }
}
.tug-bar.hit { animation: bar-shake 0.55s ease; }
@keyframes bar-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.tug-face.attack { animation: attack-pop 0.65s ease; }
@keyframes attack-pop {
  0%, 100% { transform: translateY(-50%) scale(1); }
  35% { transform: translateY(-50%) scale(1.55) rotate(-14deg); }
  65% { transform: translateY(-50%) scale(1.25) rotate(8deg); }
}

.game-card { margin-top: 10px; padding: 20px 18px; }

.banner {
  font-size: 18px; font-weight: 800;
  border-radius: 16px; padding: 6px 14px;
  background: #fff4d6; color: #b07d12;
  transition: background 0.25s, color 0.25s;
  /* 固定兩行高度：文字一行或兩行都不會推擠下方版面 */
  min-height: 64px;
  display: flex; align-items: center; justify-content: center;
}
.banner.open       { background: #fff4d6; color: #b07d12; }
.banner.steal-me   { background: #d3f9d8; color: #2b8a3e; animation: pulse 0.8s ease-in-out infinite; }
.banner.steal-them { background: #ffe3e3; color: #c92a2a; }
.banner.win        { background: #d3f9d8; color: #2b8a3e; }
.banner.lose       { background: #ffe3e3; color: #c92a2a; }
.banner.draw       { background: #e7e2f3; color: #6741d9; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.03); } }

/* 題目區固定高度，單字長短、聽力模式按鈕都不會改變版面 */
.question-box { margin: 12px 0; height: 118px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; overflow: hidden; }
.question-word {
  font-size: 40px; font-weight: 800; color: #5d4a66;
  word-break: break-word; line-height: 1.15;
  max-height: 96px; overflow: hidden;
}
.question-word.listen-mode { font-size: 50px; animation: pulse 1.5s ease-in-out infinite; }
.replay-btn {
  border: 3px solid #d0ebff; background: #e7f5ff; color: #1971c2;
  border-radius: 999px; padding: 8px 18px;
  font-size: 16px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.replay-btn:active { transform: scale(0.95); }

/* 倒數計時：常駐固定高度的格子，用 visibility 顯示/隱藏，不推擠選項 */
.timer-wrap { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; height: 30px; }
.timer-wrap.invisible { visibility: hidden; }
.timer-label { font-weight: 800; font-size: 14px; color: #e8590c; white-space: nowrap; }
.timer-track { flex: 1; height: 14px; background: #ffe8cc; border-radius: 999px; overflow: hidden; }
.timer-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #ffa94d, #ff6b6b);
  border-radius: 999px;
  transition: width 0.1s linear;
}
.timer-num { font-weight: 800; font-size: 20px; color: #e8590c; min-width: 30px; }

/* 選項（直式單欄，適合手機） */
.options { display: grid; grid-template-columns: 1fr; gap: 10px; }
.option {
  padding: 13px 14px;
  border: 3px solid #e6d9f2; border-radius: 18px;
  background: #faf6ff; color: #5d4a66;
  font-size: 20px; font-weight: 700; font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s, border-color 0.2s;
  word-break: break-word;
  min-height: 54px;
}
.option:active:not(:disabled) { transform: scale(0.96); }
.option:disabled { cursor: default; }
.option.pop-in { animation: pop-in 0.3s ease backwards; }
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1); }
}
.option.picked { border-color: #9775fa; background: #f3f0ff; }
.option.crossed {
  text-decoration: line-through;
  opacity: 0.45; background: #f1f3f5; border-color: #dee2e6;
  position: relative;
}
.option.crossed::after { content: " ❌"; }
.option.correct {
  background: linear-gradient(135deg, #d3f9d8, #b2f2bb);
  border-color: #51cf66; color: #2b8a3e;
  animation: correct-bounce 0.5s ease;
}
@keyframes correct-bounce {
  0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); }
}
.option.wrong {
  background: #ffe3e3; border-color: #ff8787; color: #c92a2a;
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); } 75% { transform: translateX(6px); }
}

/* ===== 結算 ===== */
.end-card { margin-top: 6vh; }
.end-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

/* 複習單字浮窗 */
.review-card { max-width: 420px; width: 100%; }
.review-list {
  list-style: none; margin: 10px 0 16px; padding: 0 4px;
  max-height: 50vh; overflow-y: auto;
  text-align: left;
}
.review-list li {
  padding: 9px 6px;
  border-bottom: 2px dashed #f0e6f8;
  font-weight: 700; font-size: 17px;
}
.review-list li:last-child { border-bottom: none; }
.end-emoji { font-size: 80px; animation: bounce 1s ease-in-out infinite; }
.end-title { font-size: 34px; margin: 8px 0; }
.end-detail { font-size: 17px; color: #8a7796; margin-bottom: 20px; }
#btn-rematch { width: 100%; }

/* 斷線遮罩 */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(93, 74, 102, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.overlay .card { max-width: 380px; }

/* 手機直式微調 */
@media (max-width: 480px) {
  .screen { padding: 12px; }
  .card { padding: 22px 16px; border-radius: 24px; }
  .home-card { margin-top: 3vh; }
  .question-word { font-size: 38px; }
  .player-tag { font-size: 14px; padding: 5px 10px; }
  .player-tag b { font-size: 18px; }
}
@media (max-width: 380px) {
  .title { font-size: 34px; }
  .question-word { font-size: 32px; }
  .option { font-size: 17px; padding: 14px 8px; }
  .char-img { width: 72px; height: 72px; }
}
