/* ===========================================================================
 * G4 · 神探初體驗 — style.css
 * GDD §2：暖色調少兒偵探繪本風——米黃羊皮紙底(#FDF6E3/#F5E6C8) + 棕色放大鏡/指紋/腳印
 *         (#8B6914/#6B4423) + 金色線索高亮(#FFD700)，圓角卡片 UI + 輕量動效，
 *         整體「好奇、溫暖、成就感」的少年偵探氛圍。
 * =========================================================================== */

/* ------------------------------- CSS Variables ----------------------------- */
:root {
  /* 核心色板（GDD §2） */
  --parchment: #FDF6E3;
  --parchment-dark: #F5E6C8;
  --detective-brown: #8B6914;
  --detective-brown-dark: #6B4423;
  --clue-gold: #FFD700;
  --clue-gold-soft: #FFE066;
  --evidence-teal: #2A9D8F;
  --evidence-teal-light: #A8DADC;
  --mystery-purple: #6A4C93;
  --success-green: #52B788;
  --fail-red: #E63946;
  --warn-orange: #F4A261;
  --ink-charcoal: #3D3D3D;
  --grey-60: #8D99AE;
  --grey-30: #D3D3D3;
  --card-shadow: rgba(139, 105, 20, 0.12);

  /* 字體 */
  --font-title: 'Nunito', 'Noto Sans TC', sans-serif;
  --font-body: 'Noto Sans TC', 'Nunito', sans-serif;
  --font-number: 'Nunito', sans-serif;
  --font-clock: 'Orbitron', 'Nunito', monospace;

  /* 圓角 */
  --radius-btn: 16px;
  --radius-bar: 4px;
  --radius-modal: 24px;
  --radius-card: 18px;
}

/* ------------------------------- Reset & Base ------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background: var(--parchment);
  color: var(--ink-charcoal);
  min-height: 100vh;
  overflow-x: hidden;
  /* 羊皮紙紋理漸層背景 */
  background-image:
    radial-gradient(circle at 15% 20%, rgba(139, 105, 20, 0.04) 0%, transparent 35%),
    radial-gradient(circle at 85% 80%, rgba(106, 76, 147, 0.03) 0%, transparent 35%),
    radial-gradient(circle at 50% 50%, rgba(255, 215, 0, 0.02) 0%, transparent 50%);
}

/* 偵探社主背景（底層，z-2）— 參考 G1 bg-main-hall 寫法 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url('images/g4_bg_detective.webp') center/cover no-repeat;
}

/* ------------------------------- Top Bar ----------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--parchment-dark);
  border-bottom: 3px solid var(--detective-brown);
  flex-wrap: wrap;
  justify-content: center;
  box-shadow: 0 2px 8px var(--card-shadow);
}

.game-title {
  font-family: var(--font-title);
  font-size: 26px;
  font-weight: 800;
  color: var(--detective-brown-dark);
  margin-right: auto;
  text-shadow: 1px 1px 0 rgba(255, 215, 0, 0.3);
}

.btn-secondary {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  background: var(--parchment);
  color: var(--ink-charcoal);
  border: 2px solid var(--detective-brown);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  min-height: 44px;
}

.btn-secondary:hover {
  box-shadow: 0 2px 8px var(--card-shadow);
  border-color: var(--detective-brown-dark);
  background: var(--parchment-dark);
}

.btn-secondary:active {
  transform: scale(0.92);
}

.btn-secondary[aria-pressed="true"] {
  background: var(--detective-brown);
  color: #fff;
  border-color: var(--detective-brown-dark);
}

/* ------------------------------- Detective Office Layout ------------------ */
.detective-office {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

/* ------------------------------- Case Folder (案件卷宗) -------------------- */
.case-folder {
  background: var(--parchment-dark);
  border: 3px solid var(--detective-brown);
  border-radius: var(--radius-card);
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.case-folder-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.case-folder-icon {
  font-size: 36px;
}

.case-folder-name {
  font-family: var(--font-title);
  font-size: 20px;
  font-weight: 800;
  color: var(--detective-brown-dark);
}

.case-folder-progress {
  font-size: 14px;
  color: var(--grey-60);
  font-weight: 600;
}

/* ------------------------------- HUD (§4.2) -------------------------------- */
.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--parchment-dark);
  border: 2px solid var(--detective-brown);
  border-radius: var(--radius-card);
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
  box-shadow: 0 2px 12px var(--card-shadow);
}

