:root {
  --ink: #3a2a1a;
  --ink-soft: #5c4632;
  --cream: #fff8ee;
  --panel: rgba(255, 248, 238, 0.92);
  --panel-strong: rgba(255, 248, 238, 0.97);
  --accent: #d06b3a;
  --accent-2: #2f7d6d;
  --accent-3: #c9a227;
  --danger: #c44b4b;
  --ok: #2f8f5b;
  --shadow: 0 8px 20px rgba(40, 24, 10, 0.26);
  --radius: 14px;
  /* 漫畫感標題字：KuaiLe 筆畫清楚；正文用 Noto 保證可讀 */
  --font-display: "ZCOOL KuaiLe", "ZCOOL QingKe HuangYou", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  --font-body: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--ink);
  background: #1b1410;
}

button, input { font-family: inherit; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.screen.active { display: flex; }

.overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(20,12,6,0.18), rgba(20,12,6,0.42));
  pointer-events: none;
}

/* ===== Home ===== */
#screen-home {
  background-image: url("../assets/bg/bg_home.jpg");
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px;
  -webkit-overflow-scrolling: touch;
}

.home-panel {
  position: relative;
  z-index: 2;
  width: min(720px, 100%);
  max-height: calc(100dvh - 32px);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  padding: 16px 18px 14px;
  background: var(--panel);
  border-radius: 22px;
  box-shadow: var(--shadow);
  border: 3px solid rgba(208, 107, 58, 0.35);
  animation: riseIn 0.7s ease both;
  overflow: hidden;
}

.home-panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(1.85rem, 5.5vw, 2.8rem);
  color: var(--accent);
  letter-spacing: 0.04em;
  text-align: center;
  text-shadow:
    0 0 1px #fff8ee,
    1px 1px 0 #fff8ee,
    -1px -1px 0 #fff8ee,
    2px 2px 0 rgba(197, 93, 44, 0.28);
  -webkit-text-stroke: 0.35px rgba(90, 50, 20, 0.28);
  paint-order: stroke fill;
  line-height: 1.3;
  flex-shrink: 0;
  font-weight: 400;
}

.brand-sub {
  font-family: var(--font-display);
  text-align: center;
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: clamp(1rem, 2.8vw, 1.2rem);
  letter-spacing: 0.04em;
  flex-shrink: 0;
  -webkit-text-stroke: 0.2px rgba(90, 50, 20, 0.15);
  paint-order: stroke fill;
}

.story-blurb {
  margin: 10px auto 12px;
  max-width: 640px;
  line-height: 1.55;
  text-align: center;
  background: rgba(255,255,255,0.55);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 12px;
}

.field label {
  display: block;
  margin-bottom: 4px;
  font-weight: 700;
  font-size: 0.95rem;
}

.field input {
  width: min(280px, 80vw);
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid rgba(90, 60, 30, 0.25);
  background: #fff;
  font-size: 1rem;
}

.hero-label {
  text-align: center;
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 0.95rem;
  font-family: var(--font-display);
}

.hero-pick {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: nowrap;
}

.hero-card {
  width: min(140px, 42vw);
  border: 3px solid transparent;
  border-radius: 16px;
  background: rgba(255,255,255,0.7);
  padding: 8px;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.hero-card:hover { transform: translateY(-3px); }

.hero-card.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(47, 125, 109, 0.2);
}

.hero-card img {
  width: 100%;
  height: clamp(88px, 16vh, 130px);
  object-fit: contain;
  display: block;
}

.hero-card span {
  display: block;
  text-align: center;
  margin-top: 4px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.home-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  padding-top: 10px;
  flex-shrink: 0;
  border-top: 1px solid rgba(90, 60, 30, 0.12);
  background: linear-gradient(180deg, rgba(255,248,238,0), rgba(255,248,238,0.95) 30%);
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.16);
}

.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, #e8874d, #c55d2c);
  color: #fff;
}

.btn-secondary {
  background: linear-gradient(180deg, #4ea892, #2f7d6d);
  color: #fff;
}

.btn-ghost {
  background: rgba(255,255,255,0.85);
  color: var(--ink);
  border: 2px solid rgba(90,60,30,0.2);
}

.music-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
}

/* ===== Story / CG ===== */
#screen-story {
  align-items: flex-end;
  justify-content: center;
  background-size: cover;
  background-position: center;
}

