/* ============================================================
   風的練習 — THE FIRST GLIDE · MONUMENT SANCTUARY
   Design System: Monument Valley Aesthetic x Supercell Chunky 3D
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --font-main: "Outfit", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --bg-day: #e9f4ef;
  --bg-night: #24354c;
  --text-day: #2d3f3b;
  --text-muted-day: #7a9892;
  --text-night: #e6f1f5;
  --text-muted-night: #8aa5b8;
  --glass-day: rgba(255, 255, 255, 0.82);
  --glass-border-day: rgba(217, 235, 228, 0.85);
  --glass-shadow-day: 0 8px 24px rgba(45, 75, 68, 0.08);
  --glass-night: rgba(26, 40, 60, 0.85);
  --glass-border-night: rgba(85, 125, 165, 0.35);
  --glass-shadow-night: 0 8px 24px rgba(5, 15, 25, 0.35);
  --accent-gold: #ffc83b;
  --accent-cyan: #63d2c6;
  --accent-primary: #2d3f3b;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-day);
  font-family: var(--font-main);
  color: var(--text-day);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 50%, rgba(95, 135, 125, 0.14) 100%);
}

/* ---------- 紀念碑谷：關卡登場優雅揭示橫幅 ---------- */
#level-banner {
  position: absolute;
  top: 36px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 10;
  text-align: center;
}

#level-banner.hidden {
  display: none;
}

.banner-inner {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 12px 36px rgba(45, 75, 68, 0.16);
  border-radius: 24px;
  padding: 12px 32px 14px;
}

.banner-world {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: #559e8f;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.banner-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-day);
}

.banner-line {
  width: 36px;
  height: 2px;
  margin: 6px auto 0;
  background: linear-gradient(90deg, transparent, #559e8f, transparent);
  border-radius: 1px;
}

.banner-fadein {
  animation: bannerIn 0.55s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

.banner-fadeout {
  animation: bannerOut 0.55s ease forwards;
}

@keyframes bannerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(0.95); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes bannerOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(0.97); }
}

/* Monument Valley Menu Emblem & Subtitles */
/* (.menu-card 已由全螢幕首頁封面取代；封面樣式見下方「全螢幕首頁封面」區塊) */

.menu-emblem {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin: 0 auto 10px;
  background: radial-gradient(circle, rgba(174, 217, 222, 0.4), transparent 70%);
  border: 1.5px dashed rgba(111, 174, 159, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: emblemPulse 4s ease-in-out infinite;
}

@keyframes emblemPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.emblem-gem {
  font-size: 28px;
  animation: floatGem 3s ease-in-out infinite;
}

@keyframes floatGem {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.menu-eng {
  font-size: 9px !important;
  letter-spacing: 0.32em !important;
  color: #8fa8a1 !important;
  font-weight: 700;
  margin: 2px 0 8px !important;
  text-transform: uppercase;
}

.menu-quote {
  font-size: 13px !important;
  letter-spacing: 0.12em !important;
  color: #53756d !important;
  font-style: italic;
  margin: 6px 0 12px !important;
}

.menu-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #497167;
  background: rgba(174, 217, 222, 0.28);
  border: 1px solid rgba(111, 174, 159, 0.35);
  border-radius: 999px;
  padding: 4px 14px;
  display: inline-block;
  margin-bottom: 6px;
}

.theme-row {
  margin-top: 14px;
  margin-bottom: 6px;
}

.win-eval {
  color: #559e8f !important;
  font-weight: 800;
  letter-spacing: 0.18em;
  margin-top: 4px !important;
  font-size: 14px !important;
}

/* Chapter Tabs */
.chapter-tabs {
  display: flex;
  gap: 6px;
  margin: 8px 0 16px;
  background: rgba(238, 244, 241, 0.85);
  padding: 4px;
  border-radius: 14px;
  border: 1px solid rgba(217, 231, 225, 0.9);
}

.chap-tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 4px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #6b8580;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}

.chap-tab.active {
  background: #ffffff;
  color: #33413d;
  box-shadow: 0 2px 8px rgba(60, 90, 85, 0.14);
}

body[data-theme='night'] #banner-chapter {
  color: #79cddb;
}

body[data-theme='night'] #banner-title {
  color: #e8f4fb;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6);
}

body[data-theme='night'] .banner-ornament {
  color: #559db2;
}

/* ---------- 頂部標題（Monument Valley 詩意排版） ---------- */
#title {
  position: absolute;
  top: 24px;
  left: 28px;
  pointer-events: none;
  animation: fadeDown 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

#title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.26em;
  color: var(--text-day);
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.6);
}

