/* ============================================================
   億萬寶藏島 — 變數、重置、版面、背景、工具列、頁尾、畫面切換
   ============================================================ */
:root {
  --navy: #0b2540;
  --navy-2: #12385c;
  --sea: #0e7490;
  --gold: #ffc93c;
  --gold-2: #ffb300;
  --coral: #ff6b57;
  --mint: #34d399;
  --sky: #38bdf8;
  --violet: #a78bfa;
  --parchment: #fff6dc;
  --parchment-2: #f4e3b5;
  --ink: #2b2118;
  --ink-2: #5b4a33;
  --text: #f4f8ff;
  --muted: #bcd0e6;
  --panel: rgba(8, 30, 56, 0.78);
  --panel-line: rgba(255, 255, 255, 0.16);
  --accent: var(--sky);
  --radius: 18px;
  --appbar-h: 52px;
  --footer-h: 40px;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: #0b2540; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background-color: #0b2540;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
img { max-width: 100%; height: auto; }
button { font-family: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- 背景 ---------- */
.bg { position: fixed; inset: 0; z-index: 0; background: linear-gradient(180deg, #123a5e 0%, #0b2540 60%, #07182b 100%); }
.bg__img {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  background-image: var(--bg-image, none);
  transition: opacity .4s ease;
}
.bg__shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(5, 20, 40, .45) 0%, rgba(5, 20, 40, .68) 100%); }
body[data-region="0"] { --bg-image: url("../images/hero.webp"); }
body[data-region="1"] { --bg-image: url("../images/bg-bay.webp"); --accent: #38bdf8; }
body[data-region="2"] { --bg-image: url("../images/bg-reef.webp"); --accent: #2dd4bf; }
body[data-region="3"] { --bg-image: url("../images/bg-jungle.webp"); --accent: #4ade80; }
body[data-region="4"] { --bg-image: url("../images/bg-volcano.webp"); --accent: #fb923c; }
body[data-region="5"] { --bg-image: url("../images/bg-temple.webp"); --accent: #fbbf24; }
body[data-screen="map"] { --bg-image: url("../images/map.webp"); }
body[data-screen="collection"] { --bg-image: url("../images/map.webp"); }
body[data-screen="map"] .bg__shade, body[data-screen="collection"] .bg__shade { background: linear-gradient(180deg, rgba(5, 20, 40, .72), rgba(5, 20, 40, .82)); }
body[data-screen="play"] .bg__shade { background: linear-gradient(180deg, rgba(5, 20, 40, .62), rgba(5, 20, 40, .8)); }

/* ---------- 常駐工具列 ---------- */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 70;
  height: calc(var(--appbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(12px, env(safe-area-inset-right, 0px)) 0 max(14px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: linear-gradient(180deg, rgba(5, 20, 40, .88), rgba(5, 20, 40, .55));
  backdrop-filter: blur(6px);
}
.appbar__brand { font-weight: 800; letter-spacing: .04em; color: var(--gold); font-size: 1rem; white-space: nowrap; }
.appbar__tools { display: flex; gap: 8px; }

/* ---------- 頁尾 ---------- */
.site-footer {
  /* z-index 85：高於分步引導（75）與計算紙遮罩（80），遮罩開啟時頁尾仍清楚可見 */
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 85;
  min-height: var(--footer-h);
  padding: 8px max(14px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: .78rem; line-height: 1.4; color: #e3eefb;
  background: rgba(5, 20, 40, .92);
  border-top: 1px solid var(--panel-line);
}
.site-footer { text-wrap: balance; }
.site-footer a { color: var(--gold); font-weight: 700; }

/* ---------- 畫面 ---------- */
.game {
  position: relative; z-index: 1;
  padding-top: calc(var(--appbar-h) + env(safe-area-inset-top, 0px) + 8px);
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px) + 20px);
  max-width: 1120px; margin: 0 auto;
}
.screen { display: none; }
.screen.is-active { display: block; animation: screen-in .35s ease backwards; }

/* ---------- 首頁 ---------- */
.home { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: 8px 0 12px; }
.home__kicker { color: var(--gold); font-weight: 700; letter-spacing: .08em; font-size: .95rem; text-shadow: 0 2px 8px rgba(0, 0, 0, .6); }
.home__title { display: flex; flex-direction: column; line-height: 1.05; font-size: clamp(2.8rem, 11vw, 5.6rem); font-weight: 900; letter-spacing: .06em; }
.home__title span:first-child { color: #fff3c4; -webkit-text-stroke: 2px rgba(60, 30, 0, .55); text-shadow: 0 6px 0 #b45309, 0 12px 24px rgba(0, 0, 0, .55); }
.home__title span:last-child { color: var(--gold); -webkit-text-stroke: 2px rgba(60, 30, 0, .55); text-shadow: 0 6px 0 #b45309, 0 12px 24px rgba(0, 0, 0, .55); }
.home__tagline { max-width: 34em; color: #eaf3ff; text-shadow: 0 2px 8px rgba(0, 0, 0, .7); font-size: 1.05rem; }
.home__cast { position: relative; display: flex; align-items: flex-end; justify-content: center; min-height: 150px; }
.home__captain { width: clamp(150px, 34vw, 260px); filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .5)); animation: bob 3.6s ease-in-out infinite; }
.home__parrot { width: clamp(90px, 20vw, 150px); margin-left: -14px; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .5)); animation: bob 3s ease-in-out infinite .6s; }
.home__cta { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.home__progress { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.progress-chip { background: var(--panel); border: 1px solid var(--panel-line); padding: 6px 14px; border-radius: 999px; font-size: .92rem; }
.progress-chip strong { color: var(--gold); margin: 0 2px; }

/* ---------- 上方標題列 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 0 12px; }
.topbar__title { flex: 1; min-width: 0; }
.topbar__kicker { display: block; color: var(--gold); font-size: .82rem; font-weight: 700; }
.topbar h1 { font-size: 1.5rem; line-height: 1.2; }
.topbar__stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- 地圖 ---------- */
.region-list { display: grid; gap: 18px; }
.region { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 22px; padding: 16px; backdrop-filter: blur(4px); }
.region__head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.region__badge { width: 52px; height: 52px; flex: none; display: grid; place-items: center; font-size: 1.8rem; border-radius: 16px; background: rgba(255, 255, 255, .12); }
.region__heading { flex: 1; min-width: 0; }
.region__title { font-size: 1.2rem; }
.region__tagline { color: var(--muted); font-size: .9rem; }
.region__progress { font-weight: 800; color: var(--gold); }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 12px; }
.map-foot { display: flex; justify-content: center; padding: 18px 0 4px; }

/* ---------- 介紹 ---------- */
.intro { display: grid; place-items: center; padding: 8px 0; }
.intro__card { width: min(100%, 720px); background: var(--panel); border: 1px solid var(--panel-line); border-radius: 26px; padding: 22px; display: flex; flex-direction: column; gap: 12px; backdrop-filter: blur(5px); }
.intro__card h1 { font-size: clamp(1.6rem, 6vw, 2.3rem); line-height: 1.2; }
.intro__concept { color: var(--gold); font-weight: 800; font-size: 1.1rem; }
.intro__story { color: #eaf3ff; }
.intro__boss { text-align: center; }
.intro__boss img { width: min(60vw, 220px); animation: bob 2.8s ease-in-out infinite; }
.intro__meta { display: flex; flex-wrap: wrap; gap: 8px; }
.intro__chip { background: rgba(255, 255, 255, .12); border-radius: 12px; padding: 6px 12px; font-size: .9rem; }
.intro__actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; margin-top: 6px; }

/* ---------- 結算 ---------- */
.result { display: grid; place-items: center; padding: 8px 0; }
.result__card { width: min(100%, 720px); background: var(--panel); border: 1px solid var(--panel-line); border-radius: 26px; padding: 22px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; backdrop-filter: blur(5px); }
.result__kicker { color: var(--gold); font-weight: 800; letter-spacing: .06em; }
.result__card h1 { font-size: clamp(1.5rem, 6vw, 2.2rem); line-height: 1.2; }
.result__subtitle { color: #eaf3ff; }
.result__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 4px; }

/* ---------- 圖鑑 ---------- */
.collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 14px; }

/* ---------- 小螢幕 ---------- */
@media (max-width: 640px) {
  :root { --footer-h: 52px; }
  .site-footer { font-size: .72rem; }
  .appbar__brand { font-size: .9rem; }
  .topbar h1 { font-size: 1.3rem; }
  .region { padding: 12px; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .intro__actions .btn { flex: 1 1 auto; }
}
@media (min-width: 641px) and (max-width: 900px) { :root { --footer-h: 44px; } }