.resource-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--parchment);
  border: 2px solid transparent;
  transition: border-color 0.3s, background 0.3s;
}

.resource-bar.clue-bar {
  border-color: var(--clue-gold);
}

.resource-bar.score-bar {
  border-color: var(--detective-brown);
}

.resource-label {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--ink-charcoal);
}

.bar-track {
  flex: 1;
  height: 10px;
  background: var(--grey-30);
  border-radius: var(--radius-bar);
  overflow: hidden;
  min-width: 60px;
}

.bar-fill {
  height: 100%;
  border-radius: var(--radius-bar);
  transition: width 0.4s ease;
}

.bar-fill.clue-fill { background: var(--clue-gold); }
.bar-fill.fragment-fill { background: var(--evidence-teal); }
.bar-fill.score-fill { background: var(--detective-brown); }

.bar-fill.bar-gain {
  animation: bar-flash-gain 0.32s ease;
}

.resource-value {
  font-family: var(--font-number);
  font-size: 16px;
  font-weight: 700;
  min-width: 36px;
  text-align: right;
  color: var(--detective-brown-dark);
}

/* 線索圖示行（3 個放大鏡） */
.clue-icons {
  display: flex;
  gap: 6px;
  font-size: 22px;
}

.clue-icon {
  opacity: 0.3;
  transition: opacity 0.4s ease, transform 0.4s ease;
  filter: grayscale(1);
}

.clue-icon.found {
  opacity: 1;
  filter: grayscale(0);
  transform: scale(1.1);
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}

.resource-value.value-bump {
  animation: value-bump 0.22s ease;
}

/* ------------------------------- Investigation Cards (調查階段卡片) -------- */
.investigations {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.investigation-card {
  position: relative;
}

.investigation-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  width: 100%;
  background: var(--parchment);
  border: 3px solid var(--detective-brown);
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s;
  font-family: var(--font-body);
  color: var(--ink-charcoal);
  position: relative;
  overflow: hidden;
  min-height: 160px;
}

.investigation-btn:hover:not(:disabled) {
  border-color: var(--clue-gold);
  box-shadow: 0 6px 20px var(--card-shadow);
  transform: translateY(-3px);
}

.investigation-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.investigation-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-style: dashed;
}

.investigation-card.done .investigation-btn {
  border-color: var(--success-green);
  background: #E8F8F0;
}

.investigation-card.locked .investigation-btn {
  background: #EDE5D0;
  border-color: var(--grey-30);
}

.investigation-icon {
  font-size: 40px;
  line-height: 1;
}

.investigation-stage {
  font-size: 12px;
  font-weight: 700;
  color: var(--detective-brown);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.investigation-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--detective-brown-dark);
  text-align: center;
}

.investigation-desc {
  font-size: 13px;
  color: var(--grey-60);
  text-align: center;
}

.investigation-status {
  font-size: 13px;
  font-weight: 700;
  color: var(--grey-60);
  background: var(--parchment-dark);
  padding: 4px 12px;
  border-radius: 10px;
  margin-top: 4px;
}

.investigation-status.completed {
  color: var(--success-green);
  background: #E8F8F0;
}

/* 資源 badge */
.resource-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 22px;
  background: var(--parchment);
  border: 2px solid var(--detective-brown);
  border-radius: 14px;
  padding: 3px 10px;
  line-height: 1.3;
  pointer-events: none;
  z-index: 2;
}

.investigation-card.locked .resource-badge {
  display: none;
}

.investigation-card.locked .investigation-icon {
  filter: grayscale(0.7);
}

.lock-icon {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 20px;
  opacity: 0.6;
}

/* 漣漪效果 */
.investigation-btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(139, 105, 20, 0.3);
  transform: scale(0);
  animation: ripple-anim 0.5s ease-out;
  pointer-events: none;
}

@keyframes ripple-anim {
  to { transform: scale(2.5); opacity: 0; }
}

/* ------------------------------- Game Root (iframe 遮罩) ------------------- */
.game-root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(61, 61, 61, 0.92);
  z-index: 105;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  gap: 8px;
}

.game-root.active {
  opacity: 1;
  visibility: visible;
}

/* 控制按鈕行 */
.game-controls {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  width: min(880px, 96vw);
}

.game-root iframe {
  width: min(880px, 96vw);
  height: min(640px, 88vh);
  border: 3px solid var(--detective-brown);
  border-radius: var(--radius-modal);
  background: var(--parchment);
  display: block;
}

