/* 星光精靈寶盒：樣式（淺色／深色、手機優先） */
:root {
  --bg: #fff6fb;
  --bg2: #f1e9ff;
  --surface: #ffffff;
  --surface2: #faf5ff;
  --text: #3a2a4d;
  --muted: #6f6083;
  --primary: #7c4ef0;
  --primary-ink: #ffffff;
  --accent: #ff4f87;
  --border: #e6d9f5;
  --input-bg: #ffffff;
  --input-text: #3a2a4d;
  --focus: #009e9e;
  --ok: #2e9b4f;
  --shadow: 0 6px 18px rgba(80, 40, 140, .12);
  --sky1: #ffe9f4;
  --sky2: #dcd0ff;
  --grass: #b9eab0;
  --drop: #e9fbff;
  --drop-border: #00a0b4;
  --sil: #c9bedb;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15112a;
  --bg2: #1d1738;
  --surface: #251e42;
  --surface2: #2d2550;
  --text: #f4eeff;
  --muted: #bdb0dc;
  --primary: #a98bff;
  --primary-ink: #170f33;
  --accent: #ff7aa6;
  --border: #40356b;
  --input-bg: #1b1633;
  --input-text: #f4eeff;
  --focus: #4fe0e0;
  --ok: #6ee08e;
  --shadow: 0 6px 18px rgba(0, 0, 0, .45);
  --sky1: #221a4a;
  --sky2: #0e0b22;
  --grass: #23503a;
  --drop: #10394a;
  --drop-border: #4fe0e0;
  --sil: #4a4070;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  color: var(--text);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--surface); padding: 8px 12px; border-radius: 10px; }

/* 頂部 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 19px; }
.brand-star { color: #ffb300; font-size: 22px; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.star-count { font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 20px;
}
.icon-btn[aria-pressed="false"] { opacity: .6; }

main { max-width: 960px; margin: 0 auto; padding: 12px 16px; }
.screen-title { margin: 6px 0 2px; font-size: 26px; text-align: center; }
.hint { text-align: center; color: var(--muted); margin: 4px 0 12px; }
.sub-title { font-size: 19px; margin: 24px 0 8px; }

/* 按鈕 */
.btn {
  min-height: 48px; padding: 10px 18px; border-radius: 16px; border: 2px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 700; box-shadow: var(--shadow);
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.big { display: block; margin: 14px auto 6px; font-size: 20px; padding: 14px 26px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 15px; border-radius: 12px; box-shadow: none; }
.row-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }

/* 寶盒 */
.box-stage { position: relative; width: min(92vw, 420px); aspect-ratio: 300 / 260; margin: 0 auto; touch-action: none; user-select: none; }
.treasure { width: 100%; height: 100%; display: block; overflow: visible; }
.treasure .lid { transform-box: fill-box; transform-origin: 50% 100%; transition: transform .8s cubic-bezier(.3, 1.6, .5, 1); }
.treasure .rays { opacity: 0; transition: opacity .6s; }
.box-stage.open .lid { transform: translateY(-34px) rotate(-14deg); }
.box-stage.open .rays { opacity: 1; animation: pulse 1.4s ease-in-out infinite; }
.box-stage:not(.open) .treasure { animation: wiggle 3s ease-in-out infinite; }
.trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: auto; }
.progress-line { text-align: center; font-weight: 700; }
.sparkle { position: absolute; pointer-events: none; font-size: 22px; animation: fly 1.1s ease-out forwards; }
@keyframes wiggle { 0%, 88%, 100% { transform: rotate(0); } 92% { transform: rotate(-2deg); } 96% { transform: rotate(2deg); } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes fly { from { opacity: 1; transform: translate(0, 0) scale(.6); } to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.3); } }

/* 草原 */
.field {
  position: relative; height: min(62vh, 520px); min-height: 360px; border-radius: 24px; overflow: hidden;
  background: radial-gradient(circle at 20% 15%, rgba(255,255,255,.7) 0 2px, transparent 3px),
              radial-gradient(circle at 70% 25%, rgba(255,255,255,.7) 0 2px, transparent 3px),
              radial-gradient(circle at 45% 8%, rgba(255,255,255,.8) 0 1.5px, transparent 2.5px),
              linear-gradient(180deg, var(--sky2) 0%, var(--sky1) 62%, var(--grass) 62%, var(--grass) 100%);
  border: 2px solid var(--border); box-shadow: var(--shadow);
}
.moon { position: absolute; right: 18px; top: 16px; width: 54px; height: 54px; border-radius: 50%; background: #fff3b0; box-shadow: 0 0 24px #fff3b0; }
.moon::after { content: ""; position: absolute; left: 14px; top: -6px; width: 50px; height: 50px; border-radius: 50%; background: var(--sky2); }
.bush { position: absolute; bottom: 0; width: 34%; height: 18%; border-radius: 50% 50% 0 0; background: color-mix(in srgb, var(--grass) 70%, #2d7a3e); }
.bush.b1 { left: -6%; } .bush.b2 { left: 36%; height: 13%; } .bush.b3 { right: -6%; height: 16%; }
.wild {
  position: absolute; width: 96px; height: 96px; padding: 0; border: none; background: none; cursor: pointer;
  transition: left 1.8s ease-in-out, top 1.8s ease-in-out; transform: translate(-50%, -50%);
  filter: drop-shadow(0 6px 6px rgba(0,0,0,.18));
}
.wild .sprite-svg { width: 100%; height: 100%; animation: bob 1.2s ease-in-out infinite; }

.wild.caught { transition: all .7s ease-in; opacity: 0; transform: translate(-50%, -50%) scale(.2); }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* 對話框 */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(20, 10, 40, .55); display: grid; place-items: center; padding: 16px; }
.modal-back[hidden] { display: none; }
.modal {
  width: min(100%, 460px); max-height: 92vh; overflow: auto; background: var(--surface); color: var(--text);
  border-radius: 24px; padding: 20px; box-shadow: var(--shadow); border: 2px solid var(--border); text-align: center;
  animation: popIn .25s ease-out;
}
.modal h2 { margin: 4px 0 10px; font-size: 23px; }
.modal .q { font-size: 22px; font-weight: 800; margin: 8px 0 14px; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choice { min-height: 64px; font-size: 26px; font-weight: 800; border-radius: 18px; border: 3px solid var(--border); background: var(--surface2); cursor: pointer; }
.choice.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 22%, var(--surface)); }
.choice.wrong { animation: shake .4s; }
.stars-board { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 10px; border-radius: 16px; background: var(--surface2); font-size: 28px; line-height: 1; min-height: 90px; }
.pattern { font-size: 34px; letter-spacing: 4px; padding: 8px; border-radius: 16px; background: var(--surface2); }
.lights { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; max-width: 260px; margin: 10px auto; }
.light { height: 84px; border-radius: 22px; border: 3px solid rgba(0,0,0,.12); cursor: pointer; opacity: .5; transition: opacity .1s, transform .1s; }
.light.on { opacity: 1; transform: scale(1.06); box-shadow: 0 0 18px currentColor; }
.light:disabled { cursor: default; }
.big-sprite { display: grid; place-items: center; margin: 4px auto; }
.big-sprite .sprite-svg { width: 180px; height: 180px; }
.reveal .sprite-svg { animation: popIn .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes popIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.modal .actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 14px; }
.modal input[type="text"] {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--border);
  background: var(--input-bg); color: var(--input-text); font-size: 18px;
}
.modal input[type="text"]:focus { border-color: var(--focus); outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent); background: var(--input-bg); color: var(--input-text); }

