:root {
  --ink: #1a2230;
  --mist: #e8f0f7;
  --jade: #2a7a6e;
  --gold: #c9a227;
  --rose: #8b4a6b;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-border: rgba(201, 162, 39, 0.45);
  --shadow: 0 12px 40px rgba(20, 30, 50, 0.28);
  --font-display: "ZCOOL XiaoWei", "Noto Serif TC", serif;
  --font-body: "Noto Serif TC", "Songti TC", serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: #0d1520;
  overflow-x: hidden;
}

.screen {
  display: none;
  min-height: 100vh;
  position: relative;
  background-size: cover;
  background-position: center;
}
.screen.active { display: flex; }

.btn {
  font-family: var(--font-body);
  border: none;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.7rem 1.4rem;
  font-size: 1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, #2f6f66, #1d4d47);
  color: #f7f3ea;
  box-shadow: 0 6px 18px rgba(30, 80, 70, 0.35);
}
.btn.ghost {
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  border: 1px solid rgba(26, 34, 48, 0.2);
}

/* —— 首頁 —— */
#screen-home {
  align-items: center;
  justify-content: center;
  background-image: url("../assets/bg_home.jpg");
}
.home-veil {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255, 240, 220, 0.25), transparent 55%),
    linear-gradient(180deg, rgba(10, 20, 35, 0.35), rgba(10, 20, 35, 0.55));
}
.home-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 92vw);
  padding: 2rem 2.2rem 1.6rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  text-align: center;
  animation: riseIn 0.7s ease both;
}
.brand {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 3.4rem);
  margin: 0;
  letter-spacing: 0.18em;
  color: #1d4d47;
}
.home-panel h1 {
  margin: 0.2rem 0 0.8rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: #5a4a3a;
}
.tagline {
  margin: 0 0 1.4rem;
  line-height: 1.7;
  color: #4a5568;
  font-size: 0.95rem;
}
.field { display: block; text-align: left; margin-bottom: 1rem; }
.field span, .field-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.92rem;
  color: #3d4a5c;
}
.field input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(45, 70, 90, 0.25);
  font-family: inherit;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.9);
}
.hero-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.2rem;
}
.hero-card {
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 0.6rem;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.hero-card img {
  width: 100%;
  height: 180px;
  object-fit: contain;
  display: block;
}
.hero-card span {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.hero-card.selected {
  border-color: #2a7a6e;
  box-shadow: 0 0 0 3px rgba(42, 122, 110, 0.2);
  transform: translateY(-3px);
}
.music-fab {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  min-width: 96px;
  background: rgba(255, 252, 247, 0.92) !important;
  border: 1px solid rgba(45, 70, 90, 0.25) !important;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  pointer-events: auto;
}

/* —— 故事 / 關卡介紹 —— */
#screen-story, #screen-level-intro {
  align-items: flex-end;
  justify-content: center;
  padding: 2rem;
  background-image: url("../assets/bg_home.jpg");
}
.story-layout, .intro-layout {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1rem;
  align-items: end;
}
.intro-layout {
  grid-template-columns: 200px 1fr 160px;
}
.story-char, .intro-boss, .intro-hero {
  max-height: 320px;
  width: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.35));
  animation: floaty 3.5s ease-in-out infinite;
}
.story-box, .intro-box {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 1.3rem 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.story-box h2, .intro-box h2 {
  font-family: var(--font-display);
  margin: 0 0 0.6rem;
  color: #1d4d47;
}
.intro-stage {
  margin: 0;
  color: var(--rose);
  letter-spacing: 0.12em;
  font-size: 0.85rem;
}
.story-box p, .intro-box p { line-height: 1.75; margin: 0 0 1rem; }

/* —— 答題 —— */
#screen-play {
  flex-direction: column;
  cursor: auto;
}
/* 射擊關：保留可見游標，改為十字準星樣式（不再隱藏滑鼠） */
#screen-play.shoot-mode .play-stage {
  cursor: crosshair;
}
#screen-play.shoot-mode.answered .play-stage {
  cursor: auto;
}
#screen-play.shoot-mode .shoot-target {
  cursor: crosshair;
}
#screen-play.shoot-mode.answered .shoot-target {
  cursor: default;
}
.play-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.2rem;
  background: rgba(12, 22, 34, 0.55);
  color: #f4efe6;
  backdrop-filter: blur(6px);
  z-index: 20;
  position: relative;
  cursor: auto;
  pointer-events: auto;
}
.play-hud .btn {
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 21;
}
.hud-left, .hud-right { display: flex; gap: 0.8rem; align-items: center; font-size: 0.9rem; }
.hud-mid { flex: 1; max-width: 360px; text-align: center; font-size: 0.85rem; }
.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.25rem;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #c9a227, #7ec8b5);
  transition: width 0.3s ease;
}
.play-stage {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem 1rem 1rem;
}
.stage-boss, .stage-hero {
  position: absolute;
  bottom: 0.5%;
  /* 人物放大約三分之一 */
  height: min(32vh, 240px);
  width: auto;
  max-width: 22vw;
  object-fit: contain;
  object-position: bottom center;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,0.3));
  z-index: 1;
  opacity: 0.98;
}
.stage-boss { left: 0.5%; animation: floaty 4s ease-in-out infinite; }
.stage-hero { right: 0.5%; animation: floaty 3.6s ease-in-out infinite reverse; }