#title p {
  margin: 5px 0 0;
  font-size: 10px;
  letter-spacing: 0.38em;
  color: var(--text-muted-day);
  font-weight: 600;
}

/* ---------- 視角切換器 ---------- */
#view-toggle {
  position: absolute;
  top: 22px;
  right: 24px;
  display: flex;
  background: var(--glass-day);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid var(--glass-border-day);
  border-radius: 16px;
  padding: 4px;
  gap: 4px;
  box-shadow: var(--glass-shadow-day);
  z-index: 3;
}

#view-toggle button {
  border: 0;
  background: transparent;
  padding: 7px 15px;
  border-radius: 12px;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted-day);
  cursor: pointer;
  transition: all 0.22s ease;
}

#view-toggle button.active {
  background: #ffffff;
  color: var(--text-day);
  box-shadow: 0 3px 12px rgba(45, 75, 68, 0.12);
}

/* ---------- 浮空極簡 HUD 膠囊群 ---------- */
#lvl-chip, #steps-chip, #gems-chip {
  position: absolute;
  right: 24px;
  background: var(--glass-day);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid var(--glass-border-day);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 12px;
  box-shadow: var(--glass-shadow-day);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 3;
  /* 膠囊單行：避免文字換行造成高度參差、與其他膠囊重疊 */
  white-space: nowrap;
  overflow: hidden;
}

#lvl-chip {
  top: 78px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-day);
}

#lvl-chip .chip-icon {
  color: var(--accent-cyan);
  font-size: 11px;
}

#steps-chip {
  top: 124px;
  color: var(--text-muted-day);
}

#steps-chip .chip-label {
  font-size: 11px;
  letter-spacing: 0.08em;
}

#steps-chip b {
  font-size: 16px;
  color: var(--text-day);
}

#steps-chip .par-tag {
  font-size: 11px;
  color: var(--text-muted-day);
}

#gems-chip {
  top: 170px;
  color: #8c6a28;
}

#gems-chip b {
  font-size: 15px;
  color: #8c6a28;
}

/* ---------- 浮空圓形按鈕（選單 / 暫停） ---------- */
#btn-menu, #btn-pause {
  position: absolute;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--glass-border-day);
  background: var(--glass-day);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 17px;
  color: var(--text-day);
  cursor: pointer;
  box-shadow: var(--glass-shadow-day);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, background 0.18s ease;
  z-index: 3;
}

#btn-menu { top: 218px; }
#btn-pause { top: 218px; right: 78px; }

#btn-menu:hover, #btn-pause:hover {
  background: #ffffff;
  transform: translateY(-2px);
}

#btn-menu:active, #btn-pause:active {
  transform: scale(0.92);
}

/* ---------- 主角指示氣泡 & 預覽 ---------- */
#bubble {
  position: absolute;
  left: 32%;
  top: 42%;
  transform: translate(-50%, -140%);
  background: #ffffff;
  border-radius: 14px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-day);
  box-shadow: 0 10px 28px rgba(45, 75, 68, 0.16);
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.4s ease;
  animation: float 2.4s ease-in-out infinite;
  z-index: 4;
}

#bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #ffffff;
  border-bottom: 0;
}

#bubble.hidden { opacity: 0; }

#drag-preview {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: rgba(43, 62, 58, 0.94);
  color: #ffffff;
  font-size: 22px;
  line-height: 48px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.85);
  z-index: 8;
  transition: transform 0.08s;
}

#drag-preview.hidden { display: none; }

#toast {
  position: absolute;
  bottom: 128px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(43, 62, 58, 0.92);
  color: #ffffff;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  transition: opacity 0.4s;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

#toast.hidden { opacity: 0; }

#ability-bar {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 4;
  display: flex;
  gap: 8px;
  padding: 7px;
  border: 2px solid rgba(70, 56, 47, 0.34);
  border-radius: 20px 20px 25px 17px;
  background: rgba(238, 248, 245, 0.96);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.72), 0 6px 0 rgba(70, 56, 47, 0.14), 0 16px 30px rgba(45, 75, 68, 0.16);
  transform: translateX(-50%);
  max-width: min(76vw, 920px);
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

#ability-bar.hidden { display: none; }

#ability-bar button {
  position: relative;
  display: grid;
  grid-template-columns: 42px auto;
  align-items: center;
  gap: 5px;
  min-height: 54px;
  padding: 5px 12px 6px 6px;
  border: 2px solid rgba(70, 56, 47, 0.2);
  border-radius: 14px 16px 17px 13px;
  background: #f7fbf8;
  color: #405b56;
  font: 800 12px/1 var(--font-main);
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.8), 0 4px 0 rgba(70, 56, 47, 0.12);
  transition: transform 180ms cubic-bezier(.16,1,.3,1), box-shadow 180ms cubic-bezier(.16,1,.3,1), border-color 180ms ease;
}

