/* ============================================================
   《分數與圖形奇幻谷》主樣式：變數、版面、畫面切換、響應式
   ============================================================ */
:root {
  --bg: #fff8ec;
  --bg-2: #fdeedd;
  --ink: #3b2f4a;
  --ink-soft: #5f5075;
  --line: #e4d8f2;
  --card: #ffffff;
  --violet: #6d4aff;
  --violet-dark: #5236d4;
  --violet-soft: #ece6ff;
  --pink: #e63a8a;
  --pink-soft: #fde1ef;
  --teal: #0a9f9f;
  --teal-soft: #d3f6f3;
  --gold: #e08a00;
  --gold-soft: #fff0c2;
  --green: #1f9d63;
  --green-soft: #d9f7e8;
  --red: #d93a5f;
  --red-soft: #fde2e8;
  --accent: var(--violet);
  --accent-soft: var(--violet-soft);
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 6px 18px rgba(82, 54, 212, 0.14);
  --shadow-lg: 0 14px 38px rgba(82, 54, 212, 0.22);
  --footer-h: 46px;
  --sys-w: 168px;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg-img: none;
  color-scheme: light;
}

#game[data-zone="1"] { --accent: #e63a8a; --accent-soft: #fde1ef; }
#game[data-zone="2"] { --accent: #0a9f9f; --accent-soft: #d3f6f3; }
#game[data-zone="3"] { --accent: #6d4aff; --accent-soft: #ece6ff; }
#game[data-zone="4"] { --accent: #e08a00; --accent-soft: #fff0c2; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

img, svg { max-width: 100%; }
button { font-family: inherit; }
a { color: var(--violet-dark); }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }

/* 背景圖：依畫面切換，上面蓋一層奶油色紗網確保文字對比 */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: var(--bg);
  background-image: linear-gradient(rgba(255, 248, 236, 0.72), rgba(255, 248, 236, 0.9)), var(--bg-img);
  background-size: cover;
  background-position: center;
  transition: opacity 0.4s ease;
}
body[data-screen="home"] .backdrop {
  background-image: linear-gradient(rgba(255, 248, 236, 0.15), rgba(255, 248, 236, 0.45)), var(--bg-img);
}
body[data-screen="result"] .backdrop {
  background-image: linear-gradient(rgba(255, 248, 236, 0.3), rgba(255, 248, 236, 0.6)), var(--bg-img);
}

.game {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px calc(var(--footer-h) + env(safe-area-inset-bottom, 0px) + 18px);
}

.screen { display: none; width: 100%; max-width: 1180px; margin: 0 auto; }
.screen.is-active { display: block; animation: screen-in 0.35s ease both; }

/* 系統圖示列：固定右上角 */
.sysbar {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: 10px;
  z-index: 70;
  display: flex;
  gap: 8px;
}

/* 頁尾：固定在底部，所有畫面可見 */
.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* 高於計算紙、彩帶、提示訊息、密技橫幅等所有遮罩，任何畫面都清楚可見 */
  z-index: 140;
  padding: 6px 14px calc(6px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.93);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.site-footer a { font-weight: 700; }
/* 觸控範圍至少 44px 高，但不改變頁尾的版面高度 */
.site-footer a { display: inline-block; padding-block: 14px; margin-block: -14px; }

/* ---------- 頂列 ---------- */
.topbar, .playbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding-right: var(--sys-w);
}
.topbar__title { flex: 1; min-width: 0; }
.topbar__title h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.topbar__kicker { font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.topbar__stats { display: flex; align-items: center; gap: 8px; }

.playbar__info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.playbar__level {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 首頁 ---------- */
.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: 56px 20px 26px;
}
.home__kicker {
  margin: 0;
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--violet-dark);
  font-weight: 800;
  font-size: 14px;
}
.home__title { margin: 0; line-height: 1.05; display: flex; flex-direction: column; align-items: center; }
.home__title-top {
  font-size: clamp(34px, 8vw, 56px);
  font-weight: 900;
  color: var(--violet-dark);
  text-shadow: 0 3px 0 #fff, 0 0 18px rgba(255, 255, 255, 0.95);
  letter-spacing: 2px;
}
.home__title-bottom {
  font-size: clamp(54px, 14vw, 96px);
  font-weight: 900;
  color: var(--pink);
  text-shadow: 0 4px 0 #fff, 0 0 24px rgba(255, 255, 255, 0.95);
  letter-spacing: 6px;
}
.home__tagline {
  margin: 0;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  font-weight: 700;
  font-size: 17px;
  max-width: 440px;
}
.home__mascot img { width: min(46vw, 210px); height: auto; filter: drop-shadow(0 8px 10px rgba(59, 47, 74, 0.25)); }
.home__cta { margin-top: 2px; }
.home__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.home__progress { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.progress-chip {
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--line);
  font-weight: 700;
  font-size: 15px;
}
.progress-chip strong { color: var(--violet-dark); }

