/* ===========================================================================
 * G5 · 反應訓練營 — style.css
 * GDD §2：極簡日式道場風——淺木紋底色 + 朱紅/墨黑主色，
 *         信號用朱紅鳥居/燈籠圖標，計時/數據用電子秒錶風格。
 *         整體「專注、競技、自我超越」的反應力修煉氛圍。
 * =========================================================================== */

/* ------------------------------- CSS Variables ----------------------------- */
:root {
  /* 核心色板（GDD §2 — 日式道場） */
  --dojo-bg: #F5EFE0;          /* 淺木紋底色 */
  --dojo-light: #FAF6EC;       /* 更淺的木紋 */
  --crimson: #C0392B;          /* 朱紅（鳥居/燈籠） */
  --crimson-dark: #962D22;     /* 深朱紅 */
  --crimson-soft: rgba(192, 57, 43, 0.12);
  --ink-black: #1A1A1A;        /* 墨黑 */
  --ink-soft: #2C2C2C;         /* 軟墨 */
  --gold-accent: #C9A84C;      /* 金色點綴（徽章） */
  --gold-dark: #A88A36;
  --jade: #2E8B57;             /* 翡翠綠（成功/通過） */
  --wood: #C8A57A;             /* 木紋色 */
  --wood-dark: #8B6F47;
  --stone: #6B6B6B;            /* 石灰 */
  --charcoal: #2A2A2A;
  --grey-60: #7A7A7A;
  --success: #2E8B57;
  --fail: #C0392B;
  --warm-shadow: rgba(26, 26, 26, 0.12);

  /* 字體 */
  --font-title: 'Noto Sans TC', 'Noto Sans JP', sans-serif;
  --font-body: 'Noto Sans TC', 'Noto Sans JP', sans-serif;
  --font-number: 'Orbitron', 'Noto Sans TC', monospace;  /* 秒錶風格 */
  --font-clock: 'Orbitron', monospace;

  /* 圓角 */
  --radius-btn: 12px;
  --radius-bar: 3px;
  --radius-modal: 20px;
  --radius-card: 12px;

  /* 排行榜模組兼容變數 */
  --panel: #1A1A1A;
  --azure: #C9A84C;
  --cyan: #C0392B;
  --blue: #8B6F47;
  --dusk: #7A7A7A;
  --white: #F5EFE0;
}

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

body {
  font-family: var(--font-body);
  background: var(--dojo-bg);
  color: var(--charcoal);
  min-height: 100vh;
  overflow-x: hidden;
  /* 木紋紋理背景 */
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 40px,
      rgba(139, 111, 71, 0.04) 40px,
      rgba(139, 111, 71, 0.04) 41px,
      transparent 41px,
      transparent 80px
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 4px,
      rgba(139, 111, 71, 0.015) 4px,
      rgba(139, 111, 71, 0.015) 5px
    );
}

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

.game-title {
  font-family: var(--font-title);
  font-size: 26px;
  font-weight: 800;
  color: var(--ink-black);
  margin-right: auto;
  letter-spacing: 2px;
}

.btn-secondary {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  background: var(--dojo-bg);
  color: var(--charcoal);
  border: 2px solid var(--wood);
  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(--crimson);
  color: #fff;
  border-color: var(--crimson-dark);
}

/* ── 漢堡選單按鈕（僅手機端顯示） ── */
.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(--crimson);
  border-radius: var(--radius-btn);
  cursor: pointer;
  z-index: 100;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-hamburger:hover {
  background: var(--crimson-soft);
}

.hamburger-line {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--crimson);
  border-radius: 2px;
  transition: all 0.3s ease;
  transform-origin: center;
}

/* 漢堡 → ✕ 動畫 */
.btn-hamburger.open .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.btn-hamburger.open .hamburger-line:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.btn-hamburger.open .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── 手機端選單遮罩 ── */
.mobile-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.55);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.mobile-menu-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* 英文按鈕文字過長 → 自動縮小（僅頂欄操作鈕） */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
html[lang="en"] .topbar-actions .btn-secondary {
  font-size: 11px;
  letter-spacing: 0;
  padding: 8px 10px;
}

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

/* ------------------------------- HUD --------------------------------------- */
.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--dojo-light);
  border: 3px solid var(--crimson);
  border-radius: 14px;
  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(--dojo-bg);
  border: 2px solid transparent;
  transition: border-color 0.3s, background 0.3s;
}

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

.bar-track {
  flex: 1;
  height: 8px;
  background: var(--wood);
  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.reflex-score { background: var(--gold-accent); }
.bar-fill.badge-progress { background: var(--crimson); }

.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(--ink-black);
}

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

/* 徽章顯示區 */
.badge-display {
  min-width: 120px;
  padding: 8px 14px;
  border: 2px solid var(--gold-accent);
  background: var(--dojo-bg);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-icon {
  font-size: 24px;
}

.badge-info {
  display: flex;
  flex-direction: column;
}

.badge-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-black);
}