.game-controls button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border: 2px solid var(--detective-brown);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  min-height: 44px;
}

.game-controls .btn-control {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 2px solid var(--detective-brown);
  background: rgba(61, 61, 61, 0.85);
  color: #fff;
  cursor: pointer;
  font-family: var(--font-body);
}

.game-controls .btn-control-help {
  font-size: 18px;
  line-height: 1;
}

.game-controls button:hover {
  box-shadow: 0 4px 16px var(--card-shadow);
  transform: translateY(-1px);
}

.game-controls button:active {
  transform: scale(0.92);
}

/* ------------------------------- Modal Frames ------------------------------ */
.modal-frame {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(rgba(253, 246, 227, 0.7), rgba(245, 230, 200, 0.75)), url('images/g4_bg_modal.webp') center/cover no-repeat;
  z-index: 1000;
}

.modal-frame[hidden] { display: none; }

/* 過場故事遮罩 */
.story-content {
  background: var(--parchment-dark);
  border: 3px solid var(--detective-brown);
  border-radius: var(--radius-modal);
  padding: 36px 44px;
  text-align: center;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 8px 32px var(--card-shadow);
  animation: modal-bounce 0.4s ease;
}

.story-icon {
  font-size: 56px;
  margin-bottom: 12px;
}

.story-text {
  font-size: 16px;
  color: var(--ink-charcoal);
  line-height: 1.7;
  margin-bottom: 20px;
  font-weight: 500;
}

/* 結局遮罩 */
.gamewin-content {
  background: var(--parchment-dark);
  border: 3px solid var(--clue-gold);
  border-radius: var(--radius-modal);
  padding: 32px 40px;
  text-align: center;
  max-width: 460px;
  width: 90%;
  box-shadow: 0 8px 32px var(--card-shadow);
  animation: modal-bounce 0.4s ease;
}

@keyframes modal-bounce {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.gamewin-content h2 {
  font-family: var(--font-title);
  font-size: 28px;
  color: var(--detective-brown-dark);
  margin-bottom: 8px;
}

.gamewin-medal {
  font-size: 64px;
  margin-bottom: 8px;
  animation: medal-glow 1.5s ease-in-out infinite;
}

@keyframes medal-glow {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(255,215,0,0.4)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 16px rgba(255,215,0,0.8)); }
}

.gamewin-rank {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 12px;
}

