/* ============================================================
   common.css — 全站共用設計權杖 + 導覽列 + toast/loading
   注意：
   - 不下全域 `*` reset，避免污染既有頁面排版
   - navbar 樣式全部框在 .site-nav 命名空間下
   - :root 只「新增」變數，既有頁（如 lobby）自有的 :root 會後載覆寫
   ============================================================ */

:root {
  --wx-bg:      #0d0f1a;
  --wx-surface: #131629;
  --wx-border:  #1e2540;
  --wx-accent:  #e94560;
  --wx-accent-d:  #d63350;   /* accent 紅，hover/按下加深 */
  --wx-accent2: #3b82f6;
  --wx-accent2-d: #2563eb;   /* accent2 藍，hover/按下加深 */
  --wx-gold:    #f59e0b;
  --wx-text:    #e2e8f0;
  --wx-muted:   #64748b;
  --wx-green:   #22c55e;
  --wx-nav-h:   54px;
  --wx-radius:  8px;
}

/* ============================================================
   全域導覽列（.site-nav）
   ============================================================ */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--wx-nav-h);
  padding: 0 16px;
  background: rgba(13, 15, 26, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--wx-border);
  font-family: 'Segoe UI', system-ui, sans-serif;
  box-sizing: border-box;
}
.site-nav * { box-sizing: border-box; }

.site-nav__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--wx-text);
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.site-nav__brand img {
  height: 30px;
  width: auto;
}

.site-nav__toggle {
  display: none;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--wx-border);
  color: var(--wx-text);
  font-size: 20px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.site-nav__links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}
.site-nav__links a {
  display: block;
  padding: 8px 12px;
  color: var(--wx-muted);
  text-decoration: none;
  font-size: 14px;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.site-nav__links a:hover {
  color: var(--wx-text);
  background: rgba(255, 255, 255, 0.06);
}
.site-nav__links a.is-active {
  color: #fff;
  background: var(--wx-accent2);
}
.site-nav__links a:focus-visible {
  outline: 2px solid var(--wx-gold);
  outline-offset: 2px;
}

/* 帳號區 */
.site-nav__account { display: flex; align-items: center; gap: 8px; }
.site-nav__user { color: var(--wx-gold); font-size: 13px; font-weight: 700; white-space: nowrap; }
.site-nav__logout-form { margin: 0; }
.site-nav__logout {
  background: transparent; border: 1px solid var(--wx-border); color: var(--wx-muted);
  font-size: 13px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.site-nav__logout:hover { color: var(--wx-text); border-color: var(--wx-accent); }
.site-nav__links a.site-nav__cta { background: var(--wx-accent); color: #fff; }
.site-nav__links a.site-nav__cta:hover { filter: brightness(1.1); color: #fff; }

/* 精簡模式（卡表頁等已有自己的功能列） */
.site-nav--compact {
  min-height: 44px;
}
.site-nav--compact .site-nav__links a {
  padding: 6px 10px;
  font-size: 13px;
}

/* 頁面專屬功能鈕插槽（如卡表頁的 牌組製作/篩選/中文/抽包） */
.site-nav__tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
/* 用後代選擇器覆寫頁面 css 的 .menu-button，使其在頁首內變精簡 */
.site-nav__tools .menu-button {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 6px;
  line-height: 1.2;
}

/* 手機：漢堡選單 */
@media (max-width: 768px) {
  .site-nav {
    flex-wrap: wrap;
    gap: 8px;
  }
  .site-nav__toggle {
    display: block;
  }
  .site-nav__links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    margin: 0;
    gap: 2px;
    padding-bottom: 8px;
  }
  .site-nav__links.is-open {
    display: flex;
  }
  .site-nav__links a {
    padding: 10px 12px;
    font-size: 15px;
  }

  /* 手機：功能鈕獨立成一整列（在 品牌/漢堡 那列下方），不與導覽列擠在一起 */
  .site-nav__tools {
    order: 3;          /* 排到 品牌、漢堡 之後 */
    flex-basis: 100%;  /* 強制換到自己的一行 */
    width: 100%;
    justify-content: center;
    gap: 6px;
  }
  .site-nav__tools .menu-button {
    padding: 6px 8px;
    font-size: 12px;
  }
  .site-nav__links {
    order: 4;          /* 展開時排在功能鈕下方 */
  }
}

/* ============================================================
   Toast（右下角非阻斷提示）
   ============================================================ */
.wx-toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.wx-toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--wx-radius);
  color: #fff;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  background: #334155;
  border-left: 4px solid var(--wx-accent2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  word-break: break-word;
}
.wx-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.wx-toast--success { border-left-color: var(--wx-green); }
.wx-toast--error   { border-left-color: var(--wx-accent); }
.wx-toast--info    { border-left-color: var(--wx-accent2); }

/* ============================================================
   confirmDialog（自訂確認對話框）
   ============================================================ */
.wx-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.wx-modal-overlay.is-visible { opacity: 1; }
.wx-modal {
  background: var(--wx-surface);
  color: var(--wx-text);
  border: 1px solid var(--wx-border);
  border-radius: 12px;
  padding: 24px;
  width: min(400px, calc(100vw - 40px));
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  font-family: 'Segoe UI', system-ui, sans-serif;
}
.wx-modal__msg {
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 20px;
}
.wx-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.wx-modal__btn {
  padding: 8px 18px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  cursor: pointer;
}
.wx-modal__btn--cancel {
  background: transparent;
  color: var(--wx-muted);
  border: 1px solid var(--wx-border);
}
.wx-modal__btn--confirm {
  background: var(--wx-accent);
  color: #fff;
}
.wx-modal__btn:focus-visible {
  outline: 2px solid var(--wx-gold);
  outline-offset: 2px;
}

/* ============================================================
   Loading（按鈕 spinner / 防連點）
   ============================================================ */
.wx-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}
.wx-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: wx-spin 0.7s linear infinite;
}
@keyframes wx-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .wx-toast,
  .wx-modal-overlay { transition: none; }
  .wx-loading::after { animation: none; }
}