#ability-bar button:hover { transform: translateY(-1px); background: #fbfefd; }
#ability-bar button:active,
#ability-bar button.active { transform: translateY(2px); border-color: #d39b24; background: #f4ecd2; box-shadow: inset 0 2px 0 rgba(255,255,255,.72), 0 2px 0 rgba(70,56,47,.15); }
#ability-bar .icy-icon { width: 28px; height: 28px; }
#ability-bar .game-art-compact { width: 48px; height: 48px; margin: -2px -3px; }
#ability-bar button > small {
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--biome-dark, #405b56);
  color: #f5faf8;
  font: 800 10px/17px var(--font-main);
}
#ability-bar button.spent { color: #71807b; background: #dfe8e4; border-style: dashed; filter: saturate(.32); }
#ability-bar button.spent::after { content: "已用"; position: absolute; right: 5px; top: 4px; padding: 2px 4px; border-radius: 5px; background: #46382f; color: #f5faf8; font-size: 8px; letter-spacing: .04em; }
#ability-bar button:disabled { cursor: default; transform: none; }
body:not([data-screen='game']) #ability-bar { display: none; }
body[data-theme='night'] #ability-bar { background: rgba(31, 51, 72, 0.96); border-color: rgba(150, 184, 198, 0.42); }
body[data-theme='night'] #ability-bar button { background: rgba(42, 68, 92, 0.9); color: #e8f4fb; border-color: rgba(112, 163, 194, 0.3); }

#dpad {
  position: absolute;
  right: 28px;
  bottom: 28px;
  display: grid;
  grid-template-columns: repeat(3, auto);
  grid-template-rows: repeat(2, auto);
  grid-template-areas:
    ".    up   ."
    "left down right";
  gap: 8px;
  z-index: 3;
}

#dpad .row {
  display: contents;
}

#dpad [data-dir="up"]    { grid-area: up; }
#dpad [data-dir="down"]  { grid-area: down; }
#dpad [data-dir="left"]  { grid-area: left; }
#dpad [data-dir="right"] { grid-area: right; }

#dpad button {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 1px solid var(--glass-border-day);
  background: var(--glass-day);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-family: var(--font-main);
  font-size: 22px;
  font-weight: 700;
  color: #4a635e;
  cursor: pointer;
  box-shadow: var(--glass-shadow-day);
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}

#dpad button:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

#dpad button:active,
#dpad button.active {
  transform: scale(0.92);
  background: #ffffff;
}

#compass {
  position: absolute;
  left: 28px;
  bottom: 28px;
  font-size: 11px;
  font-weight: 800;
  color: #8da9a2;
  display: flex;
  flex-direction: column;
  align-items: center;
  letter-spacing: 0.14em;
  z-index: 3;
}

#compass span {
  font-size: 12px;
  margin-top: 1px;
}

/* ---------- 啟動 Loading 畫面 ---------- */
#boot {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  background: var(--bg-day);
  z-index: 50;
}

#boot.hidden { display: none; }

#boot .spin {
  font-size: 42px;
  color: #6ca599;
  animation: spin 2s linear infinite;
}

#boot p {
  color: #6b8580;
  font-size: 14px;
  letter-spacing: 0.2em;
  margin: 0;
}

#boot-retry {
  border: 0;
  background: var(--accent-primary);
  color: #ffffff;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 12px 30px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
}

#boot-retry.hidden { display: none; }

/* ---------- 紀念碑谷風格：彈窗、選關、通關卡片 ---------- */
#menu, #pause, #win, #fail, #select, #howto, #settings {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(225, 238, 232, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 6;
  transition: opacity 0.3s ease;
}

#menu.hidden, #pause.hidden, #win.hidden, #fail.hidden, #select.hidden, #howto.hidden, #settings.hidden {
  display: none;
}
/* 疊層修正：同 z-index 時 DOM 後者在上，#select(76)/#settings(115) 會被 #menu(139)/#pause(163)
   的封面與卡片蓋住 → 章節探索／設定從封面或暫停開啟時不可見也不可點。提到 7 壓過所有卡片層。 */
#select, #settings {
  z-index: 7;
}

