@import url("https://fonts.googleapis.com/css2?family=ZCOOL+KuaiLe&family=Noto+Sans+TC:wght@400;700&display=swap");

:root {
  --pink: #ff8fb8;
  --peach: #ffc4a3;
  --mint: #7ed6c1;
  --sky: #8ec5ff;
  --lavender: #c9b6ff;
  --orange: #ff9f43;
  --cream: #fff7fb;
  --ink: #4a3b55;
  --panel: rgba(255, 255, 255, 0.88);
  --shadow: 0 10px 30px rgba(90, 60, 120, 0.18);
  --radius: 22px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 20%, #ffe4f2, transparent 40%),
    radial-gradient(circle at 80% 10%, #d9f5ff, transparent 35%),
    linear-gradient(180deg, #f7e9ff 0%, #e8fff7 45%, #fff0e8 100%);
  overflow-x: hidden;
  padding-bottom: 70px;
}

body.playing {
  overflow: hidden;
}

h1, h2, h3, .brand {
  font-family: "ZCOOL KuaiLe", "Noto Sans TC", cursive;
  letter-spacing: 0.02em;
}

button, input {
  font: inherit;
}

.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
  position: relative;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ===== Home ===== */
#home {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0.55)),
    url("../assets/bg/bg1.jpg") center/cover no-repeat;
}

.home-shell {
  width: min(920px, 100%);
  background: var(--panel);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 28px 28px 32px;
  backdrop-filter: blur(6px);
  animation: floatIn 0.7s ease both;
}

.brand {
  font-size: clamp(2rem, 5vw, 3.2rem);
  margin: 0 0 6px;
  text-align: center;
  background: linear-gradient(90deg, #ff6fa8, #6ec8ff, #7ed6c1);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  text-align: center;
  margin: 0 0 22px;
  color: #6d5a7c;
}

.home-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 22px;
}

.panel-block {
  background: linear-gradient(180deg, #fff, #fff6fb);
  border: 2px solid #ffd0e6;
  border-radius: var(--radius);
  padding: 18px;
}

.panel-block label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

#playerName {
  width: 100%;
  border: 2px solid #ffb7d5;
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
  background: #fff;
}

#playerName:focus {
  border-color: #7ec8ff;
  box-shadow: 0 0 0 3px rgba(126, 200, 255, 0.25);
}

.story-box {
  margin-top: 14px;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #5d4b6a;
}

.char-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.char-card {
  border: 3px solid transparent;
  border-radius: 18px;
  background: #fff;
  cursor: pointer;
  padding: 10px;
  text-align: center;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.char-card img {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  filter: drop-shadow(0 10px 8px rgba(90, 60, 100, 0.22));
  background: radial-gradient(ellipse at 50% 88%, rgba(255, 214, 230, 0.55) 0%, rgba(255, 255, 255, 0) 62%);
}

.char-card span {
  display: block;
  margin-top: 6px;
  font-weight: 700;
}

.char-card:hover { transform: translateY(-3px); }

.char-card.selected {
  border-color: #7ed6c1;
  box-shadow: 0 0 0 4px rgba(126, 214, 193, 0.25);
}

.home-actions {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 6px 0 rgba(0,0,0,0.08);
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); box-shadow: 0 2px 0 rgba(0,0,0,0.08); }

.btn-primary {
  background: linear-gradient(90deg, #ff8fb8, #ffa86b);
  color: #fff;
}

.btn-secondary {
  background: linear-gradient(90deg, #8ec5ff, #7ed6c1);
  color: #fff;
}

.btn-ghost {
  background: #fff;
  color: var(--ink);
  border: 2px solid #ffd0e6;
}

.music-bottom {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 60;
}

#game.aim-mode,
#game.aim-mode .stage,
#game.aim-mode .shoot-arena,
#game.aim-mode .flying-target {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Ccircle cx='20' cy='20' r='14' fill='none' stroke='%23ff4d6d' stroke-width='2'/%3E%3Ccircle cx='20' cy='20' r='3' fill='%23ff4d6d'/%3E%3Cpath d='M20 2v8M20 30v8M2 20h8M30 20h8' stroke='%23ff4d6d' stroke-width='2'/%3E%3C/svg%3E") 20 20, crosshair;
}

/* ===== Story / Level intro ===== */
#intro, #cg, #result, #feedback {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: min(860px, 100%);
  background: var(--panel);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 22px;
  animation: popIn 0.35s ease both;
}