.gamewin-rank.gold { color: #D4A017; }
.gamewin-rank.silver { color: #A0A0A0; }
.gamewin-rank.bronze { color: #CD7F32; }

.gamewin-content p {
  color: var(--grey-60);
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.6;
}

.gamewin-stats {
  font-size: 14px;
  color: var(--ink-charcoal);
  margin-bottom: 16px;
  line-height: 1.8;
}

.gamewin-stats strong {
  color: var(--detective-brown-dark);
  font-weight: 800;
}

/* ------------------------------- Buttons ----------------------------------- */
.btn-primary {
  font-family: var(--font-title);
  font-size: 16px;
  font-weight: 800;
  padding: 12px 32px;
  background: var(--detective-brown);
  color: #fff;
  border: none;
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  min-height: 44px;
}

.btn-primary:hover {
  box-shadow: 0 4px 12px rgba(139, 105, 20, 0.4);
}

.btn-primary:active {
  transform: scale(0.92);
}

.btn-primary.gold {
  background: linear-gradient(135deg, var(--clue-gold), #D4A017);
  color: var(--detective-brown-dark);
}

.gamewin-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ------------------------------- Animations -------------------------------- */
@keyframes value-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

@keyframes bar-flash-gain {
  0% { filter: brightness(1); }
  30% { filter: brightness(1.8); }
  100% { filter: brightness(1); }
}

/* ------------------------------- 語言下拉選單 ------------------------------- */
.lang-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--parchment);
  border: 2px solid var(--detective-brown);
  border-radius: 12px;
  padding: 4px 0;
  z-index: 500;
  min-width: 140px;
  box-shadow: 0 4px 16px var(--card-shadow);
}
.lang-dropdown[hidden] { display: none; }
.lang-dropdown button {
  display: block;
  width: 100%;
  padding: 10px 18px;
  background: transparent;
  color: var(--ink-charcoal);
  border: none;
  font-size: 15px;
  font-family: var(--font-body);
  cursor: pointer;
  text-align: left;
}
.lang-dropdown button:hover { background: var(--detective-brown); color: #fff; }
.lang-dropdown button.active { color: var(--detective-brown-dark); font-weight: bold; }
.lang-wrapper { position: relative; display: inline-block; }

/* ------------------------------- 手機端漢堡選單 + 側邊抽屜（參考 G11 UI 規格） ------------------------------- */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 2px solid var(--detective-brown);
  border-radius: 8px;
  cursor: pointer;
  z-index: 100;
  transition: all .15s ease;
  flex-shrink: 0;
}
.btn-hamburger:hover {
  background: rgba(139, 105, 20, 0.1);
  box-shadow: 0 0 10px rgba(139, 105, 20, 0.3);
}
.hamburger-line {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--detective-brown);
  border-radius: 2px;
  transition: transform .3s, opacity .3s;
  transform-origin: center;
}
/* 漢堡 → ✕ 動畫 */
.btn-hamburger.is-open .hamburger-line:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.btn-hamburger.is-open .hamburger-line:nth-child(2) { opacity: 0; transform: scaleX(0); }
.btn-hamburger.is-open .hamburger-line:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* 手機端選單遮罩 */
.mobile-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.mobile-menu-backdrop:not([hidden]) {
  opacity: 1;
  visibility: visible;
}

/* 英文按鈕文字過長 → 自動縮小 */
html[lang="en"] .topbar-actions .btn-secondary {
  font-size: 11px;
  letter-spacing: 0;
  padding: 8px 10px;
}

/* ------------------------------- Responsive -------------------------------- */
/* 玩法說明彈窗 */
.help-body { text-align: left; font-size: 14px; line-height: 1.8; color: var(--ink-charcoal); margin-bottom: 16px; }
.help-body p { margin-bottom: 8px; }
.help-content { max-width: 480px; }

@media (max-width: 640px) {
  .game-title { font-size: 20px; margin-right: 0; }
  .topbar { gap: 8px; padding: 10px 12px; }
  .hud { gap: 8px; padding: 10px 12px; }
  .resource-bar { min-width: 120px; }
  .investigations { grid-template-columns: 1fr; }
  .game-root iframe { height: min(500px, 88vh); }
  .game-controls { width: 96vw; }
  .investigation-btn { min-height: 120px; padding: 16px 12px; }
  .investigation-icon { font-size: 32px; }
  .case-folder { flex-direction: column; text-align: center; }
}

/* ------------------------------- 響應式（≤880px / ≤480px，參考 G11 UI 規格） ------------------------------- */
@media (max-width: 880px) {
  .btn-hamburger { display: flex; }

  .topbar {
    justify-content: flex-start;
    gap: 8px;
    flex-wrap: nowrap;
    padding: 8px 12px;
  }
  .game-title {
    flex: 1;
    font-size: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 0;
  }

  /* 操作按鈕 → 右側滑入抽屜 */
  .topbar-actions {
    position: fixed;
    top: 0;
    right: 0;
    width: 260px;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 80px 20px 20px;
    background: var(--parchment-dark);
    border-left: 2px solid var(--detective-brown);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    z-index: 95;
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto;
  }
  .topbar-actions.mobile-open { transform: translateX(0); }

  /* 抽屜內按鈕全寬 + 左對齊文字 */
  .topbar-actions .btn-secondary {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    font-size: 15px;
    padding: 12px 16px;
  }

  /* 語言下拉在手機抽屜內展開 */
  .topbar-actions .lang-wrapper { display: block; width: 100%; }
  .topbar-actions .lang-dropdown {
    position: static;
    margin-top: 4px;
    box-shadow: none;
    border-radius: 6px;
    width: 100%;
  }
  .topbar-actions #btn-lang {
    width: 100%;
    justify-content: flex-start;
  }

  /* HUD 資源條手機端堆疊 */
  .hud { gap: 10px; padding: 12px; }
  .resource-bar { min-width: 100%; }

  /* iframe：手機端用 vh/dvh 撐滿 */
  .game-root { padding: 8px; }
  .game-controls { width: min(98vw, 880px); }
  .game-root iframe {
    width: min(98vw, 880px);
    height: min(88vh, 88dvh, 600px);
  }
}

/* 小手機（≤480px） */
@media (max-width: 480px) {
  .topbar-actions { width: 100%; }
  .game-root { padding: 4px; }
  .game-controls { width: 100%; }
  .game-root iframe {
    width: 100%;
    height: min(92vh, 92dvh, 560px);
  }
  .game-title { font-size: 15px; letter-spacing: 0; }
}