.question-panel {
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  /* 問題框縮小約三分之一，避免遮蓋人物 */
  width: min(430px, 58vw);
  max-height: calc(100vh - 56px - 7.5rem);
  overflow: auto;
  z-index: 10;
  background: rgba(255, 252, 247, 0.96);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 0.75rem 0.85rem 0.9rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(5px);
}
.question-panel h3 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  line-height: 1.5;
}

.play-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.7rem 1.2rem;
  background: rgba(12, 22, 34, 0.72);
  backdrop-filter: blur(6px);
  z-index: 30;
  position: relative;
  cursor: auto;
  pointer-events: auto;
}
.footer-feedback {
  flex: 1;
  color: #f4efe6;
  font-size: 0.9rem;
  line-height: 1.45;
}
.footer-feedback .ok { color: #8ee0c8; font-weight: 700; }
.footer-feedback .bad { color: #ffb4b4; font-weight: 700; }
.footer-feedback[hidden] { display: none !important; }
#btn-next-q {
  flex-shrink: 0;
  min-width: 120px;
  cursor: pointer;
  pointer-events: auto;
  z-index: 31;
}
#btn-next-q:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.answer-result {
  margin-top: 0.85rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  background: rgba(240, 248, 245, 0.95);
  border: 1px solid rgba(42, 122, 110, 0.3);
}
.answer-result.wrong {
  background: rgba(255, 244, 242, 0.98);
  border-color: rgba(160, 60, 60, 0.3);
}
.answer-result .result-title {
  margin: 0 0 0.35rem;
  font-weight: 700;
}
.answer-result .result-title.ok { color: #1d4d47; }
.answer-result .result-title.bad { color: #8b3a3a; }
.answer-result p { margin: 0.25rem 0; line-height: 1.55; font-size: 0.92rem; }

/* 射擊模式 */
.shoot-arena {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  margin-top: 0.4rem;
  min-height: 0;
}
.shoot-target {
  position: relative;
  left: auto !important;
  top: auto !important;
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: linear-gradient(145deg, #fff8e8, #e7f3ef);
  border: 2px solid #2a7a6e;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  cursor: crosshair;
  font-size: 0.95rem;
  white-space: normal;
  text-align: left;
  line-height: 1.45;
  animation: drift 3.2s ease-in-out infinite alternate;
  user-select: none;
  z-index: 11;
}
.shoot-target:hover {
  background: #fff;
  border-color: var(--gold);
  transform: scale(1.01);
}
.shoot-target:disabled,
.choice-btn:disabled {
  opacity: 0.85;
  cursor: default;
  pointer-events: none;
}

/* 選擇題 */
.choice-list { display: grid; gap: 0.55rem; }
.choice-btn {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid rgba(45, 70, 90, 0.22);
  background: rgba(255,255,255,0.85);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.choice-btn:hover {
  border-color: #2a7a6e;
  background: #f0faf7;
}

/* 重組拖放／點選 */
.reorder-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 56px;
  padding: 0.55rem;
  border: 2px dashed rgba(42, 122, 110, 0.45);
  border-radius: 10px;
  background: rgba(255,255,255,0.55);
  margin-bottom: 0.7rem;
}
.slot {
  min-width: 48px;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid rgba(45,70,90,0.2);
  background: rgba(240, 248, 245, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.45rem;
  font-size: 0.9rem;
  color: #6a7788;
  cursor: pointer;
  font-family: inherit;
}
.slot.filled {
  color: var(--ink);
  background: #fff;
  border-color: #2a7a6e;
  font-weight: 600;
}
.slot.drag-over {
  border-color: var(--gold);
  background: #fff8e0;
  transform: scale(1.04);
}
.pool-label {
  margin: 0.35rem 0;
  font-size: 0.82rem;
  color: #5a6675;
}
.block-pool, .punct-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}
.drag-chip {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: #fff;
  border: 1px solid rgba(45,70,90,0.25);
  cursor: pointer;
  font-size: 0.95rem;
  user-select: none;
  font-family: inherit;
  touch-action: manipulation;
}
.drag-chip.selected {
  border-color: #2a7a6e;
  box-shadow: 0 0 0 3px rgba(42, 122, 110, 0.25);
  background: #eef8f4;
}
.drag-chip.punct {
  background: #fff;
  border: 2px solid #c9a227;
  min-width: 40px;
  text-align: center;
  font-weight: 700;
}
.drag-chip.used {
  opacity: 0.35;
  pointer-events: none;
}
.punct-zone {
  background: #ffffff;
  border: 2px solid rgba(201, 162, 39, 0.55);
  border-radius: 10px;
  padding: 0.55rem;
}
.reorder-actions { display: flex; gap: 0.5rem; margin-top: 0.6rem; }

/* 準星 */
#crosshair {
  display: none !important; /* 改用系統 crosshair 游標，避免滑鼠消失 */
}

/* CG */
#screen-cg {
  align-items: center;
  justify-content: center;
  background: #05080e;
}
.cg-wrap {
  width: min(1100px, 96vw);
  position: relative;
  animation: fadeZoom 0.6s ease;
}
.cg-wrap img {
  width: 100%;
  max-height: 78vh;
  object-fit: cover;
  border-radius: 12px;
  display: block;
  box-shadow: var(--shadow);
}
.cg-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 1.2rem 1.4rem;
  background: linear-gradient(transparent, rgba(8, 14, 24, 0.88));
  color: #f7f1e6;
  border-radius: 0 0 12px 12px;
}
.cg-caption p { margin: 0 0 0.8rem; line-height: 1.7; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 24, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(440px, 92vw);
  background: #fffaf3;
  border-radius: 14px;
  padding: 1.3rem 1.4rem;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 0.6rem; color: #8b3a3a; }
.modal-card p { margin: 0 0 0.6rem; line-height: 1.65; }

/* 總結 */
#screen-summary {
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 3rem;
  background-image: url("../assets/bg_home.jpg");
  overflow-y: auto;
}
.summary-panel {
  width: min(860px, 96vw);
  background: var(--panel);
  border-radius: 18px;
  padding: 1.5rem 1.6rem;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.summary-panel h2 {
  font-family: var(--font-display);
  margin: 0 0 1rem;
  color: #1d4d47;
}
.sum-chars {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}
.sum-chars figure {
  margin: 0;
  text-align: center;
  background: rgba(255,255,255,0.55);
  border-radius: 10px;
  padding: 0.4rem;
}
.sum-chars img {
  width: 100%;
  height: 110px;
  object-fit: contain;
}
.sum-chars figcaption { font-size: 0.75rem; margin-top: 0.2rem; }
.sum-scores {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}
.score-card {
  background: rgba(255,255,255,0.7);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  border: 1px solid rgba(42,122,110,0.2);
}
.score-card strong { color: #1d4d47; }
.sum-wrong h3 { margin: 0 0 0.6rem; font-size: 1.05rem; }
.wrong-item {
  background: rgba(255,255,255,0.65);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.55;
}
.wrong-item .ok { color: #1d4d47; font-weight: 600; }
.sum-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}
@keyframes fadeZoom {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 820px) {
  .story-layout { grid-template-columns: 1fr; }
  .intro-layout { grid-template-columns: 1fr; text-align: center; }
  .intro-boss, .intro-hero, .story-char { max-height: 220px; margin: 0 auto; }
  .play-stage { padding: 0.8rem 0.6rem; }
  .stage-boss, .stage-hero { height: min(26vh, 190px); max-width: 30vw; opacity: 0.95; }
  .question-panel { width: min(72vw, 430px); max-height: calc(100vh - 56px - 7rem); }
  .play-footer { flex-wrap: wrap; }
  .music-fab { top: 8px; right: 8px; min-width: 84px; font-size: 0.9rem; }
  .sum-chars { grid-template-columns: repeat(3, 1fr); }
  .sum-scores { grid-template-columns: 1fr; }
  #screen-play { cursor: auto; }
  #crosshair { display: none !important; }
}