/* 小屋 */
.house-sprite .sprite-svg { width: 200px; height: 200px; transition: transform .2s; }
.house-sprite.bounce .sprite-svg { animation: bounce .6s; }
.house-sprite.spin .sprite-svg { animation: spin .9s ease-in-out; }
.house-sprite.munch .sprite-svg { animation: munch .5s 2; }
@keyframes bounce { 30% { transform: translateY(-26px) scaleY(1.05); } 60% { transform: translateY(0) scaleY(.92); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes munch { 50% { transform: scale(1.08, .92); } }
.love { font-size: 22px; letter-spacing: 2px; }
.tag { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 9px; border-radius: 999px; color: #fff; }
.rar { color: #e0a000; font-size: 14px; }
:root[data-theme="dark"] .rar { color: #ffd257; }
.desc { color: var(--muted); margin: 6px 0; }

/* 工具列 */
.toolbar { display: grid; gap: 8px; margin: 8px 0; }
.tb-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tb-row.meta { justify-content: space-between; color: var(--muted); font-size: 15px; }
.seg { display: inline-flex; border: 2px solid var(--border); border-radius: 14px; overflow: hidden; }
.seg button { min-height: 44px; padding: 0 12px; border: none; background: var(--surface); cursor: pointer; font-weight: 700; }
.seg button[aria-checked="true"] { background: var(--primary); color: var(--primary-ink); }
.toolbar select, .toolbar input {
  min-height: 44px; padding: 8px 12px; border-radius: 14px; border: 2px solid var(--border);
  background: var(--input-bg); color: var(--input-text);
}
.toolbar select:focus, .toolbar input:focus { border-color: var(--focus); outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent); background: var(--input-bg); color: var(--input-text); }
.toolbar select option { background: var(--input-bg); color: var(--input-text); }
#searchBox { flex: 1 1 180px; min-width: 0; }
.drag-tip { font-size: 14px; color: var(--muted); margin: 4px 0 8px; }

/* 群組與卡片 */
.group { margin: 10px 0 16px; border-radius: 20px; background: color-mix(in srgb, var(--surface) 55%, transparent); border: 2px dashed transparent; padding: 6px; }
.group.drop-on { border-color: var(--drop-border); background: var(--drop); }
.group-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px; }
.group-head .gname { font-weight: 800; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-head .gcount { color: var(--muted); font-size: 14px; }
.collapse-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; min-height: 64px; }
.cards.list { grid-template-columns: 1fr; }
.cards:empty::before { content: "把精靈卡片拖到這裡"; display: grid; place-items: center; min-height: 64px; border: 2px dashed var(--border); border-radius: 16px; color: var(--muted); font-size: 14px; grid-column: 1 / -1; }
.card {
  position: relative; background: var(--surface); border: 2px solid var(--border); border-radius: 20px; padding: 10px;
  box-shadow: var(--shadow); text-align: center; touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab;
  -webkit-touch-callout: none;
}
.card:focus-visible { outline: 3px solid var(--focus); }
.card .sprite-svg { width: 96px; height: 96px; pointer-events: none; }
.card .cname { font-weight: 800; font-size: 18px; }
.card .crow { display: flex; justify-content: center; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.card .cactions { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.cards.list .card { display: grid; grid-template-columns: 56px 1fr auto; text-align: left; align-items: center; gap: 10px; padding: 6px 10px; }
.cards.list .card .sprite-svg { width: 56px; height: 56px; }
.cards.list .card .crow { justify-content: flex-start; }
.cards.list .card .cactions { margin: 0; }
.cards.list .card .cdesc { display: none; }
.card.lifted { outline: 3px solid var(--focus); transform: scale(1.04); }
.card.placeholder { opacity: .35; border-style: dashed; border-color: var(--drop-border); background: var(--drop); }
.drag-ghost { position: fixed; z-index: 60; pointer-events: none; transform: rotate(3deg) scale(1.05); box-shadow: 0 14px 30px rgba(0,0,0,.3); opacity: .95; cursor: grabbing; }
.card .new-badge { position: absolute; top: 6px; left: 8px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; padding: 1px 7px; border-radius: 999px; }
body.dragging { cursor: grabbing; user-select: none; }
body.dragging .card { cursor: grabbing; }
mark { background: #fff07a; color: #3a2a4d; border-radius: 4px; padding: 0 2px; }
.unknown { display: flex; flex-wrap: wrap; gap: 8px; color: var(--sil); }
.unknown .sprite-svg { width: 64px; height: 64px; }
.unknown-item { display: grid; justify-items: center; font-size: 13px; color: var(--muted); }

/* 選單 */
.menu { display: grid; gap: 8px; text-align: left; }
.menu button { min-height: 48px; text-align: left; padding: 8px 14px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface2); cursor: pointer; font-weight: 700; }
.menu button.danger { color: #d0304f; }
:root[data-theme="dark"] .menu button.danger { color: #ff8aa0; }

/* 下方選單 */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button { min-height: 64px; border: none; background: none; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 14px; color: var(--muted); }
.bottom-nav button span { font-size: 24px; line-height: 1; }
.bottom-nav button[aria-current="page"] { color: var(--primary); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 16px; font-weight: 700; box-shadow: var(--shadow);
  display: flex; gap: 10px; align-items: center; max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.toast button { background: none; border: none; color: var(--accent); font-weight: 800; cursor: pointer; min-height: 36px; text-decoration: underline; }
:root[data-theme="light"] .toast button { color: #ffb3cd; }

@media (min-width: 720px) {
  .wild { width: 120px; height: 120px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.sprite-svg.silhouette { color: var(--sil); }
.glow { animation: pulse 1.2s ease-in-out infinite; }

/* ===== 3D 版新增 ===== */
.stage-wrap { position: relative; margin: 0 auto; border-radius: 24px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage-wrap .stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-wrap.home { width: min(100%, 520px); aspect-ratio: 1 / 0.92; background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--surface) 80%, #fff3c0) 0%, transparent 70%); }
.stage-wrap.home .trail { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; }
.stage-wrap.field { width: 100%; height: min(72vh, 700px); min-height: 420px; cursor: grab; border: 2px solid var(--border); box-shadow: var(--shadow);
  background: linear-gradient(180deg, var(--sky2) 0%, var(--sky1) 100%); }
.stage-wrap.show { width: 100%; height: min(34vh, 300px); min-height: 200px; background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--surface2) 70%, #ffe7f3) 0%, var(--surface2) 75%); border-radius: 20px; }
:root[data-theme="dark"] .stage-wrap.show { background: radial-gradient(circle at 50% 35%, #3b2f6a 0%, var(--surface2) 75%); }
.modal.wide { width: min(100%, 560px); }
.big-word { display: block; font-size: 34px; font-weight: 900; letter-spacing: 1px; color: var(--primary); font-family: "Avenir Next", "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif; }
.word-line .big-word { display: inline; font-size: 28px; }
.big-icon { display: block; font-size: 64px; line-height: 1.1; }
.choices .choice { font-size: 40px; }
.choices.words .choice { font-size: 22px; font-family: "Avenir Next", "Nunito", system-ui, sans-serif; }
.subtitle { min-height: 3em; margin: 6px 0; padding: 8px 12px; border-radius: 14px; background: var(--surface2); }
.subtitle strong { font-size: 19px; color: var(--primary); }
.pet-name { margin: 6px 0 2px; }
.house-actions .btn { min-width: 44%; }
.card .thumb { width: 110px; height: 110px; display: block; margin: 0 auto; pointer-events: none; -webkit-user-drag: none; }
.cards.list .card { grid-template-columns: 64px 1fr auto; }
.cards.list .card .thumb { width: 64px; height: 64px; }
.card .cword { font-size: 15px; }
.card .cword b { color: var(--primary); font-size: 17px; }
.card .cdesc { font-size: 13px; color: var(--muted); margin-top: 4px; }
.cards.list .card .cdesc { display: none; }
.cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.theme-progress { display: grid; grid-template-columns: 130px 1fr 56px; gap: 8px; align-items: center; width: 100%; font-size: 14px; color: var(--muted); }
.unknown { display: grid; gap: 8px; }
.bar { height: 12px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffb3d1, var(--primary)); border-radius: 999px; }

.stage-wrap.home.opened .trail { pointer-events: none; }
.stage-wrap.home.opened { cursor: pointer; }

/* ===== 公主、英文課、聊天 ===== */
.stage-wrap.show.princess { height: min(40vh, 340px); }
.daily { margin: 10px auto 0; max-width: 520px; padding: 10px 14px; border-radius: 16px; background: var(--surface2); border: 1px solid var(--border); text-align: center; }
.daily:empty { display: none; }
.lesson, .lesson-sent { display: grid; gap: 8px; margin: 10px 0; text-align: left; }
.lesson-word { display: grid; grid-template-columns: 44px 1fr auto auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px; background: var(--surface2); border: 1px solid var(--border); }
.lesson-sent .lesson-word { grid-template-columns: 1fr auto; }
.lesson-word .li { font-size: 30px; text-align: center; }
.lesson-word .lw b { display: block; font-size: 20px; color: var(--primary); font-family: "Avenir Next", "Nunito", system-ui, sans-serif; }
.lesson-word .lw small { color: var(--muted); }
.mic.recording { background: #ff5d8f; color: #fff; border-color: #ff5d8f; }
.quiz-bar { height: 10px; border-radius: 999px; background: var(--surface2); overflow: hidden; margin: 4px 0 8px; }
.quiz-bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffb3d1, var(--primary)); }
.chat-box:empty { display: none; }
.chat-box { margin-top: 10px; text-align: left; }
.chat-log { max-height: 34vh; overflow-y: auto; display: grid; gap: 8px; padding: 6px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 16px; }
.bubble b { display: block; font-size: 17px; }
.bubble small { color: var(--muted); }
.bubble.me { justify-self: end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.bubble.me small { color: inherit; }
.bubble.her { justify-self: start; background: var(--surface2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.typing { letter-spacing: 3px; animation: pulse 1s infinite; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 2px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 700; color: var(--text); }
.chat-input { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.chat-input input { min-height: 44px; padding: 8px 12px; border-radius: 14px; border: 2px solid var(--border); background: var(--input-bg); color: var(--input-text); font-size: 16px; min-width: 0; }
.chat-input input:focus { border-color: var(--focus); outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent); background: var(--input-bg); color: var(--input-text); }
.card .thumb.princess { object-fit: contain; background: radial-gradient(circle, color-mix(in srgb, var(--surface2) 60%, #ffe3f3), transparent 70%); border-radius: 16px; }

/* ===== 登入門、小朋友檔案 ===== */
body.gated { overflow: hidden; }
body.gated .bottom-nav, body.gated .topbar .top-actions { visibility: hidden; }
.gate { position: fixed; inset: 0; z-index: 40; overflow-y: auto; padding: calc(16px + env(safe-area-inset-top)) 16px 32px;
  background: radial-gradient(circle at 50% 0%, #b48cff 0%, transparent 55%), linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%); }
:root[data-theme="dark"] .gate { background: radial-gradient(circle at 50% 0%, #4b3394 0%, transparent 55%), linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%); }
.gate[hidden] { display: none; }
.gate-card { max-width: 480px; margin: 24px auto; background: var(--surface); border: 2px solid var(--border); border-radius: 28px; padding: 24px 20px; text-align: center; box-shadow: var(--shadow); }
.gate-card.wide { max-width: 760px; }
.gate-logo { border-radius: 28px; box-shadow: var(--shadow); }
.gate-card h1 { margin: 10px 0 6px; font-size: 28px; }
.gate-sub { color: var(--muted); margin: 0 0 12px; }
.gate-list { text-align: left; display: inline-block; margin: 0 0 12px; padding-left: 0; list-style: none; }
.gate-list li { margin: 4px 0; }
.gate-note { background: var(--surface2); border-radius: 14px; padding: 10px 12px; }
.gsi-btn { display: flex; justify-content: center; min-height: 48px; align-items: center; margin: 14px 0; color: var(--muted); }
.gate-legal { font-size: 13px; color: var(--muted); }
.gate-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; text-align: left; }
.gate-actions { display: flex; gap: 6px; }
.kid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 14px 0; }
.kid-card { position: relative; display: grid; justify-items: center; gap: 4px; padding: 12px 8px; border-radius: 22px; border: 2px solid var(--border);
  background: var(--surface2); color: var(--text); cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: pan-y; -webkit-touch-callout: none; font: inherit; }
.kid-card img { width: 96px; height: 128px; object-fit: contain; pointer-events: none; }
.kid-card b { font-size: 18px; }
.kid-card:hover, .kid-card:focus-visible { border-color: var(--primary); }
.kid-card.dragging { outline: 3px dashed var(--drop-border); background: var(--drop); transform: scale(1.04); }
.kid-card.add { justify-content: center; align-content: center; min-height: 170px; border-style: dashed; }
.kid-card.add span { font-size: 40px; color: var(--primary); }
.kid-acts { position: absolute; top: 6px; right: 6px; }
.gate-danger { margin-top: 18px; text-align: left; color: var(--muted); }
.btn.danger, .btn.small.danger { color: #fff; background: #d0304f; border-color: #d0304f; }
.kid-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 2px 10px 2px 2px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer; font-weight: 700; max-width: 140px; }
.kid-chip img { width: 36px; height: 40px; object-fit: contain; }
.kid-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatar-pick button { padding: 2px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface2); cursor: pointer; }
.avatar-pick button[aria-checked="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent); }
.avatar-pick img { width: 100%; height: 58px; object-fit: contain; }
.modal label { display: block; text-align: left; margin: 6px 0; font-weight: 700; }
.rep { text-align: left; border-top: 1px solid var(--border); padding-top: 8px; }
.rep h3 { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.rep h3 img { width: 36px; height: 44px; object-fit: contain; }
.rep table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rep th, .rep td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: left; }
@media (max-width: 420px) {
  .brand span:last-child { display: none; }
  .kid-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ===== 寶盒色彩（美術規格：奶油陶瓷＋夜空靛藍＋香檳金） ===== */
:root { --box-body: #FFF1DC; --box-lid: #4B4FB0; --box-gold: #F2C766; --box-glow: #FFF3B0; }
:root[data-theme="dark"] { --box-body: #FFE8CC; --box-lid: #5A5FCC; --box-gold: #FFD877; --box-glow: #FFE98A; }

/* ===== 變身 ===== */
.transform { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--g) 55%, #fff) 0%, #1d1450 70%); color: #fff; text-align: center; padding: 16px; }
.tf-stage { position: relative; z-index: 2; display: grid; justify-items: center; gap: 12px; max-width: 420px; }
.tf-step { font-size: 22px; font-weight: 800; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.tf-box { width: 180px; height: 170px; border: none; background: none; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .08s; display: grid; justify-items: center; }
.tf-box svg { width: 160px; height: 160px; filter: drop-shadow(0 0 18px var(--box-glow)); }
.tf-meter { display: block; width: 160px; height: 14px; border-radius: 999px; background: rgba(255,255,255,.25); overflow: hidden; margin-top: 6px; }
.tf-meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fff3b0, var(--g)); }
.tf-chant { font-size: 24px; background: rgba(0,0,0,.25); padding: 10px 16px; border-radius: 16px; }
.tf-chant small { font-size: 15px; }
.tf-items { display: flex; gap: 14px; min-height: 110px; }
.tf-item { display: grid; justify-items: center; gap: 4px; animation: popIn .5s cubic-bezier(.3,1.6,.5,1); }
.tf-item svg { width: 84px; height: 84px; filter: drop-shadow(0 0 12px #fff); }
.tf-item span { font-weight: 800; font-size: 15px; }
.tf-ribbons { position: absolute; inset: -20%; z-index: 1; opacity: 0; transition: opacity .4s; }
.tf-ribbons i { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(from 0deg, transparent 0 20%, var(--g) 25%, transparent 32% 55%, #fff3b0 60%, transparent 67%); filter: blur(8px); }
.tf-ribbons i:nth-child(2) { inset: 12%; animation-direction: reverse; }
.tf-ribbons i:nth-child(3) { inset: 25%; }
.transform.spin .tf-ribbons { opacity: .85; }
.transform.spin .tf-ribbons i { animation: spinR 2.4s linear infinite; }
@keyframes spinR { to { transform: rotate(360deg); } }
.tf-final h2 { font-size: 30px; margin: 6px 0; }
.tf-final .desc { color: #f2ecff; }
.tf-hero { display: flex; justify-content: center; gap: 8px; }
.tf-hero svg { width: 110px; height: 110px; filter: drop-shadow(0 0 16px #fff); animation: bob 1.4s ease-in-out infinite; }
.tf-skip { position: absolute; z-index: 3; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); color: var(--text); background: var(--surface); }

/* ===== 雷達畫面 ===== */
.guardian-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 20px; border: 2px solid var(--border);
  background: linear-gradient(120deg, color-mix(in srgb, var(--g, #b48cff) 22%, var(--surface)), var(--surface)); margin: 8px 0 14px; }
.guardian-card .gc-icons { display: flex; }
.guardian-card svg { width: 54px; height: 54px; }
.guardian-card > div:nth-child(2) { flex: 1; }
.radar-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.mode-card { display: grid; justify-items: center; gap: 4px; padding: 18px 12px; min-height: 140px; border-radius: 22px; border: 2px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font: inherit; box-shadow: var(--shadow); }
.mode-card span { font-size: 42px; }
.mode-card b { font-size: 20px; }
.mode-card small { color: var(--muted); }
.mode-card:focus-visible, .mode-card:hover { border-color: var(--primary); }

/* ===== AR 疊層（雷達、相機） ===== */
.ar-overlay { position: fixed; inset: 0; z-index: 85; background: #0d0a24; color: #fff; display: grid; overflow: hidden; }
.radar-ov { grid-template-rows: auto auto 1fr auto auto auto; justify-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); text-align: center;
  background: radial-gradient(circle at 50% 40%, #2a1f5c, #0d0a24 75%); }
.radar-top, .ar-top { display: flex; justify-content: space-between; align-items: center; width: 100%; gap: 8px; font-size: 18px; }
.radar-safe { background: rgba(255,200,80,.18); border: 1px solid rgba(255,200,80,.5); border-radius: 12px; padding: 8px 10px; font-size: 14px; margin: 0; }
.radar { width: min(86vw, 52vh, 420px); aspect-ratio: 1; touch-action: none; align-self: center; }
.radar-hint { margin: 0; color: #e8e0ff; }
.radar-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; font-size: 14px; }
.radar-list span { padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.12); }
.radar-list span.on { background: #ffd23f; color: #3a2a4d; font-weight: 800; }
.cam-ov { background: linear-gradient(180deg, #8fb6ff, #ffd9ec); }
.cam-ov .ar-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-ov.no-cam .ar-video { display: none; }
.cam-ov .ar-gl { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.ar-hud { position: absolute; inset: 0; pointer-events: none; display: grid; grid-template-rows: auto 1fr auto; padding: calc(12px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom)); }
.ar-hud button, .ar-hud .ar-bottom { pointer-events: auto; }
.ar-top b { text-shadow: 0 2px 6px rgba(0,0,0,.6); }
.ar-msg { align-self: end; justify-self: center; margin: 0 0 10px; padding: 8px 14px; border-radius: 14px; background: rgba(20,12,50,.6); font-weight: 700; text-align: center; max-width: 92%; }
.ar-bottom { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.wand-charge { width: 160px; height: 14px; border-radius: 999px; background: rgba(255,255,255,.3); overflow: hidden; }
.wand-charge i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fff3b0, #ffc21a); transition: width .2s; }
.cam-ov.captured .ar-msg { background: rgba(255,210,63,.85); color: #3a2a4d; }
.xr-dom { position: fixed; inset: 0; z-index: 95; pointer-events: none; color: #fff; padding: 16px; display: grid; grid-template-rows: auto 1fr auto; }
.xr-dom button { pointer-events: auto; }
.xr-dom .ar-msg { align-self: end; }
.modal .check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin-top: 10px; }
.modal .check input { width: 22px; height: 22px; flex: none; }

@media (prefers-reduced-motion: reduce) {
  .transform.spin .tf-ribbons i, .tf-hero svg { animation: none !important; }
}

/* AR 疊層裡的按鈕：白底要配深色字，避免白底白字 */
.ar-overlay .btn:not(.primary), .xr-dom .btn:not(.primary) { color: var(--text); background: var(--surface); }

/* =====================================================================
   寶盒外殼（整個 App 就是一個 3D 的星光寶盒）
   圓頂＝頁首、盒身＝內容、金色盒緣＋寶石＝導覽；外面是星空。
   ===================================================================== */
:root {
  --shell-w: min(100vw, 560px);
  --gold-1: #fff3c4; --gold-2: #f2c766; --gold-3: #c9922e; --gold-4: #8a5a17;
  --dome-1: #6d73e0; --dome-2: #4B4FB0; --dome-3: #2c2f7a;
  --body-1: #fffaf1; --body-2: #FFF1DC; --body-3: #ecd6b8;   /* 奶油陶瓷內壁 */
  --ink: #3a2a4d;
}
:root[data-theme="dark"] {
  --body-1: #3a2d63; --body-2: #2a2150; --body-3: #1c1638;   /* 絨布內襯 */
}
html, body { height: 100%; }
body { overflow: hidden; padding-bottom: 0; background: #0f0b2a; }
.night-sky { position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 28% 72%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70% 12%, #fff6c8 50%, transparent 51%), radial-gradient(1px 1px at 86% 64%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 52% 88%, #fff6c8 50%, transparent 51%), radial-gradient(1px 1px at 92% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 52%, #fff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 40% 40%, #fff 50%, transparent 51%),
    radial-gradient(ellipse at 50% 110%, #6a4fc9 0%, transparent 60%), radial-gradient(ellipse at 50% -10%, #3b2f8f 0%, transparent 55%),
    linear-gradient(180deg, #16113a, #0f0b2a); }
.night-sky::after { content: ""; position: absolute; inset: 0; background: inherit; opacity: .6; animation: twinkle 4s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: .25; } to { opacity: .8; } }

.app-box { position: relative; z-index: 1; width: var(--shell-w); height: 100dvh; margin: 0 auto;
  display: grid; grid-template-rows: auto 1fr auto; perspective: 1400px;
  filter: drop-shadow(0 24px 40px rgba(0,0,0,.55)); }

/* ---------- 圓頂頁首 ---------- */
.topbar { position: relative; z-index: 3; display: flex; align-items: flex-end; justify-content: space-between;
  min-height: 104px; padding: calc(30px + env(safe-area-inset-top)) 18px 14px; border: none; backdrop-filter: none;
  color: #fff;
  background:
    radial-gradient(ellipse 60% 70% at 35% 25%, rgba(255,255,255,.28), transparent 60%),
    radial-gradient(1px 1px at 20% 40%, #fff6c8 60%, transparent 61%), radial-gradient(1px 1px at 62% 30%, #fff6c8 60%, transparent 61%),
    radial-gradient(1.5px 1.5px at 80% 55%, #fff6c8 60%, transparent 61%), radial-gradient(1px 1px at 44% 62%, #fff6c8 60%, transparent 61%),
    linear-gradient(180deg, var(--dome-1), var(--dome-2) 55%, var(--dome-3));
  border-radius: 50% 50% 18px 18px / 64px 64px 18px 18px;
  box-shadow: inset 0 -10px 18px rgba(0,0,0,.35), inset 0 6px 14px rgba(255,255,255,.25), 0 -1px 0 var(--gold-2);
  margin-top: 26px; }
.topbar::after { /* 圓頂下緣的金邊 */
  content: ""; position: absolute; left: -6px; right: -6px; bottom: -10px; height: 16px; border-radius: 10px;
  background: linear-gradient(180deg, var(--gold-1), var(--gold-2) 40%, var(--gold-3) 80%, var(--gold-4));
  box-shadow: 0 2px 0 rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.7); }
.finial { position: absolute; left: 50%; top: -24px; width: 52px; height: 58px; transform: translateX(-50%); pointer-events: none;
  background: radial-gradient(circle at 50% 38%, rgba(255,246,176,.9), transparent 62%); }
.finial::before { content: ""; position: absolute; left: 50%; top: 2px; width: 38px; height: 38px; transform: translateX(-50%);
  background: linear-gradient(135deg, #fff7c8, #ffd23f 45%, #d99a1e);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  filter: drop-shadow(0 0 6px #ffe98a); animation: finialSpin 6s linear infinite; }
.finial::after { content: ""; position: absolute; left: 50%; top: 38px; width: 8px; height: 22px; transform: translateX(-50%);
  border-radius: 4px; background: linear-gradient(90deg, var(--gold-3), var(--gold-1), var(--gold-3)); }
@keyframes finialSpin { 0% { transform: translateX(-50%) rotateY(0); } 100% { transform: translateX(-50%) rotateY(360deg); } }
.brand { color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,.4); font-size: 17px; }
.brand-star { color: #ffd23f; filter: drop-shadow(0 0 4px #ffe98a); }
/* 圓頂上的寶石狀按鈕 */
.topbar .icon-btn, .topbar .star-count, .topbar .kid-chip {
  color: var(--ink); border: 2px solid var(--gold-2);
  background: radial-gradient(circle at 35% 30%, #ffffff, #efe8ff 55%, #cfc4f2);
  box-shadow: 0 2px 0 var(--gold-4), inset 0 -2px 4px rgba(80,60,140,.25); }
.topbar .star-count { font-weight: 800; }

/* ---------- 盒身（內容區） ---------- */
main#main { position: relative; z-index: 2; max-width: none; margin: 0 8px; padding: 18px 14px 22px; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; color: var(--text);
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0) 0 calc(100% / 6 - 1px), rgba(160,120,80,.07) calc(100% / 6 - 1px) calc(100% / 6)),
    radial-gradient(ellipse at 50% 0%, rgba(0,0,0,.18), transparent 22%),
    linear-gradient(90deg, var(--body-3), var(--body-1) 18%, var(--body-2) 50%, var(--body-1) 82%, var(--body-3));
  box-shadow: inset 0 10px 18px rgba(0,0,0,.22), inset 10px 0 16px rgba(0,0,0,.12), inset -10px 0 16px rgba(0,0,0,.12);
  border-left: 3px solid var(--gold-3); border-right: 3px solid var(--gold-3); }
:root:not([data-theme="dark"]) main#main { --text: #3a2a4d; --muted: #6f6083; }
:root[data-theme="dark"] main#main { --text: #f4eeff; --muted: #c9bde6; }
.screen { animation: drawerIn .42s cubic-bezier(.2,.9,.3,1.1); transform-origin: 50% 0; }
@keyframes drawerIn { from { opacity: 0; transform: rotateX(-14deg) translateY(-14px) scale(.98); } to { opacity: 1; transform: none; } }
/* 畫面標題＝金框銘牌 */
.screen-title { display: table; margin: 0 auto 6px; padding: 4px 22px; font-size: 20px; color: #5a3a10; letter-spacing: 2px;
  background: linear-gradient(180deg, var(--gold-1), var(--gold-2) 50%, var(--gold-3)); border-radius: 12px;
  box-shadow: 0 2px 0 var(--gold-4), inset 0 1px 0 rgba(255,255,255,.8), 0 6px 12px rgba(0,0,0,.18); text-shadow: 0 1px 0 rgba(255,255,255,.6); }
.stage-wrap { box-shadow: inset 0 0 0 3px var(--gold-2), inset 0 6px 16px rgba(0,0,0,.35), 0 8px 18px rgba(0,0,0,.18); border: none; border-radius: 26px; }
.card, .mode-card, .guardian-card, .group { border-color: color-mix(in srgb, var(--gold-2) 55%, var(--border)); }

/* ---------- 盒緣導覽（四顆寶石） ---------- */
.bottom-nav { position: relative; z-index: 3; left: auto; right: auto; bottom: auto; border: none; margin: 0 -2px;
  padding: 14px 10px calc(10px + env(safe-area-inset-bottom));
  background:
    radial-gradient(2.5px 2.5px at 8% 30%, #fff 40%, transparent 50%), radial-gradient(2.5px 2.5px at 92% 30%, #fff 40%, transparent 50%),
    linear-gradient(180deg, var(--gold-1), var(--gold-2) 30%, var(--gold-3) 75%, var(--gold-4));
  border-radius: 14px 14px 28px 28px; box-shadow: inset 0 2px 0 rgba(255,255,255,.75), inset 0 -4px 8px rgba(0,0,0,.25), 0 -2px 0 rgba(0,0,0,.25); }
.bottom-nav button { min-height: 72px; gap: 2px; color: #5a3a10; font-size: 13px; font-weight: 800; text-shadow: 0 1px 0 rgba(255,255,255,.55); }
.bottom-nav button span { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; font-size: 22px;
  background: var(--gem-img, radial-gradient(circle at 35% 30%, #ffffff, var(--gem) 45%, color-mix(in srgb, var(--gem) 60%, #1b1240)));
  background-size: cover; border: 3px solid var(--gold-2);
  box-shadow: 0 3px 0 var(--gold-4), inset 0 -3px 6px rgba(0,0,0,.25), 0 0 0 2px rgba(0,0,0,.15); transition: transform .2s, box-shadow .2s; }
.bottom-nav button:nth-child(1) span { --gem: #ff8fc0; }
.bottom-nav button:nth-child(2) span { --gem: #6fd6f0; }
.bottom-nav button:nth-child(3) span { --gem: #7fdc9a; }
.bottom-nav button:nth-child(4) span { --gem: #b48cff; }
.bottom-nav button[aria-current="page"] { color: #3a1e00; }
.bottom-nav button[aria-current="page"] span { transform: translateY(-6px) scale(1.12);
  box-shadow: 0 6px 0 var(--gold-4), 0 0 18px 4px color-mix(in srgb, var(--gem) 70%, #fff), inset 0 -3px 6px rgba(0,0,0,.2); }
.bottom-nav button:active span { transform: translateY(1px) scale(.96); }

/* 提示訊息放在盒緣上方 */
.toast { bottom: calc(118px + env(safe-area-inset-bottom)); }
/* 寬螢幕：寶盒置中，看起來像擺在桌上的物件 */
@media (min-width: 600px) {
  .app-box { height: min(100dvh, 980px); margin-top: max(0px, calc((100dvh - 980px) / 2)); }
  .app-box::after { content: ""; position: absolute; left: 6%; right: 6%; bottom: -18px; height: 30px; border-radius: 50%; background: rgba(0,0,0,.45); filter: blur(12px); z-index: 0; }
}
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } .finial::before { animation: none; } .night-sky::after { animation: none; } }

/* ===== 生成美術零件與 3D 圖示（取代 emoji） ===== */
/* 頁首頂冠：原創天文台圓頂 */
.finial { width: 92px; height: 100px; top: -64px; background: url("../img/shell/dome-crest.png") center / contain no-repeat; filter: drop-shadow(0 6px 10px rgba(0,0,0,.4)); }
.finial::before, .finial::after { display: none; }
.topbar { margin-top: 58px; }
/* 導覽寶石：寶石底圖＋3D 圖示 */
.bottom-nav button span.gem { position: relative; width: 58px; height: 58px; border: none; border-radius: 50%; box-shadow: none;
  background: var(--gem-img) center / contain no-repeat; display: grid; place-items: center; }
.bottom-nav button:nth-child(1) span.gem { --gem-img: url("../img/shell/gem-pink.png"); --gem: #ff8fc0; }
.bottom-nav button:nth-child(2) span.gem { --gem-img: url("../img/shell/gem-aqua.png"); --gem: #6fd6f0; }
.bottom-nav button:nth-child(3) span.gem { --gem-img: url("../img/shell/gem-mint.png"); --gem: #7fdc9a; }
.bottom-nav button:nth-child(4) span.gem { --gem-img: url("../img/shell/gem-violet.png"); --gem: #b48cff; }
.bottom-nav button[aria-current="page"] span.gem { transform: translateY(-6px) scale(1.12); filter: drop-shadow(0 0 10px color-mix(in srgb, var(--gem) 80%, #fff)); box-shadow: none; }
.gem-ico { width: 30px; height: 30px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
/* 通用圖示 */
.ico { width: 26px; height: 26px; object-fit: contain; vertical-align: middle; flex: none; pointer-events: none; }
.ico.sm { width: 20px; height: 20px; }
.btn .ico { margin-right: 6px; }
.btn.small .ico { margin-right: 0; width: 26px; height: 26px; }
.btn.small { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.btn { display: inline-flex; align-items: center; justify-content: center; }
.btn.big { display: flex; }
.icon-btn { display: grid; place-items: center; padding: 0; }
.icon-btn .ico { width: 28px; height: 28px; }
.star-count { display: inline-flex; align-items: center; gap: 4px; }
.star-count .ico { width: 22px; height: 22px; }
.brand-ico { width: 24px; height: 24px; filter: drop-shadow(0 0 4px #ffe98a); }
.heart-ico { width: 20px; height: 20px; vertical-align: middle; }
.love .heart-ico { width: 26px; height: 26px; }
.rar-ico { width: 16px; height: 16px; vertical-align: middle; }
.mode-ico { width: 72px; height: 72px; object-fit: contain; filter: drop-shadow(0 6px 8px rgba(0,0,0,.18)); }
.add-ico { width: 56px; height: 56px; }
.choice-img { width: 76px; height: 76px; object-fit: contain; pointer-events: none; filter: drop-shadow(0 4px 6px rgba(0,0,0,.15)); }
.choices .choice { display: grid; place-items: center; min-height: 92px; }
img.big-icon { display: block; width: 120px; height: 120px; margin: 0 auto 6px; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,.18)); }
.lesson-word img.li { width: 48px; height: 48px; object-fit: contain; }
.missed { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0; }
.missed span { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface2); }
.missed img { width: 32px; height: 32px; }
.gate-list li { display: flex; align-items: center; gap: 8px; }
.gate-list .ico { width: 30px; height: 30px; }
.daily .ico { width: 28px; height: 28px; margin-right: 6px; }
.guardian-card .ico { width: 24px; height: 24px; }
.mic.recording { animation: pulse .8s infinite; }
.mic-state { font-size: 12px; margin-left: 2px; }
.mic.passed { background: color-mix(in srgb, var(--ok) 22%, var(--surface)); }
.menu button { display: flex; align-items: center; gap: 8px; }
h2 .ico { width: 30px; height: 30px; margin-right: 6px; }

/* 手機：中間內容不可撐高外框，否則底部寶石導覽會被擠出螢幕 */
main#main { min-height: 0; }
.app-box { height: 100dvh; max-height: 100dvh; overflow: hidden; }
@supports not (height: 100dvh) { .app-box { height: 100vh; max-height: 100vh; } }
@media (max-width: 599px) {
  .topbar { min-height: 84px; margin-top: 46px; padding-top: calc(18px + env(safe-area-inset-top)); }
  .finial { width: 74px; height: 80px; top: -52px; }
  .bottom-nav button { min-height: 62px; font-size: 12px; }
  .bottom-nav button span.gem { width: 50px; height: 50px; }
  .gem-ico { width: 26px; height: 26px; }
}

/* AR：精靈不在畫面裡時的提示箭頭 */
.ar-arrow { position: absolute; z-index: 5; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 2px; pointer-events: none;
  animation: arrowPulse 1s ease-in-out infinite; }
.ar-arrow img { width: 56px; height: 56px; transform: rotate(var(--rot, 0rad)); filter: drop-shadow(0 0 10px #fff3b0); }
.ar-arrow span { font-weight: 800; font-size: 14px; color: #3a2a4d; background: #fff3b0; padding: 2px 10px; border-radius: 999px; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
@keyframes arrowPulse { 50% { transform: translate(-50%, -50%) scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .ar-arrow { animation: none; } }

/* hidden 屬性要能真的隱藏箭頭（.ar-arrow 設了 display: grid 會蓋掉預設的 hidden） */
.ar-arrow[hidden] { display: none; }

/* 外框固定貼齊可見畫面四邊（Android Chrome 網址列收合時 100dvh 會算錯，底部寶石被切掉） */
html { overflow: hidden; height: 100%; overscroll-behavior: none; }
.app-box { position: fixed; top: 0; bottom: 0; left: 0; right: 0; margin: 0 auto; width: var(--shell-w); height: auto; max-height: none; }
.bottom-nav { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 600px) { .app-box { top: max(0px, calc((100% - 980px) / 2)); bottom: max(0px, calc((100% - 980px) / 2)); margin-top: auto; } }

/* 圖層順序：英文題、公主英文課、提示訊息要顯示在 AR 相機畫面（85）與 WebXR（95）之上，
   否則點滿 3 下之後題目被相機蓋住、無法收服 */
.modal-back { z-index: 120; }
.toast { z-index: 130; }

/* ---------- 進化精靈與對戰 ---------- */
.card .thumb.mon { object-fit: contain; background: radial-gradient(circle, color-mix(in srgb, var(--surface2) 60%, #e3ecff), transparent 70%); border-radius: 16px; }
.lv-tag { display: inline-block; font-size: 12px; font-weight: 800; padding: 1px 8px; border-radius: 999px; background: var(--primary); color: var(--primary-ink); vertical-align: middle; }
.word-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0; }
.wchip { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 82px; padding: 6px 4px; border-radius: 16px; border: 2px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer; font: inherit; }
.wchip img { width: 44px; height: 44px; object-fit: contain; }
.wchip b { font-size: 14px; }
.wchip small { font-size: 12px; color: var(--muted); }
.wchip:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; max-height: 52vh; overflow-y: auto; padding: 4px; }
.pick { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px 10px; border-radius: 18px; border: 3px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer; font: inherit; }
.pick img { width: 84px; height: 84px; object-fit: contain; }
.pick:hover, .pick:focus-visible { border-color: var(--primary); outline: none; transform: translateY(-2px); }
.pk-name { font-weight: 800; font-size: 15px; }
.pk-row { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.pk-adv { position: absolute; top: 6px; right: 6px; font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 999px; color: #fff; }
.pk-adv.good { background: #2e9e5b; }
.pk-adv.bad { background: #8a8aa0; }

.modal.battle-modal { width: min(100%, 600px); }
.battle-top { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.hpbox { background: var(--surface2); border: 2px solid var(--border); border-radius: 14px; padding: 6px 10px; font-size: 14px; }
.hpbox.foe { text-align: right; }
.hp, .xpbar { height: 12px; border-radius: 999px; background: color-mix(in srgb, var(--text) 14%, transparent); overflow: hidden; margin-top: 4px; }
.hp i { display: block; height: 100%; background: linear-gradient(90deg, #4cd07a, #9be86a); border-radius: inherit; transition: width .5s ease; }
.hp i.low { background: linear-gradient(90deg, #ff6b6b, #ffa94d); }
.hpbox.foe .hp i { margin-left: auto; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, #7c8cff, #c38bff); border-radius: inherit; transition: width .8s ease; }
.stage-wrap.battle { width: 100%; height: min(34vh, 290px); min-height: 200px; border-radius: 20px; }
.battle-msg { min-height: 2.6em; margin: 8px 0 4px; font-weight: 700; text-align: center; }
.battle-msg small { display: block; font-weight: 600; color: var(--muted); }
.battle-q { text-align: center; }
.battle-q .q { margin: 4px 0 8px; }
.battle-q .choices .choice { min-height: 58px; }
.btn.big { font-size: 20px; padding: 14px 26px; }
.xp-panel { background: var(--surface2); border: 2px solid var(--border); border-radius: 16px; padding: 10px 14px; text-align: left; }
.xp-panel p { margin: 0 0 6px; }

.grow-panel { background: var(--surface2); border: 2px solid var(--border); border-radius: 16px; padding: 10px 14px; margin-top: 8px; }
.grow-panel p { margin: 6px 0; }
.evo-line { display: flex; align-items: center; justify-content: center; gap: 4px; margin: 10px 0 4px; }
.evo { display: flex; flex-direction: column; align-items: center; width: 92px; }
.evo img { width: 80px; height: 80px; object-fit: contain; }
.evo small { font-size: 12px; font-weight: 700; text-align: center; }
.evo.locked img { filter: brightness(0) opacity(.45); }
:root[data-theme="dark"] .evo.locked img { filter: brightness(0) invert(1) opacity(.35); }
.evo-arrow { font-size: 26px; color: var(--muted); font-weight: 800; }

.stage-wrap.evolve.glowing { animation: evoGlow .52s ease-in-out infinite alternate; }
.stage-wrap.evolve.flash::after { content: ''; position: absolute; inset: 0; background: #fff; animation: evoFlash .45s ease-out forwards; pointer-events: none; }
@keyframes evoGlow { from { box-shadow: 0 0 0 0 rgba(255, 236, 150, .0) inset; } to { box-shadow: 0 0 60px 20px rgba(255, 236, 150, .85) inset; } }
@keyframes evoFlash { from { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .stage-wrap.evolve.glowing { animation: none; } }
.evo-line { flex-wrap: wrap; }
@media (max-width: 480px) { .evo { width: 66px; } .evo img { width: 58px; height: 58px; } .evo-arrow { font-size: 18px; } }
.practice { display: grid; gap: 6px; }
.battle-q .big-icon { width: 84px; height: 84px; }
.battle-q .big-word { font-size: 30px; }
@media (max-width: 480px) {
  .stage-wrap.battle { height: 26vh; min-height: 170px; }
  .battle-q .big-icon { width: 64px; height: 64px; }
  .battle-top { gap: 6px; }
  .hpbox { font-size: 13px; padding: 5px 8px; }
}
@media (max-width: 480px) { .evo-line { flex-wrap: nowrap; gap: 0; } .evo { width: 60px; } .evo img { width: 50px; height: 50px; } .evo small { font-size: 11px; } .evo-arrow { font-size: 14px; } }
