/* ===== 合成動物園 — 視覺系統 =====
 * 方向：繪本玩具箱。奶油紙底＋深梅紫墨色，按鈕像有厚度的積木（底部陰影），
 * 四個世界各有主色（動物園橘、海洋藍、甜點粉、太空紫），形狀以圓潤為主，呼應圓滾滾的角色。
 */
:root {
  --paper: #FFF6E6;
  --paper-2: #FFFDF7;
  --ink: #3B2E4A;
  --ink-2: #6B5C7B;
  --line: #E8D9C0;
  --coral: #FF7A59;
  --coral-d: #D2543A;
  --mint: #4FC6A0;
  --mint-d: #2E9B79;
  --sun: #FFC93C;
  --sun-d: #D69A12;
  --sky: #5FB8F0;
  --grape: #9B7BFF;
  --pink: #FF8DB8;
  --danger: #E8485C;
  --w-zoo: #F4A23C;
  --w-ocean: #3EA3D6;
  --w-sweets: #FF7FAE;
  --w-space: #8F7BFF;
  --radius: 18px;
  --tap: 48px;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --topbar: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink); background: var(--paper);
  -webkit-tap-highlight-color: transparent; overflow: hidden; overscroll-behavior: none;
  background-image: radial-gradient(circle at 12px 12px, rgba(232, 217, 192, 0.55) 2px, transparent 2.5px);
  background-size: 28px 28px;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, a { font: inherit; color: inherit; }
img { -webkit-user-drag: none; user-select: none; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }

#app { position: fixed; inset: 0; display: grid; grid-template-rows: calc(var(--topbar) + var(--safe-t)) 1fr; }

/* ---------- 頂列 ---------- */
.topbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: var(--safe-t) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
  background: rgba(255, 246, 230, 0.92); border-bottom: 2px solid var(--line); z-index: 20;
}
.top-left, .top-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.top-right { justify-content: flex-end; }
.top-title { font-weight: 800; font-size: clamp(15px, 2.2vw, 19px); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 14px 0 8px; border-radius: 999px;
  background: var(--paper-2); border: 2px solid var(--ink); box-shadow: 0 3px 0 var(--ink); text-decoration: none; font-weight: 800; white-space: nowrap;
}
.pill-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- 按鈕（積木感） ---------- */
.btn {
  appearance: none; -webkit-appearance: none; border: 2.5px solid var(--ink); border-radius: 16px; background: var(--paper-2); color: var(--ink);
  min-height: var(--tap); min-width: var(--tap); padding: 8px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 800; font-size: 16px; line-height: 1.2; cursor: pointer; box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s, filter .15s;
  touch-action: manipulation; user-select: none; text-align: center;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; transform: none; box-shadow: 0 4px 0 var(--ink); }
