/* ===========================================================================
 * G3 · 每日大腦體操 — style.css
 * GDD §2：清新益智訓練室——白(#FFFFFF)/淺藍(#5B9BD5)/薄荷綠(#4CAF50)配色
 *         + 圓角卡片 UI + 輕量動效，整體「清爽、專注、每日進步」氛圍。
 * =========================================================================== */

/* ------------------------------- CSS Variables ----------------------------- */
:root {
  /* 核心色板（GDD §2） */
  --pure-white: #FFFFFF;
  --soft-blue: #5B9BD5;
  --soft-blue-dark: #2E7DB5;
  --soft-blue-light: #8FC8E8;
  --mint-green: #4CAF50;
  --mint-dark: #2E8B57;
  --mint-light: #C8E6C9;
  --sky-bg: #F0F7FF;
  --mint-bg: #F0FBF4;
  --warm-orange: #FF7043;
  --honey-amber: #FFA726;
  --lavender: #B39DDB;
  --charcoal: #37474F;
  --grey-60: #78909C;
  --grey-30: #CFD8DC;
  --success-green: #4CAF50;
  --fail-red: #EF5350;
  --card-shadow: rgba(91, 155, 213, 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;
}

/* ------------------------------- 排行榜面板（leaderboard.js 深色浮層覆蓋） ------------------------------ */
/* G3 為淺色頁面，顯式指定面板內文字為淺色，確保深色浮層上可讀 */
#leaderboard-panel { color: #E6EDF3; }
#leaderboard-panel .lb-title { color: #5EEAD4; }
#leaderboard-panel .lb-tab { color: #5B9BD5; border-color: #5B9BD5; }
#leaderboard-panel .lb-tab.active { background: #5B9BD5; color: #0A1020; }
#leaderboard-panel .lb-rename { color: #5B9BD5; border-color: #8FC8E8; }
#leaderboard-panel .lb-row .lb-handle { color: #E6EDF3; }
#leaderboard-panel .lb-row .lb-rank { color: #A0B4C8; }
#leaderboard-panel .lb-privacy { color: #F5A623; border-color: #F5A623; }

/* 排行榜背景：leaderboard 場景照（g3_bg_leaderboard.webp） */
#leaderboard-panel.lb-overlay {
  background:
    linear-gradient(rgba(10, 16, 32, 0.55), rgba(10, 16, 32, 0.62)),
    url('images/g3_bg_leaderboard.webp') center / cover no-repeat;
}
#leaderboard-panel .lb-panel {
  background:
    linear-gradient(rgba(10, 16, 32, 0.74), rgba(10, 16, 32, 0.84)),
    url('images/g3_bg_leaderboard.webp') center / cover no-repeat;
  border-color: #1A7AB8;
}

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

body {
  font-family: var(--font-body);
  background: var(--sky-bg);
  color: var(--charcoal);
  min-height: 100vh;
  overflow-x: hidden;
}
/* G3 主廳背景：gym 場景照（g3_bg_gym.webp），淺色疊層保文字可讀 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url('images/g3_bg_gym.webp') center / cover no-repeat;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(rgba(240, 248, 255, 0.74), rgba(224, 242, 255, 0.86));
}

/* ------------------------------- Top Bar ----------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--pure-white);
  border-bottom: 2px solid var(--soft-blue-light);
  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(--soft-blue-dark);
  margin-right: auto;
}
.game-logo {
  height: 34px;
  width: auto;
  border-radius: 8px;
  box-shadow: 0 2px 6px var(--card-shadow);
}

.btn-secondary {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  background: var(--pure-white);
  color: var(--charcoal);
  border: 2px solid var(--soft-blue-light);
  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(--soft-blue);
}

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

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

/* ------------------------------- Gym Layout ------------------------------- */
.gym {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

/* ------------------------------- HUD (§4.2) -------------------------------- */
.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--pure-white);
  border: 2px solid var(--soft-blue-light);
  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(--sky-bg);
  border: 2px solid transparent;
  transition: border-color 0.3s, background 0.3s;
}

