/* styles/base.css — 全域設計系統 (M0) */
/* 繁體中文 (香港書面語)，手機直向優先，零外部 URL (系統字體，無 webfont)。 */
:root {
  --bg: #f6f3ea;
  --card: #fffdf6;
  --ink: #2b2b26;
  --muted: #6f6a5e;
  --line: #ddd5c2;
  --accent: #d97706;
  --accent-ink: #fff;
  --good: #15803d;
  --bad: #b91c1c;
  --blue: #1d4ed8;
  --radius: 14px;
  --nav-h: 58px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang HK", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.3; margin: 0 0 8px; }
p { margin: 0 0 10px; }
a { color: var(--blue); }
button {
  font: inherit; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
  padding: 10px 16px; min-height: 44px;
}
button.primary {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 700;
}
button:disabled { opacity: 0.45; cursor: default; }
input, select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff; }

/* App Shell */
#app { max-width: 860px; margin: 0 auto; padding: 12px 14px calc(var(--nav-h) + 18px); }
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 2px 10px; }
.app-header h1 { font-size: 20px; margin: 0; }
.app-header .sub { font-size: 12px; color: var(--muted); }
.mute-btn { min-width: 44px; padding: 6px 10px; }
#view { min-height: 50vh; }
.card {
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
/* 六區導覽 (手機底部固定) */
.app-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1.5px solid var(--line);
  height: var(--nav-h); padding-bottom: env(safe-area-inset-bottom);
}
.app-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: 12px; gap: 1px;
}
.app-nav a .ico { font-size: 19px; line-height: 1; }
.app-nav a.active { color: var(--accent); font-weight: 700; }
/* 主頁 */
.hero { text-align: center; padding: 18px 14px; }
.hero .big-btn { font-size: 18px; padding: 14px 26px; min-height: 56px; }
.team-preview { display: flex; gap: 10px; justify-content: center; margin: 10px 0; }
.team-slot {
  width: 84px; min-height: 96px; border: 1.5px dashed var(--line); border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #fff; padding: 6px; text-align: center; font-size: 13px;
}
.team-slot img { width: 56px; height: 56px; object-fit: contain; }
.team-slot .empty { color: var(--muted); font-size: 12px; }
.quick-links { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.quick-links a { text-decoration: none; }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 90px; background: #fff; border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 10px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); }
.pass { color: var(--good); font-weight: 700; }
.fail { color: var(--bad); font-weight: 700; }
.placeholder { text-align: center; padding: 30px 10px; }
/* 測試畫面 */
.test-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.test-table th, .test-table td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
.test-table th { background: #f0ead8; }
.test-log {
  background: #1e1e1e; color: #d7ffd7; border-radius: 10px;
  padding: 10px 12px; font-family: ui-monospace, monospace; font-size: 12.5px;
  white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
}
/* 同機雙人對坐：上方玩家區域旋轉 180 度 */
.pvp-zone { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; background: var(--card); }
.pvp-zone.flipped { transform: rotate(180deg); }
.pvp-zone.flipped button, .pvp-zone.flipped .no-flip { transform: rotate(180deg); }
.hp-bar { height: 12px; background: #e5e0d0; border-radius: 6px; overflow: hidden; }
.hp-bar > i { display: block; height: 100%; background: var(--good); }
.hp-bar.low > i { background: var(--bad); }
.sp-bar { height: 8px; background: #e5e0d0; border-radius: 4px; overflow: hidden; }
.sp-bar > i { display: block; height: 100%; background: var(--blue); }
/* 平板／桌面：導覽移左側 */
@media (min-width: 760px) {
  #app { padding: 16px 20px 24px 96px; }
  .app-nav {
    top: 0; bottom: 0; left: 0; right: auto; width: 76px; height: auto;
    flex-direction: column; justify-content: flex-start; padding-top: 14px;
    border-top: none; border-right: 1.5px solid var(--line);
  }
  .app-nav a { flex: none; padding: 12px 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 成就分區 (M1) */
.ach-list { display: flex; flex-direction: column; gap: 8px; }
.ach-row { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fffdf6; }
.ach-row.done { border-color: #b7d9a8; background: #f2f8ec; }
.ach-icon { font-size: 22px; }
.ach-state { margin-left: auto; font-size: 13px; white-space: nowrap; }
.mile-chip { display: inline-block; padding: 4px 10px; margin: 2px; border: 1px solid var(--line); border-radius: 20px; background: #fff8e1; font-size: 13px; }

/* M2：抽卡 */
.pity-bars { margin: 10px auto; max-width: 340px; text-align: left; }
.pity-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.pity-row span:first-child { min-width: 92px; text-align: right; }
.pity-track { flex: 1; height: 6px; border-radius: 3px; background: #e5e0d0; overflow: hidden; }
.pity-fill { display: block; height: 100%; background: linear-gradient(90deg, #ffd700, #ff8c00); }
.pack-result { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0; }
.pack-card {
  position: relative; border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
  padding: 8px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 13px; text-align: center; min-height: 96px; justify-content: center;
}
.pack-card.shiny { border: 2px solid transparent; background: linear-gradient(#fffdf6, #fffdf6) padding-box, linear-gradient(45deg, #ff004c, #ff9a00, #ffee00, #00d26a, #0090ff, #b200ff) border-box; }
.pack-card .new-tag {
  position: absolute; top: -9px; right: -6px; background: #16a34a; color: #fff;
  font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 8px; transform: rotate(8deg);
}
.rarity-badge { font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 4px; color: #fff; }
.rarity-badge.t2 { color: #222; }
/* M2：篩選列 */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.filter-row input[type="search"] { flex: 1; min-width: 140px; }
/* M2：收藏 */
.coll-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.coll-card {
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff; padding: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  cursor: pointer; font-size: 13px;
}
.coll-card.in-team { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.25); }
.coll-card img { width: 64px; height: 64px; object-fit: contain; }
.coll-noimg { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--muted); }
.xp-bar { width: 100%; height: 6px; background: #e5e0d0; border-radius: 3px; overflow: hidden; }
.xp-bar > i { display: block; height: 100%; background: var(--good); }
/* M2：圖鑑 */
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.dex-cell {
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  cursor: pointer; font-size: 12px; min-height: 108px; justify-content: center;
}
.dex-cell.owned { border-color: #b7d9a8; background: #f7fbf2; }
.dex-cell img { width: 56px; height: 56px; object-fit: contain; }
.dex-silhouette {
  width: 56px; height: 56px; display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 900; color: #fff; background: #3a3a3a; border-radius: 50%;
}
.dex-noimg { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--muted); }
.dex-name { font-weight: 700; font-size: 12px; }
/* M2：道館 */
.gym-boss { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; margin-bottom: 10px; }
.boss-img { width: 72px; height: 72px; object-fit: contain; flex-shrink: 0; }
.boss-img.placeholder { display: flex; align-items: center; justify-content: center; font-size: 30px; color: var(--muted); background: #eee; border-radius: 10px; }
.gym-boss-info { display: flex; flex-direction: column; gap: 4px; }
.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.opt-grid button { min-height: 52px; font-size: 17px; font-weight: 700; }

/* M3：同機雙人對戰 */
/* 面對面佈局移植 math-battle v9：直屏雙人時上方 (P1) 區倒轉 180°，下方 (P2) 正向；
   AI 模式唔倒轉 (v9c 定案：真人下半、AI 上半，兩區同向)。 */
.pvp-arena { display: flex; flex-direction: column; }
.pvp-half { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 10px; background: var(--card); }
.pvp-half.side0, .pvp-half[data-side="0"] { border-top: 3px solid var(--blue); }
.pvp-half.side1, .pvp-half[data-side="1"] { border-top: 3px solid var(--bad); }
.pvp-side-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pvp-side-head img.fighter-img { width: 44px; height: 44px; object-fit: contain; margin-left: auto; }
.pvp-q { font-size: 22px; text-align: center; margin: 8px 0; }
.pvp-half .opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pvp-half .opt-grid button { min-height: 48px; font-size: 17px; }
/* 安全間距：上下兩區之間至少 24px (中央控制帶本身 56px 高，內含題號／離開掣) */
.pvp-safe-zone { min-height: 24px; }
.pvp-centerbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; padding: 4px 8px; }
/* AI 模式：AI 區答案掣鎖死 (math-battle v9：AI 經 aiAct 直接作答，防用戶誤觸上方 AI 區) */
.pvp-arena.ai-mode .ai-half button[data-i] { pointer-events: none; }
@media (orientation: portrait) {
  /* 直屏雙人：上方 P1 區整區倒轉 180° (中央控制帶唔旋轉) */
  .pvp-arena.faceoff .pvp-half.top { transform: rotate(180deg); }
}
@media (orientation: landscape) {
  /* 橫屏：左右雙區＋中央直帶，兩區都唔旋轉；安全間距改為左右 24px */
  .pvp-arena { flex-direction: row; align-items: stretch; gap: 0; }
  .pvp-arena .pvp-half { flex: 1 1 0; min-width: 0; }
  .pvp-arena .pvp-safe-zone { min-height: 0; min-width: 24px; display: flex; align-items: stretch; }
  .pvp-arena .pvp-centerbar { flex-direction: column; justify-content: space-between; min-height: 0; min-width: 56px; padding: 8px 4px; }
}
/* M3：輪流選角 */
.draft-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin: 10px 0; }
.draft-card { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; min-height: 96px; }
.draft-card img { width: 52px; height: 52px; object-fit: contain; }
.draft-card .draft-noimg { font-size: 28px; }
.draft-card.picked-p1 { border-color: var(--blue); background: #eef4ff; }
.draft-card.picked-p2 { border-color: var(--bad); background: #fff0f0; }

/* M4：觸控反饋＋效能 */
/* touch-action: manipulation 消除手機雙撳縮放延遲；:active 即時變暗做按下反饋 */
button { touch-action: manipulation; }
button:active { filter: brightness(0.96); }
.dex-cell:active, .coll-card:active, .draft-card:active { filter: brightness(0.97); }
/* 長列表：離屏卡片唔渲染，捲動更順 (intrinsic-size 避免捲動條跳動) */
.dex-cell, .coll-card { content-visibility: auto; contain-intrinsic-size: auto 120px; }
.coll-card { contain-intrinsic-size: auto 220px; }
@media (prefers-reduced-motion: reduce) {
  button:active, .dex-cell:active, .coll-card:active, .draft-card:active { filter: none; }
}
