/* ===========================================================================
 * G7 · 週五下班大逃殺 — style.css
 * 美術聖經：opc-doc/art/G7-friday-escape-art.md
 * 基調：扁平卡通辦公室喜劇 — 暖色日光燈 + 格子間，粗圓線條
 * =========================================================================== */

/* ------------------------------- CSS Variables ----------------------------- */
:root {
  /* 核心色板（§2.1） */
  --office-paper: #FFF6E9;
  --cubicle-beige: #F3E9D8;
  --carpet-taupe: #D4C4A8;
  --fluorescent: #F8F5F0;
  --slack-orange: #FF9F43;
  --post-it-yellow: #FECB6F;
  --coffee-teal: #4ECDC4;
  --boss-blue: #5B8DEF;
  --patience-red: #FF6B6B;
  --clock-black: #333333;
  --charcoal: #2C3E50;
  --grey-60: #6B7280;
  --success-green: #20BF6B;
  --alert-orange: #F7B731;
  --fail-red: #E74C3C;
  --warm-shadow: rgba(44, 62, 80, 0.12);

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

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

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

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

/* 辦公室主廳全屏背景（底層，z-2）— 參考 G1/G2 body::before 寫法 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url('images/g7_bg_office.webp') center/cover no-repeat;
}

/* 淺色半透明遮罩（保可讀性，z-1）— 純遮罩，無格線 */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(rgba(255, 246, 233, 0.52), rgba(255, 246, 233, 0.58));
}

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

.game-title {
  font-family: var(--font-title);
  font-size: 28px;
  font-weight: 800;
  color: var(--slack-orange);
  margin-right: auto;
  text-shadow: 1px 1px 0 var(--post-it-yellow);
}

/* 遊戲 logo（參考 G3 寫法）— 放在 h1 外面，避免被 i18n textContent 覆寫摧毀 */
.game-logo {
  height: 40px;
  width: auto;
  vertical-align: middle;
  margin-right: 8px;
  border-radius: 8px;
}

.btn-secondary {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  background: var(--office-paper);
  color: var(--charcoal);
  border: 2px solid var(--cubicle-beige);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.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(--slack-orange);
  color: #fff;
  border-color: var(--slack-orange);
}

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

/* ------------------------------- HUD (§5.1) -------------------------------- */
.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--fluorescent);
  border: 3px solid var(--cubicle-beige);
  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(--office-paper);
  border: 2px solid transparent;
  transition: border-color 0.3s, background 0.3s;
}

.resource-bar.alert-warning {
  border-color: var(--alert-orange);
  animation: pulse-warn 0.6s ease-in-out infinite;
}

.resource-bar.alert-critical {
  border-color: var(--fail-red);
  background: #FFF0F0;
  animation: pulse-crit 0.3s ease-in-out infinite;
}

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

.bar-track {
  flex: 1;
  height: 8px;
  background: var(--cubicle-beige);
  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.sobriety { background: var(--coffee-teal); }
.bar-fill.boss-favor { background: var(--boss-blue); }
.bar-fill.patience { background: var(--patience-red); }

/* 回血彈跳 + 色閃 */
.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(--slack-orange);
  background: var(--post-it-yellow);
}

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

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

/* ------------------------------- Task Hall --------------------------------- */
.disasters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.disaster-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 140px;
  padding: 28px 14px 18px;
  background: var(--fluorescent);
  border: 3px solid var(--cubicle-beige);
  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;
}

.disaster-btn:hover {
  border-color: var(--slack-orange);
  box-shadow: 0 4px 16px rgba(255, 159, 67, 0.2);
  transform: translateY(-2px);
}

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

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

/* 災難主名（類似 G6 .room-name） */
.disaster-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--slack-orange);
  text-align: center;
  line-height: 1.3;
}

/* 災難玩法副標題（類似 G6 .room-games） */
.disaster-games {
  font-size: 12px;
  font-weight: 600;
  color: var(--grey-60);
  text-align: center;
  line-height: 1.4;
}

/* 資源 badge */
.resource-badge {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 18px;
  background: #FFF6E9;
  border: 2px solid #FF9F43;
  border-radius: 14px;
  padding: 2px 8px;
  line-height: 1.2;
  pointer-events: none;
  z-index: 2;
}

/* 漣漪效果 */
.disaster-btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 159, 67, 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 --------------------------------- */
/* 全屏遮罩（參考 G1），阻止點擊下方的災變按鈕 */
.game-root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(44, 62, 80, 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;
}

/* 按鈕行：跟 iframe 同寬，右對齊，在 iframe 上方 */
.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(--cubicle-beige);
  border-radius: var(--radius-modal);
  background: var(--office-paper);
  display: block;
}

.game-controls button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border: 2px solid var(--cubicle-beige);
  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.25);
}

.game-controls .btn-back-hub {
  background: var(--slack-orange);
  color: #fff;
  border-color: var(--slack-orange);
}

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

