/* 拼字（Spell）：沿用 app.css 的色彩 tokens，所有類別以 sp- 開頭，不影響打字練習。 */
:root { --spell: #7c5cf0; --spell-50: #f1ecff; --spell-700: #4c2fc0; }
.chip.violet { background: var(--spell-50); color: var(--spell-700); }

/* 頂部：拼字星星（與打字星星分開，只在拼字區顯示） */
.star-pill.spell { background: var(--spell-50); border-color: #d9ccff; color: var(--spell-700); }
.star-pill.spell .i { color: var(--spell); }
[data-spell-nav][hidden], #spellStarPill[hidden] { display: none !important; }
body.in-spell #starPill { display: none; }
body:not(.in-spell) #spellStarPill { display: none !important; }

.sp-hero { display: flex; gap: 20px; align-items: center; justify-content: space-between; flex-wrap: wrap; border-radius: var(--r-xl); padding: 26px 28px; margin-bottom: 20px;
  background: linear-gradient(120deg, #2b1c6b, var(--spell) 62%, #a58bff); color: #fff; }
.sp-hero h1 { color: #fff; display: flex; align-items: center; gap: 10px; margin: 2px 0 6px; font-size: clamp(1.5rem, 3vw, 2.1rem); font-weight: 900; }
.sp-hero .eyebrow { color: #e5dcff; }
.sp-hero p { margin: 0; opacity: .92; max-width: 560px; }
.sp-hero-stars { background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .28); border-radius: 18px; padding: 12px 22px; text-align: center; }
.sp-hero-stars b { display: block; font-size: 2rem; line-height: 1.1; }
.sp-hero-stars span { font-size: .8rem; opacity: .9; font-weight: 800; }
.sp-h { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; font-weight: 900; margin: 26px 0 12px; }
.sp-h small { font-size: .8rem; color: var(--muted); font-weight: 700; }
.sp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.sp-card { display: flex; flex-direction: column; gap: 8px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); text-decoration: none !important; color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s; }
.sp-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #cdbff9; }
.sp-card h3 { margin: 0; font-size: 1.05rem; font-weight: 900; }
.sp-card-top { display: flex; gap: 6px; flex-wrap: wrap; }
.sp-desc { margin: 0; color: var(--muted); font-size: .88rem; flex: 1; }
.sp-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sp-stars { display: inline-flex; gap: 1px; color: var(--gold); }
.sp-stars .i { width: 17px; height: 17px; }
.sp-stars .off { color: #dfe3ec; }

/* 作答 */
.sp-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.sp-title { display: grid; line-height: 1.25; min-width: 0; }
.sp-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-progress { flex: 1; min-width: 140px; height: 10px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.sp-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--spell)); transition: width .3s; }
.sp-stage { padding: 34px 22px 26px; text-align: center; }
.sp-prompt { font-size: clamp(2.2rem, 8vw, 3.6rem); font-weight: 900; line-height: 1.15; margin-top: 12px; word-break: break-word; }
.sp-prompt small { display: block; font-size: .92rem; font-weight: 700; color: var(--muted); margin-top: 8px; }
.sp-ans-row { max-width: 520px; margin: 26px auto 8px; }
.sp-ans { width: 100%; font-size: 1.6rem; text-align: center; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line-2); background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s; font-family: inherit; }
.sp-ans:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(61, 91, 224, .18); }
.sp-ans.ok { border-color: var(--mint); background: var(--mint-50); }
.sp-ans.bad { border-color: var(--coral); background: var(--coral-50); animation: sp-shake .3s; }
@keyframes sp-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.sp-hintbox { min-height: 34px; margin-top: 6px; font-family: var(--mono); font-size: 1.25rem; letter-spacing: .2em; color: var(--brand-700); }
.sp-fb { min-height: 28px; margin-top: 6px; font-weight: 800; text-align: center; }
.sp-fb.ok { color: var(--mint-ink); } .sp-fb.bad { color: var(--coral-ink); } .sp-fb.warn { color: var(--gold-ink); }
.sp-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.sp-tip { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 12px; }

/* 挖空 */
.sp-cloze-card { padding: 22px 24px 24px; }
.sp-cloze { font-size: 1.35rem; line-height: 3.1; text-align: left; padding: 6px 4px 10px; overflow-wrap: anywhere; }
.sp-blank { display: inline-block; position: relative; margin: 0 4px; vertical-align: baseline; }
.sp-blank input { width: var(--w, 6em); max-width: 70vw; font-size: 1.1rem; text-align: center; font-family: inherit; border: 0; border-bottom: 3px solid var(--brand);
  background: var(--brand-50); border-radius: 8px 8px 0 0; padding: 3px 6px; outline: none; }
.sp-blank input:focus { background: #fff; box-shadow: 0 3px 0 0 var(--spell); }
.sp-blank.ok input { border-color: var(--mint); background: var(--mint-50); }
.sp-blank.bad input { border-color: var(--coral); background: var(--coral-50); }
.sp-blank.reveal input { border-color: var(--gold); background: var(--gold-50); }
.sp-bulb { position: absolute; right: -9px; top: -15px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--gold); color: #3b2800; cursor: pointer; padding: 0; display: grid; place-items: center; }
.sp-bulb .i { width: 13px; height: 13px; }
.sp-bh { position: absolute; left: 50%; transform: translateX(-50%); top: 100%; margin-top: -20px; font-size: .74rem; line-height: 1.2; color: var(--brand-700); font-weight: 800; white-space: nowrap; pointer-events: none; }

/* 結算 */
.sp-result { text-align: center; padding: 28px 22px; }
.sp-big-stars .sp-stars .i { width: 38px; height: 38px; }
.sp-score { margin: 6px 0; }
.sp-score b { font-size: 3rem; color: var(--brand-700); }
.sp-score span { color: var(--muted); font-weight: 800; margin-left: 4px; }
.sp-msg { margin: 0 0 12px; font-weight: 800; }
.sp-ok { color: var(--mint-ink); font-weight: 700; } .sp-no { color: var(--coral-ink); font-weight: 700; }

/* 榮譽榜外框：打字／拼字切換 */
.honor-switch { margin-bottom: 14px; }
.honor-switch .seg button.active { color: var(--spell-700); }

@media (max-width: 640px) {
  .sp-hero { padding: 20px; }
  .sp-cloze { font-size: 1.15rem; }
  .sp-stage { padding: 24px 14px 20px; }
}
@media (prefers-reduced-motion: reduce) { .sp-ans.bad, .sp-card { animation: none; transition: none; } }

/* ── 後台：拼字題組編輯器 ── */
.sp-kind { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sp-kind-b { display: grid; gap: 6px; text-align: left; padding: 16px; border: 1px solid var(--line-2); border-radius: var(--r); background: #fff; cursor: pointer; font: inherit; }
.sp-kind-b:hover { border-color: var(--spell); background: var(--spell-50); }
.sp-kind-b b { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.sp-kind-b span { color: var(--muted); font-size: .88rem; }
.sp-ta { font-family: var(--mono); font-size: .92rem; line-height: 1.6; width: 100%; resize: vertical; }
.sp-ed2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.sp-pairs { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r); }
.sp-try { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.sp-try .input { flex: 1; min-width: 140px; }
.sp-res.ok { color: var(--mint-ink); font-weight: 800; } .sp-res.near { color: var(--gold-ink); font-weight: 800; } .sp-res.bad { color: var(--coral-ink); font-weight: 800; }
.sp-pre { white-space: pre-wrap; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; max-height: 160px; overflow: auto; font-size: .85rem; margin: 6px 0 0; }
.sp-classes { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.sp-classes legend { font-weight: 800; font-size: .88rem; padding: 0 6px; }
.coral-t { color: var(--coral-ink); }

.spe-steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.spe-steps span { background: var(--bg); border-radius: 99px; padding: 4px 12px; font-size: .86rem; color: var(--ink-2); }
.spe-steps b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--brand); color: #fff; font-size: .75rem; margin-right: 4px; }
.spe-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spe-dbl { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.spe-msg { min-height: 3.1em; display: flex; align-items: center; border-radius: 10px; padding: 8px 12px; background: var(--bg); font-size: .9rem; margin: 8px 0; color: var(--ink-2); }
.spe-msg.ok { background: var(--mint-50); color: var(--mint-ink); } .spe-msg.warn { background: var(--coral-50); color: var(--coral-ink); }
.spe-msg.pick { background: var(--gold-50); color: var(--gold-ink); font-weight: 800; }
.spe-passage { font-size: 1.25rem; line-height: 2.5; padding: 14px 16px; border: 2px dashed var(--line-2); border-radius: var(--r); white-space: pre-wrap; cursor: text; user-select: text; min-height: 80px; background: #fff; }
.spe-passage ::selection { background: #ffe08a; }
.spe-cb { display: inline-block; background: var(--brand-50); border-bottom: 3px solid var(--brand); color: var(--brand-700); font-weight: 800; padding: 0 6px; border-radius: 6px 6px 0 0; cursor: pointer; line-height: 1.7; margin: 0 2px; user-select: none; }
.spe-cb.act { background: var(--brand); color: #fff; }
.spe-cb.pick { outline: 3px solid var(--gold); animation: spe-pulse 1s infinite; }
@keyframes spe-pulse { 50% { outline-color: transparent; } }
.spe-cb i { font-style: normal; font-size: .68rem; margin-left: 4px; background: var(--gold-50); color: var(--gold-ink); border-radius: 99px; padding: 0 5px; }
.spe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; align-items: start; }
.spe-grid h4 { margin: 0 0 8px; font-size: .95rem; }
.spe-bp { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.spe-bp.on { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(61, 91, 224, .15); }
.spe-bph { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.spe-bph .chip button { border: 0; background: none; cursor: pointer; color: inherit; font-weight: 900; padding: 0 0 0 4px; }
.spe-f { display: flex; gap: 8px; align-items: center; margin-top: 6px; font-size: .86rem; color: var(--muted); }
.spe-f > span { width: 2.6em; flex: none; }
.spe-pv { font-size: 1.05rem; line-height: 2.3; background: var(--bg); border-radius: var(--r); padding: 12px 14px; }
.spe-pb { display: inline-block; border-bottom: 3px solid var(--brand); background: var(--brand-50); padding: 0 .6em; border-radius: 6px 6px 0 0; margin: 0 2px; color: var(--brand-700); font-weight: 800; }
.spe-ph { display: inline-block; background: var(--gold-50); color: var(--gold-ink); border-radius: 99px; padding: 0 8px; font-size: .78rem; margin-right: 2px; }
.spe-adv { margin-top: 12px; } .spe-adv summary { cursor: pointer; font-weight: 800; }
@media (max-width: 820px) { .sp-ed2, .spe-grid, .sp-kind { grid-template-columns: minmax(0, 1fr); } }

/* 手機底部導覽：拼字開啟時由 4 項變 5 項 */
@media (max-width: 640px) {
  .tabbar.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* 拼字徽章牆（沿用打字徽章的 .badges／.badge-item 版型） */
.sp-newbadges { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 4px 0 12px; }
.sp-newbadges .reward { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 6px; border-radius: 99px; background: var(--gold-50); border: 1px solid var(--gold-100); font-weight: 800; color: var(--gold-ink); }

/* ══ 作答畫面：固定在「可視區域」，iPad 鍵盤彈出時題目與輸入區仍完整可見 ══ */
.sp-play {
  position: fixed; z-index: 70; left: var(--vvl, 0px); top: var(--vvt, 0px); width: var(--vvw, 100vw); height: var(--vvh, 100dvh);
  display: flex; flex-direction: column; box-sizing: border-box; background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.sp-play .sp-head { margin: 0 0 8px; flex: none; flex-wrap: nowrap; }
.sp-play .sp-progress { flex: none; width: 100%; margin: 0 0 10px; }
.sp-play-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
.sp-play-body > .card { margin-top: auto; margin-bottom: auto; width: 100%; }
.sp-play-body > .sp-tip { flex: none; }
.sp-stage, .sp-cloze-card { max-width: 860px; margin-left: auto !important; margin-right: auto !important; }
.sp-prompt { font-size: clamp(1.9rem, min(7vw, 9vh), 3.6rem); }
.sp-ans-row { display: flex; gap: 10px; max-width: 640px; margin: 20px auto 6px; align-items: stretch; }
.sp-ans { flex: 1 1 auto; min-width: 0; width: auto; font-size: clamp(1.25rem, 3vw, 1.7rem); }
.sp-go { flex: none; min-height: 54px; padding: 0 22px; font-size: 1.05rem; }
.sp-ok { color: var(--mint-ink); font-weight: 700; }

/* 鍵盤開啟或可視高度很矮（iPad 橫向＋鍵盤）：縮小間距，題目與輸入一起顯示 */
body.kb-open .sp-stage, body.sp-short .sp-stage { padding: 12px 14px 12px; }
body.kb-open .sp-prompt, body.sp-short .sp-prompt { font-size: clamp(1.5rem, min(6vw, 10vh), 2.4rem); margin-top: 2px; }
body.kb-open .sp-prompt small, body.sp-short .sp-prompt small { display: none; }
body.kb-open .sp-ans-row, body.sp-short .sp-ans-row { margin: 8px auto 2px; }
body.kb-open .sp-ans, body.sp-short .sp-ans { padding: 8px 12px; }
body.kb-open .sp-go, body.sp-short .sp-go { min-height: 46px; }
body.kb-open .sp-hintbox, body.sp-short .sp-hintbox { min-height: 22px; font-size: 1rem; margin-top: 2px; }
body.kb-open .sp-fb, body.sp-short .sp-fb { min-height: 20px; margin-top: 2px; font-size: .9rem; }
body.kb-open .sp-tip, body.sp-short .sp-tip { display: none; }
body.kb-open .sp-cloze, body.sp-short .sp-cloze { font-size: 1.12rem; line-height: 2.7; }
body.kb-open .sp-cloze-card, body.sp-short .sp-cloze-card { padding: 12px 14px; }
body.kb-open .sp-play .sp-head, body.sp-short .sp-play .sp-head { margin-bottom: 4px; }
body.kb-open .sp-play .sp-progress, body.sp-short .sp-play .sp-progress { margin-bottom: 6px; }
body.kb-open .sp-actions, body.sp-short .sp-actions { margin-top: 6px; }
.sp-cloze { padding-bottom: 28px; }

/* ══ 連對、回饋與進場動畫 ══ */
.sp-combo { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; padding: 4px 12px; border-radius: 99px; font-weight: 900; flex: none;
  background: #fff3e0; color: #b45309; border: 1px solid #ffd9a0; }
.sp-combo[hidden] { display: none; }
.sp-combo .i { width: 18px; height: 18px; color: #f97316; }
.sp-combo small { font-weight: 800; opacity: .8; }
.sp-combo[data-lv="1"] { background: #ffe9d6; border-color: #ffc08a; }
.sp-combo[data-lv="2"] { background: #ffd9c9; border-color: #ff9f7a; color: #b3320c; box-shadow: 0 0 0 3px rgba(249, 115, 22, .18); }
.sp-combo[data-lv="3"] { background: linear-gradient(120deg, #ffb199, #ffd36b); border-color: #ff8a5c; color: #8a1d00; box-shadow: 0 0 14px rgba(249, 115, 22, .55); }
.sp-combo[data-lv="4"] { background: linear-gradient(120deg, #7c5cf0, #ff6b57, #f5b301); background-size: 200% 100%; color: #fff; border-color: transparent;
  box-shadow: 0 0 18px rgba(124, 92, 240, .6); animation: sp-rainbow 1.6s linear infinite; }
.sp-combo[data-lv="4"] .i { color: #fff; }
.sp-combo.bump { animation: sp-bump .42s cubic-bezier(.3, 1.7, .5, 1); }
.sp-combo[data-lv="4"].bump { animation: sp-bump .42s cubic-bezier(.3, 1.7, .5, 1), sp-rainbow 1.6s linear infinite; }
.sp-combo.lost { animation: sp-lost .45s ease; }
@keyframes sp-bump { 0% { transform: scale(.7); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes sp-lost { 25% { transform: translateX(-5px) rotate(-4deg); } 50% { transform: translateX(5px) rotate(4deg); opacity: .5; } 100% { transform: none; } }
@keyframes sp-rainbow { to { background-position: 200% 0; } }

.sp-pop { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); z-index: 5; pointer-events: none; opacity: 0; white-space: nowrap;
  font-weight: 900; font-size: clamp(1.2rem, 3.4vw, 1.9rem); padding: 6px 20px; border-radius: 99px; color: #fff; background: linear-gradient(120deg, #f97316, #ef4444); box-shadow: 0 10px 24px -8px rgba(239, 68, 68, .6); }
.sp-pop[data-lv="2"] { background: linear-gradient(120deg, #ef4444, #db2777); }
.sp-pop[data-lv="3"], .sp-pop[data-lv="4"] { background: linear-gradient(120deg, #7c5cf0, #ec4899, #f59e0b); }
.sp-pop.show { animation: sp-pop 1.5s ease both; }
@keyframes sp-pop { 0% { opacity: 0; transform: translate(-50%, 16px) scale(.6); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); } 25% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -18px) scale(1); } }

.sp-enter { animation: sp-enter .35s ease both; }
@keyframes sp-enter { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.sp-ans.ok { animation: sp-correct .5s ease; }
@keyframes sp-correct { 0% { transform: scale(1); } 35% { transform: scale(1.04); box-shadow: 0 0 0 8px rgba(18, 168, 119, .28); } 100% { transform: scale(1); } }
.sp-blank.ok input { animation: sp-correct .5s ease; }

.sp-burst { position: fixed; z-index: 120; width: 0; height: 0; pointer-events: none; }
.sp-burst i { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 3px; background: var(--c, #f5b301); transform: rotate(45deg);
  animation: sp-burst .7s ease-out forwards; }
@keyframes sp-burst { 0% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(280deg) scale(.4); } }

/* 結算：星星依序彈出 */
.sp-big-stars .sp-st { display: inline-block; animation: sp-starpop .55s cubic-bezier(.3, 1.8, .5, 1) both; animation-delay: calc(var(--i) * .16s + .15s); }
.sp-big-stars .sp-stars .i { width: 42px; height: 42px; }
@keyframes sp-starpop { 0% { opacity: 0; transform: scale(0) rotate(-50deg); } 100% { opacity: 1; transform: none; } }
.sp-newbadges .reward { animation: sp-enter .5s ease both; animation-delay: calc(var(--i, 0) * .2s + .8s); }
.sp-card.cleared { border-color: #bfe8d6; background: linear-gradient(135deg, #f3fcf8, #fff 60%); }
.sp-no { font-size: .72rem; font-weight: 900; padding: 2px 9px; border-radius: 99px; background: var(--ink); color: #fff; }
.sp-hero-stars b { font-variant-numeric: tabular-nums; }

/* 榮譽榜：頒獎台升起、名單滑入、數字滾動 */
.sp-podium .pod { animation: sp-rise .75s cubic-bezier(.2, 1.1, .3, 1) both; animation-delay: var(--d, 0s); }
.sp-podium .pod .block { transform-origin: bottom; animation: sp-grow .8s cubic-bezier(.2, 1, .3, 1) both; animation-delay: var(--d, 0s); }
.sp-podium .pod.p1 .crown { animation: sp-crown 1.8s ease-in-out infinite; transform-origin: bottom; }
.sp-podium .pod.p1 .who { background: linear-gradient(90deg, #b45309, #f5b301, #b45309); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: sp-rainbow 2.4s linear infinite; }
@keyframes sp-rise { from { opacity: 0; transform: translateY(46px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes sp-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes sp-crown { 0%, 100% { transform: translateY(0) rotate(-5deg); } 50% { transform: translateY(-5px) rotate(5deg); } }
.sp-anim-list li { animation: sp-slide .5s ease both; animation-delay: calc(var(--i) * 70ms + .7s); }
.sp-anim-list li.me { box-shadow: 0 0 0 2px var(--spell); }
@keyframes sp-slide { from { opacity: 0; transform: translateX(-26px); } to { opacity: 1; transform: none; } }
.sp-board [data-cu] { font-variant-numeric: tabular-nums; }

/* ══ 競賽 ══ */
.sp-contests { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.sp-contest { display: block; padding: 16px 18px; border-radius: var(--r-lg); border: 1px solid #ecd9a6; background: linear-gradient(135deg, #fffaf0, #fff 65%);
  text-decoration: none !important; color: inherit; box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s; }
.sp-contest:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.sp-contest h3 { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; font-size: 1.05rem; font-weight: 900; }
.sp-contest-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sp-contest.live { border-color: #f5b301; animation: sp-glow2 2s ease-in-out infinite; }
.sp-contest.ended { background: #fff; border-color: var(--line); opacity: .85; }
@keyframes sp-glow2 { 50% { box-shadow: 0 0 0 4px rgba(245, 179, 1, .25); } }
.sp-ready { max-width: 720px; margin: 0 auto; }
.sp-checks { display: grid; gap: 10px; }
.sp-check { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.sp-check > span { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; background: #fff; flex: none; }
.sp-check.ok > span { background: var(--mint); color: #fff; } .sp-check.bad > span { background: var(--coral); color: #fff; }
.sp-check.warn > span { background: var(--gold); color: #3b2800; } .sp-check.wait > span { background: var(--brand-100); color: var(--brand-700); }
.sp-check b { display: block; } .sp-check small { color: var(--muted); }
.sp-ready-info { display: flex; justify-content: center; gap: 28px; margin: 18px 0; text-align: center; }
.sp-ready-info b { display: block; font-size: 1.8rem; font-weight: 900; color: var(--brand-700); line-height: 1.1; }
.sp-ready-info span { font-size: .8rem; color: var(--muted); font-weight: 800; }
.sp-start-zone { text-align: center; }
.sp-wait { font-size: 1.05rem; margin-bottom: 10px; }
.sp-wait b { font-size: 1.6rem; font-variant-numeric: tabular-nums; color: var(--spell-700); }
.sp-countdown { display: grid; place-items: center; align-content: center; min-height: 50vh; text-align: center; }
.sp-countdown b { font-size: clamp(5rem, min(24vw, 36vh), 12rem); line-height: 1; color: var(--spell); font-weight: 900; }
.sp-countdown b.pop { animation: sp-bump .6s cubic-bezier(.3, 1.7, .5, 1); }
.sp-countdown span { font-size: 1.3rem; font-weight: 900; color: var(--ink-2); }
.sp-timer { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 99px; background: #fff; border: 1px solid var(--line-2); font-weight: 900; font-variant-numeric: tabular-nums; flex: none; }
.sp-timer.urgent { background: var(--coral-50); border-color: var(--coral); color: var(--coral-ink); animation: sp-bump 1s ease infinite; }
.sp-slip { margin: 14px auto; max-width: 420px; padding: 12px 16px; border-radius: 14px; border: 2px dashed var(--line-2); background: #fffdf5; display: grid; gap: 2px; }
.sp-slip span { font-size: .75rem; color: var(--muted); font-weight: 800; letter-spacing: .1em; }
.sp-slip b { font-family: var(--mono); font-size: 1.35rem; letter-spacing: .08em; }
.sp-slip small { color: var(--muted); }
.sp-sync { margin: 10px auto; max-width: 560px; padding: 8px 14px; border-radius: 12px; font-weight: 800; display: flex; gap: 8px; align-items: center; justify-content: center; }
.sp-sync.ok { background: var(--mint-50); color: var(--mint-ink); } .sp-sync.wait { background: var(--bg); color: var(--muted); }
.sp-sync.queued, .sp-sync.rejected { background: var(--coral-50); color: var(--coral-ink); }

@media (prefers-reduced-motion: reduce) {
  .sp-enter, .sp-combo, .sp-pop.show, .sp-ans.ok, .sp-blank.ok input, .sp-podium .pod, .sp-podium .pod .block, .sp-podium .pod.p1 .crown, .sp-podium .pod.p1 .who,
  .sp-anim-list li, .sp-big-stars .sp-st, .sp-newbadges .reward, .sp-contest.live, .sp-timer.urgent { animation: none !important; }
  .sp-pop.show { opacity: 1; }
}

/* ══ 主題世界、小關卡、玩法選擇 ══ */
.sp-review-card { display: flex; align-items: center; gap: 14px; padding: 14px 18px; margin-bottom: 8px; border-radius: var(--r-lg); border: 1px solid #ffd9a0;
  background: linear-gradient(135deg, #fff7e8, #fff 70%); text-decoration: none !important; color: inherit; }
.sp-review-card .i { width: 26px; height: 26px; color: #f97316; flex: none; }
.sp-review-card > div { flex: 1; } .sp-review-card b { display: block; } .sp-review-card span { color: var(--muted); font-size: .86rem; }
.sp-topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.sp-topic { display: grid; gap: 4px; padding: 16px 14px 14px; border-radius: var(--r-lg); background: #fff; border: 1px solid var(--line); text-align: center;
  text-decoration: none !important; color: inherit; box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s, border-color .15s; }
.sp-topic:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: #cdbff9; }
.sp-topic-ic { font-size: 2.4rem; line-height: 1.1; }
.sp-topic b { font-size: 1.02rem; } .sp-topic small { color: var(--muted); font-weight: 700; }
.sp-topic .bar { height: 6px; margin-top: 6px; }
.sp-levels { display: grid; gap: 10px; }
.sp-level { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: var(--r-lg); background: #fff; border: 1px solid var(--line);
  text-decoration: none !important; color: inherit; transition: transform .12s, box-shadow .12s; }
.sp-level:hover { transform: translateX(3px); box-shadow: var(--shadow-sm); }
.sp-lv-no { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--bg-2); font-weight: 900; color: var(--ink-2); }
.sp-lv-main { flex: 1; min-width: 0; } .sp-lv-main b { display: block; overflow: hidden; text-overflow: ellipsis; }
.sp-lv-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.sp-lv-end { display: flex; align-items: center; gap: 10px; flex: none; }
.sp-level.mastered { border-color: #f5d27a; background: linear-gradient(135deg, #fffbee, #fff 60%); } .sp-level.mastered .sp-lv-no { background: var(--gold); color: #3b2800; }
.sp-level.cleared { border-color: #bfe8d6; } .sp-level.cleared .sp-lv-no { background: var(--mint); color: #fff; }
.sp-level.next { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(61, 91, 224, .15); } .sp-level.next .sp-lv-no { background: var(--brand); color: #fff; }
.sp-level.locked { opacity: .78; }
.sp-stage-chip { display: inline-block; font-size: .72rem; font-weight: 900; padding: 1px 9px; border-radius: 99px; background: var(--bg-2); color: var(--ink-2); }
.st-S0 { background: #e8f1ff; color: #1d4ed8; } .st-S1 { background: #e0f7ec; color: #0b6e4f; } .st-S2 { background: #e6f4ff; color: #0369a1; }
.st-S3 { background: #fff1d6; color: #9a5b00; } .st-S4 { background: #ffe2e2; color: #b42318; } .st-S5 { background: #efe5ff; color: #5b34c4; }
.sp-stagebar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.sp-intro { max-width: 760px; margin: 0 auto; }
.sp-intro-top { display: flex; gap: 28px; margin-bottom: 14px; }
.sp-intro-top > div { text-align: center; } .sp-intro-top b { display: block; font-size: 1.5rem; color: var(--brand-700); } .sp-intro-top span { font-size: .78rem; color: var(--muted); font-weight: 800; }
.sp-modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sp-mode { display: grid; gap: 4px; justify-items: start; text-align: left; padding: 12px; border-radius: var(--r); border: 2px solid var(--line-2); background: #fff; cursor: pointer; font: inherit; }
.sp-mode .ic { color: var(--spell); } .sp-mode small { color: var(--muted); }
.sp-mode.on { border-color: var(--spell); background: var(--spell-50); box-shadow: 0 0 0 3px rgba(124, 92, 240, .15); }

/* 玩法：看圖、聽音、重組、補字 */
.sp-pic { font-size: clamp(4rem, min(18vw, 22vh), 8rem); line-height: 1.1; margin: 6px 0; animation: sp-enter .4s ease both; }
.sp-pic-s { font-size: clamp(2.6rem, min(10vw, 12vh), 4.5rem); }
.sp-prompt.sp-small { font-size: clamp(1.2rem, min(4vw, 5vh), 1.8rem); }
.sp-speaker { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; margin: 10px 0 6px; padding: 18px 30px; border-radius: 26px; border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--spell), var(--brand)); color: #fff; font: inherit; font-weight: 900; box-shadow: 0 12px 24px -10px rgba(124, 92, 240, .7); }
.sp-speaker .i { width: 44px; height: 44px; }
.sp-speaker.ring { animation: sp-bump .5s cubic-bezier(.3, 1.7, .5, 1); }
.sp-rate { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; margin: 2px 0 6px; font-size: .8rem; font-weight: 800; color: var(--muted); }
.sp-rate span { margin-right: 4px; }
.sp-rate button { min-width: 48px; height: 32px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font: inherit; font-weight: 800; cursor: pointer; }
.sp-rate button.on { background: var(--spell); border-color: var(--spell); color: #fff; }
body.kb-open .sp-rate, body.sp-short .sp-rate { margin: 0 0 2px; }
.sp-tiles { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 14px 0 4px; }
.sp-tile { min-width: 46px; height: 52px; padding: 0 10px; border-radius: 12px; border: 2px solid var(--brand-200, #c3cffd); background: #fff; font: inherit; font-size: 1.5rem; font-weight: 900;
  color: var(--brand-700); cursor: pointer; box-shadow: 0 4px 0 rgba(61, 91, 224, .25); }
.sp-tile:active { transform: translateY(3px); box-shadow: none; }
.sp-tile:disabled { opacity: .25; transform: none; box-shadow: none; }
.sp-pattern { font-family: var(--mono); font-size: clamp(1.6rem, min(7vw, 9vh), 2.6rem); letter-spacing: .18em; font-weight: 900; color: var(--brand-700); margin: 10px 0 2px; }
body.kb-open .sp-pic, body.sp-short .sp-pic { font-size: clamp(2.4rem, 12vh, 3.6rem); margin: 0; }
body.kb-open .sp-speaker, body.sp-short .sp-speaker { padding: 8px 22px; flex-direction: row; margin: 4px 0; }
body.kb-open .sp-speaker .i, body.sp-short .sp-speaker .i { width: 28px; height: 28px; }
body.kb-open .sp-tiles, body.sp-short .sp-tiles { margin: 6px 0 2px; }
body.kb-open .sp-tile, body.sp-short .sp-tile { height: 42px; min-width: 40px; font-size: 1.2rem; }
body.kb-open .sp-pattern, body.sp-short .sp-pattern { font-size: 1.4rem; margin: 2px 0; }

/* 橫向且可視高度很矮（iPad 橫向＋鍵盤）：題目在左、輸入在右，兩欄並排 */
@media (min-width: 700px) {
  body.kb-open .sp-stage, body.sp-short .sp-stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); column-gap: 20px; align-items: center; text-align: left; padding: 10px 16px; }
  body.kb-open .sp-st-l, body.sp-short .sp-st-l { text-align: center; }
  body.kb-open .sp-st-r, body.sp-short .sp-st-r { min-width: 0; }
  body.kb-open .sp-st-r .sp-actions, body.sp-short .sp-st-r .sp-actions { justify-content: flex-start; }
  body.kb-open .sp-st-r .sp-hintbox, body.sp-short .sp-st-r .sp-hintbox { text-align: left; }
  body.kb-open .sp-st-r .sp-fb, body.sp-short .sp-st-r .sp-fb { text-align: left; }
  body.kb-open .sp-ans-row, body.sp-short .sp-ans-row { margin: 0 0 4px; max-width: none; }
}

/* 後台：主題開關 */
.sp-topic-sw { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.sp-tsw { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: center; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; }
.sp-tsw input { grid-row: span 2; width: 18px; height: 18px; }
.sp-tsw small { color: var(--muted); }
.sp-tsw.on { border-color: var(--mint); background: var(--mint-50); }

/* 學生首頁子分頁：主題世界／起步關卡／班級題組／競賽 */
.sp-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 12px; padding: 4px; background: var(--bg-2); border-radius: 16px; width: fit-content; max-width: 100%; }
.sp-tabs button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 9px 16px; border-radius: 12px; font: inherit; font-weight: 800;
  color: var(--ink-2); cursor: pointer; min-height: 44px; }
.sp-tabs button small { background: rgba(22, 33, 62, .08); border-radius: 99px; padding: 0 7px; font-size: .72rem; }
.sp-tabs button.active { background: #fff; color: var(--spell-700); box-shadow: var(--shadow-sm); }
.sp-tabs button.active small { background: var(--spell-50); }
.sp-tabnote { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }
@media (max-width: 640px) { .sp-tabs { width: 100%; } .sp-tabs button { flex: 1 1 auto; justify-content: center; padding: 9px 8px; } }

/* 中英並列標題、拼字基地子分頁與單元 */
.sp-h1-en { font-size: .55em; font-weight: 800; opacity: .8; margin-left: 4px; }
.sp-tabs button { padding: 6px 14px; }
.sp-tab-l { display: grid; line-height: 1.15; text-align: left; }
.sp-tab-l b { font-size: .98rem; }
.sp-tab-l em { font-style: normal; font-size: .7rem; font-weight: 700; color: var(--muted); }
.sp-tabs button.active .sp-tab-l em { color: var(--spell-700); }
.sp-sub { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.sp-sub button { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 14px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; font: inherit; min-height: 48px; }
.sp-sub button > span:nth-child(2) { display: grid; line-height: 1.15; text-align: left; }
.sp-sub button em { font-style: normal; font-size: .7rem; color: var(--muted); font-weight: 700; }
.sp-sub button small { background: var(--bg-2); border-radius: 99px; padding: 0 8px; font-weight: 800; }
.sp-sub-ab { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--spell); color: #fff; font-weight: 900; }
.sp-sub button.active { border-color: var(--spell); background: var(--spell-50); box-shadow: 0 0 0 3px rgba(124, 92, 240, .12); }
.sp-unit { margin-top: 18px; }
.sp-unit-h { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 1.05rem; font-weight: 900; flex-wrap: wrap; }
.sp-unit-h small { font-weight: 700; color: var(--muted); font-size: .8rem; }
.sp-unit-prog { margin-left: auto; font-size: .8rem; font-weight: 800; color: var(--muted); }
.sp-unit-inline { margin: 14px 0 6px; font-size: .95rem; }
/* 句子題 */
.sp-sentence { font-size: clamp(1.3rem, min(5vw, 7vh), 2.2rem); font-weight: 800; line-height: 1.45; margin: 10px 0 4px; overflow-wrap: anywhere; }
.sp-zh { color: var(--muted); font-weight: 700; margin-bottom: 4px; }
body.kb-open .sp-sentence, body.sp-short .sp-sentence { font-size: clamp(1.1rem, 4.5vh, 1.6rem); margin: 2px 0; }

.sp-sep { width: 1px; height: 24px; background: var(--line-2); margin: 0 6px; display: inline-block; }

.sp-series { display: flex; align-items: center; gap: 10px; margin: 14px 0 8px; color: var(--muted); font-size: .82rem; font-weight: 800; }
.sp-series::before, .sp-series::after { content: ''; height: 1px; background: var(--line-2); flex: 1; }
.sp-review-bottom { margin-top: 26px; }
.sp-steps { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 12px; }
.sp-steps button { display: inline-flex; align-items: baseline; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; font: inherit; min-height: 44px; }
.sp-steps button b { font-weight: 900; }
.sp-steps button span { font-size: .8rem; color: var(--muted); font-weight: 700; }
.sp-steps button small { background: var(--bg-2); border-radius: 99px; padding: 0 8px; font-weight: 800; }
.sp-steps button.active { background: var(--brand-50); border-color: var(--brand-600); color: var(--brand-700); }
.sp-hide { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: .9rem; min-height: 44px; cursor: pointer; }
.sp-hide input { width: 20px; height: 20px; }
.sp-allclear { display: flex; align-items: center; gap: 8px; margin: 6px 0 14px; color: var(--muted); font-weight: 700; }
.seg.wrap { flex-wrap: wrap; overflow: visible; max-width: 100%; height: auto; }
.seg.wrap button { flex: 0 0 auto; }

.sp-ta { max-height: 60dvh; }
.sp-pairs, .spe-pv { contain: content; }