#screen-cg {
  align-items: stretch;
  justify-content: flex-end;
  flex-direction: column;
  background: #1b1410;
}

.story-box {
  position: relative;
  z-index: 2;
  width: min(600px, 88vw);
  margin-bottom: 3vh;
  padding: 12px 15px;
  background: var(--panel-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 2px solid rgba(201, 162, 39, 0.45);
  animation: riseIn 0.45s ease both;
}

.story-box h2 {
  font-family: var(--font-display);
  color: var(--accent);
  margin-bottom: 6px;
  font-size: 1.15rem;
  letter-spacing: 0.03em;
  -webkit-text-stroke: 0.2px rgba(90, 50, 20, 0.18);
  paint-order: stroke fill;
}

.story-box p {
  line-height: 1.65;
  margin-bottom: 10px;
  white-space: pre-wrap;
  font-size: 0.88rem;
}

.cg-frame {
  position: absolute;
  inset: 0;
  background-color: #1b1410;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center center;
  animation: zoomSoft 0.8s ease both;
}

.cg-caption-box {
  position: relative;
  z-index: 3;
  width: min(600px, 88vw);
  margin: 0 auto;
  padding: 10px 14px 6px;
  background: var(--panel-strong);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 2px solid rgba(201, 162, 39, 0.45);
  border-bottom: none;
  box-shadow: var(--shadow);
}

.cg-caption-box h2 {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 1.05rem;
  margin-bottom: 4px;
  letter-spacing: 0.03em;
}

.cg-caption-box p {
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--ink);
}

.cg-bottom {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: center;
  padding: 8px 16px 16px;
  background: linear-gradient(180deg, rgba(255,248,238,0.97), rgba(20,12,6,0.55) 85%);
  width: min(600px, 88vw);
  margin: 0 auto;
  border-radius: 0 0 var(--radius) var(--radius);
  border: 2px solid rgba(201, 162, 39, 0.45);
  border-top: none;
}

/* ===== Game ===== */
#screen-game {
  flex-direction: column;
}

.game-top {
  position: relative;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  background: rgba(255, 248, 238, 0.88);
  border-bottom: 2px solid rgba(208,107,58,0.3);
}

.game-top .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-weight: 700;
  font-size: 0.88rem;
}

.game-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.game-stage.shoot-mode {
  cursor: none;
}

.char-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.char-hero, .char-boss {
  position: absolute;
  bottom: 0;
  height: min(42vh, 320px);
  width: auto;
  max-width: 32vw;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.28));
  animation: floaty 3.2s ease-in-out infinite;
}

.char-hero { left: 0; }
.char-boss { right: 0; animation-delay: 0.4s; }

