/* ===========================================================================
 * G2 · 晨間咖啡館 — style.css
 * GDD §2：暖色手繪咖啡館——奶白(#FFF8F0)/焦糖(#D4A574)/抹茶綠(#7DAA5C)配色
 *         + 木紋質感 UI，蒸汽與咖啡香氣粒子，溫馨治愈、忙碌但有序。
 * =========================================================================== */

/* ------------------------------- CSS Variables ----------------------------- */
:root {
  /* 核心色板（GDD §2） */
  --cream-white: #FFF8F0;
  --caramel: #D4A574;
  --caramel-dark: #B8865A;
  --matcha-green: #7DAA5C;
  --matcha-dark: #5C8A3E;
  --espresso-brown: #6B4423;
  --latte-foam: #F5E6D3;
  --wood-grain: #C8A57A;
  --wood-dark: #A07850;
  --honey-gold: #E8B84B;
  --amber-tip: #D49A3F;
  --coffee-brown: #5C3A1E;
  --charcoal: #3D2B1F;
  --grey-60: #8B7D6B;
  --success-green: #5C8A3E;
  --alert-orange: #D4811F;
  --fail-red: #C75450;
  --warm-shadow: rgba(107, 68, 35, 0.15);

  /* 字體 */
  --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: 14px;

  /* 排行榜模块兼容变量（leaderboard.js 自带样式引用） */
  --panel:  #3D2B1F;
  --azure:  #A07850;
  --cyan:   #E8B84B;
  --blue:   #D4A574;
  --dusk:   #8B7D6B;
  --white:  #FFF8F0;
}

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

body {
  font-family: var(--font-body);
  background: var(--cream-white);
  color: var(--charcoal);
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* 淡木紋紋理疊加層（裝飾，z-1） */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 40px,
      rgba(200, 165, 122, 0.04) 40px,
      rgba(200, 165, 122, 0.04) 41px,
      transparent 41px,
      transparent 80px
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 3px,
      rgba(168, 130, 90, 0.015) 3px,
      rgba(168, 130, 90, 0.015) 4px
    );
}

/* ------------------------------- Top Bar ----------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--latte-foam);
  border-bottom: 3px solid var(--wood-grain);
  flex-wrap: wrap;
  justify-content: center;
}

.game-title {
  font-family: var(--font-title);
  font-size: 28px;
  font-weight: 800;
  color: var(--espresso-brown);
  margin-right: auto;
  text-shadow: 1px 1px 0 var(--honey-gold);
}

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

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

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

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

/* ------------------------------- HUD (§4.1) -------------------------------- */
.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--latte-foam);
  border: 3px solid var(--wood-grain);
  border-radius: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

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

.resource-label {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.bar-track {
  flex: 1;
  height: 10px;
  background: var(--wood-grain);
  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.star-rating { background: var(--honey-gold); }
.bar-fill.tip { background: var(--amber-tip); }
.bar-fill.cup-tier { background: var(--coffee-brown); }

/* 回血彈跳 + 色閃 */
.bar-fill.bar-gain {
  animation: bar-flash-gain 0.32s ease;
}

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

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

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

/* 營業計時器 */
.resource-bar.clock-bar {
  min-width: 120px;
  border: 2px solid var(--caramel);
  background: var(--latte-foam);
}

.clock-value {
  font-family: var(--font-clock);
  font-size: 20px;
  font-weight: 800;
  color: var(--espresso-brown);
}

.resource-bar.clock-bar.clock-near {
  animation: pulse-clock 0.5s ease-in-out infinite;
}

/* ------------------------------- Task Hall (三步出餐) ----------------------- */
.tasks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.task-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 12px;
  background: var(--latte-foam);
  border: 3px solid var(--wood-grain);
  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);
  font-size: 14px;
  font-weight: 700;
  color: var(--charcoal);
  position: relative;
  overflow: hidden;
  min-height: 90px;
}

.task-btn:hover {
  border-color: var(--caramel);
  box-shadow: 0 4px 16px rgba(212, 165, 116, 0.25);
  transform: translateY(-2px);
}

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

.task-icon {
  font-size: 36px;
  line-height: 1;
}

.task-label {
  text-align: center;
  line-height: 1.3;
}

/* 資源 badge — 顯示該小遊戲產出什麼資源 */
.resource-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 22px;
  background: var(--cream-white);
  border: 2px solid var(--honey-gold);
  border-radius: 14px;
  padding: 3px 10px;
  line-height: 1.3;
  pointer-events: none;
  z-index: 2;
}

