:root {
  --sky: #7ec8ff;
  --pink: #ff8fb8;
  --mint: #7decc8;
  --peach: #ffc28a;
  --cream: #fff7ef;
  --ink: #3a2f4a;
  --orange: #ff8a3d;
  --panel: rgba(255, 247, 239, 0.92);
  --shadow: 0 12px 30px rgba(58, 47, 74, 0.18);
  --radius: 22px;
  --font: "Zen Maru Gothic", "Microsoft JhengHei", "PingFang TC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #bfe4ff;
  overflow-x: hidden;
}

button, input { font-family: inherit; }

.music-toggle {
  position: fixed;
  top: auto;
  bottom: 16px;
  right: 16px;
  z-index: 100;
  border: 2px solid #ffd0e4;
  background: rgba(255, 247, 239, 0.95);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.music-toggle.on {
  border-color: #7ec8ff;
  background: linear-gradient(135deg, #dff3ff, #fff7ef);
}

.music-hint {
  margin: 0;
  color: #7a6a8a;
  font-size: 0.9rem;
}

#app {
  min-height: 100vh;
  position: relative;
}

.screen {
  display: none;
  min-height: 100vh;
  position: relative;
  background-size: cover;
  background-position: center;
}

.screen.active { display: flex; align-items: center; justify-content: center; }

#screen-home {
  background-image: linear-gradient(180deg, rgba(126,200,255,.25), rgba(255,143,184,.2)), url("../assets/bg/bg_home.jpg");
}

#screen-story,
#screen-level-intro,
#screen-level-done {
  background-image: linear-gradient(180deg, rgba(255,247,239,.35), rgba(126,200,255,.25)), url("../assets/bg/bg_home.jpg");
}

#screen-summary {
  background-image: linear-gradient(180deg, rgba(255,247,239,.45), rgba(255,143,184,.25)), url("../assets/bg/bg_summary.jpg");
  align-items: flex-start;
  padding: 24px 12px 40px;
}

.overlay-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(40, 28, 58, 0.45);
  backdrop-filter: blur(2px);
}

.home-overlay,
.dialog-panel,
.summary-panel {
  width: min(720px, 94vw);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  text-align: center;
  animation: pop-in .45s ease;
}

.game-title {
  margin: 0 0 8px;
  padding: 0 8px;
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: 0.04em;
  text-shadow: 0 4px 0 #fff, 0 8px 18px rgba(255,143,184,.45);
  position: relative;
  z-index: 2;
}

.game-title span {
  display: inline-block;
  padding: 0 .12em;
}

