:root {
  --sesame-red: #E63946;
  --sesame-yellow: #F4D03F;
  --sesame-blue: #3498DB;
  --sesame-green: #2ECC71;
  --white: #FFF9F0;
  --text-dark: #2D2D2D;
  --shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  --cursor-url: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><circle cx="16" cy="16" r="14" fill="%23E63946" stroke="white" stroke-width="2.5"/><circle cx="12" cy="12" r="2.8" fill="white"/><circle cx="20" cy="12" r="2.8" fill="white"/><path d="M12 20 Q16 24.5 20 20" stroke="white" stroke-width="2.5" fill="none" stroke-linecap="round"/></svg>') 16 16, auto;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'M PLUS Rounded 1c', 'Noto Sans TC', sans-serif;
  background-color: #A8D8F0;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: var(--cursor-url);
}

button,
.game-btn,
.sheep,
.box,
.ingredient,
.speech-bubble,
.call-sheep-btn,
.music-btn,
#custom-alert-ok,
.quiz-option {
  cursor: var(--cursor-url);
}

#game-container {
  width: 100%;
  max-width: 1024px;
  height: 100%;
  max-height: 768px;
  background: var(--white);
  border-radius: 40px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* 場景基礎樣式 */
.scene {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

/* 品牌場景（開頭/結尾）直接用背景圖片填滿 */
.scene.brand-scene {
  padding: 0;
  justify-content: center;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.scene.brand-intro {
  background-image: url('assets/brand-intro-desktop.png');
}

.scene.brand-outro {
  background-image: url('assets/brand-outro-desktop.png');
}

/* 結尾重新開始按鈕定位 */
.scene.brand-outro .game-btn {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
}

/* 動態背景容器 */
.dynamic-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.dynamic-bg .floating {
  position: absolute;
  font-size: 1.5rem;
  color: rgba(255, 255, 255, 0.6);
  animation: float-around 10s infinite linear;
  opacity: 0.7;
}

@keyframes float-around {
  0% {
    transform: translate(0, 100vh) rotate(0deg);
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  90% {
    opacity: 1;
  }

  100% {
    transform: translate(20px, -100vh) rotate(360deg);
    opacity: 0;
  }
}

/* 對話氣泡 */
.speech-bubble {
  background: white;
  border: 4px solid var(--sesame-red);
  border-radius: 30px;
  padding: 15px 20px;
  font-size: clamp(0.8rem, 3.1vw, 1.4rem);
  font-weight: 700;
  color: var(--text-dark);
  max-width: 88%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop-in 0.3s ease;
  word-break: break-word;
  overflow-wrap: break-word;
  line-height: 1.4;
  position: relative;
  flex-shrink: 1;
  min-height: 0;
  max-height: 35vh;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.speech-bubble::-webkit-scrollbar {
  display: none;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 20px solid var(--sesame-red);
}

/* 角色頭像 */
.character-img {
  width: clamp(90px, 18vw, 140px);
  height: clamp(90px, 18vw, 140px);
  object-fit: contain;
  background: #FFD166;
  border-radius: 50%;
  border: 4px solid var(--sesame-blue);
  flex-shrink: 0;
  animation: float 3s ease-in-out infinite;
}

/* 按鈕 */
.game-btn {
  background: var(--sesame-red);
  color: white;
  border: none;
  border-radius: 50px;
  padding: clamp(10px, 2.5vw, 18px) clamp(20px, 5vw, 40px);
  font-size: clamp(0.9rem, 3.2vw, 1.5rem);
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

.game-btn::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
}

.game-btn:hover::after {
  opacity: 1;
}

.game-btn:active {
  transform: scale(0.95);
  background: #c12f3a;
}

/* 學習卡片網格 */
.vocab-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 15px;
  width: 100%;
  max-width: 700px;
  margin: 10px 0;
}

.vocab-card {
  background: white;
  border-radius: 20px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  width: clamp(80px, 20vw, 120px);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.2s;
  animation: pop-in 0.4s ease;
}

.vocab-card:hover {
  transform: scale(1.05);
}

.vocab-card img {
  width: 70%;
  height: auto;
  object-fit: contain;
}

.vocab-card .word {
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  font-weight: 700;
  color: var(--sesame-blue);
  margin-top: 5px;
  text-transform: capitalize;
}

/* 測驗階段 */
.quiz-prompt {
  font-size: clamp(1rem, 4vw, 1.8rem);
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 10px;
}

.quiz-image {
  width: clamp(100px, 25vw, 180px);
  height: clamp(100px, 25vw, 180px);
  object-fit: contain;
  background: #FFF3CD;
  border-radius: 30px;
  padding: 10px;
  box-shadow: var(--shadow);
  margin: 10px 0;
}

.quiz-options {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
  margin: 10px 0;
}

.quiz-option {
  background: white;
  border: 4px solid var(--sesame-blue);
  border-radius: 30px;
  padding: 12px 25px;
  font-size: clamp(0.9rem, 3vw, 1.4rem);
  font-weight: 700;
  color: var(--sesame-blue);
  transition: transform 0.2s, background 0.2s;
  font-family: inherit;
}

.quiz-option:hover {
  background: #E3F2FD;
  transform: scale(1.05);
}

.quiz-option.correct {
  background: var(--sesame-green);
  color: white;
  border-color: var(--sesame-green);
}

.quiz-option.wrong {
  background: var(--sesame-red);
  color: white;
  border-color: var(--sesame-red);
}

/* 羊群 */
.sheep-container {
  display: flex;
  gap: 20px;
  margin: 5px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.sheep {
  width: clamp(70px, 14vw, 100px);
  height: clamp(70px, 14vw, 100px);
  background: white;
  border-radius: 50% 50% 40% 40%;
  border: 5px solid #BDC3C7;
  box-shadow: var(--shadow);
  background-size: cover;
  background-position: center;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
  animation: idle-bounce 2s infinite;
}

.sheep:hover {
  transform: scale(1.1);
}

.sheep.selected {
  border-color: var(--sesame-yellow);
  transform: scale(1.15);
  box-shadow: 0 0 0 8px rgba(244, 208, 63, 0.6);
  animation: selected-pulse 0.8s infinite;
}

/* 第三關羊疊疊樂 */
.sheep-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 5px 0;
}

.sheep-stack .sheep {
  margin-bottom: -50px;
  animation: wobble 1.5s infinite ease-in-out;
}

.sheep-stack .sheep:nth-child(1) {
  transform: rotate(-4deg);
}

.sheep-stack .sheep:nth-child(2) {
  transform: rotate(3deg);
}

.sheep-stack .sheep:nth-child(3) {
  transform: rotate(-2deg);
}

.sheep-stack .sheep:last-child {
  margin-bottom: 0;
}

/* 盒子 */
.boxes {
  display: flex;
  gap: 20px;
  margin: 5px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.box {
  width: clamp(70px, 14vw, 100px);
  height: clamp(70px, 14vw, 100px);
  background: #D4AF37;
  border: 5px solid #8B7500;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s, box-shadow 0.3s;
  animation: float-box 4s infinite;
}

.box:hover {
  transform: scale(1.1);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.box img {
  width: 85%;
  height: 85%;
  object-fit: contain;
}

/* 材料 */
.ingredients {
  display: flex;
  gap: 15px;
  margin: 5px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.ingredient {
  width: clamp(60px, 12vw, 90px);
  height: clamp(60px, 12vw, 90px);
  background: #FDEBD0;
  border: 4px solid #D35400;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: ingredient-float 3s infinite alternate;
}

.ingredient img {
  width: 80%;
  height: 80%;
  object-fit: contain;
}

.ingredient:active {
  transform: scale(0.85);
}

.ingredient:hover {
  box-shadow: 0 0 15px rgba(211, 84, 0, 0.5);
}

/* 碗 (第二關) */
.bowl-wrapper {
  position: relative;
  width: clamp(100px, 22vw, 160px);
  height: clamp(70px, 15vw, 110px);
  margin: 5px 0;
  flex-shrink: 0;
  animation: pop-in 0.5s ease;
}

.bowl-wrapper img.bowl-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.4s;
}

.bowl-wrapper.cake-complete img.bowl-img {
  transform: scale(1.1);
}

.bowl-checkmarks {
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  font-size: 1.5rem;
  color: green;
}

/* 呼叫按鈕 */
.call-sheep-btn {
  margin: 5px 0;
  padding: clamp(12px, 2.5vw, 20px) clamp(25px, 6vw, 45px);
  font-size: clamp(0.9rem, 3.2vw, 1.5rem);
}

/* 音樂按鈕 */
.music-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: white;
  border: 3px solid var(--sesame-blue);
  border-radius: 50%;
  font-size: 1.5rem;
  z-index: 1000;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sesame-blue);
  transition: transform 0.2s;
}

.music-btn:active {
  transform: scale(0.9);
}

.music-btn.muted {
  color: var(--sesame-red);
  border-color: var(--sesame-red);
}

/* 自訂提示框 */
.custom-alert-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.custom-alert-overlay.active {
  display: flex;
}

.custom-alert-box {
  background: white;
  border-radius: 40px;
  padding: 30px;
  max-width: 85%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border: 5px solid var(--sesame-yellow);
  animation: pop-in 0.3s ease;
}

#custom-alert-message {
  font-size: clamp(0.9rem, 3.2vw, 1.5rem);
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 20px;
  word-break: break-word;
}

/* 動畫 */
@keyframes pop-in {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

@keyframes float-box {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-5px);
  }
}

@keyframes idle-bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-6px);
  }

  60% {
    transform: translateY(0);
  }
}

@keyframes selected-pulse {

  0%,
  100% {
    transform: scale(1.15);
  }

  50% {
    transform: scale(1.05);
  }
}

@keyframes wobble {

  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(3deg);
  }

  75% {
    transform: rotate(-3deg);
  }
}

@keyframes ingredient-float {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(-4px);
  }
}

/* 響應式品牌背景切換 */
@media (max-width: 700px) {
  .scene.brand-intro {
    background-image: url('assets/brand-intro-mobile.png');
  }

  .scene.brand-outro {
    background-image: url('assets/brand-outro-mobile.png');
  }

  .scene.brand-outro .game-btn {
    bottom: 8%;
  }

  .scene {
    padding: 12px;
    gap: 8px;
  }

  .music-btn {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }
}