/* ── UA 能量/顏色圖示徽章（由 scripts/card-icons.js 的 window.uaCost 產出）──
   目前用純 CSS 彩色圓圈；日後要換真 icon 圖只需在 .ua-cost--* 加 background-image。 */
.ua-cost {
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 50%;
  vertical-align: middle;
  border: 1.5px solid rgba(0, 0, 0, .3);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .35), inset 0 -2px 3px rgba(0, 0, 0, .25);
  margin: 0 1px;
  background-size: cover;
}
.ua-cost--red    { background-color: #ef4444; }
.ua-cost--blue   { background-color: #3b82f6; }
.ua-cost--yellow { background-color: #f59e0b; }
.ua-cost--green  { background-color: #22c55e; }
.ua-cost--purple { background-color: #a855f7; }
.ua-cost--none {
  width: auto; height: auto;
  border-radius: 6px;
  padding: 0 7px;
  background-color: #64748b;
  color: #fff; font-size: .78rem; line-height: 18px; font-weight: 700;
  box-shadow: none;
}
.ua-cost-num {
  display: inline-block;
  margin-left: 4px;
  font-weight: 800;
  vertical-align: middle;
}

/* 卡面角落的能量徽章（卡表小卡 / 組牌頁 / 牌組頁清單共用）。父層需 position:relative，
   既有 .card / .deck-card 已有絕對定位子元素，故已是 relative。 */
.ua-card-cost {
  position: absolute;
  top: 6px; left: 6px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 5px;
  background: rgba(0, 0, 0, .62);
  border-radius: 9px;
  z-index: 4;
  pointer-events: none;
  line-height: 1;
}
.ua-card-cost .ua-cost { width: 15px; height: 15px; }
.ua-card-cost .ua-cost-num { margin-left: 2px; color: #fff; font-size: .82rem; }
.ua-card-cost .ua-cost--none { font-size: .7rem; line-height: 15px; padding: 0 5px; }

/* ── 關鍵字能力徽章（效果文字內，由 highlightKeywords 產出）── */
.ua-kw {
  display: inline-block;
  padding: 0 8px;
  border-radius: 11px;
  font-size: .82em;
  font-weight: 800;
  line-height: 1.6;
  color: #e8e8ea;  /* 稍暗的白，降低刺眼感 */
  margin: 0 2px;
  vertical-align: 2px; /* 比基線抬高 2px，與周圍文字視覺對齊 */
  white-space: nowrap;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .22);
}
/* 亮底色（琥珀/橘）用深色字，對比較清楚 */
.ua-kw--amber  { background: #f59e0b; color: #1e293b; }
.ua-kw--red    { background: #ef4444; }
.ua-kw--blue   { background: #3b82f6; }
.ua-kw--green  { background: #22c55e; }
.ua-kw--purple { background: #a855f7; }
.ua-kw--orange { background: #fb923c; color: #1e293b; }
.ua-kw--teal   { background: #14b8a6; }
.ua-kw--none   { background: #cbd5e1; color: #1e293b; }  /* 衝擊無效/失效：淺灰底＋黑字 */
.ua-kw--timing { background: #2563eb; color: #fff; }  /* 時機（登場時/主啟動…）藍 pill＋白字 */
.ua-kw--white  { background: #fff; color: #1e293b; }  /* 次數限制（1回合1次）白底深字 pill */
/* 關鍵字數值（如 衝擊（1）的 1）：白底深字小圓圈 */
.ua-kw-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3em;
  height: 1.3em;
  border-radius: 50%;
  background: #111827;
  color: #e8e8ea;  /* 稍暗的白 */
  border: 1px solid rgba(255, 255, 255, .55);
  font-weight: 800;
  font-size: .8em;
  line-height: 1;
  margin-left: 4px;
  vertical-align: middle;
}
/* 條件前綴：淡藍粗體文字（非 pill） */
.ua-kw-t { color: #7dd3fc; font-weight: 700; }

/* ── 價格走勢小圖 ── */
.ua-pchart {
  margin: 6px 0 2px;
  background: linear-gradient(180deg, rgba(148, 163, 184, .10), rgba(148, 163, 184, .03));
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 118px; /* 預留走勢圖高度：fetch 載入前後高度一致，避免彈窗縱向跳動 */
  box-sizing: border-box;
}
.ua-pchart-title { font-size: .78rem; color: #94a3b8; font-weight: 700; margin-bottom: 6px; letter-spacing: .3px; }
.ua-pchart-svg { display: block; width: 100%; overflow: visible; }
.ua-pchart-grid { stroke: rgba(148, 163, 184, .18); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ua-pchart-line { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .30)); }
.ua-pchart-dot { cursor: pointer; transition: r .12s ease; }
.ua-pchart-dot:hover { r: 4.2; }
.ua-pchart-dot.is-last { filter: drop-shadow(0 0 3px currentColor); }
.ua-pchart-empty { font-size: .8rem; color: #64748b; padding: 6px 0; }
/* 右側價格刻度（Y 軸）：圖預留右側空間，刻度依 px 對齊格線 */
.ua-pchart-plot { position: relative; padding-right: 56px; }
.ua-pchart-yaxis { position: absolute; top: 0; right: 0; width: 56px; height: 100%; pointer-events: none; }
.ua-pchart-yaxis span {
  position: absolute; right: 0; transform: translateY(-50%);
  font-size: .66rem; font-weight: 600; color: #94a3b8; white-space: nowrap;
}
.ua-pchart-axis {
  display: flex; justify-content: space-between;
  font-size: .68rem; color: #64748b; margin-top: 4px;
  padding-right: 56px; /* 與圖等寬，頭尾日期對齊折線兩端 */
}
/* 位置條件（位於前線/能量線）+ 休息：文字加紅色底線 */
.ua-kw-u {
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: #ef4444;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  margin: 0 3px;  /* 相鄰的底線詞（如「位於能量線時休息」）之間留間距，底線不連成一條 */
}