.btn .ico { display: inline-grid; place-items: center; width: 24px; height: 24px; flex: 0 0 auto; }
.btn .ico svg { width: 24px; height: 24px; }
.btn-label { min-width: 0; }
.btn-primary { background: var(--coral); color: #fff; }
.btn-primary .ico { color: #fff; }
.btn-icon { padding: 0; width: 44px; min-width: 44px; min-height: 44px; height: 44px; border-radius: 14px; box-shadow: 0 3px 0 var(--ink); }
.btn-ghost { background: transparent; box-shadow: none; border-style: dashed; }
.btn-mini { min-height: 40px; padding: 4px 12px; font-size: 14px; border-radius: 12px; box-shadow: 0 3px 0 var(--ink); }
.btn-round { border-radius: 50%; width: 64px; height: 64px; padding: 0; }
.btn-round .ico, .btn-round .ico svg { width: 30px; height: 30px; }
.btn-chip { min-height: 46px; padding: 6px 14px; border-radius: 999px; font-size: 15px; box-shadow: 0 3px 0 var(--ink); }
.btn-big { flex-direction: column; gap: 2px; border-radius: 22px; padding: 14px 16px; min-height: 92px; font-size: clamp(20px, 3vw, 26px); }
.btn-big .btn-sub, .btn .btn-sub { font-size: 13px; font-weight: 700; opacity: .85; }
.btn-big.continue { flex-direction: row; flex-wrap: wrap; min-height: 64px; background: var(--sun); font-size: 18px; width: 100%; }
.btn-big.continue .btn-sub { flex-basis: 100%; }
.mode-classic { background: var(--w-zoo); color: #fff; }
.mode-levels { background: var(--mint); color: #fff; }
.mode-daily { background: var(--w-space); color: #fff; }

/* ---------- 畫面容器與自繪捲軸 ---------- */
.screen { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.sa { position: relative; min-height: 0; }
.sa-view { height: 100%; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; -ms-overflow-style: none; overscroll-behavior: contain; outline: none; }
.sa-view::-webkit-scrollbar { display: none; width: 0; height: 0; }
.sa-view:focus-visible { box-shadow: inset 0 0 0 3px var(--sky); }
.sa-bar { position: absolute; top: 6px; right: 3px; bottom: 6px; width: 10px; border-radius: 10px; background: rgba(59, 46, 74, 0.08); }
.sa-bar.hidden { display: none; }
.sa-thumb { position: absolute; left: 1px; right: 1px; top: 0; border-radius: 10px; background: var(--ink-2); opacity: .55; cursor: grab; touch-action: none; }
.sa-thumb:hover, .sa-thumb:active { opacity: .85; }
.screen-scroll { height: 100%; }
.screen-scroll > .sa-view > * { padding-left: calc(16px + var(--safe-l)); padding-right: calc(18px + var(--safe-r)); padding-bottom: calc(24px + var(--safe-b)); }

/* ---------- 首頁 ---------- */
.home { max-width: 760px; margin: 0 auto; padding-top: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: calc(100dvh - var(--topbar) - var(--safe-t) - 8px); }
@media (min-height: 900px) { .hero-pile { width: min(440px, 80vw); height: min(250px, 46vw); } .home-big .btn-big { min-height: 120px; } }
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; width: 100%; }
.hero-pile { position: relative; width: min(340px, 80vw); height: min(190px, 44vw); }
.hp { position: absolute; bottom: 0; filter: drop-shadow(0 4px 0 rgba(59, 46, 74, 0.18)); }
.hp-10 { width: 46%; left: 27%; bottom: -6%; }
.hp-8 { width: 34%; left: 0; }
.hp-6 { width: 30%; right: 0; }
.hp-4 { width: 22%; left: 8%; bottom: 52%; animation: bob 3s ease-in-out infinite; }
.hp-3 { width: 20%; right: 8%; bottom: 46%; animation: bob 3.4s .4s ease-in-out infinite; }
.hp-1 { width: 14%; left: 43%; bottom: 72%; animation: bob 2.6s .2s ease-in-out infinite; }
.hp-1b { width: 12%; left: 34%; bottom: 86%; animation: bob 2.9s .8s ease-in-out infinite; opacity: .9; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.logo { margin: 6px 0 0; font-size: clamp(36px, 8vw, 60px); font-weight: 900; letter-spacing: .04em; line-height: 1.1; }
.logo-a { color: var(--coral); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }
.tagline { margin: 10px 0 0; font-weight: 800; color: var(--ink-2); font-size: clamp(15px, 2.4vw, 18px); }
.home-main { width: 100%; display: flex; flex-direction: column; gap: 14px; }
.home-big { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.home-small { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
@media (max-width: 520px) {
  .home-big { grid-template-columns: 1fr; }
  .btn-big { min-height: 72px; flex-direction: row; flex-wrap: wrap; gap: 2px 10px; }
  .btn-big .btn-sub { flex-basis: 100%; }
}

/* ---------- 設定畫面（世界與難度） ---------- */
.setup { max-width: 860px; margin: 0 auto; padding-top: 6px; }
.sec-title { font-size: 18px; margin: 18px 0 10px; font-weight: 900; }
.choice-grid { display: grid; gap: 12px; }
.worlds { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.diffs { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 760px) { .worlds { grid-template-columns: repeat(2, minmax(0, 1fr)); } .diffs { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 420px) { .diffs { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.choice {
  appearance: none; border: 2.5px solid var(--ink); border-radius: 18px; background: var(--paper-2); box-shadow: 0 4px 0 var(--ink);
  padding: 10px; min-height: 64px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; text-align: center; font: inherit; color: inherit;
}
.choice b { font-size: 17px; }
.choice small { font-size: 13px; color: var(--ink-2); font-weight: 700; line-height: 1.3; }
.choice small.best { color: var(--coral-d); }
.choice[aria-checked="true"] { background: #FFF0C2; border-color: var(--coral-d); box-shadow: 0 4px 0 var(--coral-d), inset 0 0 0 3px var(--sun); }
.choice:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.choice-pics { display: flex; align-items: flex-end; justify-content: center; height: 64px; }
.choice-pics img { width: 34px; margin: 0 -4px; } .choice-pics img:nth-child(2) { width: 46px; } .choice-pics img:nth-child(3) { width: 62px; }
.world-choice.w-zoo { background-color: #FFEBC9; } .world-choice.w-ocean { background-color: #D8F1FC; }
.world-choice.w-sweets { background-color: #FFE3EE; } .world-choice.w-space { background-color: #E6E1FF; }
.world-choice.w-polar { background-color: #E8F5FD; } .world-choice.w-jungle { background-color: #E2F4D6; } .world-choice.w-dino { background-color: #FBE6CC; } .world-choice.w-farm { background-color: #FBF0D2; }
.setup-go { display: flex; justify-content: center; margin: 22px 0 8px; }
.big-go { min-width: 220px; min-height: 60px; font-size: 22px; border-radius: 20px; }
.daily-card { display: flex; align-items: center; gap: 16px; margin-top: 14px; padding: 14px 16px; border: 2.5px solid var(--ink); border-radius: 20px; background: #EEE9FF; box-shadow: 0 4px 0 var(--ink); }
.daily-card p { margin: 3px 0; font-size: 16px; }
.daily-card .lbl { color: var(--ink-2); font-weight: 700; }
.daily-pic { width: 88px; flex: 0 0 auto; }
.daily-date { font-weight: 900; font-size: 18px !important; }
.streak { color: var(--coral-d); font-weight: 800; }

/* ---------- 闖關選關 ---------- */
.levels-screen { width: 100%; min-width: 0; height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
.tabs { width: 100%; min-width: 0; display: flex; gap: clamp(6px, 1vw, 10px); padding: 10px calc(14px + var(--safe-r)) 6px calc(14px + var(--safe-l)); overflow-x: auto; overscroll-behavior-inline: contain; scroll-snap-type: x proximity; scroll-padding-inline: 14px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 4px 14px; border: 2.5px solid var(--ink); border-radius: 16px; background: var(--paper-2); box-shadow: 0 3px 0 var(--ink); font-weight: 800; white-space: nowrap; cursor: pointer; scroll-snap-align: center; }
.tab img { width: 34px; }
.tab.w-zoo { --tab-tint: #FFEBC9; } .tab.w-ocean { --tab-tint: #D8F1FC; }
.tab.w-sweets { --tab-tint: #FFE3EE; } .tab.w-space { --tab-tint: #E6E1FF; }
.tab.w-polar { --tab-tint: #E8F5FD; } .tab.w-jungle { --tab-tint: #E2F4D6; }
.tab.w-dino { --tab-tint: #FBE6CC; } .tab.w-farm { --tab-tint: #FBF0D2; }
.tab[aria-selected="true"] { background: var(--tab-tint, var(--sun)); box-shadow: 0 4px 0 var(--ink), inset 0 0 0 2px rgba(255, 255, 255, .7); transform: translateY(-1px); }
.tab.locked { opacity: .55; }
.tab .ico { width: 18px; height: 18px; } .tab .ico svg { width: 18px; height: 18px; }
.level-summary { width: max-content; max-width: calc(100% - 24px); min-width: 0; margin: 6px auto 4px; padding: 5px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: rgba(255, 253, 247, .88); box-shadow: 0 2px 0 rgba(59, 46, 74, .08); text-align: center; font-size: 14px; line-height: 1.3; font-weight: 800; color: var(--ink-2); }
.levels-scroll { min-width: 0; min-height: 0; }
.level-grid { width: 100%; min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: clamp(8px, 1.2vw, 12px); max-width: 980px; margin: 6px auto 0; }
.lv { position: relative; min-width: 0; aspect-ratio: 1; min-height: 64px; border: 2.5px solid var(--ink); border-radius: clamp(14px, 2vw, 20px); background: linear-gradient(145deg, #FFFDF7, #FFF8E9); box-shadow: 0 4px 0 var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, background-color .15s ease; }
.lv b { font-size: 22px; font-weight: 900; }
.lv.done { background: linear-gradient(145deg, #EEFFF6, #D8F5E8); }
.lv.boss { background: linear-gradient(145deg, #FFF2E8, #FFE1CD); }
.lv.boss.done { background: linear-gradient(145deg, #FFF5D4, #FFE3A8); }
.lv.locked { background: linear-gradient(145deg, #F5EEE4, #E9DFD1); color: #A69A8C; box-shadow: 0 3px 0 #A69A8C; border-color: #A69A8C; }
.lv:not(.locked):hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.lv:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.lv-stars { display: flex; gap: 0; }
.lv-stars .ico, .lv-stars svg { width: 16px; height: 16px; }
.lv-crown { position: absolute; top: -12px; color: var(--sun-d); }
.lv-crown svg { width: 22px; height: 22px; }
.ico.on { color: var(--sun); filter: drop-shadow(0 1px 0 var(--sun-d)); }
.ico.off { color: #D8CBB8; }
@media (min-width: 1120px) {
  .tabs { justify-content: center; }
  .level-summary { font-size: 15px; }
}
@media (max-width: 520px) {
  .tabs { gap: 7px; padding-top: 8px; padding-bottom: 6px; }
  .tab { min-height: 48px; gap: 5px; padding: 4px 10px; border-radius: 14px; font-size: 14px; }
  .tab img { width: 28px; }
  .tab .ico, .tab .ico svg { width: 16px; height: 16px; }
  .level-summary { margin-top: 2px; margin-bottom: 6px; padding: 5px 12px; font-size: 13px; }
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; margin-top: 2px; }
  .lv { min-height: 0; border-radius: 15px; box-shadow: 0 3px 0 var(--ink); }
  .lv b { font-size: clamp(18px, 5vw, 21px); }
  .lv-stars .ico, .lv-stars svg { width: 14px; height: 14px; }
  .lv-crown { top: -10px; }
}
@media (max-width: 360px) {
  .tabs { gap: 6px; }
  .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
}
.level-info { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.goal-line { display: flex; align-items: center; gap: 8px; font-size: 19px; margin: 0; }
.lim-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lim-list li { padding: 6px 12px; border-radius: 999px; background: #F3EADB; font-weight: 700; font-size: 14px; }
.lv-items { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lv-item { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 14px; }
.lv-item img { width: 28px; }

/* ---------- 圖鑑、成就、排行 ---------- */
.codex, .achv-screen, .rank-screen { max-width: 900px; min-width: 0; margin: 0 auto; }
.codex-progress { text-align: center; font-weight: 800; color: var(--ink-2); margin: 12px 0 0; }
.codex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.codex-card { position: relative; border: 2.5px solid var(--ink); border-radius: 18px; background: var(--paper-2); box-shadow: 0 4px 0 var(--ink); padding: 8px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; min-height: 120px; }
.codex-card img { width: 78%; max-width: 92px; }
.codex-card.locked img { filter: brightness(0) opacity(.18); }
.codex-name { font-size: 13px; font-weight: 800; line-height: 1.2; min-height: 2.4em; display: flex; align-items: center; text-align: center; }
.codex-lv { position: absolute; top: 4px; left: 8px; font-size: 12px; font-weight: 800; color: var(--ink-2); }
.codex-world.w-zoo .codex-card:not(.locked) { background: #FFF3DF; } .codex-world.w-ocean .codex-card:not(.locked) { background: #E3F5FD; }
.codex-world.w-sweets .codex-card:not(.locked) { background: #FFEDF4; } .codex-world.w-space .codex-card:not(.locked) { background: #EEEBFF; }
.codex-world.w-polar .codex-card:not(.locked) { background: #EEF8FE; } .codex-world.w-jungle .codex-card:not(.locked) { background: #EAF7E0; } .codex-world.w-dino .codex-card:not(.locked) { background: #FDEEDB; } .codex-world.w-farm .codex-card:not(.locked) { background: #FCF4DE; }
.codex-detail { text-align: center; }
.codex-detail img { width: min(220px, 60vw); }
.codex-meta { font-weight: 800; color: var(--ink-2); }
.achv-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.achv { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 16px; background: var(--paper-2); }
.achv.done { border-color: var(--ink); background: #FFF3C9; box-shadow: 0 3px 0 var(--ink); }
.achv-ico { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: #EFE7DA; color: #A69A8C; flex: 0 0 auto; }
.achv.done .achv-ico { background: var(--sun); color: var(--ink); }
.achv-txt { display: flex; flex-direction: column; min-width: 0; }
.achv-txt small { color: var(--ink-2); font-weight: 700; }
.rank-screen { padding-top: 6px; }
.rank-filters { display: grid; gap: 10px; margin-top: 8px; padding: 14px; border: 2px solid var(--line); border-radius: 20px; background: rgba(255, 253, 247, .94); box-shadow: 0 4px 0 rgba(59, 46, 74, .08); }
.rank-filter-group { display: grid; grid-template-columns: 58px minmax(0, 1fr); align-items: center; gap: 10px; min-width: 0; }
.rank-filter-label { color: var(--ink-2); font-size: 13px; font-weight: 900; white-space: nowrap; }
.chip-row { display: flex; flex-wrap: wrap; gap: 7px; min-width: 0; }
.chip { min-height: 42px; padding: 6px 13px; border: 1.5px solid var(--line); border-radius: 999px; background: #FFF9EE; font-weight: 800; cursor: pointer; transition: background-color .15s, border-color .15s, transform .12s, box-shadow .12s; }
@media (hover: hover) { .chip:hover { border-color: var(--ink-2); transform: translateY(-1px); } }
.chip[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); box-shadow: 0 2px 0 rgba(59, 46, 74, .2); }
.rank-filter-mode .chip-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 15px; background: #F2EBDD; }
.rank-filter-mode .chip { min-height: 38px; border: 0; background: transparent; box-shadow: none; }
.rank-filter-mode .chip:hover { transform: none; }
.rank-filter-mode .chip[aria-checked="true"] { background: var(--paper-2); color: var(--ink); box-shadow: 0 2px 6px rgba(59, 46, 74, .14); }
.rank-list { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 10px; }
.rank-row { display: grid; grid-template-columns: 42px 50px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 72px; padding: 9px 12px; border: 2px solid var(--line); border-radius: 18px; background: linear-gradient(135deg, #FFFDF8, #FFF9EE); box-shadow: 0 3px 0 rgba(59, 46, 74, .08); }
.rank-row.top1 { background: linear-gradient(120deg, #FFF7D9, #FFE8A8); border-color: var(--sun-d); }
.rank-row.top2 { background: linear-gradient(120deg, #FBFCFF, #E9EDF5); border-color: #B9C2D1; }
.rank-row.top3 { background: linear-gradient(120deg, #FFF7EF, #F5E2D2); border-color: #C89570; }
.rank-no { display: grid; place-items: center; width: 36px; height: 36px; margin: 0 auto; border-radius: 50%; background: #F1E9DB; font-weight: 900; font-size: 18px; font-variant-numeric: tabular-nums; }
.rank-row.top1 .rank-no { background: linear-gradient(145deg, #FFE27A, #FFBF24); color: #624600; }
.rank-row.top2 .rank-no { background: linear-gradient(145deg, #E7ECF5, #BFC9D9); color: #3E4A5A; }
.rank-row.top3 .rank-no { background: linear-gradient(145deg, #F4D0AE, #D99D6F); color: #603719; }
.rank-pic { width: 48px; height: 48px; padding: 3px; border: 2px solid rgba(59, 46, 74, .1); border-radius: 50%; background: rgba(255, 255, 255, .74); object-fit: contain; }
.rank-score { min-width: 0; font-size: clamp(17px, 2.4vw, 21px); font-weight: 900; font-variant-numeric: tabular-nums; }
.rank-date { color: var(--ink-2); font-size: 12px; font-weight: 700; white-space: nowrap; }
.empty-note { margin: 18px 0 0; padding: 24px 16px; border: 2px dashed var(--line); border-radius: 20px; background: rgba(255, 253, 247, .8); text-align: center; color: var(--ink-2); font-weight: 800; }
@media (max-width: 520px) {
  .rank-screen { padding-top: 0; }
  .rank-filters { gap: 9px; padding: 11px; border-radius: 18px; }
  .rank-filter-group { grid-template-columns: 48px minmax(0, 1fr); gap: 8px; }
  .rank-filter-label { font-size: 12px; }
  .chip-row { gap: 6px; }
  .chip { min-height: 40px; padding: 6px 10px; font-size: 13px; }
  .rank-list { gap: 9px; margin-top: 14px; }
  .rank-row { grid-template-columns: 34px 42px minmax(0, 1fr); grid-template-rows: minmax(22px, auto) 18px; gap: 2px 8px; min-height: 64px; padding: 8px 10px; border-radius: 16px; }
  .rank-no { grid-column: 1; grid-row: 1 / span 2; width: 32px; height: 32px; font-size: 16px; }
  .rank-pic { grid-column: 2; grid-row: 1 / span 2; width: 38px; height: 38px; }
  .rank-score { grid-column: 3; grid-row: 1; align-self: end; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
  .rank-date { grid-column: 3; grid-row: 2; align-self: start; font-size: 11px; }
}
@media (max-width: 360px) {
  .rank-filter-group { grid-template-columns: 42px minmax(0, 1fr); gap: 7px; }
  .rank-filters { padding: 9px; }
  .chip { padding-inline: 8px; font-size: 12px; }
  .rank-row { grid-template-columns: 30px 38px minmax(0, 1fr); column-gap: 7px; padding-inline: 8px; }
  .rank-no { width: 28px; height: 28px; }
  .rank-pic { width: 34px; height: 34px; }
  .rank-score { font-size: 16px; }
}
.howto { padding-left: 1.4em; line-height: 1.7; font-weight: 600; margin-top: 0; }
.howto-items { display: grid; gap: 8px; }
.howto-item { display: grid; grid-template-columns: 40px auto 1fr; gap: 8px; align-items: center; }
.howto-item img { width: 40px; }
.howto-item span { color: var(--ink-2); font-weight: 600; }

/* ---------- 遊戲畫面 ---------- */
.play { position: absolute; inset: 0; display: grid;
  --stage-h: calc(100dvh - var(--topbar) - var(--safe-t));
  grid-template-columns: clamp(170px, calc(100vw - var(--stage-h) * 1.02), 330px) minmax(0, 1fr); }
.hud { container-type: inline-size; position: relative; min-height: 0; background: rgba(255, 246, 230, 0.94); border-right: 2px solid var(--line); z-index: 2; display: flex; flex-direction: column; }
.hud-scroll { flex: 1 1 auto; min-height: 0; }
.hud-inner {
  display: flex; flex-direction: column; gap: 10px; min-height: 100%;
  padding: 12px 14px calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
}
.hud-title { display: none; }
.hud-card { border: 2.5px solid var(--ink); border-radius: 16px; background: var(--paper-2); padding: 8px 10px; box-shadow: 0 3px 0 var(--ink); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hud-label { font-size: 12px; font-weight: 800; color: var(--ink-2); letter-spacing: .04em; }
.hud-num { font-size: clamp(22px, 2.6vw, 30px); font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hud-sub { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.hud-goal { font-weight: 800; font-size: 14px; line-height: 1.35; }
.hud-limit { font-weight: 800; font-size: 14px; color: var(--coral-d); font-variant-numeric: tabular-nums; }
.next-pic { display: flex; justify-content: center; }
.next-pic img { width: 64px; height: 64px; }
.next-pic img.gold { filter: drop-shadow(0 0 6px #FFD23C); }
.hud-energy { height: 16px; }
.hud-energy { display: flex; align-items: center; gap: 6px; }
.hud-energy[hidden] { display: none; }
.energy-num { flex: none; min-width: 4.2em; text-align: right; font-size: 11px; font-weight: 800; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.energy-track { flex: 1 1 auto; min-width: 0; display: block; height: 14px; border-radius: 10px; border: 2px solid var(--ink); background: #F1E6D4; overflow: hidden; }
.energy-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--sun), var(--coral)); transition: width .25s; }
.items { display: grid; grid-template-columns: repeat(3, minmax(0, 64px)); gap: 6px; align-items: center; }
.item-slot { min-width: 0; width: 100%; height: 56px; border: 2.5px solid var(--ink); border-radius: 14px; background: #FFF0C2; box-shadow: 0 3px 0 var(--ink); display: grid; place-items: center; padding: 3px; cursor: pointer; }
.item-slot img { display: block; width: 40px; height: 40px; object-fit: contain; }
.item-slot.empty { background: #F1E6D4; border-style: dashed; box-shadow: none; cursor: default; }
.item-slot:not(.empty):active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.end-btn { margin-top: auto; }
.swap-btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 40px; padding: 2px 8px; border: 2px solid var(--ink); border-radius: 12px; background: #E3F3FF; box-shadow: 0 2px 0 var(--ink); font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap; }
.swap-btn:active { transform: translateY(2px); box-shadow: none; }
.swap-btn:disabled { opacity: .45; cursor: default; }
.swap-btn .ico, .swap-btn .ico svg { width: 18px; height: 18px; }
.keycap { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 4px; border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: 6px; background: #fff; font: 800 11px/1 var(--font); }
.poke-hint { font-size: 12px; font-weight: 700; color: var(--ink-2); line-height: 1.35; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.poke-cost { white-space: nowrap; padding: 1px 8px; border-radius: 999px; background: #FFE9A8; border: 1.5px solid #E8B93C; color: #7A5200; font-size: 11px; font-weight: 800; }
.hud-time { font-size: clamp(20px, 2.2vw, 26px); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
.hud-time.warn { color: var(--danger); animation: blink .5s ease-in-out infinite alternate; }
.hud-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 8px; margin: 0; }
.hud-stat { display: flex; flex-direction: column; min-width: 0; }
.hud-stat dt { font-size: 11px; font-weight: 800; color: var(--ink-2); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-stat dd { margin: 0; font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.15; }
.hud-stat.hot dd { color: var(--coral); }
.hud-chain { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; }
.chain-cell { position: relative; display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; }
.chain-cell img { width: 100%; height: 100%; object-fit: contain; filter: grayscale(1) opacity(.3); }
.chain-cell.got img { filter: none; }
.chain-cell.top { background: #FFF0C2; }
.chain-cell.held { box-shadow: inset 0 0 0 2.5px var(--sky); background: #E3F3FF; }
.chain-cell.held img, .chain-cell.result img { filter: none; }
.chain-cell.result { box-shadow: inset 0 0 0 2.5px var(--coral); }
.chain-cell.result img { opacity: .85; }
.chain-hint { font-size: 12px; font-weight: 800; color: var(--ink-2); line-height: 1.35; }
.chain-hint b { color: var(--coral-d); }
.nowrap { white-space: nowrap; }

.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; touch-action: none; outline: none; cursor: crosshair; }
.stage:focus-visible { box-shadow: inset 0 0 0 4px var(--sky); }
.stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-overlay { position: absolute; inset: 0; pointer-events: none; }
.stage-overlay > * { pointer-events: auto; }
.danger-tag { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); padding: 6px 14px; border-radius: 999px; background: var(--danger); color: #fff; font-weight: 900; border: 2px solid #fff; box-shadow: 0 3px 0 rgba(0, 0, 0, .2); animation: blink .5s ease-in-out infinite alternate; pointer-events: none; white-space: nowrap; }
@keyframes blink { from { opacity: 1; } to { opacity: .55; } }
.arm-tag { position: absolute; top: 10px; right: 10px; display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 16px; background: var(--paper-2); border: 2.5px solid var(--ink); font-weight: 800; box-shadow: 0 3px 0 var(--ink); max-width: calc(100% - 20px); }
.rot-btn { position: absolute; bottom: calc(14px + var(--safe-b)); z-index: 2; background: var(--sun); }
.rot-btn.on { background: var(--coral); color: #fff; }
.rot-l { left: 14px; } .rot-r { right: calc(14px + var(--safe-r)); }

/* 倒數遮罩：只蓋遊戲主區 */
.countdown { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(59, 46, 74, 0.32); touch-action: none; }
.count-num { display: grid; place-items: center; width: clamp(110px, 30vmin, 210px); height: clamp(110px, 30vmin, 210px); border-radius: 50%; background: var(--paper-2); border: 4px solid var(--ink); box-shadow: 0 7px 0 var(--ink); font-size: clamp(56px, 16vmin, 120px); font-weight: 900; }
.count-num.go { width: auto; min-width: clamp(160px, 40vmin, 300px); padding: 0 28px; border-radius: 999px; background: var(--coral); color: #fff; font-size: clamp(40px, 11vmin, 84px); }
.countdown.go { background: transparent; pointer-events: none; }
.countdown.bump .count-num { animation: bump .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 0% { transform: scale(.4); } 100% { transform: scale(1); } }
.reduce-motion .countdown.bump .count-num, .reduce-motion .hp, .reduce-motion .tut-finger { animation: none !important; }

/* 教學 */
.tut-card { position: absolute; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); width: min(440px, calc(100% - 24px)); padding: 14px 16px; border-radius: 20px; background: var(--paper-2); border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink); text-align: center; }
.tut-card p { margin: 6px 0 10px; font-size: 18px; font-weight: 800; line-height: 1.4; }
.tut-step { font-weight: 900; color: var(--coral-d); font-size: 13px; }
.tut-actions { display: flex; justify-content: center; gap: 8px; }
.tut-finger { position: absolute; top: 12%; left: 50%; width: 56px; height: 56px; margin-left: -28px; border-radius: 50%; background: rgba(255, 255, 255, .85); border: 3px solid var(--ink); animation: swipe 2.2s ease-in-out infinite; pointer-events: none !important; }
@keyframes swipe { 0%, 100% { transform: translateX(-90px); } 50% { transform: translateX(90px); } }

/* 直向：資訊放上方 */
@media (orientation: portrait), (max-aspect-ratio: 1/1) {
  .play { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .hud { border-right: 0; border-bottom: 2px solid var(--line); }
  .hud-scroll .sa-view { height: auto; max-height: 46vh; }
  .hud-inner { flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: 8px; min-height: 0; padding: 8px calc(14px + var(--safe-r)) 8px calc(10px + var(--safe-l)); }
  .hud-title { display: none; }
  .hud-card { padding: 6px 8px; }
  .hud-scorecard { flex: 1 1 110px; }
  .hud-goalcard { flex: 1 1 100%; order: 5; flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
  .hud-nextcard { flex: 0 0 auto; align-items: center; }
  .next-pic img { width: 46px; height: 46px; }
  .hud-itemcard { flex: 1 1 150px; }
  .item-slot { height: 46px; }
  .items { grid-template-columns: repeat(3, minmax(0, 52px)); }
  .end-btn { margin-top: 0; flex: 0 0 auto; min-height: 44px; align-self: center; }
  .hud-timecard { flex: 0 0 auto; min-width: 76px; }
  .hud-statcard { flex: 1 1 100%; order: 6; padding: 4px 8px; }
  .hud-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hud-stat dd { font-size: 15px; }
  .hud-chaincard { flex: 1 1 100%; order: 7; flex-direction: row; align-items: center; gap: 8px; padding: 4px 8px; }
  .hud-chain { flex: 1; grid-template-columns: repeat(10, minmax(0, 1fr)); max-width: 420px; }
}
/* 手機直向：資訊改成三欄格線，統計與升級順序各占一列 */
@media (orientation: portrait) and (max-height: 900px) {
  .hud-inner { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; }
  .hud-scorecard { grid-column: 1; }
  .hud-timecard { grid-column: 2; min-width: 64px; }
  .hud-nextcard { grid-column: 3; }
  .hud-goalcard { grid-column: 1 / -1; }
  .hud-itemcard { grid-column: 1; }
  .hud-statcard { grid-column: 2 / -1; padding: 4px 8px; }
  .hud-chaincard { grid-column: 1 / -1; padding: 3px 8px; }
  .hud-chaincard .hud-label { display: none; }
  .hud-chain { grid-template-columns: repeat(10, minmax(0, 1fr)); max-width: none; }
  .hud-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 8px; }
  .hud-stat dt { font-size: 10px; }
  .hud-stat dd { font-size: 14px; }
  .hud-time { font-size: 20px; }
  .end-btn { grid-column: 1 / -1; min-height: 40px; }
  .hud-nextcard { align-items: center; }
  .swap-txt, .keycap { display: none; }
  .swap-btn { min-height: 40px; min-width: 40px; padding: 2px 6px; }
  .poke-hint { display: none; }
}
@media (orientation: portrait) and (max-width: 420px) {
  .hud-num { font-size: 22px; }
  .hud-scorecard { flex-basis: 90px; }
}
/* 矮螢幕（手機橫向） */
@media (max-height: 500px) {
  :root { --topbar: 48px; }
  .btn-icon { width: 40px; min-width: 40px; height: 40px; min-height: 40px; }
  .pill-btn { min-height: 40px; }
  .play { grid-template-columns: clamp(176px, calc(100vw - var(--stage-h) * 1.02), 330px) minmax(0, 1fr); }
  .items { gap: 4px; }
  .hud-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-content: start; gap: 5px; }
  .hud-goalcard, .end-btn { grid-column: 1 / -1; }
  .hud-num { font-size: 20px; }
  .hud-time { font-size: 17px; }
  .hud-nextcard { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .swap-txt, .keycap { display: none; }
  .swap-btn { min-height: 40px; min-width: 40px; padding: 2px 6px; }
  .poke-hint { display: none; }
  .next-pic img { width: 34px; height: 34px; }
  .item-slot { height: 42px; }
  .item-slot img { width: 32px; height: 32px; }
  .hud-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 6px; }
  .hud-nextcard .hud-label { white-space: nowrap; }
  .hud-stat dt { font-size: 10px; }
  .hud-stat dd { font-size: 13px; }
  .hud-chaincard .hud-label { display: none; }
  .hud-chain { grid-template-columns: repeat(10, minmax(0, 1fr)); }
  .hud-card { box-shadow: 0 2px 0 var(--ink); border-width: 2px; border-radius: 12px; }
  .hud-inner { gap: 6px; padding-top: 6px; }
  .hud-card { padding: 4px 8px; }
  .hud-title { font-size: 13px; }
  .next-pic img { width: 44px; height: 44px; }
  .btn-round { width: 52px; height: 52px; }
}

/* ---------- 彈窗 ---------- */
.modal-layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-layer > * { pointer-events: auto; }
.modal-scrim { position: fixed; inset: 0; display: grid; place-items: center; padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); background: rgba(43, 34, 51, 0.5); animation: fade .15s; }
.result-scrim { background: rgba(43, 34, 51, 0.32); }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(520px, 100%); max-height: calc(100dvh - 24px - var(--safe-t) - var(--safe-b)); display: flex; flex-direction: column; background: var(--paper); border: 3px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 8px 20px; }
.modal-title { margin: 0; font-size: 21px; font-weight: 900; min-width: 0; overflow-wrap: anywhere; }
.modal-scroll { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.modal-scroll > .sa-view { flex: 1 1 auto; min-height: 0; height: auto; }
.modal-body { padding: 4px 22px 16px 20px; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 12px 16px 16px; border-top: 2px dashed var(--line); }
.modal-actions .btn { flex: 1 1 140px; }
.modal-actions .btn { min-width: fit-content; }
.modal-actions .btn-label { white-space: nowrap; }
@media (max-width: 420px) { .modal-actions .btn { padding: 8px 10px; gap: 6px; font-size: 15px; } }
.pause-actions { display: flex; flex-direction: column; gap: 12px; padding: 6px 0 8px; }
.intro-body p { font-size: 18px; font-weight: 700; line-height: 1.5; text-align: center; }

/* 設定 */
.settings { display: flex; flex-direction: column; gap: 4px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 6px 0; border-bottom: 1.5px solid var(--line); }
.row-label { font-weight: 800; display: flex; flex-direction: column; min-width: 0; }
.row-note { font-weight: 600; color: var(--ink-2); font-size: 13px; }
.switch { appearance: none; border: 0; background: none; padding: 4px; cursor: pointer; flex: 0 0 auto; min-height: 44px; display: grid; place-items: center; }
.switch-track { position: relative; display: block; width: 58px; height: 32px; border-radius: 999px; background: #D9CDBB; border: 2.5px solid var(--ink); transition: background .15s; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 23px; height: 23px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); transition: transform .15s; }
.switch[aria-checked="true"] .switch-track { background: var(--mint); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(25px); }
.setting-slider { flex-wrap: wrap; }
.slider-wrap { display: flex; align-items: center; gap: 10px; flex: 1 1 150px; min-width: 0; max-width: 280px; }
.slider { position: relative; flex: 1; height: 44px; cursor: pointer; touch-action: none; outline: none; }
.slider-track { position: absolute; left: 0; right: 0; top: 50%; height: 12px; margin-top: -6px; border-radius: 10px; background: #E9DDC9; border: 2px solid var(--ink); overflow: hidden; }
.slider-fill { display: block; height: 100%; background: var(--sun); }
.slider-thumb { position: absolute; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; background: #fff; border: 2.5px solid var(--ink); box-shadow: 0 2px 0 var(--ink); }
.slider:focus-visible .slider-thumb { box-shadow: 0 0 0 4px var(--sky); }
.slider-val { width: 44px; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.settings-extra { padding-top: 12px; display: flex; justify-content: center; }

/* 結算 */
.result-modal { width: min(560px, 100%); }
.result-card { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 10px; border-radius: 20px; background: var(--paper-2); border: 2px solid var(--line); }
.result-modal .modal-head { display: none; }
.result-head { text-align: center; }
.result-title { margin: 0; font-size: 30px; font-weight: 900; color: var(--coral); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; }
.result-sub { margin: 4px 0 0; font-weight: 800; color: var(--ink-2); }
.result-stars { display: flex; gap: 6px; }
.result-stars .ico, .result-stars svg { width: 44px; height: 44px; }
.result-stars.small .ico, .result-stars.small svg { width: 32px; height: 32px; }
.result-reason { margin: 0; font-weight: 800; color: var(--coral-d); }
.result-main { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; width: 100%; }
.result-score { display: flex; flex-direction: column; align-items: center; }
.result-score b { font-size: 42px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.lbl { font-size: 13px; font-weight: 800; color: var(--ink-2); }
.result-best { font-weight: 800; color: var(--ink-2); }
.result-best.new { color: #fff; background: var(--coral); padding: 2px 10px; border-radius: 999px; }
.result-big { margin: 0; display: flex; align-items: center; gap: 8px; }
.result-big img { width: 96px; height: 96px; }
.result-big figcaption { display: flex; flex-direction: column; }
.result-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; width: 100%; margin: 0; }
.stat { background: #F6EEDF; border-radius: 12px; padding: 6px 4px; text-align: center; }
.stat dt { font-size: 12px; font-weight: 800; color: var(--ink-2); }
.stat dd { margin: 0; font-weight: 900; font-size: 18px; font-variant-numeric: tabular-nums; }
.result-codex { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; justify-content: center; }
.result-codex img { width: 44px; height: 44px; }
@media (max-width: 420px) { .result-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .result-score b { font-size: 34px; } }
@media (max-height: 560px) {
  .result-card { gap: 6px; padding: 8px; }
  .result-big img { width: 64px; height: 64px; }
  .result-title { font-size: 24px; }
  .modal-actions { padding: 8px 12px 10px; gap: 8px; }
  .modal-actions .btn { min-height: 44px; flex-basis: 120px; }
}
.result-share-dialog-layer { --ink: #3B2E4A; }

/* 下拉選單 */
.menu-scrim { position: fixed; inset: 0; }
.menu { position: fixed; min-width: 160px; padding: 6px; border-radius: 16px; background: var(--paper-2); border: 2.5px solid var(--ink); box-shadow: 0 5px 0 var(--ink); display: flex; flex-direction: column; gap: 4px; }
.menu-item { appearance: none; border: 0; background: none; min-height: 44px; padding: 8px 14px; border-radius: 12px; text-align: left; font-weight: 800; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: #FFF0C2; }
.menu-item.on { background: var(--ink); color: var(--paper); }

/* 提示 */
.toasts { position: fixed; left: 50%; top: calc(var(--safe-t) + var(--topbar) + 6px); transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { padding: 8px 14px; font-size: 15px; border-radius: 16px; background: var(--ink); color: var(--paper); font-weight: 800; box-shadow: 0 4px 0 rgba(0, 0, 0, .2); transition: opacity .4s, transform .4s; text-align: center; }
.toast.achv { background: var(--sun); color: var(--ink); border: 2.5px solid var(--ink); }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* 橫向且資訊欄夠寬：卡片排成兩欄，不用捲動 */
@media (orientation: landscape) and (min-aspect-ratio: 1/1) {
  @container (min-width: 280px) {
    .hud-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-content: start; gap: 10px; }
    .hud-goalcard, .end-btn, .hud-itemcard, .hud-chaincard { grid-column: 1 / -1; }
    .hud-nextcard { justify-content: space-between; }
    .hud-itemcard, .hud-chaincard, .end-btn { order: 2; }
    .hud-stats { gap: 2px 6px; }
    .hud-stat dt { font-size: 10px; letter-spacing: -0.01em; }
    .hud-chain { grid-template-columns: repeat(10, minmax(0, 1fr)); }
    .end-btn { margin-top: 0; }
  }
  @container (min-width: 400px) {
    .hud-num { font-size: clamp(22px, 4.2vh, 34px); }
    .hud-time { font-size: clamp(18px, 3.6vh, 30px); }
    .next-pic img { width: clamp(36px, 9vh, 76px); height: clamp(36px, 9vh, 76px); }
  }
}

/* ===== 手機：遊戲滿版，只留交換與道具，其餘資訊收進側拉面板 ===== */
.dock, .hud-backdrop, .hud-close { display: none; }
.play.phone { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.play.phone .stage { grid-row: 1; grid-column: 1; }
/* 工具列本身就是一張卡片；裡面的「下一隻」「道具」卡片拆開（display: contents）直接排進格線 */
.play.phone .dock { grid-row: 2; grid-column: 1; display: grid; z-index: 3; min-width: 0;
  grid-template-columns: auto auto auto minmax(0, 1fr); grid-template-areas: "info next swap energy" "items items items items";
  align-items: center; gap: 6px 8px;
  padding: 6px calc(10px + var(--safe-r)) calc(6px + var(--safe-b)) calc(10px + var(--safe-l));
  background: rgba(255, 246, 230, 0.97); border-top: 2px solid var(--line); }
.play.phone .dock .hud-card { display: contents; }
.play.phone .dock .hud-label, .play.phone .dock .poke-hint, .play.phone .dock .keycap { display: none; }
.play.phone .dock .info-btn { grid-area: info; }
.play.phone .dock .next-pic { grid-area: next; }
.play.phone .dock .swap-btn { grid-area: swap; }
.play.phone .dock .hud-energy { grid-area: energy; min-width: 0; }
.play.phone .dock .items { grid-area: items; }
.play.phone .dock .next-pic img { width: 40px; height: 40px; }
.play.phone .dock .swap-btn { min-height: 44px; min-width: 44px; padding: 2px 10px; font-size: 14px; border-radius: 13px; }
.play.phone .dock .swap-txt { display: inline; }
.play.phone .dock .items { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.play.phone .dock .item-slot { height: 50px; }
.play.phone .dock .item-slot img { width: 36px; height: 36px; }
.info-btn { flex: 0 0 auto; width: 44px; height: 44px; min-height: 44px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 13px;
  background: var(--paper-2); box-shadow: 0 2px 0 var(--ink); color: var(--ink); cursor: pointer; padding: 0; }
.info-btn:active, .swap-btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
.info-btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
/* 側拉資訊面板 */
.play.phone .hud { position: absolute; top: 0; bottom: 0; left: 0; width: min(380px, 88vw); z-index: 20;
  border-right: 2px solid var(--line); border-bottom: 0; transform: translateX(-104%); transition: transform .22s ease; visibility: hidden;
  box-shadow: 6px 0 24px rgba(59, 46, 74, .25); padding-top: calc(52px + var(--safe-t)); }
.play.phone.hud-open .hud { transform: none; visibility: visible; }
.play.phone .hud-scroll .sa-view { height: 100%; max-height: none; }
.play.phone .hud-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-content: start; gap: 8px; padding: 4px 12px 14px calc(12px + var(--safe-l)); }
.play.phone .hud-inner > * { grid-column: auto; order: 0; }
.play.phone .hud-goalcard, .play.phone .hud-statcard, .play.phone .hud-chaincard, .play.phone .end-btn { grid-column: 1 / -1; }
.play.phone .hud-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.play.phone .hud-chaincard { flex-direction: column; align-items: stretch; }
.play.phone .hud-chaincard .hud-label { display: block; }
.play.phone .hud-chain { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.play.phone .hud-close { display: grid; place-items: center; position: absolute; top: calc(6px + var(--safe-t)); right: 8px; width: 40px; height: 40px;
  border: 2px solid var(--ink); border-radius: 12px; background: var(--paper-2); box-shadow: 0 2px 0 var(--ink); cursor: pointer; padding: 0; color: var(--ink); }
.play.phone.hud-open .hud-backdrop { display: block; position: absolute; inset: 0; z-index: 19; background: rgba(59, 46, 74, .35); }
@media (prefers-reduced-motion: reduce) { .play.phone .hud { transition: none; } }
/* 很窄的手機（≤360）：交換與戳只留圖示 */
@media (orientation: portrait) and (max-width: 360px) {
  .play.phone .dock { gap: 5px 6px; padding-left: calc(6px + var(--safe-l)); padding-right: calc(6px + var(--safe-r)); }
  .play.phone .dock .swap-txt { display: none; }
  .play.phone .dock .next-pic img { width: 34px; height: 34px; }
  .play.phone .dock .item-slot { height: 46px; }
}
/* 手機橫向：工具列改放左側一欄 */
@media (orientation: landscape) {
  .play.phone { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .play.phone .stage { grid-row: 1; grid-column: 2; }
  .play.phone .dock { grid-row: 1; grid-column: 1; width: calc(196px + var(--safe-l)); border-top: 0; border-right: 2px solid var(--line);
    grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "info next swap" "energy energy energy" "items items items";
    align-content: center; gap: 8px; padding: 8px 8px calc(8px + var(--safe-b)) calc(8px + var(--safe-l)); }
  .play.phone .dock .next-pic { justify-self: center; }
  .play.phone .dock .swap-txt { display: none; }
  .play.phone .dock .item-slot { height: 46px; }
}
/* 手機直向但比較寬（500–600）：工具列內容置中、不要拉太開 */
.play.phone .dock { padding-left: max(calc(10px + var(--safe-l)), calc((100% - 400px) / 2)); padding-right: max(calc(10px + var(--safe-r)), calc((100% - 400px) / 2)); }
@media (orientation: landscape) { .play.phone .dock { padding-left: calc(8px + var(--safe-l)); padding-right: 8px; } }
/* 闖關沒有能量條：工具列第一列右邊改顯示這關還能戳幾次 */
.play.phone .dock .hud-energy[hidden] ~ .poke-hint { display: block; grid-area: energy; font-size: 12px; line-height: 1.3; }

.home-support {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 5px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  font-size: .875rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.home-support:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

#app:not([data-screen="home"]) .home-support { display: none; }

.home-support .support-label:not([lang="zh-Hant"]),
:is(html:lang(zh-Hans), html:lang(zh-CN)) .home-support .support-label[lang="zh-Hant"],
html:lang(en) .home-support .support-label[lang="zh-Hant"] { display: none; }
:is(html:lang(zh-Hans), html:lang(zh-CN)) .home-support .support-label[lang="zh-Hans"],
html:lang(en) .home-support .support-label[lang="en"] { display: inline; }

@media (max-width: 480px) {
  .home-support {
    flex-direction: column;
    gap: 2px;
    width: 50px;
    padding-inline: 3px;
    font-size: 11px;
    letter-spacing: 0;
  }
  .home-support > [aria-hidden="true"] { font-size: 1rem; }
}

@media (max-width: 380px) {
  #btn-lobby { padding-inline: 8px; font-size: .8rem; }
}
