/* 哈囉動物園：樣式。系統字體堆疊，無外部字型。 */
:root {
  --ink: #4a3426;
  --ink-soft: #7a6454;
  --cream: #fff8e1;
  --paper: #ffffff;
  --leaf: #3fae6a;
  --leaf-dark: #2c8a50;
  --sun: #ffc93c;
  --orange: #ff8a3d;
  --sky: #5ec2f2;
  --berry: #ef5b7b;
  --good: #35b35a;
  --bad: #e5484d;
  --shadow: 0 5px 0 var(--ink);
  --radius: 20px;
  --topbar-h: 56px;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-en: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #bfe8c8;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.en, [lang="en"] { font-family: var(--font-en); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 4px solid #1e6bff; outline-offset: 2px; }
img { max-width: 100%; user-select: none; -webkit-user-drag: none; }
[hidden] { display: none !important; }

/* ---------- 版面骨架：頁尾在 flex 版面最下方，永遠不會蓋住內容 ---------- */
.app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background-color: #bfe8c8;
  background-size: cover;
  background-position: center;
  background-image: url("../assets/img/bg/menu.webp");
  transition: background-image .3s;
  overflow: hidden;
}
.app[data-bg="gate"] { background-image: url("../assets/img/bg/gate.webp"); }
.app[data-bg="savanna"] { background-image: url("../assets/img/bg/savanna.webp"); }
.app[data-bg="school"] { background-image: url("../assets/img/bg/school.webp"); }
.app[data-bg="night"] { background-image: url("../assets/img/bg/night.webp"); }
.app::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 248, 225, .55), rgba(255, 248, 225, .2) 40%, rgba(255, 248, 225, .55));
  pointer-events: none;
}
.app[data-bg="night"]::before { background: linear-gradient(180deg, rgba(20, 18, 60, .35), rgba(20, 18, 60, .1) 40%, rgba(20, 18, 60, .4)); }
.app > * { position: relative; }
.app[data-bg="night"] .topbar-title, .app[data-bg="night"] .topbar-sub { color: #fff6dc; text-shadow: 0 2px 0 rgba(0, 0, 0, .45); }
.app[data-bg="night"] .order-hint, .app[data-bg="night"] .mem-note { color: #fff6dc; text-shadow: 0 1px 0 rgba(0, 0, 0, .5); }

.site-footer {
  flex: 0 0 auto;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  background: var(--ink);
  color: #fff6dc;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  z-index: 100;
}
.site-footer a { color: #ffe27a; text-decoration: underline; text-underline-offset: 2px; }
.site-footer a:focus-visible { outline-color: #fff; }
.noscript { padding: 16px; text-align: center; }

/* ---------- 上方工具列 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--topbar-h);
  padding: 6px 12px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  padding-top: max(6px, env(safe-area-inset-top, 0px));
  z-index: 5;
}
.topbar-title { flex: 1; min-width: 0; font-weight: 900; font-size: 20px; text-shadow: 0 2px 0 #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-sub { font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.tools { display: flex; gap: 8px; }
.icon-btn {
  position: relative;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  color: var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active, .icon-btn.pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.icon-btn[hidden] { display: none; }
.fs-exit { display: none; }
.is-fullscreen .fs-exit { display: inline; }
.is-fullscreen .fs-enter { display: none; }

/* ---------- 畫面 ---------- */
.screens { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.screen { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 8px 14px 14px; padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); -webkit-overflow-scrolling: touch; }
.screen[hidden] { display: none; }

/* 通用按鈕 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  min-width: 52px;
  padding: 10px 22px;
  background: var(--leaf);
  color: #fff;
  font-weight: 900;
  font-size: 20px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active, .btn.pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.alt { background: var(--sun); color: var(--ink); text-shadow: none; }
.btn.sky { background: var(--sky); }
.btn.danger { background: var(--bad); }
.btn.small { min-height: 44px; font-size: 16px; padding: 8px 16px; }
.btn[disabled] { filter: grayscale(.8); opacity: .6; cursor: not-allowed; }

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, .7);
  transform: scale(0);
  animation: ripple .5s ease-out forwards;
  pointer-events: none;
}
@keyframes ripple { to { transform: scale(2.6); opacity: 0; } }

/* ---------- 主選單 ---------- */
.menu { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.logo { margin: 0; line-height: 1.1; }
.logo-main {
  display: block;
  font-size: clamp(40px, 11vw, 76px);
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
  letter-spacing: .04em;
}
.logo-sub { display: block; margin-top: 4px; font-size: clamp(18px, 4.4vw, 28px); font-weight: 900; color: var(--orange); text-shadow: 0 2px 0 #fff; letter-spacing: .12em; }
.menu-mascot { width: clamp(120px, 26vh, 220px); height: auto; filter: drop-shadow(0 8px 0 rgba(74, 52, 38, .25)); }
.menu-mascot.bob { animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.menu-actions { display: flex; flex-direction: column; gap: 12px; width: min(320px, 100%); }
.menu-actions .btn { width: 100%; font-size: 24px; }
.star-total { display: inline-flex; gap: 6px; align-items: center; padding: 6px 14px; background: rgba(255, 255, 255, .85); border: 3px solid var(--ink); border-radius: 999px; font-weight: 900; }

/* ---------- 選關 ---------- */
.levels { display: flex; flex-direction: column; gap: 14px; max-width: 980px; margin: 0 auto; }
.levels-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.levels-head h2 { margin: 0; font-size: 26px; text-shadow: 0 2px 0 #fff; }
.section-card { background: rgba(255, 255, 255, .88); border: 3px solid var(--ink); border-radius: 24px; padding: 12px; box-shadow: var(--shadow); }
.section-card h3 { margin: 0 0 2px; font-size: 20px; }
.section-card p { margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); }
.level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.level-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 112px;
  padding: 8px 4px;
  background: #fff3c4;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--ink);
  text-align: center;
  transition: transform .08s, box-shadow .08s;
}
.level-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.level-btn .num { font-size: 26px; font-weight: 900; line-height: 1; }
.level-btn .name { font-size: 13px; font-weight: 800; line-height: 1.2; }
.level-btn .stars { font-size: 16px; letter-spacing: 1px; }
.level-btn .best { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.level-btn.locked { background: #d8d2c4; color: #8c8272; }
.level-btn.locked .lock { font-size: 22px; }
.level-btn.cleared { background: #d9f5df; }
.shake { animation: shake .4s; }
.star-on { filter: none; }
.star-off { filter: grayscale(1) opacity(.35); }

/* ---------- 遊戲畫面 ---------- */
.screen#screen-game { position: relative; display: flex; flex-direction: column; padding: 4px 10px 10px; padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); overflow: hidden; }
.game { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 6px; max-width: 1000px; width: 100%; margin: 0 auto; }
.hud { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: nowrap; font-weight: 900; }
.hud-chip { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 2px 9px; background: rgba(255, 255, 255, .92); border: 3px solid var(--ink); border-radius: 999px; font-size: 15px; white-space: nowrap; }
.hud-score { font-size: 20px; font-variant-numeric: tabular-nums; }
.hud-lives { letter-spacing: 2px; }
.hud-streak { background: #ffe0b2; }
.hud-streak.hot { background: var(--orange); color: #fff; animation: pop .35s; }
.timerbar { height: 14px; background: rgba(255, 255, 255, .85); border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; flex: 0 0 auto; }
.timerbar > i { display: block; height: 100%; width: 100%; background: var(--good); transform-origin: left; transition: background .2s; }
.timerbar.warn > i { background: var(--orange); }
.timerbar.danger > i { background: var(--bad); animation: blink .4s infinite; }
@keyframes blink { 50% { opacity: .55; } }

.stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; overflow-x: hidden; padding: 2px 2px 6px; }
.stage-main { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-height: 0; }
.stage-left { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.prompt-row { display: flex; align-items: center; gap: 10px; }
.mascot { width: 64px; height: 64px; object-fit: contain; flex: 0 0 auto; filter: drop-shadow(0 3px 0 rgba(74, 52, 38, .3)); }
.mascot.pop { animation: pop .4s; }
.bubble {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 4px 0 var(--ink);
}
.bubble::before { content: ""; position: absolute; left: -11px; top: 50%; width: 16px; height: 16px; background: #fff; border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: translateY(-50%) rotate(45deg); }
.bubble-text { flex: 1; min-width: 0; }
.bubble-zh { font-size: 14px; color: var(--ink-soft); font-weight: 700; }
.bubble-en { font-size: clamp(22px, 5.5vw, 32px); font-weight: 900; line-height: 1.15; overflow-wrap: anywhere; }
.bubble-trans { font-size: 14px; color: var(--leaf-dark); font-weight: 700; }
.speak {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  background: var(--sky);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 4px 0 var(--ink);
  font-size: 26px;
  padding: 0;
}
.speak:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.speak.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.1); } }

.visual { display: grid; place-items: center; min-height: 120px; max-height: 220px; padding: 6px; background: rgba(255, 255, 255, .85); border: 3px solid var(--ink); border-radius: 24px; }
.visual .pic { height: min(170px, 24vh); }

/* 圖像 */
.pic { display: inline-flex; align-items: center; justify-content: center; position: relative; }
.pic-img { height: 100%; width: auto; max-width: 100%; object-fit: contain; }
.pic-emoji { font-size: 72px; line-height: 1; }
.pic svg { height: 100%; width: auto; max-width: 100%; }
.pic-badge { position: absolute; right: -4px; bottom: -4px; font-size: 26px; }
.pic-digit { font-family: var(--font-en); font-weight: 900; font-size: 64px; line-height: 1; color: var(--ink); }
.pic-age { font-family: var(--font-en); font-weight: 900; font-size: 56px; line-height: 1; color: var(--ink); }
.pic-age small { font-size: 22px; font-family: var(--font); margin-left: 2px; }
.pic-avatar { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pic-avatar .face { font-size: 64px; line-height: 1; }
.pic-avatar .tag { padding: 0 12px; background: #fff; border: 3px solid var(--ink); border-radius: 10px; font-family: var(--font-en); font-weight: 900; font-size: 20px; }
.pic-count { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; width: min(320px, 90%); height: auto !important; }
.pic-count img { width: 100%; max-height: 58px; object-fit: contain; }

/* 選項 */
.options { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); grid-auto-rows: minmax(96px, 1fr); align-content: stretch; flex: 1 1 auto; max-height: 440px; }
.options[data-n="3"] { grid-template-columns: repeat(3, 1fr); }
.opt {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 108px;
  padding: 8px 6px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.opt:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.opt .pic { height: 84px; }
.opt .pic-emoji { font-size: 64px; }
.opt .pic-digit { font-size: 52px; }
.opt .pic-age { font-size: 46px; }
.opt .pic-avatar .face { font-size: 48px; }
.opt .opt-label { font-family: var(--font-en); font-weight: 900; font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.opt .opt-sub { font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.opt .key { position: absolute; left: 8px; top: 6px; width: 22px; height: 22px; display: grid; place-items: center; font-size: 12px; font-weight: 900; background: var(--cream); border: 2px solid var(--ink); border-radius: 7px; }
.opt.text-only .opt-label { font-size: clamp(18px, 4.6vw, 24px); padding: 0 14px; }
.opt.is-correct { background: #c8f5d4; border-color: var(--good); box-shadow: 0 0 0 5px rgba(53, 179, 90, .45), var(--shadow); animation: pop .45s; }
.opt.is-wrong { background: #ffd4d4; border-color: var(--bad); animation: shake .4s; }
.opt.is-dim { opacity: .45; }
.opt[disabled] { cursor: default; }

/* 下落版面 */
.fall-area { position: relative; flex: 1 1 auto; min-height: 240px; border-radius: 22px; background: linear-gradient(180deg, rgba(255, 255, 255, .35), rgba(255, 255, 255, .1)); overflow: hidden; }
.fall-area::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 18px; background: repeating-linear-gradient(90deg, #4cb860 0 16px, #3fae6a 16px 32px); border-top: 3px solid var(--ink); }
.fall-area .opt { position: absolute; width: 47%; min-height: 0; padding: 6px; will-change: transform; }
.fall-area .opt .pic { height: 64px; }
/* 純文字卡片較窄、句子會換行：文字從數字鍵標記下方開始，避免標記蓋住第一個字 */
.fall-area .opt.text-only { padding-top: 30px; }

/* 打地鼠版面 */
.holes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; flex: 1 1 auto; align-content: start; }
.hole { position: relative; height: clamp(120px, 20vh, 180px); display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.hole::before { content: ""; position: absolute; left: 4%; right: 4%; bottom: 0; height: 40%; background: #6d4c33; border: 3px solid var(--ink); border-radius: 50%; box-shadow: inset 0 8px 0 rgba(0, 0, 0, .25); }
.hole .opt { position: absolute; left: 8%; right: 8%; bottom: 15%; min-height: 0; height: 82%; padding: 4px; background: rgba(255, 255, 255, .92); transform: translateY(0); transition: transform .28s cubic-bezier(.3, 1.5, .5, 1), opacity .2s; }
.hole .opt .pic { height: auto; flex: 1 1 0; min-height: 0; }
.hole .opt .opt-label { font-size: 15px; }
.hole .opt.down { transform: translateY(120%); opacity: 0; pointer-events: none; }
.hole::after { content: ""; position: absolute; left: 4%; right: 4%; bottom: 0; height: 17%; background: #4a9a5a; border: 3px solid var(--ink); border-radius: 0 0 50% 50% / 0 0 100% 100%; pointer-events: none; }

/* 答案橫幅 */
.answer-banner { min-height: 0; padding: 6px 12px; text-align: center; font-weight: 900; font-size: 20px; font-family: var(--font-en); background: #fff6bf; border: 3px solid var(--ink); border-radius: 16px; animation: pop .3s; }
.answer-banner small { display: block; font-family: var(--font); font-size: 13px; color: var(--ink-soft); }
.answer-banner.ok { background: #d1f5da; }
.answer-banner.bad { background: #ffe1d4; }

/* 身體圖 */
.touch-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1 1 auto; min-height: 0; }
.body-fig { height: min(46vh, 380px); width: auto; max-width: 100%; background: rgba(255, 255, 255, .8); border: 3px solid var(--ink); border-radius: 24px; padding: 4px; }
.body-fig [data-part] { cursor: pointer; transition: filter .15s; }
.body-fig [data-part]:hover { filter: brightness(1.08); }
.body-fig .hit { fill: transparent; }
.body-fig .is-correct > *:not(.hit) { stroke: var(--good); stroke-width: 6; animation: pop .45s; }
.body-fig .is-wrong > *:not(.hit) { stroke: var(--bad); stroke-width: 6; }

/* 句子排序 */
.order-wrap { display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto; }
.slots { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; min-height: 74px; padding: 10px; background: rgba(255, 255, 255, .9); border: 3px dashed var(--ink); border-radius: 20px; }
.slots.is-correct { border-color: var(--good); background: #d1f5da; }
.slots.is-wrong { border-color: var(--bad); background: #ffe1e1; animation: shake .4s; }
.tiles { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.tile { min-height: 52px; padding: 6px 16px; background: var(--sun); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); font-family: var(--font-en); font-weight: 900; font-size: 22px; transition: transform .08s, box-shadow .08s; }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.slots .tile { background: #fff; }
.order-hint { text-align: center; font-size: 14px; color: var(--ink-soft); font-weight: 700; }

/* 記憶翻牌 */
.memory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; align-content: start; flex: 1 1 auto; max-width: 720px; width: 100%; margin: 0 auto; }
.mem-card { position: relative; aspect-ratio: 1 / 1.05; padding: 0; background: none; border: 0; perspective: 600px; }
.mem-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .35s; }
.mem-card.up .mem-inner { transform: rotateY(180deg); }
.mem-face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; backface-visibility: hidden; -webkit-backface-visibility: hidden; border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); overflow: hidden; }
.mem-back { background: repeating-linear-gradient(45deg, #5ec27a 0 10px, #4cb860 10px 20px); font-size: 34px; color: #fff; }
.mem-front { background: #fff; transform: rotateY(180deg); padding: 4px; }
.mem-front .pic { height: 62%; }
.mem-front .mem-word { font-family: var(--font-en); font-weight: 900; font-size: clamp(16px, 4.6vw, 24px); }
.mem-card.matched .mem-front { background: #c8f5d4; border-color: var(--good); }
.mem-card.matched { animation: pop .4s; }
.mem-card.bad .mem-front { background: #ffd4d4; border-color: var(--bad); }
.mem-note { text-align: center; font-weight: 900; font-size: 18px; }

/* 開始卡與倒數 */
.overlay { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(255, 248, 225, .82); }
.start-card { width: min(420px, 100%); text-align: center; background: #fff; border: 3px solid var(--ink); border-radius: 28px; box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.start-card .lv { font-size: 16px; font-weight: 900; color: var(--orange); letter-spacing: .1em; }
.start-card h2 { margin: 0; font-size: 30px; }
.start-card p { margin: 0; color: var(--ink-soft); font-weight: 700; }
.start-card .mascot { width: 110px; height: 110px; }
.countdown { font-family: var(--font-en); font-size: clamp(90px, 28vw, 180px); font-weight: 900; color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 8px 0 var(--ink); animation: pop .6s; }

/* 結算 */
.result { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; max-width: 520px; margin: 0 auto; }
.result-card { width: 100%; background: rgba(255, 255, 255, .94); border: 3px solid var(--ink); border-radius: 28px; box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.result h2 { margin: 0; font-size: 30px; }
.result .mascot { width: 120px; height: 120px; }
.big-stars { display: flex; gap: 6px; font-size: 54px; line-height: 1; }
.big-stars span { display: inline-block; filter: grayscale(1) opacity(.3); transform: scale(.6); transition: transform .4s cubic-bezier(.3, 1.8, .5, 1), filter .3s; }
.big-stars span.on { filter: none; transform: scale(1); }
.result-score { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; }
.result-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-weight: 800; color: var(--ink-soft); }
.new-best { padding: 2px 12px; background: var(--berry); color: #fff; border-radius: 999px; font-weight: 900; animation: pop .5s; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* 對話框 */
.modal-root { position: absolute; inset: 0; z-index: 50; pointer-events: none; }
.modal-backdrop { position: absolute; inset: 0; display: grid; place-items: center; padding: 14px; background: rgba(74, 52, 38, .45); pointer-events: auto; overflow-y: auto; }
.modal { width: min(460px, 100%); max-height: 100%; overflow-y: auto; background: #fffdf4; border: 3px solid var(--ink); border-radius: 26px; box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 12px; animation: pop .3s; }
.modal h2 { margin: 0; font-size: 24px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.setting-row { display: grid; grid-template-columns: 6.5em 1fr 3em; align-items: center; gap: 10px; font-weight: 800; }
.setting-row output { text-align: right; font-variant-numeric: tabular-nums; }
.setting-row.toggle { grid-template-columns: 1fr auto; }
.setting-row input[type="range"] { width: 100%; height: 34px; accent-color: var(--leaf); }
.setting-row input[type="checkbox"] { width: 30px; height: 30px; accent-color: var(--leaf); }
.install-steps { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.install-steps svg { width: 22px; height: 22px; vertical-align: -5px; }
.confirm-box { padding: 10px 12px; background: #ffe9e0; border: 3px solid var(--bad); border-radius: 16px; display: flex; flex-direction: column; gap: 10px; font-weight: 800; }

/* 提示、特效 */
.toast-root { position: absolute; left: 0; right: 0; top: calc(var(--topbar-h) + 8px); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { max-width: 100%; padding: 10px 18px; background: #fff; border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink); font-weight: 900; font-size: 18px; text-align: center; animation: toast-in .3s, toast-out .4s 2.6s forwards; }
.toast.secret { background: linear-gradient(90deg, #ffe27a, #ffb3d1, #9de3ff); font-size: 22px; }
@keyframes toast-in { from { transform: translateY(-20px) scale(.9); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(-14px); opacity: 0; } }
.fx-layer { position: fixed; inset: 0; z-index: 90; pointer-events: none; overflow: hidden; }
.fx-bit { position: absolute; left: 0; top: 0; font-size: 22px; line-height: 1; will-change: transform, opacity; }
.fx-float { position: absolute; left: 0; top: 0; font-weight: 900; font-size: 26px; color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; white-space: nowrap; will-change: transform, opacity; }
.fx-flash { position: absolute; inset: 0; opacity: 0; }

@keyframes pop { 0% { transform: scale(.85); } 60% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }

/* ---------- 動畫減弱（系統設定或遊戲設定）：保留顏色與圖示回饋，移除移動 ---------- */
html[data-reduce-motion="true"] *, html[data-reduce-motion="true"] *::before, html[data-reduce-motion="true"] *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- 響應式 ---------- */
@media (max-width: 480px) {
  .level-grid { gap: 6px; }
  .level-btn { min-height: 104px; padding: 6px 2px; }
  .level-btn .name { font-size: 12px; }
  .opt { min-height: 96px; }
  .opt .pic { height: 72px; }
  .mascot { width: 52px; height: 52px; }
  .modal { padding: 12px; }
}
@media (min-width: 760px) {
  .opt { min-height: 140px; }
  .opt .pic { height: 108px; }
  .opt .pic-emoji { font-size: 88px; }
  .options { max-height: 400px; }
  .options { gap: 14px; }
  .options[data-n="4"] { grid-template-columns: repeat(4, 1fr); }
  .options[data-n="5"] { grid-template-columns: repeat(5, 1fr); }
  .options[data-n="3"] { grid-template-columns: repeat(3, 1fr); }
  .visual .pic { height: min(190px, 26vh); }
  .memory { grid-template-columns: repeat(6, 1fr); }
}
/* 手機橫向或低高度：問題在左、選項在右 */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --topbar-h: 44px; }
  .topbar { padding-top: max(3px, env(safe-area-inset-top, 0px)); padding-bottom: 3px; }
  .icon-btn { width: 40px; height: 40px; border-radius: 13px; }
  .site-footer { padding-top: 3px; padding-bottom: calc(3px + env(safe-area-inset-bottom, 0px)); font-size: 11px; }
  .screen { padding-top: 2px; padding-bottom: 6px; }
  .hud-chip { min-height: 30px; font-size: 14px; }
  .hud-score { font-size: 17px; }
  .timerbar { height: 10px; }
  .stage { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 8px; align-items: start; }
  .stage-left { grid-column: 1; }
  .stage-main { grid-column: 2; }
  .stage.single { display: flex; }
  .mascot { width: 44px; height: 44px; }
  .bubble-en { font-size: 22px; }
  .visual { min-height: 80px; }
  .visual .pic { height: min(110px, 30vh); }
  .opt { min-height: 78px; }
  .opt .pic { height: 52px; }
  .opt .pic-emoji { font-size: 40px; }
  .opt .opt-label { font-size: 16px; }
  .hole { height: 88px; }
  .fall-area { min-height: 160px; }
  .body-fig { height: min(60vh, 230px); }
  .memory { grid-template-columns: repeat(6, 1fr); gap: 5px; max-width: min(720px, calc((100dvh - 180px) * 2.8)); }
  .mem-back { font-size: 24px; }
  .mem-note { font-size: 15px; }
  .mem-front .mem-word { font-size: clamp(14px, 2.6vw, 20px); }
  /* 句子排序：題目在左、格子與積木在右，積木不會被擠到畫面外 */
  .order-wrap { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); grid-auto-rows: auto; gap: 6px 10px; align-content: start; }
  .order-wrap .prompt-row { grid-column: 1; grid-row: 1 / span 4; align-self: start; }
  .order-wrap > :not(.prompt-row) { grid-column: 2; }
  .slots { min-height: 62px; padding: 6px; }
  .tile { min-height: 46px; font-size: 19px; padding: 4px 12px; }
  .order-hint { font-size: 13px; }
  .menu { flex-direction: row; flex-wrap: wrap; gap: 8px 24px; }
  .menu-mascot { width: 110px; }
  .start-card { padding: 10px; gap: 4px; }
  .start-card .mascot { width: 64px; height: 64px; }
  .start-card h2 { font-size: 22px; }
  .result .mascot { width: 70px; height: 70px; }
  .big-stars { font-size: 38px; }
  .result-score { font-size: 28px; }
}