.modal-card h2 {
  margin: 0 0 10px;
  color: #d45d8d;
}

.boss-row {
  display: flex;
  gap: 16px;
  align-items: center;
}

.boss-row img {
  width: 140px;
  height: 140px;
  object-fit: contain;
  filter: drop-shadow(0 12px 10px rgba(70, 50, 90, 0.25));
  background: radial-gradient(ellipse at 50% 90%, rgba(255, 214, 230, 0.5) 0%, rgba(255, 255, 255, 0) 60%);
  padding-bottom: 6px;
}

.cg-frame {
  width: min(980px, 100%);
  background: #fff;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: popIn 0.4s ease both;
}

.cg-frame img {
  width: 100%;
  display: block;
  max-height: 58vh;
  object-fit: cover;
}

.cg-caption {
  padding: 16px 18px 18px;
  background: linear-gradient(180deg, #fff, #fff4fa);
}

/* ===== Game stage ===== */
#game {
  height: 100vh;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.game-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(255,255,255,0.55));
  z-index: 5;
}

.pill {
  background: rgba(255,255,255,0.92);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.char-layer {
  position: absolute;
  inset: auto 0 0 0;
  height: 38%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 4% 1%;
  pointer-events: none;
  z-index: 2;
}

.char-layer img {
  height: min(34vh, 260px);
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 14px 10px rgba(70, 50, 90, 0.28));
  background: radial-gradient(ellipse at 50% 92%, rgba(255, 210, 230, 0.5) 0%, rgba(255, 255, 255, 0) 58%);
  padding: 0 8px 6px;
  animation: idleBob 2.8s ease-in-out infinite;
}

.char-layer .boss {
  animation-delay: 0.4s;
}

.question-dock {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  width: min(720px, 92%);
  z-index: 4;
  background: rgba(255,255,255,0.94);
  border: 3px solid #ffc1dc;
  border-radius: 18px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  max-height: 22%;
  overflow: auto;
}

#game.drag-mode .question-dock {
  top: 6px;
  max-height: none;
  width: min(560px, 66%);
  padding: 8px 12px;
  z-index: 6;
}

#game.drag-mode .question-dock .q-text {
  font-size: 0.95rem;
  margin-bottom: 2px;
}

#game.drag-mode .question-dock .hint {
  font-size: 0.78rem;
}

#game.drag-mode .char-layer {
  height: 30%;
  z-index: 5;
  padding: 0 2% 0;
}

#game.drag-mode .char-layer img {
  height: min(26vh, 200px);
}

.question-dock .q-text {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 8px;
  line-height: 1.45;
}

.question-dock .hint {
  margin: 0;
  color: #7a678b;
  font-size: 0.9rem;
}

/* Level 1 shoot - fixed positions */
.shoot-arena {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  width: min(680px, 94%);
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 14px;
  z-index: 5;
  pointer-events: auto;
}

.flying-target {
  min-width: 88px;
  padding: 14px 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fff, #ffe8f3);
  border: 3px solid #ff9fc4;
  font-weight: 700;
  box-shadow: 0 8px 16px rgba(0,0,0,0.12);
  transition: transform 0.1s;
}

.flying-target:hover { transform: scale(1.05); }
.flying-target.hit-correct {
  background: #c8ffe8;
  border-color: #39c28a;
}
.flying-target.hit-wrong {
  background: #ffd0d0;
  border-color: #ef6b6b;
}