/* ---------- 全螢幕首頁封面（App 動線：封面 → 選關 → 遊玩） ---------- */
/* 覆寫上方 overlay 群的置中＋模糊：封面以上下 scrim 護文字、中段讓 3D 場景當主視覺 */
#menu {
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: max(44px, env(safe-area-inset-top, 0px) + 26px) 24px max(16px, env(safe-area-inset-bottom, 0px) + 12px);
  background: linear-gradient(180deg,
    rgba(233, 244, 239, 0.95) 0%,
    rgba(233, 244, 239, 0.72) 24%,
    rgba(233, 244, 239, 0.12) 52%,
    rgba(216, 233, 225, 0.34) 74%,
    rgba(233, 244, 239, 0.94) 100%);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.home-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  animation: fadeDown 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.home-head .menu-emblem { margin-bottom: 0; }
.home-head .menu-badge { margin: 2px 0 0; }

.home-title {
  margin: 0;
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 700;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  color: var(--text-day);
  text-shadow: 0 2px 22px rgba(255, 255, 255, 0.7);
}

.home-sub {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.38em;
  text-indent: 0.38em;
  font-weight: 700;
  color: var(--text-muted-day);
}

.home-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  width: 100%;
}

.home-play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: fadeUp 0.9s 0.12s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* MV 式：單一安靜的圓形播放鈕（play = continue 直進關卡） */
.home-playbtn {
  width: 86px;
  height: 86px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: var(--accent-primary);
  color: #ffffff;
  font-family: var(--font-main);
  font-size: 26px;
  padding-left: 6px; /* ▶ 視覺置中 */
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 18px 44px rgba(45, 75, 68, 0.42);
  transition: transform 0.15s ease, background 0.2s ease;
  animation: ctaHalo 2.8s ease-in-out infinite;
}

.home-playbtn:hover { transform: translateY(-2px); background: #3a524c; }
.home-playbtn:active { transform: scale(0.94); }

#home-play-label {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: var(--text-day);
  opacity: 0.85;
}

.home-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.home-links { display: flex; gap: 8px; }

.home-links button {
  border: 0;
  background: transparent;
  color: var(--text-day);
  opacity: 0.72;
  font-family: var(--font-main);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: opacity 0.18s ease, background 0.18s ease;
}

.home-links button:hover { opacity: 1; background: rgba(255, 255, 255, 0.55); }

.home-version {
  margin: 4px 0 0;
  font-size: 9.5px;
  letter-spacing: 0.3em;
  font-weight: 600;
  color: var(--text-muted-day);
}

.card {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.95);
  border-radius: 34px;
  padding: 38px 44px;
  text-align: center;
  box-shadow: 0 28px 80px rgba(40, 70, 65, 0.22);
  animation: pop 0.4s cubic-bezier(0.16, 1.2, 0.3, 1) both;
  width: 100%;
  max-width: min(360px, 88vw);
}

.card .ring {
  font-size: 38px;
  letter-spacing: 0.15em;
  color: var(--accent-cyan);
}

.card h2 {
  margin: 12px 0 6px;
  letter-spacing: 0.22em;
  font-size: 23px;
  font-weight: 700;
  color: var(--text-day);
}

.card .menu-sub, .card .pause-sub {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--text-muted-day);
  font-weight: 600;
}

.card p {
  color: var(--text-muted-day);
  font-size: 14px;
  margin: 4px 0;
}

.card p b {
  color: var(--text-day);
  font-size: 17px;
}

#win-stars {
  font-size: 28px !important;
  color: #e5a812 !important;
  letter-spacing: 0.22em;
  margin: 10px 0 4px !important;
}

#win-complete {
  color: #55a896 !important;
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 13px !important;
}

.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}

.btn-row.col {
  flex-direction: column;
  gap: 10px;
}

.btn-row button {
  flex: 1;
  border: 0;
  background: #e5eeea;
  color: var(--text-day);
  font-family: var(--font-main);
  font-weight: 700;
  padding: 15px 18px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 0.12em;
  transition: transform 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn-row button:hover {
  transform: translateY(-1px);
  background: #dae6e1;
}

.btn-row button:active {
  transform: scale(0.96);
}

.btn-row button.primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(45, 65, 60, 0.25);
}

.btn-row button.primary:hover {
  background: #3a524c;
}

/* 選項行列 */
.opt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding: 0 6px;
  color: var(--text-muted-day);
  font-size: 13px;
  font-weight: 600;
}

.opt-row button {
  border: 0;
  background: #e8f0ec;
  color: var(--text-day);
  font-family: var(--font-main);
  border-radius: 12px;
  padding: 7px 16px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}