.q-panel {
  position: absolute;
  left: 50%;
  top: 2%;
  transform: translateX(-50%);
  width: min(340px, 52vw);
  max-height: 22vh;
  overflow: auto;
  z-index: 6;
  background: var(--panel-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 2px solid rgba(47,125,109,0.35);
  padding: 7px 10px 6px;
  pointer-events: auto;
}

.q-panel .q-text {
  font-size: clamp(0.78rem, 1.4vw, 0.95rem);
  line-height: 1.4;
  font-weight: 700;
  margin-bottom: 3px;
}

.q-panel .hint {
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.feedback {
  position: absolute;
  left: 50%;
  top: 26%;
  transform: translate(-50%, -50%) scale(0.8);
  z-index: 12;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: #fff;
  opacity: 0;
  pointer-events: none;
}

.feedback.show {
  animation: popFeedback 0.7s ease;
}

.feedback.ok { background: var(--ok); }
.feedback.bad { background: var(--danger); }

/* 置中偏上，避開左右角色；可捲動完整顯示答案 */
.result-panel {
  position: absolute;
  left: 50%;
  top: 46%;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(340px, 48vw);
  max-height: min(38vh, 260px);
  z-index: 14;
  background: var(--panel-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 2px solid rgba(201, 162, 39, 0.5);
  padding: 8px 10px;
  text-align: center;
  animation: riseIn 0.3s ease both;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result-panel.hidden { display: none; }

.result-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin-bottom: 2px;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

.result-title.ok { color: var(--ok); }
.result-title.bad { color: var(--danger); }

.result-explain {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink);
  margin-bottom: 4px;
  text-align: left;
  white-space: pre-wrap;
  overflow: auto;
  max-height: min(22vh, 150px);
  flex: 1 1 auto;
  min-height: 0;
}

.result-panel .btn {
  flex-shrink: 0;
  align-self: center;
  padding: 6px 16px;
  font-size: 0.85rem;
}

/* Shoot mode — 中央作答區，避開左右角色 */
.shoot-arena {
  position: absolute;
  left: 22%;
  right: 22%;
  top: 20%;
  bottom: 30%;
  z-index: 4;
  cursor: none;
}

.shoot-target {
  position: absolute;
  min-width: 72px;
  max-width: 46%;
  padding: 7px 9px;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #ffe7c8);
  border: 2px solid #d06b3a;
  box-shadow: var(--shadow);
  font-weight: 800;
  font-size: 0.82rem;
  cursor: none;
  user-select: none;
  transition: transform 0.12s;
  animation: drift 4s ease-in-out infinite;
}

.shoot-target:hover { transform: scale(1.06); }
.shoot-target.hit-ok {
  background: #d8ffe8;
  border-color: var(--ok);
}
.shoot-target.hit-bad {
  background: #ffd6d6;
  border-color: var(--danger);
}

/* 瞄準標記：緊貼游標中心 */
.crosshair {
  position: absolute;
  width: 36px;
  height: 36px;
  border: 2px solid rgba(208, 107, 58, 0.95);
  border-radius: 50%;
  pointer-events: none;
  z-index: 15;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  display: none;
  box-shadow: 0 0 0 1px rgba(255, 248, 238, 0.7);
}
.crosshair::before, .crosshair::after {
  content: "";
  position: absolute;
  background: rgba(208, 107, 58, 0.95);
}
.crosshair::before { width: 2px; height: 100%; left: 50%; transform: translateX(-50%); }
.crosshair::after { height: 2px; width: 100%; top: 50%; transform: translateY(-50%); }
.crosshair .dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: rgba(208, 107, 58, 0.95);
}

/* Mole mode */
.mole-arena {
  position: absolute;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%);
  width: min(300px, 48vw);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  z-index: 4;
}

.mole-hole {
  position: relative;
  height: 68px;
  background: radial-gradient(ellipse at center, #6b4a2e 0%, #3d2918 70%);
  border-radius: 50% 50% 40% 40%;
  overflow: hidden;
  border: 2px solid #2a1a10;
  box-shadow: inset 0 8px 14px rgba(0,0,0,0.35);
}

.mole {
  position: absolute;
  left: 50%;
  bottom: -110%;
  transform: translateX(-50%);
  width: 90%;
  padding: 4px 3px;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff8ee, #ffd9a8);
  border: 2px solid #c9a227;
  text-align: center;
  font-weight: 800;
  font-size: 0.68rem;
  cursor: pointer;
  transition: bottom 0.25s ease;
  box-shadow: var(--shadow);
}

.mole.up { bottom: 10%; }
.mole.correct-flash { background: #d8ffe8; border-color: var(--ok); }
.mole.wrong-flash { background: #ffd6d6; border-color: var(--danger); }

/* Drag mode — 中央窄欄，選項可捲動，不遮角色 */
.drag-arena {
  position: absolute;
  left: 50%;
  top: 26%;
  bottom: 8%;
  transform: translateX(-50%);
  width: min(360px, 52vw);
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  min-height: 0;
}

.drop-zone {
  flex: 0 0 auto;
  min-height: 42px;
  border: 2px dashed rgba(47,125,109,0.55);
  border-radius: 12px;
  background: rgba(255,248,238,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 6px 10px;
  text-align: center;
}

.drop-zone.filled {
  border-style: solid;
  border-color: var(--accent-2);
  background: #e8fff7;
}

.drag-options {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: flex-start;
  align-items: stretch;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 2px 4px;
  -webkit-overflow-scrolling: touch;
}

.drag-item {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #ffe7c8);
  border: 2px solid #d06b3a;
  font-weight: 700;
  font-size: 0.74rem;
  line-height: 1.35;
  cursor: grab;
  width: 100%;
  max-width: none;
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: none;
  white-space: normal;
  word-break: break-word;
  text-align: left;
}

.drag-item.dragging {
  opacity: 0.45;
  cursor: grabbing;
  outline: 2px dashed var(--accent);
}
.drag-item.used { opacity: 0.35; pointer-events: none; }

/* MCQ mode */
.mcq-arena {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  width: min(360px, 52vw);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  z-index: 4;
}

.mcq-btn {
  padding: 7px 9px;
  border-radius: 12px;
  border: 2px solid #2f7d6d;
  background: linear-gradient(180deg, #fff, #e8fff7);
  font-weight: 800;
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}

.mcq-btn:hover { transform: translateY(-2px); }
.mcq-btn.correct { background: #d8ffe8; border-color: var(--ok); }
.mcq-btn.wrong { background: #ffd6d6; border-color: var(--danger); }

/* ===== Summary ===== */
#screen-summary {
  background-image: url("../assets/bg/bg_summary.jpg");
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.summary-panel {
  position: relative;
  z-index: 2;
  width: min(980px, 95vw);
  max-height: 92vh;
  overflow: auto;
  margin: 20px auto;
  padding: 22px 24px;
  background: var(--panel-strong);
  border-radius: 24px;
  box-shadow: var(--shadow);
  border: 3px solid rgba(201,162,39,0.45);
}

.summary-panel h1 {
  font-family: var(--font-display);
  color: var(--accent);
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}

.cast-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 14px 0 18px;
}

.cast-card {
  width: 110px;
  text-align: center;
  background: rgba(255,255,255,0.7);
  border-radius: 14px;
  padding: 8px;
}

.cast-card img {
  width: 100%;
  height: 96px;
  object-fit: contain;
}

.cast-card strong { display: block; font-size: 0.92rem; margin-top: 4px; }
.cast-card small { color: var(--ink-soft); }

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.score-card {
  background: rgba(255,255,255,0.75);
  border-radius: 14px;
  padding: 12px;
  border: 2px solid rgba(90,60,30,0.12);
}

.score-card h3 {
  font-size: 1rem;
  margin-bottom: 4px;
  color: var(--accent-2);
}

.wrong-list {
  background: rgba(255,255,255,0.7);
  border-radius: 14px;
  padding: 12px 14px;
  max-height: none;
  overflow: visible;
}

.wrong-item {
  padding: 10px 0;
  border-bottom: 1px dashed rgba(90,60,30,0.2);
}

.wrong-item:last-child { border-bottom: none; }
.wrong-item .q { font-weight: 700; margin-bottom: 4px; }
.wrong-item .a { color: var(--ok); }
.wrong-item .y { color: var(--danger); }

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes drift {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -10px; }
}

@keyframes zoomSoft {
  from { transform: scale(1.05); opacity: 0.6; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes popFeedback {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

@media (max-width: 800px) {
  .char-hero, .char-boss {
    height: min(32vh, 220px);
    max-width: 28vw;
    opacity: 1;
  }
  .q-panel {
    width: min(58vw, 300px);
    top: 2%;
    max-height: 20vh;
  }
  .mole-arena {
    grid-template-columns: repeat(4, 1fr);
    width: min(280px, 56vw);
    bottom: 24%;
  }
  .mcq-arena {
    width: min(56vw, 320px);
    bottom: 20%;
  }
  .drag-arena {
    width: min(58vw, 320px);
    top: 24%;
    bottom: 6%;
  }
  .result-panel {
    width: min(56vw, 300px);
    top: 44%;
    max-height: min(36vh, 220px);
  }
  .home-panel { padding: 12px 12px 10px; }
  .music-toggle { top: 10px; right: 10px; padding: 8px 14px; font-size: 0.9rem; }
  .cg-frame { background-size: contain; }
  .cg-caption-box, .cg-bottom { width: min(92vw, 600px); }
  .story-box { width: min(92vw, 600px); }
}

@media (max-height: 720px) {
  .story-blurb {
    font-size: 0.84rem;
    line-height: 1.45;
    padding: 6px 10px;
    margin: 8px auto 10px;
  }
  .hero-card img { height: clamp(72px, 14vh, 100px); }
  .brand { font-size: clamp(1.65rem, 5vw, 2.2rem); }
  .brand-sub { font-size: 1rem; }
  .char-hero, .char-boss { height: min(30vh, 200px); }
}