/* Level 2 mole */
.mole-board {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(680px, 94%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  z-index: 5;
  pointer-events: auto;
}

.mole-hole {
  height: 110px;
  border-radius: 50% 50% 40% 40%;
  background: radial-gradient(circle at 50% 30%, #8b5a3c, #5a3824);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 -10px 0 rgba(0,0,0,0.15);
}

.mole-btn {
  position: absolute;
  left: 50%;
  bottom: -80%;
  transform: translateX(-50%);
  width: 86%;
  border: none;
  border-radius: 18px 18px 10px 10px;
  padding: 12px 8px;
  background: linear-gradient(180deg, #ffe8f5, #ffd0e8);
  font-weight: 700;
  cursor: pointer;
  transition: bottom 0.18s ease;
}

.mole-btn.up { bottom: 12%; }
.mole-btn.correct { background: #c8ffe8; }
.mole-btn.wrong { background: #ffd0d0; }

/* Level 3 drag — 置中偏上，不遮題目框與左右角色 */
.drag-area {
  position: absolute;
  left: 50%;
  top: 22%;
  bottom: 32%;
  transform: translateX(-50%);
  width: min(560px, 66%);
  z-index: 3;
  display: grid;
  gap: 6px;
  align-content: start;
  pointer-events: auto;
  background: rgba(255,255,255,0.92);
  border: 2px solid #ffd0a8;
  border-radius: 16px;
  padding: 8px 10px;
  overflow: auto;
}

.sentence-bar {
  background: linear-gradient(180deg, #fff8f0, #fff);
  border: 2px solid #ffb36b;
  border-radius: 12px;
  padding: 6px 8px 8px;
}

.sentence-label,
.pool-label {
  text-align: center;
  font-weight: 700;
  color: #d36b00;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.pool-label { color: #5d6f9a; }

.slots-row, .tiles-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: stretch;
}

.sentence-slots .slot {
  min-width: 64px;
  min-height: 44px;
  border-radius: 12px;
  border: 2px dashed #b7a2c8;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px 4px;
  font-weight: 700;
  position: relative;
  font-size: 0.95rem;
}

.sentence-slots .slot::before {
  content: attr(data-num);
  position: absolute;
  top: 2px;
  left: 6px;
  font-size: 0.7rem;
  color: #8a739c;
}

.sentence-slots .punct-slot {
  /* 與一般空格相同，不提示標點位置 */
  border-color: #b7a2c8;
  background: #fff;
  min-width: 72px;
}

.tile {
  border: none;
  border-radius: 12px;
  padding: 8px 10px;
  background: #fff;
  border: 2px solid #8ec5ff;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  font-size: 0.95rem;
}

.tile.punct-tile {
  border-color: var(--orange);
  background: #fff3e6;
  color: #c45f00;
}

.tile:active { transform: scale(0.96); }

.drag-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}

/* Level 4 mcq */
.mcq-options {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  width: min(640px, 92%);
  display: grid;
  gap: 10px;
  z-index: 5;
  pointer-events: auto;
}

.mcq-btn {
  text-align: left;
  border: 3px solid #c9b6ff;
  background: rgba(255,255,255,0.94);
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s, background 0.15s;
}

.mcq-btn:hover { transform: translateX(4px); }
.mcq-btn.correct { background: #c8ffe8; border-color: #39c28a; }
.mcq-btn.wrong { background: #ffd0d0; border-color: #ef6b6b; }

/* Feedback overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(50, 30, 60, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}

.overlay.active { display: flex; }

.feedback-card {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: popIn 0.3s ease both;
}

.feedback-card.ok { border-top: 8px solid #39c28a; }
.feedback-card.bad { border-top: 8px solid #ef6b6b; }

/* Result */
#result {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.5), rgba(255,255,255,0.72)),
    url("../assets/bg/bg2.jpg") center/cover no-repeat;
}

.result-shell {
  width: min(980px, 100%);
  background: var(--panel);
  border-radius: 28px;
  padding: 22px;
  box-shadow: var(--shadow);
  max-height: 92vh;
  overflow: auto;
}

.cast-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 12px 0 18px;
}

.cast-item {
  width: 120px;
  text-align: center;
  background: #fff;
  border-radius: 16px;
  padding: 8px;
  border: 2px solid #ffe0ef;
}

.cast-item img {
  width: 100%;
  height: 100px;
  object-fit: contain;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.score-card {
  background: linear-gradient(180deg, #fff, #f3fff9);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
  border: 2px solid #b8efd8;
}

.wrong-list {
  background: #fff;
  border-radius: 16px;
  border: 2px solid #ffd0e6;
  padding: 12px;
}

.wrong-item {
  padding: 10px 0;
  border-bottom: 1px dashed #f0d4e4;
}

.wrong-item:last-child { border-bottom: none; }

@keyframes floatIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes idleBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

@media (max-width: 800px) {
  .home-grid { grid-template-columns: 1fr; }
  .score-grid { grid-template-columns: 1fr 1fr; }
  .char-layer img { height: min(28vh, 180px); }
  .question-dock { max-height: 36%; }
  .boss-row { flex-direction: column; text-align: center; }
  .mole-hole { height: 90px; }
  #game.drag-mode .question-dock {
    width: min(520px, 72%);
    max-height: 18%;
  }
  #game.drag-mode .drag-area {
    top: 20%;
    bottom: 30%;
    width: min(520px, 72%);
  }
  #game.drag-mode .char-layer img {
    height: min(22vh, 160px);
  }
}
