/* 全站基底樣式 */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  padding: 0;
  background: #f2f5ff;
  color: #222;
}

/* -------- 首頁樣式（第一層：主題選擇） -------- */

.home-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at top, #c7e5ff 0, #f2f5ff 55%);
}

.home-header {
  padding: 24px 20px 12px;
  text-align: center;
  color: #123055;
}

.home-header h1 {
  margin: 0;
  font-size: 34px;
}

.home-subtitle {
  margin: 8px 0 0;
  font-size: 16px;
}

.home-main {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 36px;
}

/* 遊戲說明卡片 */
.home-intro-card {
  background: #ffffffcc;
  border-radius: 18px;
  padding: 18px 22px;
  box-shadow: 0 6px 18px rgba(24, 61, 120, 0.14);
  margin-bottom: 20px;
  backdrop-filter: blur(4px);
}

.home-intro-card h2 {
  margin-top: 0;
  font-size: 20px;
}

.home-intro-card ul {
  margin: 8px 0 8px 22px;
  padding-left: 0;
}

.home-intro-card li {
  margin-bottom: 4px;
}

.home-tip {
  margin-top: 6px;
  font-size: 14px;
  color: #555;
}

/* 主題選擇區 */
.home-topic-section h2 {
  margin-top: 0;
  font-size: 20px;
}

.home-topic-hint {
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
}

/* 主題卡片區：一個個大方框 */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.topic-card {
  background: #ffffff;
  border-radius: 18px;
  padding: 14px 14px 12px;
  box-shadow: 0 6px 14px rgba(37, 63, 117, 0.16);
  cursor: pointer;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    border-color 0.12s ease,
    background-color 0.12s ease;
}

.topic-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 9px 20px rgba(37, 63, 117, 0.22);
}