.opt-row .seg {
  display: flex;
  background: #e8f0ec;
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.opt-row .seg button {
  border: 0;
  background: transparent;
  color: var(--text-muted-day);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.opt-row .seg button.active {
  background: #ffffff;
  color: var(--text-day);
  box-shadow: 0 2px 6px rgba(45, 75, 68, 0.12);
}

/* ---------- 設定面板（集中式 App 設定） ---------- */
#settings .opt-row { margin-top: 12px; }

.settings-link {
  margin-top: 16px;
  border: 0;
  background: transparent;
  color: var(--text-muted-day);
  font-family: var(--font-main);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.settings-link:hover { background: #eef4f1; color: var(--text-day); }

.settings-version {
  margin: 22px 0 0;
  font-size: 10px;
  letter-spacing: 0.26em;
  text-align: center;
  color: var(--text-muted-day);
}

/* 結算卡：MV 式自動前往提示（hidden 為 id 專屬規則） */
#win-auto.hidden, #win-complete.hidden { display: none; }

#win-auto {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--text-muted-day);
}

/* 設定：重置進度（危險列，雙擊確認） */
.opt-row.danger button { color: #8a4a3a; }
.opt-row.danger button.armed { background: #f3d9d4; color: #8a4a3a; }

/* ---------- 紀念碑谷：章節選關 Sheet ---------- */
.sheet {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.95);
  border-radius: 32px;
  padding: 32px 30px 36px;
  box-shadow: 0 28px 80px rgba(40, 70, 65, 0.24);
  animation: pop 0.35s cubic-bezier(0.16, 1.2, 0.3, 1) both;
  max-width: min(520px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(210, 230, 222, 0.6);
}

.sheet-title-group h2 {
  margin: 0;
  letter-spacing: 0.24em;
  font-size: 21px;
  font-weight: 700;
  color: var(--text-day);
}

.sheet-title-group .sheet-sub {
  display: block;
  font-size: 9px;
  letter-spacing: 0.3em;
  color: var(--text-muted-day);
  margin-top: 3px;
  font-weight: 600;
}

#select-close, #howto-close {
  border: 0;
  background: #eef4f1;
  width: 38px;
  height: 38px;
  border-radius: 14px;
  font-size: 15px;
  cursor: pointer;
  color: #4a635e;
  transition: all 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#select-close:hover, #howto-close:hover {
  background: #dbe8e2;
}

.world-head {
  grid-column: 1 / -1;
  margin: 14px 2px 4px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.24em;
  color: #559e8f;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.world-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(180, 215, 205, 0.5);
}

.world-head:first-child {
  margin-top: 0;
}

#select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.lvl-btn {
  border: 2px solid #dceae4;
  background: #f8fcfa;
  border-radius: 18px;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  color: var(--text-day);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.lvl-btn:hover {
  transform: translateY(-2px);
  border-color: #a8d5c8;
  box-shadow: 0 4px 12px rgba(45, 75, 68, 0.1);
}

.lvl-btn:active {
  transform: scale(0.95);
}

.lvl-btn .lid {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.lvl-btn .lname {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 95%;
}

.lvl-btn .lstars {
  font-size: 11px;
  color: #e5a812;
  letter-spacing: 0.12em;
}

.lvl-btn .lpar {
  font-size: 10px;
  color: var(--text-muted-day);
}

.lvl-btn.current {
  border-color: var(--accent-primary);
  background: #ffffff;
  box-shadow: 0 4px 16px rgba(45, 75, 68, 0.16);
}

.lvl-btn.locked {
  background: #edf3f0;
  color: #9cb5af;
  border-color: #e0eae5;
  cursor: not-allowed;
}

.lvl-btn.locked .lock {
  font-size: 18px;
}

/* 玩法指引步數列表 */
.howto-steps {
  list-style: none;
  margin: 16px 0 8px;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.howto-steps li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 13px;
  color: #435e58;
  line-height: 1.65;
}

.howto-steps .n {
  flex: 0 0 24px;
  height: 24px;
  border-radius: 8px;
  background: #e2ede8;
  color: var(--accent-primary);
  font-weight: 800;
  font-size: 13px;
  line-height: 24px;
  text-align: center;
}

/* ---------- 夜行主題（Night Mode - Monument Valley 暮夜氛圍） ---------- */
body[data-theme='night'] {
  background: var(--bg-night);
  color: var(--text-night);
}

body[data-theme='night'] #title h1 {
  color: #edf5fa;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

body[data-theme='night'] #title p {
  color: #8bb7cc;
}

body[data-theme='night'] #view-toggle {
  background: var(--glass-night);
  border-color: var(--glass-border-night);
  box-shadow: var(--glass-shadow-night);
}

body[data-theme='night'] #view-toggle button {
  color: var(--text-muted-night);
}

body[data-theme='night'] #view-toggle button.active {
  background: #273c57;
  color: #ffffff;
}

body[data-theme='night'] #lvl-chip,
body[data-theme='night'] #steps-chip,
body[data-theme='night'] #gems-chip,
body[data-theme='night'] #btn-menu,
body[data-theme='night'] #btn-pause,
body[data-theme='night'] #dpad button {
  background: var(--glass-night);
  border-color: var(--glass-border-night);
  color: var(--text-night);
  box-shadow: var(--glass-shadow-night);
}