.badge-mult {
  font-family: var(--font-number);
  font-size: 12px;
  color: var(--crimson);
  font-weight: 600;
}

/* ------------------------------- Task Hall (三塊訓練場) ---------------------- */
.tasks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.task-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 12px;
  background: var(--dojo-light);
  border: 3px solid var(--crimson);
  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: 100px;
}

.task-btn:hover {
  border-color: var(--gold-accent);
  box-shadow: 0 4px 16px var(--crimson-soft);
  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;
}

.task-sub {
  font-size: 11px;
  color: var(--grey-60);
  font-weight: 400;
}

/* 資源 badge */
.resource-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 18px;
  background: var(--dojo-bg);
  border: 2px solid var(--gold-accent);
  border-radius: 10px;
  padding: 2px 8px;
  line-height: 1.3;
  pointer-events: none;
  z-index: 2;
}

/* 漣漪效果 */
.task-btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: var(--crimson-soft);
  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(26, 26, 26, 0.85);
  z-index: 105;  /* 高於漢堡(100) + 抽屜(95)，低於模態彈窗(1000) */
  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(--crimson);
  border-radius: var(--radius-modal);
  background: var(--dojo-bg);
  display: block;
}

.game-controls button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border: 2px solid var(--crimson);
  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-help-minigame {
  background: var(--dojo-bg);
  color: var(--charcoal);
  width: 44px;
  padding: 8px 0;
  font-size: 18px;
}

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

.game-controls .btn-restart-minigame {
  background: var(--dojo-bg);
  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(26, 26, 26, 0.6);
  z-index: 1000;
}

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

.gamewin-content,
.help-content {
  background: var(--dojo-light);
  border: 3px solid var(--crimson);
  border-radius: var(--radius-modal);
  padding: 32px 40px;
  text-align: center;
  max-width: 460px;
  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; }
}

.gamewin-content h2 {
  font-family: var(--font-title);
  font-size: 26px;
  color: var(--ink-black);
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.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;
}

.g5-highlight {
  color: var(--crimson);
  font-weight: 800;
}

.g5-badge-up {
  color: var(--gold-accent);
  font-weight: 800;
}

/* 徽章升級動畫 */
.badge-up-anim {
  display: inline-block;
  animation: badge-up-pulse 0.6s ease;
}

@keyframes badge-up-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); filter: brightness(1.5); }
  100% { transform: scale(1); }
}

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

.btn-primary:hover {
  box-shadow: 0 4px 12px var(--crimson-soft);
}

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

/* ------------------------------- Colorblind Mode --------------------------- */
body.colorblind .bar-fill.reflex-score { background: #E69F00; }
body.colorblind .bar-fill.badge-progress { background: #56B4E9; }

/* ------------------------------- 語言下拉選單 ------------------------------- */
.lang-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--dojo-light);
  border: 2px solid var(--crimson);
  border-radius: 10px;
  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(--crimson); color: #fff; }
.lang-dropdown button.active { color: var(--crimson); font-weight: bold; }
.lang-wrapper { position: relative; display: inline-block; }

/* ------------------------------- 玩法說明 ----------------------------------- */
.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: 500px; }

/* ------------------------------- Responsive -------------------------------- */
/* ─── 平板 & 手機（≤880px，防止頂欄按鈕換行） ─── */
@media (max-width: 880px) {
  .btn-hamburger { display: flex; }

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

  /* 操作按鈕 → 右側滑入抽屜 */
  .topbar-actions {
    position: fixed;
    top: 0;
    right: 0;
    width: 260px;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 72px 16px 16px;
    background: var(--dojo-light);
    border-left: 3px solid var(--crimson);
    box-shadow: -4px 0 20px rgba(26, 26, 26, 0.25);
    z-index: 95;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
  }
  .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;
    min-width: unset;
    width: 100%;
  }

  /* HUD：資源不分欄，每條獨佔一行 */
  .hud { gap: 10px; padding: 12px; }
  .resource-bar { min-width: 100%; }
  .badge-display { min-width: 100%; }

  /* 訓練場：手機 2 欄 */
  .tasks { grid-template-columns: repeat(2, 1fr); }
  .task-btn { flex-direction: row; min-height: 64px; }
  .task-icon { font-size: 28px; }

  /* 遊戲層 */
  .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) {
  .game-title { font-size: 15px; letter-spacing: 0.5px; }

  /* 抽屜填滿螢幕寬度 */
  .topbar-actions { width: 100%; }

  /* 遊戲層：最小 padding */
  .game-root { padding: 4px; }
  .game-controls { width: 100%; }
  .game-root iframe { width: 100%; height: min(92vh, 92dvh, 560px); }

  /* 訓練場：緊湊 2 欄 */
  .tasks { grid-template-columns: 1fr 1fr; gap: 10px; }
}