/* 漣漪效果 */
.task-btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(212, 165, 116, 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(61, 43, 31, 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(620px, 88vh);
  border: 3px solid var(--wood-grain);
  border-radius: var(--radius-modal);
  background: var(--cream-white);
  display: block;
}

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

.game-controls .btn-restart-minigame {
  background: var(--cream-white);
  color: var(--charcoal);
}

.game-controls button:hover {
  box-shadow: 0 4px 16px var(--warm-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(61, 43, 31, 0.6);
  z-index: 1000;
}

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

.gameover-content,
.gamewin-content {
  background: linear-gradient(rgba(255, 248, 240, 0.86), rgba(255, 248, 240, 0.92)), url('images/g2_bg_modal.webp') center/cover no-repeat;
  border: 3px solid var(--wood-grain);
  border-radius: var(--radius-modal);
  padding: 32px 40px;
  text-align: center;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 8px 32px var(--warm-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; }
}

/* G2 沒有 onLose，gameover 用於 gamewin 結算遮罩 */
.gameover-content h2 {
  font-family: var(--font-title);
  font-size: 28px;
  color: var(--espresso-brown);
  margin-bottom: 12px;
}

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

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

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

.gameover-stats strong,
.g2-highlight {
  color: var(--caramel-dark);
  font-weight: 800;
}

/* ------------------------------- Buttons ----------------------------------- */
.btn-primary {
  font-family: var(--font-title);
  font-size: 16px;
  font-weight: 800;
  padding: 12px 32px;
  background: var(--caramel);
  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(212, 165, 116, 0.4);
}

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

/* ------------------------------- Animations -------------------------------- */
@keyframes pulse-clock {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@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); }
}

@keyframes bar-flash-loss {
  0% { filter: brightness(1); }
  30% { filter: brightness(0.5) saturate(0.3); }
  100% { filter: brightness(1); }
}

/* ------------------------------- Screen Shake ------------------------------ */
body.shake {
  animation: shake 0.1s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ------------------------------- Colorblind Mode (§7) --------------------- */
body.colorblind .bar-fill.star-rating { background: #E69F00; }
body.colorblind .bar-fill.tip { background: #56B4E9; }
body.colorblind .bar-fill.cup-tier { background: #009E73; }

/* ------------------------------- 語言下拉選單 ------------------------------- */
.lang-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--latte-foam);
  border: 2px solid var(--wood-grain);
  border-radius: 12px;
  padding: 4px 0;
  z-index: 500;
  min-width: 140px;
  box-shadow: 0 4px 16px var(--warm-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(--caramel); color: #fff; }
.lang-dropdown button.active { color: var(--caramel-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: 22px; margin-right: 0; }
  .topbar { gap: 8px; padding: 10px 12px; }
  .hud { gap: 8px; padding: 10px 12px; }
  .resource-bar { min-width: 120px; }
  .tasks { grid-template-columns: 1fr; }
  .game-root iframe { height: min(480px, 88vh); }
  .game-controls { width: 96vw; }
  .task-btn { flex-direction: row; min-height: 64px; }
  .task-icon { font-size: 28px; }
}

/* ------------------------------- G2 排行榜背景（g2_bg_customers.webp） ------------------------------- */
/* 仅作用于 G2 自带 #leaderboard-panel（分数榜面板），不影响 common/leaderboard.js 动态创建的改名弹窗，也不影响其他游戏。
   用 #leaderboard-panel 提权，覆盖注入样式的 .lb-overlay / .lb-panel（见 common/leaderboard.js 第 894-896 行）。 */
#leaderboard-panel.lb-overlay {
  /* 全屏遮罩层：顾客场景照片 + 半透明压暗，让面板浮起 */
  background:
    linear-gradient(rgba(20, 14, 10, 0.55), rgba(20, 14, 10, 0.62)),
    url('images/g2_bg_customers.webp') center / cover no-repeat;
}

#leaderboard-panel .lb-panel {
  /* 面板本身：照片 + 深色半透明叠层，保留注入样式的 cyan/blue 文字可读性 */
  background:
    linear-gradient(rgba(34, 24, 17, 0.74), rgba(34, 24, 17, 0.84)),
    url('images/g2_bg_customers.webp') center / cover no-repeat;
  border: 1px solid var(--wood-grain);
  box-shadow: 0 12px 40px rgba(40, 26, 16, 0.55);
}