.game-controls button:hover {
  box-shadow: 0 4px 16px rgba(44, 62, 80, 0.3);
  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(44, 62, 80, 0.5), rgba(44, 62, 80, 0.6)), url('images/g7_bg_modal.webp') center/cover no-repeat;
  z-index: 1000;
}

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

.gameover-content,
.gamewin-content {
  background: linear-gradient(rgba(255, 246, 233, 0.86), rgba(255, 246, 233, 0.92)), url('images/g7_bg_modal.webp') center/cover no-repeat;
  border: 3px solid var(--cubicle-beige);
  border-radius: var(--radius-modal);
  padding: 32px 40px;
  text-align: center;
  max-width: 420px;
  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; }
}

.gameover-content h2 {
  font-family: var(--font-title);
  font-size: 28px;
  color: var(--fail-red);
  margin-bottom: 12px;
}

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

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

#gameover-reason {
  font-size: 16px;
  font-weight: 700;
  color: var(--charcoal);
  margin-bottom: 16px;
  line-height: 1.5;
}

.gameover-stats,
.gamewin-stats {
  font-size: 13px;
  color: var(--grey-60);
  margin-bottom: 16px;
  line-height: 1.6;
}

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

.btn-primary:hover {
  box-shadow: 0 4px 12px rgba(255, 159, 67, 0.3);
}

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

/* ------------------------------- Animations -------------------------------- */
@keyframes pulse-warn {
  0%, 100% { border-color: var(--alert-orange); }
  50% { border-color: transparent; }
}

@keyframes pulse-crit {
  0%, 100% { border-color: var(--fail-red); transform: translateX(0); }
  25% { border-color: transparent; transform: translateX(-2px); }
  75% { border-color: transparent; transform: translateX(2px); }
}

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

/* ------------------------------- 色盲模式 (§9.1) --------------------------- */
body.colorblind .bar-fill.sobriety { background: #0072B2; }
body.colorblind .bar-fill.patience { background: #D55E00; }
body.colorblind .resource-bar.alert-warning { border-color: #0072B2; }
body.colorblind .resource-bar.alert-critical { border-color: #D55E00; }
body.colorblind .resource-bar.alert-critical { background: #FFF6F0; }

/* ---------- 玩法說明彈窗 ---------- */
.help-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  background: linear-gradient(rgba(44, 62, 80, 0.5), rgba(44, 62, 80, 0.6)), url('images/g7_bg_modal.webp') center/cover no-repeat;
}
.help-overlay[hidden] { display: none; }
.help-panel {
  background: linear-gradient(rgba(255, 246, 233, 0.86), rgba(255, 246, 233, 0.92)), url('images/g7_bg_modal.webp') center/cover no-repeat;
  border: 3px solid #FF9F43;
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 480px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.help-panel h2 {
  font-size: 20px;
  color: #2C3E50;
  margin-bottom: 12px;
}
.help-panel p {
  font-size: 14px;
  color: #2C3E50;
  margin-bottom: 12px;
  line-height: 1.6;
}
.help-panel ul {
  list-style: none;
  padding: 0;
  margin-bottom: 16px;
}
.help-panel ul li {
  font-size: 13px;
  color: #5D6D7E;
  padding: 4px 0;
  line-height: 1.5;
}
.help-panel .btn-primary {
  display: block;
  margin: 0 auto;
}

/* ------------------------------- Responsive -------------------------------- */
@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; }
  .disasters { grid-template-columns: repeat(2, 1fr); }
  .game-root iframe { height: min(480px, 88vh); }
  .game-controls { width: 96vw; }
}

/* ------------------------------- G7 排行榜背景（g7_bg_meeting_room.webp / g7_bg_modal.webp） ------------------------------- */
/* 仅作用于 G7 自带 #leaderboard-panel（分数榜面板），不影响 common/leaderboard.js 动态创建的改名弹窗，也不影响其他游戏。
   用 #leaderboard-panel 提权，覆盖注入样式的 .lb-overlay / .lb-panel（见 common/leaderboard.js）。 */
#leaderboard-panel.lb-overlay {
  /* 全屏遮罩层：会议室场景 + 半透明压暗，让面板浮起 */
  background:
    linear-gradient(rgba(44, 62, 80, 0.5), rgba(44, 62, 80, 0.6)),
    url('images/g7_bg_meeting_room.webp') center / cover no-repeat;
}

#leaderboard-panel .lb-panel {
  /* 面板本身：弹窗底图 + 浅色半透明叠层，保可读性（同 gameover/gamewin） */
  background:
    linear-gradient(rgba(255, 246, 233, 0.86), rgba(255, 246, 233, 0.92)),
    url('images/g7_bg_modal.webp') center / cover no-repeat;
  border: 1px solid var(--cubicle-beige);
  box-shadow: 0 12px 40px rgba(44, 62, 80, 0.4);
}