body[data-theme='night'] #steps-chip b {
  color: #ffffff;
}

body[data-theme='night'] #gems-chip {
  color: #e5b84c;
}

body[data-theme='night'] #gems-chip b {
  color: #e5b84c;
}

body[data-theme='night'] #btn-menu:hover,
body[data-theme='night'] #btn-pause:hover,
body[data-theme='night'] #dpad button:hover {
  background: #253952;
}

body[data-theme='night'] #menu,
body[data-theme='night'] #pause,
body[data-theme='night'] #win,
body[data-theme='night'] #fail,
body[data-theme='night'] #select,
body[data-theme='night'] #howto,
body[data-theme='night'] #settings {
  background: rgba(12, 22, 36, 0.72);
}

body[data-theme='night'] .card,
body[data-theme='night'] .sheet {
  background: rgba(22, 36, 56, 0.94);
  border-color: rgba(90, 135, 180, 0.35);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
  color: var(--text-night);
}

body[data-theme='night'] .card h2,
body[data-theme='night'] .sheet-title-group h2 {
  color: #edf6fb;
}

body[data-theme='night'] .card p,
body[data-theme='night'] .card .menu-sub,
body[data-theme='night'] .card .pause-sub,
body[data-theme='night'] .sheet-title-group .sheet-sub {
  color: var(--text-muted-night);
}

body[data-theme='night'] .btn-row button {
  background: #243852;
  color: #e2f0f8;
}

body[data-theme='night'] .btn-row button:hover {
  background: #314b6c;
}

body[data-theme='night'] .btn-row button.primary {
  background: #3a6892;
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(10, 30, 50, 0.4);
}

body[data-theme='night'] .opt-row {
  color: var(--text-muted-night);
}

body[data-theme='night'] .opt-row button,
body[data-theme='night'] .opt-row .seg {
  background: #18283d;
  color: #a8c2d4;
}

body[data-theme='night'] .opt-row .seg button.active {
  background: #273e5c;
  color: #ffffff;
}

body[data-theme='night'] .sheet-head {
  border-color: rgba(90, 135, 180, 0.25);
}

body[data-theme='night'] #select-close,
body[data-theme='night'] #howto-close {
  background: #1e324a;
  color: #a8c2d4;
}

body[data-theme='night'] .world-head {
  color: #6ec4db;
}

body[data-theme='night'] .world-head::after {
  background: rgba(90, 135, 180, 0.35);
}

body[data-theme='night'] .lvl-btn {
  border-color: #273e5c;
  background: #1a2c42;
  color: #e2f0f8;
}

body[data-theme='night'] .lvl-btn.current {
  border-color: #6ec4db;
  background: #243852;
}

body[data-theme='night'] .lvl-btn.locked {
  background: #142233;
  color: #58738a;
  border-color: #1a2c42;
}

body[data-theme='night'] .howto-steps li {
  color: #a8c4d6;
}

body[data-theme='night'] .howto-steps .n {
  background: #1e324a;
  color: #6ec4db;
}

/* ---------- 首頁封面／設定的夜行補充＋HUD 收合（位置需晚於上方夜行群組才會生效） ---------- */
body[data-theme='night'] #menu {
  background: linear-gradient(180deg,
    rgba(18, 30, 47, 0.95) 0%,
    rgba(18, 30, 47, 0.72) 24%,
    rgba(18, 30, 47, 0.10) 52%,
    rgba(14, 24, 40, 0.34) 74%,
    rgba(18, 30, 47, 0.95) 100%);
}

body[data-theme='night'] .home-title {
  color: var(--text-night);
  text-shadow: 0 2px 22px rgba(0, 0, 0, 0.6);
}

body[data-theme='night'] .home-sub,
body[data-theme='night'] .home-version { color: var(--text-muted-night); }