.game-title span:first-child { color: #ff5f9a; }
.game-title span:last-child { color: #3d8dff; }

.game-tagline {
  margin: 0 0 18px;
  font-size: 1.05rem;
  color: #5a4a6a;
}

.home-card { display: grid; gap: 16px; }

.field {
  display: grid;
  gap: 8px;
  text-align: left;
  font-weight: 700;
}

.field input {
  border: 3px solid #ffd0e4;
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 1.1rem;
  outline: none;
  background: #fff;
}

.field input:focus { border-color: #ff8fb8; }

.hero-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.hero-btn {
  border: 3px solid #ffe0ef;
  background: #fff;
  border-radius: 18px;
  padding: 10px;
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}

.hero-btn img {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  display: block;
}

.hero-btn strong { display: block; margin-top: 4px; font-size: 1.15rem; }
.hero-btn em { color: #7a6a8a; font-style: normal; font-size: .9rem; }

.hero-btn.selected,
.hero-btn:hover {
  border-color: #ff8fb8;
  transform: translateY(-3px);
  box-shadow: 0 10px 18px rgba(255,143,184,.28);
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}

.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(0); }

.btn.primary {
  background: linear-gradient(135deg, #ff8fb8, #ffb36b);
  color: #fff;
  box-shadow: 0 8px 0 #e36a94;
}

.btn.secondary {
  background: linear-gradient(135deg, #7ec8ff, #8be0c8);
  color: #fff;
  box-shadow: 0 8px 0 #4ea0d8;
}

.btn.ghost {
  background: rgba(255,255,255,.75);
  color: var(--ink);
  border: 2px solid #ffd0e4;
}

.btn.big { padding: 14px 28px; font-size: 1.2rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.story-chars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 140px;
}

.story-chars img { height: 130px; object-fit: contain; }
.story-chars img.tiny { height: 78px; opacity: .95; }

.intro-boss {
  height: 180px;
  object-fit: contain;
  filter: drop-shadow(0 10px 12px rgba(0,0,0,.15));
  animation: bounce-soft 1.8s ease-in-out infinite;
}

#play-stage {
  width: 100%;
  min-height: 100vh;
  position: relative;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.hud > div {
  background: rgba(255,247,239,.88);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  font-weight: 800;
}

.hud-center { text-align: center; }
.hud-right { text-align: right; color: #d45588; }

.progress-bar {
  margin-top: 6px;
  height: 10px;
  background: #ffe0ef;
  border-radius: 999px;
  overflow: hidden;
}

#progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff8fb8, #ffb36b);
  transition: width .3s ease;
}

.stage-chars {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 70px;
  pointer-events: none;
  z-index: 2;
}

.char {
  position: absolute;
  bottom: 4%;
  height: min(46vh, 340px);
  max-width: 28vw;
  object-fit: contain;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,.18));
  animation: idle 2.4s ease-in-out infinite;
}

.char.hero { left: 1%; }
.char.boss { right: 1%; animation-delay: .4s; }

.question-dock {
  position: absolute;
  left: 50%;
  top: 78px;
  bottom: auto;
  transform: translateX(-50%);
  width: min(560px, 46vw);
  max-height: calc(100vh - 110px);
  overflow: auto;
  z-index: 6;
  background: rgba(255, 247, 239, 0.9);
  border: 3px solid rgba(255, 143, 184, 0.55);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 12px 14px 16px;
}

.q-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: .92rem;
  color: #7a6a8a;
  font-weight: 700;
}

.q-text {
  margin: 0 0 12px;
  font-size: clamp(1.05rem, 2.6vw, 1.35rem);
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
}

/* Level 1 shooting */
.shoot-arena {
  position: relative;
  min-height: 150px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 4px 0 8px;
}

.target {
  width: min(150px, 42vw);
  min-height: 70px;
  border: none;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 45%, #fff 0 18%, transparent 19%),
    radial-gradient(circle at 50% 45%, #ffb3c9 0 38%, #ff8fb8 39% 58%, #ffe08a 59% 78%, #7ec8ff 79% 100%);
  color: var(--ink);
  font-weight: 900;
  font-size: 1rem;
  padding: 18px 10px;
  cursor: crosshair;
  box-shadow: 0 8px 0 rgba(0,0,0,.12);
  animation: float-target 2.2s ease-in-out infinite;
  transition: transform .12s ease;
}

.target:nth-child(2) { animation-delay: .2s; }
.target:nth-child(3) { animation-delay: .4s; }
.target:nth-child(4) { animation-delay: .6s; }
.target:hover { transform: scale(1.06); }
.target.shot { animation: pop-shot .35s ease forwards; pointer-events: none; }

.shoot-hint {
  text-align: center;
  font-size: .9rem;
  color: #7a6a8a;
  margin-top: 4px;
}

/* Level 2 mole */
.mole-board {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
}

.mole-hole {
  position: relative;
  height: 92px;
  background: radial-gradient(ellipse at center, #8b6a4a 0 42%, #6a4a30 43% 100%);
  border-radius: 50% 50% 40% 40%;
  overflow: hidden;
  box-shadow: inset 0 10px 16px rgba(0,0,0,.25);
}

.mole-btn {
  position: absolute;
  left: 50%;
  bottom: -110%;
  transform: translateX(-50%);
  width: 86%;
  border: none;
  border-radius: 18px 18px 10px 10px;
  padding: 10px 8px;
  background: linear-gradient(180deg, #d7b4ff, #b48cff);
  color: #2f2440;
  font-weight: 900;
  cursor: pointer;
  transition: bottom .25s ease;
  box-shadow: 0 4px 0 #8a66c8;
}

.mole-btn.up { bottom: 8%; }
.mole-btn:disabled { cursor: default; }

/* Level 3 drag */
.drag-prompt {
  text-align: center;
  font-size: .95rem;
  color: #7a6a8a;
  margin: -4px 0 8px;
}

.slot-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 54px;
}

.slot {
  min-width: 56px;
  min-height: 48px;
  border: 2px dashed #c9b3d8;
  border-radius: 12px;
  background: rgba(255,255,255,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  padding: 4px 8px;
  position: relative;
}

.slot .slot-num {
  position: absolute;
  top: -10px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #7ec8ff;
  color: #fff;
  font-size: .75rem;
  display: grid;
  place-items: center;
}

.chunk-tray, .punct-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
  min-height: 48px;
}

.chunk {
  border: none;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 2px solid #ffd0e4;
  font-weight: 800;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.chunk.dragging { opacity: .45; }

.punct-zone {
  background: rgba(255, 138, 61, 0.18);
  border: 2px solid var(--orange);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 10px;
}

.punct-zone .label {
  font-size: .85rem;
  font-weight: 800;
  color: #d65a10;
  margin-bottom: 6px;
  text-align: center;
}

.punct-tray .chunk {
  background: #ffe2c8;
  border-color: var(--orange);
  min-width: 44px;
}

.drag-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* Level 4 MCQ */
.mcq-list {
  display: grid;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

.mcq-btn {
  border: 3px solid #ffe0ef;
  background: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  text-align: left;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}

.mcq-btn:hover {
  transform: translateY(-2px);
  border-color: #ff8fb8;
  background: #fff5fa;
}

.mcq-btn .tag {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #7ec8ff;
  color: #fff;
  margin-right: 8px;
  font-size: .9rem;
}

.feedback-panel { max-width: 520px; }
.feedback-badge {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 1.3rem;
  font-weight: 900;
  margin-bottom: 10px;
  color: #fff;
}
.feedback-badge.ok { background: linear-gradient(135deg, #6ed39a, #4db8ff); }
.feedback-badge.bad { background: linear-gradient(135deg, #ff8fb8, #ffb36b); }

#feedback-answer { font-weight: 900; font-size: 1.15rem; }
#feedback-explain { color: #5a4a6a; line-height: 1.5; }

.cg-wrap {
  width: min(980px, 96vw);
  background: #1d1530;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: pop-in .4s ease;
}

#cg-image {
  width: 100%;
  max-height: 62vh;
  object-fit: cover;
  display: block;
  background: #000;
}

.cg-caption {
  background: var(--panel);
  padding: 14px 16px 18px;
  text-align: center;
}

.cg-caption p {
  margin: 0 0 12px;
  font-weight: 800;
  line-height: 1.5;
}

.summary-panel {
  width: min(880px, 96vw);
  text-align: left;
}

.summary-panel h2 {
  margin: 0 0 8px;
  text-align: center;
  font-size: 2rem;
  color: #ff5f9a;
}

#summary-greeting {
  text-align: center;
  font-weight: 700;
  margin-bottom: 14px;
}

.summary-chars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.summary-chars .char-card {
  width: 110px;
  text-align: center;
  background: #fff;
  border-radius: 16px;
  padding: 8px;
  border: 2px solid #ffe0ef;
}

.summary-chars img {
  width: 100%;
  height: 90px;
  object-fit: contain;
}

.summary-chars strong {
  display: block;
  font-size: .9rem;
  margin-top: 2px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.score-card {
  background: #fff;
  border-radius: 16px;
  padding: 12px;
  border: 2px solid #d9f0ff;
}

.score-card h4 { margin: 0 0 4px; color: #3d8dff; }
.score-card p { margin: 0; font-weight: 800; font-size: 1.2rem; }

.wrong-box {
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  border: 2px solid #ffe0ef;
  margin-bottom: 16px;
  max-height: 280px;
  overflow: auto;
}

.wrong-box h3 { margin: 0 0 10px; color: #d45588; }

.wrong-item {
  border-top: 1px dashed #ffd0e4;
  padding: 8px 0;
  font-size: .95rem;
  line-height: 1.45;
}

.wrong-item:first-child { border-top: none; }
.wrong-item .ans { color: #2e9d63; font-weight: 800; }

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@keyframes idle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes bounce-soft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes float-target {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes pop-shot {
  to { transform: scale(1.2); opacity: 0; }
}

@media (max-width: 720px) {
  .hud {
    grid-template-columns: 1fr;
  }
  .hud-right, .hud-left { text-align: center; }
  .char {
    height: min(26vh, 170px);
    max-width: 32vw;
    bottom: 2%;
  }
  .question-dock {
    top: 120px; /* below stacked HUD */
    bottom: auto;
    width: min(920px, 88vw);
    max-height: 42vh;
  }
  .mole-board { grid-template-columns: 1fr 1fr; }
  .score-grid { grid-template-columns: 1fr; }
  .char.hero { left: 0; }
  .char.boss { right: 0; }
  .music-toggle {
    bottom: 10px;
    right: 10px;
  }
}
