/* ============================================================
   彈窗系統：全螢幕 CG 演出、送禮、CG 畫廊、QTE、訂閱、結局、圖鑑
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(10, 12, 20, 0.74);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: #ffffff;
  color: #111827;
  border-radius: 22px;
  width: 100%;
  max-width: 920px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.45);
  animation: popUp 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes popUp { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-header { padding: 18px 24px; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-header h3 { font-size: 20px; font-weight: 900; }
.modal-subtitle { font-size: 13px; color: #6b7280; margin-top: 3px; }
.modal-close { width: 34px; height: 34px; border-radius: 10px; background: #f3f4f6; color: #374151; font-size: 16px; font-weight: 700; flex-shrink: 0; }
.modal-close:hover { background: #e5e7eb; }

/* ==================== A. 全螢幕 Galgame 精裝 CG 演出視窗 ==================== */
.cg-stage-backdrop {
  background: rgba(6, 7, 12, 0.92);
  padding: 24px;
}

.cg-stage-container {
  position: relative;
  width: 100%;
  max-width: 1100px;
  aspect-ratio: 16 / 9;
  max-height: 88vh;
  border-radius: 18px;
  overflow: hidden;
  background: #0d0f18;
  border: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
}

.cg-stage-topbar {
  position: absolute;
  top: 14px; left: 18px; right: 18px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cg-stage-badge {
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(251, 191, 36, 0.55);
  color: #fde68a;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.cg-skip-btn {
  background: rgba(15, 23, 42, 0.72);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
}
.cg-skip-btn:hover { background: rgba(255, 255, 255, 0.2); color: #fff; }

.cg-visual-viewport {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.cg-stage-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: kenBurns 18s ease-in-out infinite alternate;
}
@keyframes kenBurns { from { transform: scale(1.0); } to { transform: scale(1.07); } }

.cg-fallback-scene {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(circle at 50% 35%, #2b2345 0%, #0d0f18 100%);
}
.cg-fallback-glow { position: absolute; inset: 0; opacity: 0.45; }
.cg-fallback-sprite {
  position: relative;
  z-index: 2;
  max-height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 18px 34px rgba(0, 0, 0, 0.65));
}

.cg-vn-box {
  position: absolute;
  left: 20px; right: 20px; bottom: 18px;
  z-index: 12;
  background: rgba(12, 14, 22, 0.84);
  backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: 16px 22px 14px;
  color: #f8fafc;
}

.cg-vn-speaker {
  display: inline-block;
  font-size: 13px;
  font-weight: 900;
  color: #fde68a;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.cg-vn-text {
  font-size: 15.5px;
  line-height: 1.72;
  min-height: 54px;
  white-space: pre-wrap;
}

.cg-vn-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.cg-vn-hint { font-size: 11.5px; color: #94a3b8; }
.btn-cg-next { padding: 7px 18px; border-radius: 999px; background: #f59e0b; color: #111827; font-size: 13px; font-weight: 900; }
.btn-cg-next:hover { background: #fbbf24; transform: translateX(2px); }

/* ==================== B. 🎁 賽博投餵送禮中心 ==================== */
.gift-card { max-width: 780px; }
.gift-grid {
  padding: 18px 24px 24px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  overflow-y: auto;
}
.gift-item-card {
  border: 1.5px solid #e5e7eb;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #ffffff;
  text-align: left;
}
.gift-item-card:hover:not(:disabled) { border-color: #f59e0b; background: #fffbeb; transform: translateY(-2px); }
.gift-item-card:disabled { opacity: 0.5; cursor: not-allowed; }
.gift-icon { font-size: 28px; }
.gift-name { font-size: 14.5px; font-weight: 800; color: #111827; }
.gift-desc { font-size: 12px; color: #6b7280; line-height: 1.45; flex: 1; }

/* ==================== C. 🖼️ CG 畫廊 ==================== */
.cg-gallery-grid {
  padding: 18px 24px 24px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  overflow-y: auto;
}
.cg-card-tile {
  border: 1.5px solid #e5e7eb;
  border-radius: 14px;
  overflow: hidden;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}
.cg-card-tile.unlocked { cursor: pointer; }
.cg-card-tile.unlocked:hover { border-color: #f59e0b; transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,0.12); }
.cg-thumb-box {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cg-thumb-box img { width: 100%; height: 100%; object-fit: cover; }
.cg-thumb-locked { color: #64748b; font-family: var(--font-mono); font-size: 13px; font-weight: 800; text-align: center; padding: 14px; }
.cg-tile-meta { padding: 11px 14px; }
.cg-tile-meta h4 { font-size: 14px; font-weight: 800; color: #111827; }
.cg-tile-meta p { font-size: 12px; color: #6b7280; margin-top: 2px; }

/* ==================== 1. 3 秒 QTE 分頁修羅場 ==================== */
.qte-backdrop { background: rgba(127, 29, 29, 0.62); animation: alarmPulse 0.45s infinite alternate; }
@keyframes alarmPulse { from { background: rgba(127, 29, 29, 0.56); } to { background: rgba(185, 28, 28, 0.72); } }
.qte-card { width: 100%; max-width: 580px; background: #11131a; color: #f8fafc; border-radius: 22px; border: 2px solid #ef4444; overflow: hidden; box-shadow: 0 0 60px rgba(239, 68, 68, 0.55); padding-bottom: 20px; }
.qte-alarm-strip { background: linear-gradient(90deg, #dc2626, #b91c1c, #dc2626); color: #ffffff; font-size: 13.5px; font-weight: 900; letter-spacing: 0.06em; text-align: center; padding: 9px 14px; }
.qte-timer-bar-wrap { height: 8px; background: #27272a; width: 100%; }
.qte-timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, #facc15, #ef4444); transition: width 0.05s linear; }
.qte-countdown { text-align: center; font-family: var(--font-mono); font-size: 36px; font-weight: 900; color: #f87171; margin: 12px 0 6px; }
.qte-suspect-row { display: flex; align-items: center; gap: 14px; padding: 0 22px 16px; }
.qte-avatar { width: 78px; height: 78px; border-radius: 16px; object-fit: cover; object-position: top center; background: #1e202c; border: 2.5px solid #ef4444; flex-shrink: 0; }
.qte-bubble { flex: 1; background: #1e202c; border: 1px solid #35384a; border-radius: 14px; padding: 12px 15px; }
.qte-speaker { font-size: 12px; font-weight: 800; color: #fbbf24; margin-bottom: 4px; }
.qte-dialogue { font-size: 14.5px; line-height: 1.55; color: #f8fafc; }
.qte-choices { display: flex; flex-direction: column; gap: 9px; padding: 0 22px; }
.qte-choice-btn { text-align: left; padding: 12px 16px; border-radius: 12px; background: #1f2333; border: 1.5px solid #3f455e; color: #ffffff; font-size: 14px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.qte-choice-btn:hover { background: #dc2626; border-color: #fca5a5; transform: scale(1.015); }
.qte-key-hint { font-family: var(--font-mono); font-size: 11px; padding: 2px 7px; border-radius: 6px; background: rgba(255, 255, 255, 0.14); }

/* ==================== 2. 訂閱管理中心 ==================== */
.billing-card { max-width: 960px; }
.billing-summary-bar { display: flex; justify-content: space-around; padding: 12px 20px; background: #f8fafc; border-bottom: 1px solid #e5e7eb; font-size: 14px; }
.text-good { color: #059669; }
.text-danger { color: #dc2626; }
.billing-grid { padding: 18px 24px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; overflow-y: auto; }
.sub-plan-card { border: 1.5px solid #e5e7eb; border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #ffffff; }
.sub-plan-card.active { border-color: #f59e0b; background: linear-gradient(180deg, #fffbeb 0%, #ffffff 100%); box-shadow: 0 8px 22px rgba(245, 158, 11, 0.16); }
.sub-plan-top { display: flex; align-items: center; gap: 10px; }
.sub-plan-top img { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; object-position: top center; border: 1.5px solid #e5e7eb; background: #f8fafc; }
.sub-plan-name { font-size: 15px; font-weight: 800; }
.sub-plan-tier { font-size: 11.5px; color: #6b7280; font-family: var(--font-mono); }
.sub-plan-perk { font-size: 12px; color: #4b5563; line-height: 1.45; flex: 1; }
.btn-sub-toggle { padding: 9px 12px; border-radius: 10px; font-size: 13px; font-weight: 700; background: #111827; color: #ffffff; }
.btn-sub-toggle:hover { background: #374151; }
.btn-sub-toggle.active { background: #fef3c7; color: #b45309; border: 1px solid #f59e0b; }
.billing-special-row { padding: 14px 24px 20px; border-top: 1px solid #e5e7eb; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; background: #f9fafb; }
.special-card { border-radius: 14px; padding: 13px 15px; border: 1.5px dashed #cbd5e1; background: #ffffff; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.special-card h4 { font-size: 13.5px; font-weight: 800; margin-bottom: 3px; }
.special-card p { font-size: 11.5px; color: #6b7280; line-height: 1.4; }
.btn-special-warn { padding: 9px 14px; border-radius: 10px; background: #ea580c; color: #fff; font-size: 12.5px; font-weight: 800; flex-shrink: 0; }
.btn-special-danger { padding: 9px 14px; border-radius: 10px; background: #dc2626; color: #fff; font-size: 12.5px; font-weight: 800; flex-shrink: 0; }

/* ==================== 3. 結局演出 & 月結單 ==================== */
.ending-card { max-width: 1040px; max-height: 92vh; }
.ending-hero { padding: 20px 26px; background: linear-gradient(135deg, #111827, #1e1b4b); color: #ffffff; text-align: center; }
.ending-hero.is-true { background: linear-gradient(135deg, #be185d, #7c3aed); }
.ending-hero.is-secret { background: linear-gradient(135deg, #d97706, #ea580c, #be123c); }
.ending-type-badge { display: inline-block; font-family: var(--font-mono); font-size: 11.5px; font-weight: 800; padding: 3px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); margin-bottom: 6px; letter-spacing: 0.08em; }
.ending-title { font-size: 26px; font-weight: 900; }
.ending-subtitle { font-size: 14px; color: #e2e8f0; margin-top: 4px; }
.ending-body { display: grid; grid-template-columns: 1fr 1.08fr; gap: 20px; padding: 20px 24px; overflow-y: auto; flex: 1; }
.ending-visual-col { display: flex; flex-direction: column; gap: 14px; }
.ending-cg-frame { position: relative; height: 290px; border-radius: 18px; background: radial-gradient(circle at 50% 35%, #2e294e, #12131f); border: 2px solid #e5e7eb; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; gap: 8px; }
.ending-cg-frame img { max-height: 96%; max-width: 85%; object-fit: contain; }
.ending-cg-frame img.full-cg { width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: cover; }
.ending-cg-stamp { position: absolute; top: 14px; right: 14px; padding: 5px 12px; border: 2.5px solid #dc2626; color: #dc2626; font-family: var(--font-mono); font-size: 13px; font-weight: 900; border-radius: 8px; transform: rotate(7deg); background: rgba(255, 255, 255, 0.92); }
.ending-story-box { background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 14px; padding: 15px 17px; font-size: 14px; line-height: 1.72; color: #1f2937; white-space: pre-wrap; }
.ending-receipt-col { display: flex; flex-direction: column; gap: 10px; }
.receipt-header-bar { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; font-weight: 800; }
.btn-download-png { padding: 7px 14px; border-radius: 9px; background: #059669; color: #ffffff; font-size: 12.5px; font-weight: 700; }
.btn-download-png:hover { background: #047857; }
.receipt-canvas-wrap { border-radius: 14px; border: 1px solid #e5e7eb; background: #f1f5f9; padding: 10px; max-height: 460px; overflow-y: auto; display: flex; justify-content: center; }
#receipt-canvas { width: 100%; height: auto; border-radius: 10px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14); }
.ending-footer { padding: 14px 24px; border-top: 1px solid #e5e7eb; display: flex; justify-content: flex-end; gap: 10px; background: #f9fafb; }
.btn-primary { padding: 10px 22px; border-radius: 10px; background: #16161a; color: #ffffff; font-size: 14px; font-weight: 800; }
.btn-secondary { padding: 10px 18px; border-radius: 10px; background: #e5e7eb; color: #1f2937; font-size: 14px; font-weight: 700; }

/* ==================== 4. 結局圖鑑 & 5. 玩法指南 ==================== */
.gallery-card { max-width: 980px; }
.gallery-filters { padding: 12px 24px; display: flex; gap: 8px; border-bottom: 1px solid #e5e7eb; background: #f9fafb; }
.filter-btn { padding: 6px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 700; color: #4b5563; background: #e5e7eb; }
.filter-btn.active { background: #111827; color: #ffffff; }
.gallery-grid { padding: 18px 24px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; overflow-y: auto; }
.gallery-item { border: 1.5px solid #e5e7eb; border-radius: 14px; padding: 13px; display: flex; flex-direction: column; gap: 6px; background: #ffffff; }
.gallery-item.locked { background: #f8fafc; opacity: 0.72; }
.gallery-item.unlocked.type-true { border-color: #ec4899; background: #fdf2f8; }
.gallery-item.unlocked.type-secret { border-color: #f59e0b; background: #fffbeb; }
.gallery-badge { font-family: var(--font-mono); font-size: 10.5px; font-weight: 800; padding: 2px 7px; border-radius: 6px; align-self: flex-start; background: #111827; color: #fff; }
.gallery-item.type-bad .gallery-badge { background: #dc2626; }
.gallery-item.type-true .gallery-badge { background: #db2777; }
.gallery-item.type-secret .gallery-badge { background: #d97706; }
.gallery-title { font-size: 14.5px; font-weight: 800; }
.gallery-desc { font-size: 12px; color: #4b5563; line-height: 1.45; }
.gallery-hint { font-size: 11.5px; color: #6366f1; font-weight: 600; margin-top: auto; }

.guide-card { max-width: 720px; }
.guide-content { padding: 20px 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; overflow-y: auto; }
.guide-item { background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 14px; padding: 14px 16px; }
.guide-item h4 { font-size: 15px; font-weight: 800; margin-bottom: 6px; color: #111827; }
.guide-item p { font-size: 13px; line-height: 1.65; color: #4b5563; }

@media (max-width: 860px) {
  .billing-grid, .gallery-grid, .gift-grid { grid-template-columns: repeat(2, 1fr); }
  .ending-body, .billing-special-row, .guide-content, .cg-gallery-grid { grid-template-columns: 1fr; }
}