.topic-card.selected {
  border-color: #34c759;
  background: linear-gradient(135deg, #e8ffe9, #f3fff5);
}

.topic-emoji {
  font-size: 34px;
  flex-shrink: 0;
}

.topic-info {
  flex: 1;
}

.topic-title {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 16px;
}

.topic-count {
  font-size: 13px;
  color: #555;
}

.topic-selected-tag {
  display: none;
  margin-top: 4px;
  font-size: 12px;
  color: #1b7a33;
}

.topic-card.selected .topic-selected-tag {
  display: inline-block;
}

/* 按鈕共用樣式 */
.btn {
  border-radius: 999px;
  border: none;
  padding: 8px 18px;
  font-size: 15px;
  cursor: pointer;
  transition:
    transform 0.08s ease,
    box-shadow 0.08s ease,
    opacity 0.08s ease,
    background-color 0.12s ease;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: #34c759;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(52, 199, 89, 0.4);
}

.btn-primary:hover:not(:disabled) {
  background: #2fb151;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(52, 199, 89, 0.5);
}

.btn-secondary {
  background: #e0e0e0;
  color: #333;
}

.btn-secondary:hover:not(:disabled) {
  background: #d0d0d0;
  transform: translateY(-1px);
}

.home-footer {
  text-align: center;
  font-size: 12px;
  color: #777;
  padding: 10px 0 14px;
}

/* -------- 一般 main 頁面（舊 game.html） -------- */

header h1 {
  margin: 16px;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

.game-intro {
  background: #ffffff;
  border-radius: 18px;
  padding: 20px 24px;
  box-shadow: 0 5px 18px rgba(15, 35, 95, 0.12);
}

.game-intro h2 {
  margin-top: 0;
}

.game-intro-note {
  font-size: 14px;
  color: #666;
}

.game-intro a {
  color: #0066cc;
}

/* -------- 遊戲主畫面基底（第二層 & 第三層共用） -------- */

.game-header {
  padding-top: 20px;
  padding-bottom: 6px;
  max-width: 1100px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.game-header h1 {
  margin: 0;
  font-size: 28px;
}

.game-subtitle {
  max-width: 1100px;
  margin: 0 auto 10px;
  padding: 0 16px;
  font-size: 14px;
  color: #555;
}

/* Game 主框架（第三層遊戲頁會用到） */
.game-main-wrapper {
  max-width: 1100px;
  margin: 0 auto 40px;
  padding: 0 16px 24px;
  display: flex;
  gap: 16px;
}

.game-sidebar {
  width: 220px;
  background: #ffffff;
  border-radius: 16px;
  padding: 16px 16px 18px;
  box-shadow: 0 4px 12px rgba(15, 35, 95, 0.1);
  font-size: 14px;
}

.game-sidebar h2 {
  margin-top: 0;
  font-size: 18px;
}

.sidebar-tip {
  font-size: 12px;
  color: #666;
  margin-top: 8px;
}

.sidebar-back-btn {
  display: inline-block;
  margin-top: 10px;
  text-decoration: none;
  text-align: center;
}

.game-main {
  flex: 1;
}

/* 第二層 & 第三層：上方「選擇其他主題 / 遊戲」按鈕列 */
.top-back-row {
  max-width: 1100px;
  margin: 6px auto 0;
  padding: 0 16px;
  text-align: right;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* -------- 第二層 Game 首頁：四款遊戲選單 -------- */

.game-menu-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 10px;
}

.game-menu-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  background: #ffffff;
  border-radius: 16px;
  padding: 14px 10px;
  box-shadow: 0 4px 12px rgba(15, 35, 95, 0.12);
  color: #123055;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.game-menu-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(15, 35, 95, 0.18);
}

.game-menu-icon {
  font-size: 32px;
  margin-bottom: 6px;
}

.game-menu-title {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
}

.game-menu-desc {
  font-size: 13px;
  color: #555;
}

/* -------- 共用：階段面板 -------- */

.stage-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.stage-tab-button {
  flex: 1 1 auto;
  min-width: 160px;
  border-radius: 999px;
  border: none;
  padding: 8px 10px;
  font-size: 14px;
  cursor: pointer;
  background: #e1e8ff;
  color: #234;
  transition: background-color 0.12s ease, transform 0.08s ease;
}

.stage-tab-button.active {
  background: #4e7fff;
  color: #fff;
  transform: translateY(-1px);
}

.stage-panel {
  display: none;
  background: #ffffff;
  border-radius: 16px;
  padding: 16px 18px 20px;
  box-shadow: 0 4px 14px rgba(15, 35, 95, 0.14);
}

.stage-panel.active {
  display: block;
}

.stage-header-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.stage-header-line h2 {
  margin: 0;
  font-size: 18px;
}

.stage-note {
  font-size: 13px;
  color: #555;
  margin-top: 4px;
  margin-bottom: 10px;
}

.stage-status {
  font-size: 14px;
  margin-bottom: 8px;
}

/* 共同小提醒文字顏色 */
.stage-feedback {
  margin-top: 8px;
  font-size: 14px;
}

.stage-feedback.ok {
  color: #1b7a33;
}

.stage-feedback.error {
  color: #c0392b;
}

/* -------- 第 1 階段 -------- */

.stage1-layout {
  display: flex;
  gap: 14px;
}

.stage1-list {
  flex: 0 0 40%;
  max-width: 40%;
}

.stage1-detail {
  flex: 1;
}

.word-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.word-card {
  background: #f4f7ff;
  border-radius: 14px;
  border: none;
  padding: 10px 6px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  font-size: 14px;
}

.word-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.12);
}

.word-card-img span {
  font-size: 32px;
}

.word-card-img img {
  max-width: 50px;
  max-height: 50px;
}

.word-card-en {
  font-weight: 600;
}

/* 右側單字卡 */
.stage1-card {
  margin-top: 6px;
  border-radius: 16px;
  background: #f8f9ff;
  padding: 12px 14px 14px;
}

.stage1-card.hidden {
  display: none;
}

.stage1-main-info {
  display: flex;
  gap: 10px;
  align-items: center;
}

.stage1-img span {
  font-size: 60px;
}

.stage1-img img {
  max-width: 80px;
  max-height: 80px;
}

.stage1-en {
  font-size: 24px;
  font-weight: 700;
}

.stage1-zh {
  font-size: 16px;
  margin-top: 2px;
}

.stage1-audio-buttons {
  margin-top: 6px;
  display: flex;
  gap: 8px;
}

.btn-audio {
  background: #fff;
  border-radius: 999px;
  border: 1px solid #cfd7ff;
  padding: 4px 10px;
  font-size: 14px;
}

.btn-sm {
  font-size: 14px;
  padding: 4px 12px;
}

.stage1-spell-area {
  margin-top: 10px;
}

.stage1-spell-display {
  margin-top: 6px;
  min-height: 24px;
  font-size: 20px;
  font-weight: 600;
}