/* ---------- 地圖 ---------- */
.zone-list { display: flex; flex-direction: column; gap: 22px; padding: 6px 0 24px; }
.zone {
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 3px solid var(--zone-soft, var(--line));
}
.zone__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 118px;
  padding: 14px 16px;
  color: #fff;
  background-size: cover;
  background-position: center;
  background-color: var(--zone, var(--violet));
}
.zone__head::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(40, 24, 70, 0.78) 0%, rgba(40, 24, 70, 0.45) 60%, rgba(40, 24, 70, 0.15) 100%);
}
.zone__head > * { position: relative; }
.zone__badge { font-size: 38px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35)); }
.zone__heading { flex: 1; min-width: 0; }
.zone__title { margin: 0; font-size: 22px; line-height: 1.2; }
.zone__tagline { margin: 2px 0 0; font-size: 14px; opacity: 0.95; font-weight: 600; }
.zone__progress { font-weight: 800; font-size: 15px; background: rgba(255, 255, 255, 0.22); padding: 2px 12px; border-radius: 999px; }
.zone__guardian { width: 88px; height: 88px; object-fit: contain; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35)); }
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
  padding: 14px;
}

/* ---------- 關卡介紹 ---------- */
.intro { display: flex; justify-content: center; padding: 48px 0 12px; }
.intro__card {
  width: 100%;
  max-width: 640px;
  padding: 22px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-lg);
  border: 4px solid var(--accent-soft);
}
.intro__top { display: flex; gap: 16px; align-items: center; }
.intro__icon {
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  font-size: 46px;
  border-radius: 24px;
  background: var(--accent-soft);
}
.intro__top h1 { margin: 2px 0 0; font-size: 28px; line-height: 1.2; }
.intro__concept { margin: 2px 0 0; color: var(--ink-soft); font-weight: 700; }
.intro__story { margin: 16px 0 6px; font-size: 18px; line-height: 1.75; }
.intro__meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.intro__chip { padding: 5px 12px; border-radius: 999px; background: var(--accent-soft); font-weight: 700; font-size: 15px; }
.intro__actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; }

/* ---------- 答題 ---------- */
.screen--play { padding-top: 0; }
.hud {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 4px 0 10px;
}
.hud__item {
  position: relative;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--line);
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
}
.hud__item strong { font-size: 20px; color: var(--accent); margin-left: 2px; }
.play-stage { display: grid; gap: 14px; grid-template-columns: 1fr; align-items: start; }
.play-visual-wrap {
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid var(--accent-soft);
  box-shadow: var(--shadow);
  padding: 10px;
}
.play-visual {
  min-height: 150px;
  max-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.play-visual svg { width: 100%; height: auto; max-height: 320px; }
.play-panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.play-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 結算 ---------- */
.result { display: flex; justify-content: center; padding: 46px 0 10px; }
.result__card {
  width: 100%;
  max-width: 640px;
  text-align: center;
  padding: 24px 20px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-lg);
  border: 4px solid var(--accent-soft);
}
.result__kicker { margin: 0; font-weight: 800; color: var(--accent); }
.result__card h1 { margin: 6px 0 4px; font-size: 30px; }
.result__subtitle { margin: 0 0 8px; color: var(--ink-soft); font-weight: 700; }
.result__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }

/* ---------- 圖鑑 ---------- */
.crystal-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; padding: 8px 0 14px; }
.collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding-bottom: 20px; }

/* ---------- 響應式 ---------- */
@media (min-width: 900px) {
  .play-stage { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
  .play-visual { min-height: 260px; max-height: 420px; }
  .play-visual svg { max-height: 400px; }
  .home { padding-top: 64px; }
}

@media (max-width: 899px) {
  .play-visual-wrap--mascot { display: none; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .game { padding-left: 12px; padding-right: 12px; }
  :root { --sys-w: 156px; --footer-h: 52px; }
  .sysbar { right: 6px; gap: 6px; }
  .topbar { flex-wrap: wrap; }
  .topbar__stats { flex-basis: 100%; order: 3; padding-bottom: 4px; }
  .zone__guardian { width: 64px; height: 64px; }
  .zone__title { font-size: 19px; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 10px; }
  .intro { padding-top: 56px; }
  .intro__card { padding: 16px; }
  .intro__top h1 { font-size: 24px; }
  .result { padding-top: 56px; }
  .site-footer { font-size: 11.5px; padding-left: 10px; padding-right: 10px; }
  .collection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