.resource-bar.date-bar {
  border-color: var(--lavender);
  background: #F3E5F5;
}

.resource-label {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--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.streak-fill { background: var(--warm-orange); }
.bar-fill.brain-fill { background: var(--soft-blue); }

.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(--soft-blue-dark);
}

.date-value {
  font-family: var(--font-clock);
  font-size: 16px;
  font-weight: 800;
  color: var(--lavender);
}

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

/* ------------------------------- Challenge Cards -------------------------- */
.challenges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.challenge-card {
  position: relative;
}

.challenge-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  width: 100%;
  background: var(--pure-white);
  border: 3px solid var(--soft-blue-light);
  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(--charcoal);
  position: relative;
  overflow: hidden;
  min-height: 140px;
}

.challenge-btn:hover {
  border-color: var(--soft-blue);
  box-shadow: 0 6px 20px var(--card-shadow);
  transform: translateY(-3px);
}

.challenge-btn:active {
  transform: scale(0.96);
}

.challenge-card.done .challenge-btn {
  border-color: var(--mint-green);
  background: var(--mint-bg);
}

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

.challenge-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--soft-blue-dark);
}

.challenge-desc {
  font-size: 13px;
  color: var(--grey-60);
}

.challenge-status {
  font-size: 14px;
  font-weight: 700;
  color: var(--grey-60);
  background: var(--sky-bg);
  padding: 4px 12px;
  border-radius: 10px;
  margin-top: 4px;
}

.challenge-status.completed {
  color: var(--mint-dark);
  background: var(--mint-light);
}

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

/* 漣漪效果 */
.challenge-btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(91, 155, 213, 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 --------------------------------- */
.game-root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(55, 71, 79, 0.5);
  z-index: 50;
  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(--soft-blue-light);
  border-radius: var(--radius-modal);
  background: var(--pure-white);
  display: block;
}

.game-controls button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border: 2px solid var(--soft-blue-light);
  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-back-hub {
  background: var(--soft-blue);
  color: #fff;
  border-color: var(--soft-blue-dark);
}

.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: rgba(55, 71, 79, 0.6);
  z-index: 1000;
}

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

.gamewin-content {
  background: linear-gradient(rgba(255, 255, 255, 0.80), rgba(237, 247, 255, 0.90)), url('images/g3_bg_modal.webp') center / cover no-repeat;
  border: 3px solid var(--soft-blue-light);
  border-radius: var(--radius-modal);
  padding: 32px 40px;
  text-align: center;
  max-width: 440px;
  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(--soft-blue-dark);
  margin-bottom: 8px;
}

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

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

.gamewin-stats strong,
.g3-highlight {
  color: var(--soft-blue-dark);
  font-weight: 800;
}

/* ------------------------------- Buttons ----------------------------------- */
.btn-primary {
  font-family: var(--font-title);
  font-size: 16px;
  font-weight: 800;
  padding: 12px 32px;
  background: var(--soft-blue);
  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(91, 155, 213, 0.4);
}

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

/* ------------------------------- 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(--pure-white);
  border: 2px solid var(--soft-blue-light);
  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(--charcoal);
  border: none;
  font-size: 15px;
  font-family: var(--font-body);
  cursor: pointer;
  text-align: left;
}
.lang-dropdown button:hover { background: var(--soft-blue); color: #fff; }
.lang-dropdown button.active { color: var(--soft-blue-dark); font-weight: bold; }
.lang-wrapper { position: relative; display: inline-block; }

/* ------------------------------- Responsive -------------------------------- */
/* 玩法說明彈窗 */
.help-body { text-align: left; font-size: 14px; line-height: 1.8; color: var(--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; }
  .challenges { grid-template-columns: 1fr; }
  .game-root iframe { height: min(500px, 88vh); }
  .game-controls { width: 96vw; }
  .challenge-btn { min-height: 100px; padding: 16px 12px; }
  .challenge-icon { font-size: 32px; }
}