body[data-theme='night'] .home-playbtn {
  background: #e6f1f5;
  color: #16233a;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

body[data-theme='night'] .home-playbtn:hover { background: #ffffff; }

body[data-theme='night'] #home-play-label { color: var(--text-night); }

body[data-theme='night'] .home-links button { color: var(--text-night); }
body[data-theme='night'] .home-links button:hover { background: rgba(40, 60, 88, 0.6); opacity: 1; }

body[data-theme='night'] .menu-badge {
  background: rgba(36, 56, 82, 0.62);
  border-color: rgba(90, 135, 180, 0.42);
  color: #a8cadd;
}

body[data-theme='night'] .settings-link { color: var(--text-muted-night); }
body[data-theme='night'] .settings-link:hover { background: #1e324a; color: var(--text-night); }

body[data-theme='night'] .settings-version { color: var(--text-muted-night); }

body[data-theme='night'] #win-auto { color: var(--text-muted-night); }

body[data-theme='night'] .opt-row.danger button { color: #d8a08e; }
body[data-theme='night'] .opt-row.danger button.armed { background: #4a2a24; color: #e8b4a4; }

/* ---------- 首頁封面模式：收起遊玩 HUD，只留封面 ---------- */
body[data-screen='home'] #title,
body[data-screen='home'] #view-toggle,
body[data-screen='home'] #lvl-chip,
body[data-screen='home'] #steps-chip,
body[data-screen='home'] #gems-chip,
body[data-screen='home'] #btn-menu,
body[data-screen='home'] #btn-pause,
body[data-screen='home'] #dpad,
body[data-screen='home'] #ability-bar,
body[data-screen='home'] #compass,
body[data-screen='home'] #bubble,
body[data-screen='home'] #drag-preview { display: none !important; }

/* ---------- 封面響應式 ---------- */
@media (orientation: portrait) {
  .home-title { font-size: clamp(30px, 11vw, 46px); }
}

@media (orientation: landscape) and (max-height: 600px) {
  #menu { padding-top: 18px; padding-bottom: 12px; }
  .home-head { gap: 6px; }
  .menu-emblem { width: 46px; height: 46px; }
  .emblem-gem { font-size: 22px; }
  .home-title { font-size: 30px; }
  .home-actions { gap: 8px; }
  .home-playbtn { width: 62px; height: 62px; font-size: 20px; }
  .home-center { gap: 18px; }
}

/* ---------- 動畫 Keyframes ---------- */
@keyframes float {
  0%, 100% { transform: translate(-50%, -140%); }
  50% { transform: translate(-50%, -148%); }
}

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop {
  0% { opacity: 0; transform: scale(0.88); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- 響應式調整 ---------- */
@media (max-width: 640px) {
  #title h1 { font-size: 18px; }
  #title p { font-size: 9px; }
  #level-banner { top: 16%; }
  #banner-title { font-size: 22px; }
  #dpad { right: 18px; bottom: 18px; }
  #dpad button { width: 50px; height: 50px; border-radius: 16px; font-size: 18px; }
  #ability-bar { bottom: 142px; padding: 5px; }
  #ability-bar button { grid-template-columns: 38px; min-width: 48px; min-height: 50px; padding: 5px; }
  #ability-bar .game-art-compact { width: 42px; height: 42px; }
  #ability-bar button span { display: none; }
}

@media (orientation: portrait) {
  #title h1 { font-size: 16px; letter-spacing: 0.16em; }
  #title p { display: none; }
  #steps-chip { left: 24px; right: auto; top: 130px; }
  #lvl-chip { left: 24px; right: auto; top: 84px; }
  #gems-chip { left: 24px; right: auto; top: 176px; }
  #compass { display: none; }
  #btn-menu { left: 24px; right: auto; bottom: 24px; top: auto; }
  #btn-pause { left: 78px; right: auto; bottom: 24px; top: auto; }
  #toast { bottom: 160px; }
  #select-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .sheet { padding: 24px 18px 28px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  #lvl-chip { top: 68px; padding: 5px 14px; font-size: 11px; }
  #steps-chip { top: 104px; padding: 5px 14px; font-size: 11px; }
  #gems-chip { top: 140px; padding: 5px 14px; font-size: 11px; }
  #btn-menu { top: 178px; }
  #btn-pause { top: 178px; }
  #dpad button { width: 48px; height: 48px; }
  #ability-bar { bottom: 12px; padding: 5px; }
  #ability-bar button { grid-template-columns: 38px; min-width: 48px; min-height: 48px; padding: 4px; }
  #ability-bar .game-art-compact { width: 42px; height: 42px; }
  #ability-bar button span { display: none; }
  .card { padding: 24px 30px; }
}

/* ---------- 無障礙：鍵盤操作焦點可見 ---------- */
:where(button, a, summary, [role="tab"], [role="button"]) {
  -webkit-tap-highlight-color: transparent;
}

:where(button, a, summary, [role="tab"], [role="button"], [tabindex]):focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
  border-radius: 6px;
}

body[data-theme='night'] :where(button, a, summary, [role="tab"], [role="button"], [tabindex]):focus-visible {
  outline-color: #6ec4db;
}

/* ============================================================
   排版穩定修復（手機 / 平板）：單一覆寫區，後出現者勝
   目標：橫幅置中不偏移、卡片不爆出 viewport、按鈕文字不斷字、
   窄機優雅收縮。新增覆寫只加在這區，不要在檔尾另起爐灶。
   ============================================================ */

/* A. 彈窗 overlay 內縮，卡片永遠不貼邊、不爆出 viewport */
#menu, #pause, #win, #fail, #select, #howto {
  padding: 16px;
  box-sizing: border-box;
}
.card {
  width: 100%;
  max-width: min(360px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  box-sizing: border-box;
}
.menu-card { max-width: min(380px, 100%); }
.sheet {
  width: 100%;
  max-width: min(520px, 100%);
  max-height: 86vh;
}

/* B. 按鈕列可換行；極窄直向時非 .col 改直排，選關 3 欄改 2 欄 */
.btn-row { flex-wrap: wrap; }
.btn-row button { white-space: nowrap; }
@media (max-width: 360px) and (orientation: portrait) {
  .btn-row:not(.col) { flex-direction: column; }
  #select-grid { grid-template-columns: repeat(2, 1fr); }
}

/* C. 關卡橫幅：寬度收斂置中（置中位移全程保留在 keyframes 內），
   章節與標題單行截斷，不推出螢幕 */
#level-banner { width: max-content; max-width: 92vw; box-sizing: border-box; }
#banner-chapter {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.28em;
  color: #559e8f; text-transform: uppercase; margin-bottom: 3px; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#banner-title {
  margin: 0; font-size: 20px; font-weight: 700; letter-spacing: 0.18em;
  color: var(--text-day); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 100%;
}
body[data-theme='night'] #banner-title { color: #e8f4fb; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6); }
body[data-theme='night'] #banner-chapter { color: #79cddb; }
.banner-ornament { white-space: nowrap; }
@media (max-width: 360px) {
  #banner-chapter { font-size: 10px; letter-spacing: 0.18em; }
  #banner-title { font-size: 17px; letter-spacing: 0.12em; }
}

/* D. 選關英文副標與章節頁籤：單行不折，窄機縮字距 */
.sheet-title-group { min-width: 0; flex: 1; }
.sheet-title-group .sheet-sub {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.chapter-tabs { flex-wrap: nowrap; }
.chap-tab { white-space: nowrap; flex-shrink: 1; min-width: 0; }
@media (max-width: 420px) {
  .sheet-title-group .sheet-sub { letter-spacing: 0.18em; font-size: 8px; }
  .chap-tab { font-size: 11px; letter-spacing: 0.04em; padding: 8px 3px; }
}

/* E. 主選單主題雙鍵：標籤不折行，兩顆按鈕各自單行；
   容器可換行，窄機時整組全寬、標籤與按鈕上下排 */
#menu .opt-row { flex-wrap: wrap; row-gap: 8px; column-gap: 12px; }
#menu .opt-row > span { white-space: nowrap; flex-shrink: 0; }
#menu .opt-row .seg { flex: 1 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
#menu .opt-row .seg button {
  flex: 1 1 auto; white-space: nowrap; flex-shrink: 0;
  padding: 6px 8px; font-size: 12px;
}
@media (max-width: 340px) {
  #menu .opt-row { flex-direction: column; align-items: stretch; }
  #menu .opt-row .seg { width: 100%; justify-content: stretch; }
}

/* F. toast 單行截斷；卡片標題段落平衡換行，避免行尾孤字 */
#toast { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card h2, .card p, .menu-sub, #menu-progress { text-wrap: balance; }

/* G. 關卡橫幅自帶白底 pill：黑字永遠落在自己的底上，不跟場景/HUD 文字重疊。
   直向手機把橫幅移到 HUD 膠囊下方（膠囊約到 213px），桌面維持頂部。 */
#level-banner .banner-inner { max-width: 100%; box-sizing: border-box; }
body[data-theme='night'] .banner-inner {
  background: rgba(22, 36, 56, 0.94);
  border-color: rgba(90, 135, 180, 0.35);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
}
@media (orientation: portrait) {
  #level-banner { top: 224px; }
}
@media (max-width: 360px) {
  #level-banner { top: 218px; }
  .banner-inner { padding: 10px 20px 12px; }
}
