/* 兩個版本共用的設計 token 與元件：奶油底、粉紅／薰衣草紫／鵝黃、圓角、柔和陰影 */
:root {
  color-scheme: light;
  --page: #fff8f2;
  --surface-1: #ffffff;
  --surface-2: #fff4f7;
  --text-primary: #3b3150;
  --text-secondary: #75698a;
  --text-muted: #a69cb6;
  --border: #f4e6ee;
  --shadow: 0 6px 22px rgba(232, 128, 168, 0.13);
  --pink: #ff6f9c;
  --pink-soft: #ffe3ec;
  --lavender: #a78bfa;
  --lavender-soft: #efe9ff;
  --mint: #3fbf98;
  --mint-soft: #ddf6ee;
  --sunny: #ffd36b;
  --sunny-soft: #fff4d1;
  /* 圖表（dataviz 參考色盤的淺色模式） */
  --grid: #f1e9ee;
  --axis: #e4d8e1;
  --series-1: #2a78d6;
  --before-fill: rgba(166, 156, 182, 0.16);
  --after-fill: rgba(255, 111, 156, 0.14);
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  /* 舞台 */
  --body-left: #5b9dff;
  --body-right: #ff7f9f;
  --body-center: #a78bfa;
  --head: #ffffff;
  --floor: #c9b8f5;
  --trail: #ff9ebc;
  /* 卡牌稀有度邊框 */
  --rarity-common: #eadff0;
  --rarity-advanced: #a78bfa;
  --rarity-rare: #f5b83d;
  --radius: 22px;
  --toast-offset: 24px;
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; color: var(--text-primary); }
body {
  min-height: 100dvh;
  background:
    radial-gradient(60% 40% at 0% 0%, #ffe6ef 0%, transparent 70%),
    radial-gradient(50% 35% at 100% 15%, #e9e4ff 0%, transparent 70%),
    var(--page);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; transition: transform 0.15s ease, background 0.15s ease; }
button:active:not(:disabled) { transform: scale(0.95); }
button:disabled { opacity: 0.4; cursor: default; }
h2 { font-size: 16px; margin: 0; font-weight: 700; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.error { color: var(--critical); font-size: 14px; }

/* ── 頂欄 ─────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(255, 248, 242, 0.85); backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.brand-mark { font-size: 10px; letter-spacing: 0.12em; font-weight: 800; color: var(--pink); background: var(--pink-soft); padding: 3px 8px; border-radius: 999px; }
.brand-name { font-size: 18px; font-weight: 800; }
.score { display: flex; align-items: center; gap: 4px; padding: 5px 12px 5px 10px; border-radius: 999px; background: var(--sunny-soft); }
.score-label { font-size: 15px; }
.score strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.score.bump, .bump { animation: bump 0.7s ease; }
@keyframes bump { 35% { transform: scale(1.25) rotate(-4deg); } 70% { transform: scale(0.95) rotate(2deg); } }

/* ── 按鈕 ─────────────────────────────── */
.ghost { background: var(--surface-1); border: 0; border-radius: 999px; padding: 8px 14px; box-shadow: var(--shadow); font-weight: 600; font-size: 14px; }
.primary { background: var(--pink); color: #fff; border: 0; border-radius: 999px; padding: 0 20px; font-weight: 800; box-shadow: 0 6px 16px rgba(255, 111, 156, 0.35); }
.wide { width: 100%; height: 48px; margin-top: 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-1); box-shadow: var(--shadow); flex: none; font-size: 14px; color: var(--text-secondary); }
.menu-btn { font-size: 18px; color: var(--text-primary); }

/* ── 舞台 ─────────────────────────────── */
.stage-wrap {
  position: relative; border-radius: 28px; overflow: hidden;
  background: linear-gradient(180deg, #ffeef4 0%, #f3efff 58%, #fdf6ff 100%);
  box-shadow: var(--shadow);
}
.seg-toggle { display: flex; background: rgba(255, 255, 255, 0.8); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.seg-toggle button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font-size: 13px; color: var(--text-secondary); }
.seg-toggle button[aria-checked="true"] { background: var(--lavender); color: #fff; font-weight: 700; }
.busy {
  position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%);
  display: flex; gap: 12px; align-items: center; white-space: nowrap;
  padding: 10px 18px; border-radius: 999px; background: rgba(255, 255, 255, 0.92); box-shadow: var(--shadow); font-size: 14px; font-weight: 600;
}
.dots { display: flex; gap: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--pink); animation: hop 1s ease-in-out infinite; }
.dots i:nth-child(2) { background: var(--lavender); animation-delay: 0.15s; }
.dots i:nth-child(3) { background: var(--sunny); animation-delay: 0.3s; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-7px); } }

/* ── 卡片容器 ─────────────────────────── */
.card { background: var(--surface-1); border-radius: var(--radius); padding: 16px; margin-top: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }

/* ── 指標圖表 ─────────────────────────── */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chart { background: var(--surface-1); border-radius: 16px; padding: 10px 10px 6px; border: 2px solid var(--grid); min-width: 0; }
.chart.targeted { border-color: var(--pink); background: #fffafc; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.chart-title { background: none; border: 0; padding: 0; font-size: 13px; font-weight: 700; text-align: left; display: flex; align-items: center; gap: 4px; }
.chart-title .tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--lavender-soft); color: var(--lavender); }
.chart-value { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart canvas { display: block; width: 100%; height: 68px; touch-action: pan-y; }
.chart-foot { font-size: 11px; color: var(--text-secondary); min-height: 14px; }
@media (min-width: 640px) {
  .charts { grid-template-columns: 1fr 1fr 1fr; }
}

/* ── 子母畫面小舞台 ───────────────────── */
.pip {
  position: fixed; z-index: 4; right: 12px; top: calc(env(safe-area-inset-top) + 64px);
  width: 112px; height: 150px; padding: 0; border: 3px solid #fff; border-radius: 22px; overflow: hidden;
  background: linear-gradient(180deg, #ffeef4 0%, #f3efff 100%);
  box-shadow: 0 10px 28px rgba(167, 139, 250, 0.35);
  animation: pop-in 0.25s ease; touch-action: none;
}
.pip canvas { display: block; width: 100%; height: 100%; }
.pip-label {
  position: absolute; left: 6px; right: 6px; bottom: 6px; padding: 2px 6px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.85); font-size: 10px; font-weight: 700; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@keyframes pop-in { from { transform: scale(0.6); opacity: 0; } }
@media (min-width: 900px) { .pip { width: 150px; height: 200px; right: max(12px, calc(50vw - 520px)); } }

/* ── 提示與對話框 ─────────────────────── */
.toast { position: fixed; left: 50%; bottom: calc(var(--toast-offset) + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: var(--text-primary); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

dialog { border: 0; border-radius: 28px; background: var(--surface-1); color: var(--text-primary); padding: 24px; width: min(400px, calc(100% - 32px)); box-shadow: 0 20px 50px rgba(120, 80, 140, 0.25); }
dialog::backdrop { background: rgba(59, 49, 80, 0.35); backdrop-filter: blur(3px); }
dialog h2 { font-size: 22px; margin-bottom: 10px; }
dialog ol { padding-left: 20px; line-height: 1.7; font-size: 14px; color: var(--text-secondary); }
dialog ol li::marker { color: var(--pink); font-weight: 800; }
.intro-hero { font-size: 44px; text-align: center; margin-bottom: 4px; }

/* ── 選單與聲明 ───────────────────────── */
dialog.menu {
  margin: calc(env(safe-area-inset-top) + 58px) 12px auto auto;
  width: 200px; padding: 8px; border-radius: 22px;
  animation: pop-in 0.18s ease; transform-origin: top right;
}
dialog.menu::backdrop { background: rgba(59, 49, 80, 0.12); backdrop-filter: none; }
dialog.menu button, dialog.menu a {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: transparent; padding: 12px 14px; border-radius: 14px;
  font-size: 15px; font-weight: 600; text-align: left; color: inherit; text-decoration: none;
}
dialog.menu button:hover, dialog.menu button:focus-visible, dialog.menu a:hover, dialog.menu a:focus-visible { background: var(--surface-2); outline: none; }
dialog.credits { max-height: min(80dvh, 640px); overflow-y: auto; }
dialog.credits h3 { font-size: 14px; margin: 16px 0 6px; color: var(--pink); }
dialog.credits ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.7; color: var(--text-secondary); }
dialog.credits li { margin-bottom: 6px; }
dialog.credits b { color: var(--text-primary); }
dialog.credits a { color: var(--lavender); font-weight: 600; }