.stage1-letters {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.letter-tile {
  min-width: 36px;
  min-height: 36px;
  border-radius: 8px;
  border: none;
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.letter-tile.used {
  opacity: 0.4;
}

/* -------- 第 2 階段：配對 -------- */

.btn-orange {
  background: #ff9f43;
  color: #fff;
}

.btn-orange:hover {
  background: #ff8f21;
}

.match-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.match-card {
  flex: 0 0 calc(33.33% - 6px);
  border-radius: 14px;
  border: none;
  background: #fdfdfd;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  padding: 10px 8px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}

.match-card-inner {
  display: flex;
  align-items: center;
  gap: 6px;
}

.match-card-zh {
  background: #fff6e6;
}

.match-card-en {
  background: #e9f4ff;
}

.match-card.selected {
  outline: 2px solid #4e7fff;
}

.match-card.matched {
  opacity: 0.3;
}

/* -------- 第 3 階段：101 大樓 -------- */

.stage3-layout {
  display: flex;
  gap: 14px;
}

.stage3-left {
  flex: 1;
}

.stage3-right {
  width: 260px;
}

.stage3-question-box {
  border-radius: 12px;
  background: #f8f9ff;
  padding: 10px 12px;
  position: relative;
  min-height: 80px;
}

.stage3-question-text {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.stage3-question-prompt {
  margin-top: 2px;
  font-size: 18px;
}

.question-zh {
  font-size: 22px;
}

.question-img span {
  font-size: 44px;
}

.question-img img {
  max-width: 70px;
  max-height: 70px;
}

.question-listen {
  font-size: 16px;
}

.right-audio-btn {
  position: absolute;
  top: 10px;
  right: 10px;
}

.stage3-options {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stage3-option-card {
  border-radius: 16px;
  border: none;
  background: #f4f7ff;
  padding: 14px 10px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.stage3-bottom-buttons {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.big-btn {
  padding: 8px 16px;
  font-size: 16px;
}

.building-panel {
  background: #f3f6ff;
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.building-header {
  font-size: 14px;
  margin-bottom: 6px;
}

.building-visual-wrapper {
  position: relative;
  height: 260px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.building-tower {
  width: 70px;
  border-radius: 10px 10px 4px 4px;
  background: linear-gradient(to top, #4e7fff, #89b4ff);
  padding: 4px 2px 2px;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  height: 220px;
  overflow: hidden;
}

.building-block {
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.9);
  flex: 1 0 auto;
}

.building-change {
  position: absolute;
  top: 16px;
  right: 12px;
  font-size: 18px;
  font-weight: 700;
  color: #2ecc71;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.building-change.show {
  opacity: 1;
  transform: translateY(0);
}

.building-great {
  position: absolute;
  bottom: 12px;
  right: 10px;
  font-size: 16px;
  color: #fffbea;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
}

/* -------- 第 4 階段：火車載貨 -------- */

.stage4-layout {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stage4-top {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8f9ff;
  padding: 8px 10px;
  border-radius: 12px;
}

.stage4-img span {
  font-size: 44px;
}

.stage4-img img {
  max-width: 70px;
  max-height: 70px;
}

.stage4-zh {
  font-size: 20px;
}

.stage4-en-hint {
  font-size: 14px;
  color: #555;
}

.stage4-top-text {
  flex: 1;
}

/* 題目右側的「已裝滿火車」顯示 */
.stage4-done-display,
#stage4-done-wrapper {
  font-size: 18px;
  font-weight: 700;
  color: #e67e22;
}

.stage4-middle {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.train-area {
  position: relative;
  height: 110px;
  overflow: hidden;
}

.train-track {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  height: 4px;
  background: #888;
}

.train {
  position: absolute;
  bottom: 18px;
  right: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.8s ease;
}

.train-head {
  font-size: 32px;
}

.train-cars {
  display: flex;
  gap: 4px;
}

.letter-slot {
  min-width: 36px;
  min-height: 40px;
  border-radius: 8px;
  border: 2px dashed #aaa;
  background: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.letter-pool-wrapper {
  background: #f8f9ff;
  border-radius: 12px;
  padding: 8px 10px;
}

.letter-pool-label {
  font-size: 14px;
  margin-bottom: 4px;
}

.letter-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.big-letter {
  min-width: 40px;
  min-height: 40px;
  font-size: 22px;
}

/* 火車動畫 */
/* 正常出發：從目前位置一路開到左邊外面 */
.train-move {
  transform: translateX(-120%);
}

/* 答錯時閃一下 */
.train-flash {
  animation: trainFlash 0.4s ease-in-out 2;
}

@keyframes trainFlash {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.2;
  }
  100% {
    opacity: 1;
  }
}

.stage4-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
}

.stage4-progress {
  font-size: 14px;
}

/* -------- 煙火效果（共用） -------- */

.fireworks-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.fireworks-overlay.hidden {
  display: none;
}

.fireworks-content {
  text-align: center;
  color: #fff;
}

.fireworks-text {
  font-size: 28px;
  margin-bottom: 12px;
}

.fireworks-area {
  position: relative;
  width: 260px;
  height: 200px;
}

.firework {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffe066;
  animation: explode 1.3s ease-out infinite;
}

.firework.f1 {
  top: 50%;
  left: 50%;
}

.firework.f2 {
  top: 30%;
  left: 20%;
  animation-delay: 0.2s;
  background: #ff7675;
}

.firework.f3 {
  top: 25%;
  left: 70%;
  animation-delay: 0.4s;
  background: #74b9ff;
}

.firework.f4 {
  top: 70%;
  left: 30%;
  animation-delay: 0.1s;
  background: #55efc4;
}

.firework.f5 {
  top: 65%;
  left: 75%;
  animation-delay: 0.3s;
  background: #fd79a8;
}

@keyframes explode {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  70% {
    transform: translate(-40px, -60px) scale(2);
    opacity: 0.9;
  }
  100% {
    transform: translate(40px, 60px) scale(0);
    opacity: 0;
  }
}

/* -------- RWD 大致調整 -------- */

/* 平板以下（含手機） */
@media (max-width: 900px) {
  body {
    font-size: 16px;
  }

  .home-main {
    max-width: 100%;
    padding: 16px 14px 28px;
  }

  .home-header h1 {
    font-size: 30px;
  }

  .home-subtitle {
    font-size: 15px;
  }

  .topic-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .game-header {
    padding-top: 18px;
    padding-left: 14px;
    padding-right: 14px;
  }

  .game-header h1 {
    font-size: 24px;
  }

  .game-subtitle {
    padding: 0 14px;
    font-size: 13px;
  }

  .top-back-row {
    padding: 0 14px;
    justify-content: space-between;
  }

  .game-main-wrapper {
    flex-direction: column;
    padding: 0 14px 24px;
    gap: 12px;
  }

  .game-sidebar {
    width: 100%;
    font-size: 14px;
  }

  /* 第二層遊戲選單：手機與平板固定 2 欄 */
  .game-menu-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-panel {
    padding: 14px 12px 18px;
  }

  .stage-header-line h2 {
    font-size: 17px;
  }

  /* 第 1 階段：單字卡改 2 欄 */
  .stage1-layout {
    flex-direction: column;
  }

  .stage1-list,
  .stage1-detail {
    max-width: 100%;
    flex: 1 1 auto;
  }

  .word-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage1-en {
    font-size: 22px;
  }

  /* 第 2 階段：配對卡在窄螢幕比較寬鬆 */
  .match-card {
    flex: 0 0 calc(50% - 6px);
    font-size: 14px;
  }

  /* 第 3 階段：上下排列，大樓在下方 */
  .stage3-layout {
    flex-direction: column;
  }

  .stage3-right {
    width: 100%;
  }

  .stage3-question-box {
    min-height: 88px;
  }

  .stage3-question-text,
  .stage3-question-prompt {
    font-size: 16px;
  }

  .building-visual-wrapper {
    height: 240px;
  }

  /* 第 4 階段：題目區改成直向排版，喇叭與進度更好點 */
  .stage4-top {
    flex-direction: column;
    align-items: flex-start;
  }

  #stage4-done-wrapper {
    align-self: flex-end;
    font-size: 17px;
  }

  .stage4-zh {
    font-size: 18px;
  }

  .letter-pool-label {
    font-size: 13px;
  }

  .stage4-controls {
    flex-wrap: wrap;
  }
}

/* 更窄的手機（例如 375 以下）做一點微調 */
@media (max-width: 480px) {
  .home-header h1 {
    font-size: 26px;
  }

  .home-intro-card {
    padding: 14px 14px;
  }

  .game-header h1 {
    font-size: 22px;
  }

  .game-subtitle {
    font-size: 12px;
  }

  .word-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .match-card {
    flex: 0 0 100%;
  }

  .stage3-options {
    grid-template-columns: 1fr;
  }
}
