/* ==========================================================================
   《星光魔法學院：數學篇》夢幻星夜城堡風樣式表
   專為 iPad 橫向＋Apple Pencil 觸控筆體驗與電腦瀏覽器雙重最佳化
   ========================================================================== */

:root {
  --bg-deep: #090d24;
  --bg-mid: #141b3d;
  --card-bg: rgba(23, 31, 68, 0.84);
  --card-border: rgba(251, 191, 36, 0.34);
  --text-main: #f8fafc;
  --text-soft: #cbd5e1;
  --gold: #fbbf24;
  --gold-light: #fef08a;
  --house-primary: #ff5e57;
  --house-secondary: #ffd166;
  --house-glow: rgba(255, 94, 87, 0.45);
  --radius-lg: 20px;
  --radius-md: 14px;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 20% 10%, #1e1b4b 0%, #0f172a 55%, #070a1a 100%);
  color: var(--text-main);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

#starfield-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.screen {
  display: none;
  position: relative;
  z-index: 1;
  min-height: 100dvh;
}

.screen.active {
  display: block;
}

/* 通用按鈕 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.2s ease, background 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  text-decoration: none;
}

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

.btn-primary {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #1e1b4b;
  box-shadow: 0 6px 20px rgba(251, 191, 36, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 8px 26px rgba(251, 191, 36, 0.55);
}

.btn-accent {
  background: linear-gradient(135deg, var(--house-primary), #7c3aed);
  color: #fff;
  box-shadow: 0 6px 20px var(--house-glow);
}

.btn-secondary {
  background: rgba(51, 65, 85, 0.8);
  border-color: rgba(148, 163, 184, 0.4);
  color: #f1f5f9;
}

.btn-danger {
  background: rgba(185, 28, 28, 0.8);
  border-color: #f87171;
  color: #fff;
}

.btn-ghost {
  background: rgba(30, 41, 59, 0.72);
  border: 1.5px solid rgba(251, 191, 36, 0.32);
  color: #fef3c7;
  padding: 8px 14px;
  min-height: 40px;
  font-size: 0.92rem;
}

/* ==================== 1. 入學分院畫面 ==================== */
.enroll-container {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 44px;
  text-align: center;
}

.academy-emblem-title {
  display: inline-block;
  padding: 6px 18px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.16);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: var(--gold-light);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.enroll-title {
  margin: 6px 0 8px;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  background: linear-gradient(90deg, #fef08a, #fbbf24, #93c5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.enroll-subtitle {
  color: var(--text-soft);
  margin: 0 0 22px;
  font-size: 1.05rem;
}

.enroll-card {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.name-step {
  max-width: 520px;
  margin: 0 auto 24px;
  text-align: left;
}

.step-label {
  display: block;
  font-weight: 800;
  color: var(--gold-light);
  margin-bottom: 10px;
  font-size: 1.08rem;
}

.name-input-row {
  display: flex;
  gap: 10px;
}

#enroll-name-input {
  flex: 1;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 14px;
  border: 2px solid rgba(251, 191, 36, 0.45);
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  outline: none;
}

#enroll-name-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2);
}

.shake-input {
  animation: shake 0.4s ease;
  border-color: #fb7185 !important;
}

.house-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.house-card {
  background: rgba(15, 23, 42, 0.78);
  border: 2px solid rgba(148, 163, 184, 0.25);
  border-radius: 18px;
  padding: 16px 14px;
  color: #f8fafc;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  text-align: center;
}

.house-card:hover {
  transform: translateY(-3px);
  border-color: var(--house-secondary);
}

.house-card.selected {
  border-color: var(--house-secondary);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
  box-shadow: 0 0 0 3px var(--house-primary), 0 12px 30px rgba(0, 0, 0, 0.45);
  transform: translateY(-4px);
}

.house-crest-wrap {
  width: 78px;
  height: 78px;
  margin: 0 auto 10px;
}

.house-crest-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.house-name {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--house-secondary);
}

.house-trait {
  font-size: 0.88rem;
  color: #e2e8f0;
  margin: 4px 0;
}

.house-motto {
  font-size: 0.82rem;
  color: #94a3b8;
  margin-bottom: 8px;
}

.house-spell {
  display: inline-block;
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #fef08a;
}

.enroll-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ==================== 0. 多帳號登入大廳 ==================== */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 14px;
  text-align: left;
}

.account-card {
  position: relative;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(148, 163, 184, 0.3);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.16s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.account-card:hover {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 10px 26px rgba(251, 191, 36, 0.22);
}

.account-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-crest {
  width: 58px;
  height: 58px;
  flex-shrink: 0;
}

.account-name {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
}

.account-house-tag {
  display: inline-block;
  margin-top: 2px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  color: #fff;
}

.account-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(30, 41, 59, 0.72);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.82rem;
  color: #cbd5e1;
}

.account-stats strong {
  color: #fef08a;
}

.account-card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.account-card-actions .btn-enter {
  flex: 1;
  min-height: 42px;
  padding: 8px 12px;
  font-size: 0.94rem;
}

.account-card-actions .btn-del-acc {
  min-height: 42px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

/* ==================== 2. 星光學院主地圖 ==================== */
.top-hud {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 16, 42, 0.92);
  border-bottom: 1.5px solid var(--card-border);
  backdrop-filter: blur(12px);
  padding: 10px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hud-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-crest {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

.hud-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
}

.hud-house-pill {
  font-size: 0.78rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--house-primary);
  color: #fff;
  font-weight: 700;
}

.hud-rank-text {
  font-size: 0.85rem;
  color: var(--gold-light);
  font-weight: 700;
}

.hud-exp-track {
  width: 210px;
  max-width: 52vw;
  height: 8px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 2px;
}

.hud-exp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--house-primary), var(--gold));
  transition: width 0.4s ease;
}

.hud-exp-meta {
  font-size: 0.74rem;
  color: #94a3b8;
}

.hud-stats-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-chip {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #fef08a;
}

.rift-alert {
  background: linear-gradient(135deg, #9333ea, #ec4899) !important;
  border-color: #f5d0fe !important;
  color: #fff !important;
  animation: pulseGlow 1.5s infinite;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.74rem;
  font-weight: 800;
}

.map-main {
  max-width: 1220px;
  margin: 0 auto;
  padding: 18px 18px 60px;
}

.grade-tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.grade-pill {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.7);
  border: 1.5px solid rgba(148, 163, 184, 0.22);
  display: flex;
  flex-direction: column;
  font-size: 0.88rem;
  font-weight: 700;
}

.grade-pill small {
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 500;
}

.grade-pill.active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.55), rgba(147, 51, 234, 0.45));
  border-color: var(--gold);
  color: #fef08a;
}

.grade-pill.locked {
  opacity: 0.55;
}

.unit-filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 16px;
}

.filter-chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.75);
  color: #e2e8f0;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--gold);
  border-color: #fef08a;
  color: #1e1b4b;
}

.unit-section {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.unit-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.unit-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.unit-icon {
  font-size: 2rem;
}

.unit-title {
  margin: 0;
  font-size: 1.18rem;
  color: #fef08a;
}

.unit-sub {
  color: #93c5fd;
  font-size: 0.96rem;
}

.unit-desc {
  margin: 2px 0 0;
  font-size: 0.88rem;
  color: var(--text-soft);
}

.unit-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.unit-progress-pill {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #bae6fd;
  font-size: 0.84rem;
  font-weight: 700;
}

.junyi-mini-link {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.18);
  border: 1px solid rgba(52, 211, 153, 0.5);
  color: #a7f3d0;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 700;
}

.stages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 12px;
}

.stage-card {
  position: relative;
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid rgba(148, 163, 184, 0.25);
  border-radius: 16px;
  padding: 12px;
  color: #f8fafc;
  text-align: center;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.stage-card:hover:not(.locked) {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 8px 20px rgba(251, 191, 36, 0.22);
}

.stage-card.cleared {
  border-color: rgba(52, 211, 153, 0.65);
  background: rgba(6, 78, 59, 0.28);
}

.stage-card.miniBoss {
  border-color: rgba(251, 191, 36, 0.72);
  background: linear-gradient(180deg, rgba(120, 53, 15, 0.35), rgba(15, 23, 42, 0.88));
}

.stage-card.grandBoss {
  border-color: rgba(217, 70, 239, 0.8);
  background: linear-gradient(180deg, rgba(88, 28, 135, 0.52), rgba(15, 23, 42, 0.92));
  box-shadow: 0 0 18px rgba(192, 38, 211, 0.25);
}

.stage-card.locked {
  opacity: 0.48;
  filter: grayscale(0.45);
}

.stage-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.stage-num {
  color: #93c5fd;
  font-weight: 800;
}

.boss-badge {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.boss-badge.mini {
  background: #f59e0b;
  color: #1e1b4b;
}

.boss-badge.grand {
  background: linear-gradient(90deg, #ec4899, #facc15);
  color: #1e1b4b;
}

.stage-sprite-mini {
  width: 66px;
  height: 66px;
  margin: 2px auto;
}

.stage-sprite-mini svg {
  width: 100%;
  height: 100%;
}

.stage-name {
  font-size: 0.92rem;
  font-weight: 800;
  margin: 2px 0;
  color: #fff;
}

.stage-enemy {
  font-size: 0.78rem;
  color: #cbd5e1;
  margin-bottom: 4px;
}

.stage-stars {
  font-size: 0.86rem;
  color: #fde047;
  font-weight: 700;
}

/* ==================== 3. iPad 橫向雙欄戰鬥畫面 ==================== */
#screen-battle.active {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.battle-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(11, 16, 42, 0.94);
  border-bottom: 1.5px solid var(--card-border);
  flex-wrap: wrap;
}

.battle-top-left, .battle-top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.battle-stage-title {
  font-weight: 800;
  font-size: 1rem;
  color: #fef08a;
}

.mode-badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

.mode-badge.formal {
  background: linear-gradient(90deg, #dc2626, #f59e0b);
  color: #fff;
}

.mode-badge.practice {
  background: rgba(56, 189, 248, 0.22);
  border: 1px solid #38bdf8;
  color: #bae6fd;
}

.battle-score-pill {
  font-weight: 800;
  color: #fde047;
  font-size: 0.94rem;
}

.battle-combo-pill {
  font-weight: 800;
  color: #fb923c;
  font-size: 0.94rem;
}

/* 左右雙欄主體：預設把計算紙拉寬至約 52%（1.05fr 1.15fr），寫直式更舒適！ */
.battle-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.05fr 1.15fr;
  gap: 12px;
  padding: 10px 14px 12px;
}

.battle-layout.pad-left {
  grid-template-columns: 1.15fr 1.05fr;
}

.battle-layout.pad-left .battle-pane {
  order: 2;
}

.battle-layout.pad-left .scratchpad-pane {
  order: 1;
}

.battle-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* 攻防回合提示與計時條 */
.phase-timer-box {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  padding: 8px 12px;
}

.phase-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.phase-banner {
  font-size: 0.92rem;
  padding: 4px 10px;
  border-radius: 10px;
}

.phase-attack {
  background: rgba(245, 158, 11, 0.22);
  color: #fde68a;
}

.phase-defend {
  background: rgba(56, 189, 248, 0.22);
  color: #bae6fd;
}

.timer-text {
  font-weight: 800;
  font-size: 0.92rem;
  color: #fef08a;
  white-space: nowrap;
}

.timer-track {
  height: 9px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #a78bfa);
  transition: width 0.9s linear, background 0.3s ease;
}

.timer-bar-fill.warn {
  background: linear-gradient(90deg, #f59e0b, #fde047);
}

.timer-bar-fill.danger {
  background: linear-gradient(90deg, #ef4444, #fb7185);
}

.timer-bar-fill.practice {
  background: linear-gradient(90deg, #10b981, #38bdf8);
}

/* 魔法對戰舞台 */
.battle-stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  background: radial-gradient(circle at 50% 25%, rgba(79, 70, 229, 0.35), rgba(15, 23, 42, 0.88));
  border: 1.5px solid var(--card-border);
  border-radius: 16px;
  padding: 8px 14px;
  min-height: 152px;
  overflow: hidden;
}

.actor-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  z-index: 2;
}

.actor-name {
  font-size: 0.84rem;
  font-weight: 800;
  color: #e2e8f0;
  margin-bottom: 2px;
}

.sprite-box {
  width: 108px;
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sprite-svg {
  width: 100%;
  height: 100%;
  animation: floatIdle 2.8s ease-in-out infinite;
}

.player-hp-bar {
  font-size: 1rem;
  letter-spacing: 2px;
}

.monster-hp-wrap {
  width: 130px;
}

.monster-hp-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.monster-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #f97316);
  transition: width 0.35s ease;
}

.monster-hp-text {
  font-size: 0.76rem;
  font-weight: 800;
  color: #fecaca;
  margin-top: 2px;
}

/* 戰鬥特效層 */
.battle-fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.fx-beam {
  position: absolute;
  top: 46%;
  left: 26%;
  width: 48%;
  height: 14px;
  border-radius: 999px;
  animation: beamShoot 0.55s ease-out forwards;
}

.fx-shield {
  position: absolute;
  left: 12%;
  top: 14%;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 4px solid #7dd3fc;
  animation: shieldPulse 0.65s ease-out forwards;
}

.fx-float {
  position: absolute;
  top: 24%;
  font-size: 1.05rem;
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85);
  animation: floatUp 1.05s ease-out forwards;
  white-space: nowrap;
}

.fx-left { left: 12%; }
.fx-right { right: 10%; }
.fx-center { left: 50%; transform: translateX(-50%); }

/* 題目與答題卡片 */
.question-card {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 16px;
  padding: 12px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.question-label {
  font-size: 0.82rem;
  font-weight: 800;
  color: #93c5fd;
  letter-spacing: 0.5px;
}

.btn-hint {
  background: rgba(251, 191, 36, 0.16);
  border: 1.5px solid rgba(251, 191, 36, 0.5);
  color: #fef08a;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.question-visual {
  display: none;
  justify-content: center;
  background: rgba(15, 23, 42, 0.72);
  border-radius: 12px;
  padding: 4px;
}

.math-svg {
  max-width: 100%;
  height: auto;
  max-height: 145px;
}

.question-prompt {
  font-size: 1.18rem;
  font-weight: 800;
  color: #ffffff;
  white-space: pre-line;
  line-height: 1.6;
}

/* 漂亮分數排版 */
.mixed-frac {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}

.frac-whole {
  font-size: 1.15em;
  font-weight: 900;
}

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 3px;
  line-height: 1.05;
  font-size: 0.92em;
}

.frac-num {
  border-bottom: 2px solid currentColor;
  padding: 0 4px 1px;
}

.frac-den {
  padding: 1px 4px 0;
}

.hint-box {
  display: none;
  background: rgba(254, 240, 138, 0.12);
  border-left: 4px solid var(--gold);
  padding: 8px 12px;
  border-radius: 8px;
  color: #fef9c3;
  font-size: 0.92rem;
}

.feedback-banner {
  display: none;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.94rem;
}

.feedback-banner.success {
  background: rgba(16, 185, 129, 0.22);
  border: 1.5px solid #34d399;
  color: #d1fae5;
}

.feedback-banner.error {
  background: rgba(244, 63, 94, 0.22);
  border: 1.5px solid #fb7185;
  color: #ffe4e6;
}

.btn-next-turn {
  margin-top: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  border: none;
  background: #fbbf24;
  color: #1e1b4b;
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
}

/* 四選一大按鈕 */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.9);
  border: 2px solid rgba(148, 163, 184, 0.35);
  color: #fff;
  font-size: 1.08rem;
  font-weight: 800;
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.choice-btn:active {
  transform: scale(0.97);
}

.choice-btn:hover {
  border-color: var(--gold);
}

.choice-btn.correct {
  background: rgba(16, 185, 129, 0.45);
  border-color: #34d399;
}

.choice-btn.wrong {
  background: rgba(239, 68, 68, 0.45);
  border-color: #fb7185;
}

.choice-tag {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(251, 191, 36, 0.2);
  border: 1.5px solid var(--gold);
  color: #fef08a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
  flex-shrink: 0;
}

/* 魔法數字鍵盤 */
.keypad-wrap {
  display: none;
  margin-top: auto;
}

.keypad-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.92);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 8px 16px;
  margin-bottom: 8px;
  min-height: 50px;
}

#keypad-display-val {
  font-size: 1.45rem;
  font-weight: 900;
  color: #fef08a;
  letter-spacing: 1px;
}

#keypad-display-val.placeholder {
  font-size: 1rem;
  font-weight: 600;
  color: #64748b;
}

#keypad-unit {
  font-size: 1rem;
  font-weight: 800;
  color: #93c5fd;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.keypad-btn {
  min-height: 48px;
  border-radius: 12px;
  border: 1.5px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.92);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.keypad-btn:active {
  transform: scale(0.95);
  background: rgba(79, 70, 229, 0.7);
}

.keypad-btn.fn-btn {
  background: rgba(51, 65, 85, 0.92);
  font-size: 0.96rem;
  color: #cbd5e1;
}

.keypad-btn.submit-btn {
  grid-column: span 2;
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #1e1b4b;
  border-color: #fef08a;
  font-size: 1.05rem;
}

/* ==================== 右欄：Apple Pencil 魔法羊皮紙 ==================== */
.scratchpad-pane {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 18px;
  overflow: hidden;
  min-height: 0;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.scratchpad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, 0.9);
  border-bottom: 1px solid rgba(251, 191, 36, 0.3);
}

.scratchpad-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: #fef08a;
}

.scratchpad-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.ink-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  cursor: pointer;
}

.ink-btn.active {
  border-color: #fde047;
  transform: scale(1.14);
  box-shadow: 0 0 10px rgba(253, 224, 71, 0.8);
}

.pad-tool-btn {
  padding: 5px 9px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.pad-tool-btn.active {
  background: rgba(251, 191, 36, 0.25);
  border-color: var(--gold);
  color: #fef08a;
}

.scratchpad-canvas-wrap {
  flex: 1;
  min-height: 240px;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#scratchpad-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* ==================== 彈窗樣式 ==================== */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 7, 20, 0.78);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  overflow-y: auto;
  background: linear-gradient(180deg, #172047, #0e1430);
  border: 2px solid var(--gold);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  text-align: center;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-title {
  margin: 0;
  font-size: 1.3rem;
  color: #fef08a;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(30, 41, 59, 0.8);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

.preview-sprite {
  width: 118px;
  height: 118px;
  margin: 4px auto;
}

.preview-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(15, 23, 42, 0.72);
  border-radius: 14px;
  padding: 12px;
  margin: 12px 0;
  font-size: 0.9rem;
  text-align: left;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.study-links-box {
  background: rgba(16, 185, 129, 0.14);
  border: 1.5px solid rgba(52, 211, 153, 0.55);
  border-radius: 14px;
  padding: 12px;
  margin: 14px 0;
}

.study-links-box p {
  margin: 0 0 10px;
  font-size: 0.92rem;
  color: #d1fae5;
  font-weight: 700;
}

.study-links-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.result-stars {
  font-size: 2rem;
  margin: 6px 0 10px;
}

.result-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.res-stat {
  background: rgba(15, 23, 42, 0.78);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.res-stat span {
  font-size: 0.8rem;
  color: #94a3b8;
}

.res-stat strong {
  font-size: 1.08rem;
  color: #fef08a;
}

.levelup-banner {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.32), rgba(236, 72, 153, 0.32));
  border: 1.5px solid #fde047;
  border-radius: 14px;
  padding: 10px 14px;
  margin: 10px 0;
  color: #fef9c3;
}

/* 錯題本、間隔複習室與家長面板 */
.scroll-list {
  max-height: 45dvh;
  overflow-y: auto;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.mistake-item, .srs-skill-row {
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 12px;
  padding: 10px 12px;
}

.srs-skill-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.srs-skill-row.due {
  border-color: #ec4899;
  background: rgba(131, 24, 67, 0.32);
}

.srs-skill-row small {
  display: block;
  color: #94a3b8;
}

.srs-box-pill {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.2);
  color: #bae6fd;
  white-space: nowrap;
  font-weight: 700;
}

.srs-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.srs-kpi {
  background: rgba(15, 23, 42, 0.8);
  border-radius: 12px;
  padding: 10px;
}

.srs-kpi span {
  display: block;
  font-size: 0.78rem;
  color: #94a3b8;
}

.srs-kpi strong {
  font-size: 1.15rem;
  color: #fef08a;
}

.warn-text { color: #f472b6 !important; }

.mistake-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.mistake-tag {
  font-size: 0.78rem;
  color: #93c5fd;
  font-weight: 700;
}

.btn-mini-clear {
  background: rgba(16, 185, 129, 0.25);
  border: 1px solid #34d399;
  color: #a7f3d0;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.mistake-q {
  font-weight: 700;
  margin-bottom: 4px;
}

.mistake-exp {
  font-size: 0.86rem;
  color: #fde68a;
}

.parent-unit-row {
  margin-bottom: 8px;
}

.parent-unit-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.86rem;
  margin-bottom: 4px;
}

.parent-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  overflow: hidden;
}

.parent-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #34d399);
}

.parent-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.78);
  padding: 12px;
  border-radius: 12px;
  margin-top: 12px;
  text-align: left;
  font-size: 0.9rem;
}

.empty-tip {
  text-align: center;
  color: #94a3b8;
  padding: 20px;
}

/* ==================== 動畫關鍵影格 ==================== */
@keyframes floatIdle {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.6); }
  50% { box-shadow: 0 0 18px 4px rgba(236, 72, 153, 0.75); }
}

@keyframes beamShoot {
  0% { transform: scaleX(0); transform-origin: left; opacity: 1; }
  70% { transform: scaleX(1.05); transform-origin: left; opacity: 1; }
  100% { transform: scaleX(1.1); transform-origin: left; opacity: 0; }
}

@keyframes shieldPulse {
  0% { transform: scale(0.75); opacity: 0.2; }
  45% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1.18); opacity: 0; }
}

@keyframes floatUp {
  0% { transform: translateY(10px); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-28px); opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.anim-cast { animation: castForward 0.45s ease; }
.anim-hit { animation: hitRecoil 0.45s ease; }
.anim-lunge { animation: enemyLunge 0.45s ease; }

@keyframes castForward {
  0%, 100% { transform: translateX(0); }
  40% { transform: translateX(18px) scale(1.06); }
}

@keyframes hitRecoil {
  0%, 100% { transform: translateX(0); filter: brightness(1); }
  30% { transform: translateX(10px); filter: brightness(1.8); }
  60% { transform: translateX(-8px); }
}

@keyframes enemyLunge {
  0%, 100% { transform: translateX(0); }
  40% { transform: translateX(-24px) scale(1.08); }
}

/* ==================== 直向平板與小螢幕適配 ==================== */
@media (max-width: 860px) {
  #screen-battle.active {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }
  .battle-layout, .battle-layout.pad-left {
    grid-template-columns: 1fr;
  }
  .battle-layout.pad-left .battle-pane,
  .battle-layout.pad-left .scratchpad-pane {
    order: initial;
  }
  .scratchpad-canvas-wrap {
    min-height: 300px;
  }
}

/* ==================== 4. 商店、頭銜、授勳動畫與護眼結界樣式 ==================== */

.hud-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.35), rgba(15, 23, 42, 0.9));
  border: 2px solid var(--gold);
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.16s ease;
}

.hud-avatar:hover {
  transform: scale(1.08);
}

.hud-avatar svg {
  width: 100%;
  height: 100%;
}

.hud-title-pill {
  border: 1.5px solid #fde047;
  background: rgba(250, 204, 21, 0.18);
  color: #fef08a;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
}

.stat-chip-btn {
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.2s ease;
}

.stat-chip-btn:hover {
  border-color: #fde047;
  transform: translateY(-1px);
}

.btn-shop {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  border: 1.5px solid #f5d0fe;
  color: #fff;
  padding: 6px 14px;
  min-height: 40px;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(236, 72, 153, 0.35);
}

.shop-silver-pill {
  background: rgba(15, 23, 42, 0.45);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.84rem;
  color: #fef08a;
}

.eyecare-pill {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(52, 211, 153, 0.55);
  color: #a7f3d0;
  font-variant-numeric: tabular-nums;
}

.eyecare-pill.warn {
  background: rgba(245, 158, 11, 0.25);
  border-color: #fbbf24;
  color: #fef08a;
  animation: pulseGlow 1.6s infinite;
}

.modal-wide {
  max-width: 820px;
}

/* 家長測試工具區 */
.parent-tools-box {
  background: rgba(15, 23, 42, 0.72);
  border: 1px dashed rgba(251, 191, 36, 0.45);
  border-radius: 14px;
  padding: 12px;
  margin-top: 12px;
  text-align: left;
}

.parent-tools-title {
  font-size: 0.86rem;
  font-weight: 800;
  color: #fde68a;
  margin-bottom: 8px;
}

.parent-tools-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 🛍️ 星光魔法商店 */
.shop-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  text-align: left;
}

.shop-preview-panel {
  background: radial-gradient(circle at 50% 35%, rgba(79, 70, 229, 0.38), rgba(15, 23, 42, 0.92));
  border: 1.5px solid var(--card-border);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.shop-preview-stage {
  width: 175px;
  height: 175px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shop-preview-caption {
  font-size: 0.84rem;
  color: #fef08a;
  font-weight: 700;
  margin-top: 6px;
}

.shop-equipped-summary {
  width: 100%;
  margin-top: 10px;
  background: rgba(15, 23, 42, 0.78);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.8rem;
  color: #cbd5e1;
  text-align: left;
  line-height: 1.65;
}

.shop-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.shop-tab-btn {
  flex: 1;
  min-height: 42px;
  border-radius: 12px;
  border: 1.5px solid rgba(148, 163, 184, 0.32);
  background: rgba(15, 23, 42, 0.8);
  color: #e2e8f0;
  font-size: 0.94rem;
  font-weight: 800;
  cursor: pointer;
}

.shop-tab-btn.active {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  border-color: #fef08a;
  color: #1e1b4b;
}

.shop-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  max-height: 52dvh;
  overflow-y: auto;
  padding-right: 4px;
}

.shop-item-card {
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(148, 163, 184, 0.25);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.14s ease;
}

.shop-item-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.shop-item-card.equipped {
  border-color: #34d399;
  background: rgba(6, 78, 59, 0.32);
}

.shop-item-card.previewing {
  box-shadow: 0 0 0 2px #f472b6;
}

.shop-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.shop-item-name {
  font-weight: 800;
  color: #fff;
  font-size: 0.96rem;
}

.rarity-tag {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 800;
  background: rgba(99, 102, 241, 0.28);
  color: #c7d2fe;
}

.rarity-tag.r-史詩 { background: rgba(168, 85, 247, 0.35); color: #f3e8ff; }
.rarity-tag.r-傳說 { background: linear-gradient(90deg, #f59e0b, #ec4899); color: #fff; }

.shop-item-desc {
  font-size: 0.8rem;
  color: #94a3b8;
  flex: 1;
}

.shop-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.shop-price {
  font-weight: 800;
  color: #fef08a;
  font-size: 0.9rem;
}

.btn-buy-mini {
  padding: 6px 12px;
  border-radius: 999px;
  border: none;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-buy-mini.buy { background: #fbbf24; color: #1e1b4b; }
.btn-buy-mini.equip { background: #38bdf8; color: #0f172a; }
.btn-buy-mini.active { background: #10b981; color: #fff; }

/* 🎖️ 學院榮譽頭銜榜 */
.title-rule-banner {
  background: rgba(245, 158, 11, 0.16);
  border: 1.5px solid rgba(251, 191, 36, 0.55);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.88rem;
  color: #fef3c7;
  text-align: left;
  margin-bottom: 12px;
}

.titles-current-card {
  background: rgba(15, 23, 42, 0.82);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 12px;
  text-align: left;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(15, 23, 42, 0.78);
  border: 1.5px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  padding: 10px 14px;
}

.title-row.current {
  border-color: #fde047;
  background: linear-gradient(90deg, rgba(250, 204, 21, 0.18), rgba(79, 70, 229, 0.24));
}

.title-row.achieved {
  border-color: rgba(52, 211, 153, 0.45);
}

/* 👑 院長授勳慶祝小動畫 */
.ceremony-backdrop {
  background: radial-gradient(circle at 50% 40%, rgba(49, 46, 129, 0.92), rgba(4, 7, 20, 0.96));
  z-index: 80;
}

.ceremony-box {
  position: relative;
  overflow: hidden;
  max-width: 680px;
  border: 3px solid #fde047;
  box-shadow: 0 0 60px rgba(250, 204, 21, 0.45);
}

.ceremony-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-dot {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  animation: confettiFall 2.6s linear infinite;
}

.ceremony-title {
  margin: 8px 0 12px;
  font-size: 1.55rem;
  background: linear-gradient(90deg, #fef08a, #fbbf24, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.ceremony-stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 0.7fr 1fr;
  align-items: center;
  background: radial-gradient(circle at 50% 50%, rgba(251, 191, 36, 0.22), rgba(15, 23, 42, 0.85));
  border: 1.5px solid rgba(253, 224, 71, 0.5);
  border-radius: 18px;
  padding: 14px 10px;
  margin-bottom: 14px;
}

.ceremony-actor {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ceremony-sprite {
  width: 132px;
  height: 132px;
  position: relative;
  z-index: 2;
}

.ceremony-actor-label {
  font-size: 0.86rem;
  font-weight: 800;
  color: #fef08a;
  margin-top: 4px;
}

.headmaster-enter {
  animation: slideInLeft 0.7s ease-out;
}

.student-blessed {
  animation: studentCelebrate 1.4s ease-in-out infinite;
}

.ceremony-halo-ring {
  position: absolute;
  top: 6px;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 3px dashed #fde047;
  box-shadow: 0 0 28px rgba(250, 204, 21, 0.75);
  animation: spinSlow 6s linear infinite;
}

.ceremony-magic-arc {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ceremony-beam {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #fbbf24, #fff, #f472b6);
  box-shadow: 0 0 20px #fde047;
  animation: beamGlowPulse 1.2s ease-in-out infinite;
}

.ceremony-stars {
  font-size: 1.4rem;
  margin-top: 6px;
  animation: floatIdle 1.6s ease-in-out infinite;
}

.ceremony-title-ribbon {
  display: inline-block;
  padding: 8px 26px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  border: 2px solid #fef08a;
  color: #fff;
  font-size: 1.35rem;
  font-weight: 900;
  box-shadow: 0 8px 26px rgba(236, 72, 153, 0.45);
  animation: popIn 0.65s cubic-bezier(0.2, 1.3, 0.4, 1);
}

.ceremony-quote {
  margin: 12px 10px;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.76);
  border-left: 4px solid #fde047;
  border-radius: 10px;
  color: #fef9c3;
  font-size: 0.96rem;
}

.ceremony-bonus-pill {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.22);
  border: 1.5px solid #34d399;
  color: #a7f3d0;
  font-weight: 800;
  font-size: 0.94rem;
}

/* 🌙 全螢幕強制護眼休息結界 */
.eyecare-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: radial-gradient(circle at 50% 25%, #134e4a 0%, #0f172a 60%, #020617 100%);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.eyecare-overlay.open {
  display: flex;
}

.eyecare-card {
  width: 100%;
  max-width: 600px;
  background: rgba(15, 23, 42, 0.88);
  border: 2.5px solid #34d399;
  border-radius: 26px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.eyecare-moon {
  font-size: 2.6rem;
  margin-bottom: 6px;
}

.eyecare-title {
  margin: 0 0 8px;
  font-size: 1.65rem;
  color: #a7f3d0;
}

.eyecare-subtitle {
  color: #cbd5e1;
  font-size: 1rem;
  margin: 0 0 18px;
}

.eyecare-clock-box {
  background: rgba(6, 78, 59, 0.42);
  border: 2px solid rgba(52, 211, 153, 0.55);
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 16px;
}

.eyecare-clock-label {
  font-size: 0.9rem;
  color: #6ee7b7;
  font-weight: 700;
}

.eyecare-clock {
  font-size: 3.8rem;
  font-weight: 900;
  color: #fef08a;
  letter-spacing: 3px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.eyecare-tip {
  background: rgba(254, 240, 138, 0.12);
  border-radius: 14px;
  padding: 12px 16px;
  color: #fef9c3;
  font-size: 1.02rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.eyecare-note {
  font-size: 0.84rem;
  color: #94a3b8;
  margin: 0 0 18px;
}

.btn-parent-subtle {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #94a3b8;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}

.eyecare-unlock-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(251, 191, 36, 0.45);
}

.eyecare-input {
  width: 140px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid #fbbf24;
  background: #0f172a;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(520px) rotate(540deg); opacity: 0.1; }
}

@keyframes slideInLeft {
  0% { transform: translateX(-45px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}

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

@keyframes spinSlow {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes beamGlowPulse {
  0%, 100% { opacity: 0.7; transform: scaleY(0.9); }
  50% { opacity: 1; transform: scaleY(1.25); }
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 720px) {
  .shop-layout {
    grid-template-columns: 1fr;
  }
  .ceremony-stage {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* ==================== 5. 管理員後台與擴充商店樣式 ==================== */

.admin-only-btn {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.25), rgba(147, 51, 234, 0.35)) !important;
  border-color: #fde047 !important;
  color: #fef08a !important;
}

.admin-login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid rgba(251, 191, 36, 0.45);
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  outline: none;
}

.admin-input:focus {
  border-color: #fde047;
}

.admin-inspect-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 700;
}

.admin-select {
  flex: 1;
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: #0f172a;
  color: #fef08a;
  padding: 4px 10px;
  font-size: 0.92rem;
  font-weight: 700;
}

.shop-tabs {
  flex-wrap: wrap;
}

.shop-tab-btn {
  flex: initial;
  padding: 6px 12px;
  font-size: 0.86rem;
  min-height: 38px;
}

.shop-subfilters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.subfilter-pill {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.82);
  color: #cbd5e1;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.subfilter-pill.active {
  background: #38bdf8;
  border-color: #bae6fd;
  color: #0f172a;
}

.subfilter-pill.lv-locked {
  opacity: 0.65;
}

.shop-section-banner {
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(165, 180, 252, 0.5);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 0.83rem;
  color: #e0e7ff;
  line-height: 1.5;
}

.shop-item-card.locked-item {
  opacity: 0.78;
}

.outfit-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}

.outfit-badge.perm {
  background: rgba(16, 185, 129, 0.25);
  color: #a7f3d0;
  border: 1px solid rgba(52, 211, 153, 0.5);
}

.outfit-badge.bound {
  background: rgba(245, 158, 11, 0.25);
  color: #fef08a;
  border: 1px solid rgba(251, 191, 36, 0.6);
}

.outfit-badge.free {
  background: rgba(236, 72, 153, 0.25);
  color: #fbcfe8;
  border: 1px solid rgba(244, 114, 182, 0.6);
}

.btn-buy-mini.locked {
  background: rgba(71, 85, 105, 0.85);
  color: #cbd5e1;
}

.btn-buy-mini.free-claim {
  background: linear-gradient(135deg, #ec4899, #f59e0b);
  color: #fff;
}

/* ==================== 6. 滿版計算紙＋頂部浮動題目條（GoodNotes 體驗） ==================== */

.pad-fs-btn {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(236, 72, 153, 0.3)) !important;
  border-color: #fde047 !important;
  color: #fef08a !important;
  font-weight: 800 !important;
}

.fullscreen-question-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(90deg, #172047, #1e1b4b 60%, #172047);
  border-bottom: 2px solid var(--gold);
  flex-shrink: 0;
}

.scratchpad-pane.is-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 65;
  border-radius: 0 !important;
  border: none !important;
  width: 100vw !important;
  height: 100dvh !important;
}

.scratchpad-pane.is-fullscreen .fullscreen-question-bar {
  display: flex;
}

.fs-q-left {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.fs-q-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}

.fs-phase-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  background: rgba(245, 158, 11, 0.25);
  color: #fde68a;
}

.fs-phase-badge.defend {
  background: rgba(56, 189, 248, 0.25);
  color: #bae6fd;
}

.fs-timer-text {
  font-size: 0.88rem;
  font-weight: 900;
  color: #fef08a;
}

.fs-timer-text.danger {
  color: #fb7185;
}

.fs-gesture-tip {
  font-size: 0.78rem;
  color: #93c5fd;
  font-weight: 600;
}

.fs-question-prompt {
  font-size: 1.12rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.45;
  white-space: pre-line;
}

.fs-question-visual {
  display: none;
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.82);
  border-radius: 10px;
  padding: 2px 6px;
}

.fs-question-visual svg {
  max-height: 76px;
  width: auto;
}

.fs-done-btn {
  flex-shrink: 0;
  min-height: 44px;
  padding: 8px 18px;
  font-size: 0.96rem;
}

@media (max-width: 720px) {
  .fullscreen-question-bar {
    flex-wrap: wrap;
    padding: 8px 12px;
  }
  .fs-done-btn {
    width: 100%;
  }
}

/* ==================== 7. 科目館切換、英文全寬大畫面戰鬥與兩大特殊副本樣式 ==================== */

.subject-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.subject-tab {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.8);
  border: 2px solid rgba(148, 163, 184, 0.3);
  color: #e2e8f0;
  text-align: left;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.subject-tab:hover {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.subject-tab.active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.52), rgba(236, 72, 153, 0.34));
  border-color: #fde047;
  box-shadow: 0 8px 26px rgba(250, 204, 21, 0.22);
}

.subject-tab .subj-icon {
  font-size: 2.1rem;
}

.subject-tab strong {
  display: block;
  font-size: 1.15rem;
  color: #fef08a;
}

.subject-tab small {
  display: block;
  font-size: 0.82rem;
  color: #cbd5e1;
  margin-top: 2px;
}

.new-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ec4899, #f59e0b);
  color: #fff;
  vertical-align: middle;
  margin-left: 4px;
}

/* 英文館三大特殊副本橫幅 */
.english-dungeons-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.dungeon-banner-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 2px solid rgba(253, 224, 71, 0.55);
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.2s ease;
}

.dungeon-banner-card.speaking {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.46), rgba(236, 72, 153, 0.46));
  border-color: #f0abfc;
  box-shadow: 0 6px 20px rgba(236, 72, 153, 0.2);
}

.dungeon-banner-card.match {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.38), rgba(139, 92, 246, 0.48));
}

.dungeon-banner-card.dialogue {
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.36), rgba(245, 158, 11, 0.38));
}

.dungeon-banner-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(251, 191, 36, 0.25);
}

.dungeon-emoji {
  font-size: 2rem;
  flex-shrink: 0;
}

.dungeon-banner-card strong {
  display: block;
  font-size: 1rem;
  color: #fef08a;
}

.dungeon-banner-card small {
  display: block;
  font-size: 0.82rem;
  color: #e2e8f0;
  margin-top: 2px;
}

.dungeon-go {
  margin-left: auto;
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid #fde047;
  color: #fef08a;
  font-size: 0.82rem;
  font-weight: 800;
}

/* 英文全寬大畫面戰鬥佈局（隱藏右側數學手寫紙） */
.battle-layout.english-mode {
  grid-template-columns: 1fr !important;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

.battle-layout.english-mode .scratchpad-pane {
  display: none !important;
}

.battle-layout.english-mode .battle-stage {
  min-height: 175px;
}

.battle-layout.english-mode .sprite-box {
  width: 124px;
  height: 124px;
}

/* 英文語音朗讀與閱讀短文區 */
.en-audio-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.en-audio-btn {
  min-height: 42px;
  padding: 6px 18px;
  font-size: 0.94rem;
}

.en-reading-box {
  background: #fbf6e9;
  color: #1e293b;
  border: 2px solid #f59e0b;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.7;
  box-shadow: inset 0 0 14px rgba(180, 145, 95, 0.25);
}

/* 英文拼字字母磚與句型重組區 */
.en-interactive-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
}

.en-spell-slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 54px;
  padding: 8px;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid var(--gold);
  border-radius: 14px;
}

.spell-slot {
  width: 44px;
  height: 46px;
  border-radius: 10px;
  border: 2px dashed rgba(251, 191, 36, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  font-weight: 900;
  color: #fef08a;
  background: rgba(30, 41, 59, 0.7);
}

.spell-slot.filled {
  border-style: solid;
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.22);
}

.en-scramble-answer {
  min-height: 58px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid var(--gold);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 1.15rem;
  font-weight: 800;
  color: #fef08a;
}

.en-scramble-answer.placeholder {
  color: #64748b;
  font-size: 0.98rem;
}

.assembled-word-pill {
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.25);
  border: 1.5px solid #38bdf8;
  color: #fff;
}

.en-tiles-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.en-tile-btn {
  min-width: 50px;
  min-height: 48px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 2px solid rgba(148, 163, 184, 0.45);
  background: rgba(30, 41, 59, 0.94);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, border-color 0.15s ease;
}

.en-tile-btn:hover:not(:disabled) {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.en-tile-btn.used {
  opacity: 0.28;
  pointer-events: none;
}

.en-action-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* 雙軌口說挑戰區 */
.en-speak-card {
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid #c084fc;
  border-radius: 16px;
  padding: 14px 16px;
  text-align: center;
}

.en-speak-target {
  font-size: 1.65rem;
  font-weight: 900;
  color: #fef08a;
  letter-spacing: 0.5px;
}

.en-speak-guide {
  font-size: 0.92rem;
  color: #bae6fd;
  margin-top: 4px;
}

.en-mic-area {
  text-align: center;
}

.btn-mic-record {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  color: #fff;
  border: 2px solid #f5d0fe;
  font-size: 1.05rem;
  padding: 10px 24px;
}

.btn-mic-record.listening {
  animation: pulseGlow 1.1s infinite;
  background: linear-gradient(135deg, #ef4444, #f59e0b);
}

.en-mic-hint {
  font-size: 0.82rem;
  color: #94a3b8;
  margin-top: 4px;
}

.en-speak-fallback {
  background: rgba(30, 41, 59, 0.68);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 14px;
  padding: 10px 12px;
}

.en-fallback-label {
  font-size: 0.86rem;
  color: #fde68a;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.en-fallback-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

/* 💎 單字消消樂副本樣式 */
.match-stats-bar {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 8px 0 12px;
  font-size: 0.94rem;
  color: #cbd5e1;
}

.match-stats-bar strong {
  color: #fef08a;
}

.match-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.match-card {
  min-height: 82px;
  padding: 10px;
  border-radius: 14px;
  border: 2px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.15s ease, opacity 0.25s ease;
}

.match-card.en {
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(30, 58, 138, 0.42);
}

.match-card.zh {
  border-color: rgba(244, 114, 182, 0.5);
  background: rgba(131, 24, 67, 0.35);
}

.match-card.selected {
  border-color: #fde047;
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.65);
  transform: scale(1.04);
}

.match-card.matched {
  opacity: 0.22;
  border-color: #34d399;
  transform: scale(0.92);
}

.match-card.wrong-flash {
  border-color: #ef4444;
  animation: shake 0.4s ease;
}

.match-side-tag {
  font-size: 0.72rem;
  color: #93c5fd;
  font-weight: 800;
}

.match-card-text {
  font-size: 1.04rem;
  font-weight: 800;
}

/* 💬 英語對話冒險副本樣式 */
.dlg-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.dlg-quest-card {
  background: rgba(15, 23, 42, 0.86);
  border: 2px solid rgba(251, 191, 36, 0.4);
  border-radius: 16px;
  padding: 14px;
  color: #fff;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.dlg-quest-card:hover {
  transform: translateY(-3px);
  border-color: #fde047;
}

.dlg-quest-sprite {
  width: 78px;
  height: 78px;
  margin: 0 auto 6px;
}

.dlg-quest-title {
  font-size: 1.04rem;
  font-weight: 800;
  color: #fef08a;
  margin-bottom: 4px;
}

.dlg-quest-desc {
  font-size: 0.84rem;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.dlg-quest-reward {
  font-size: 0.82rem;
  font-weight: 800;
  color: #a7f3d0;
}

.dlg-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}

.dlg-npc-box {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(15, 23, 42, 0.84);
  border: 1.5px solid var(--card-border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}

.dlg-npc-avatar {
  text-align: center;
  flex-shrink: 0;
}

.dlg-sprite-box {
  width: 96px;
  height: 96px;
}

.dlg-npc-name {
  font-size: 0.84rem;
  font-weight: 800;
  color: #fde68a;
}

.dlg-bubble {
  flex: 1;
}

.dlg-npc-en {
  font-size: 1.25rem;
  font-weight: 900;
  color: #fff;
  margin-bottom: 4px;
}

.dlg-npc-zh {
  font-size: 0.94rem;
  color: #fde68a;
  margin-bottom: 8px;
}

.dlg-bubble-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.dlg-options-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dlg-option-btn {
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.9);
  color: #fff;
  text-align: left;
  cursor: pointer;
}

.dlg-option-btn:hover {
  border-color: var(--gold);
}

.dlg-option-btn.correct {
  background: rgba(16, 185, 129, 0.4);
  border-color: #34d399;
}

.dlg-option-btn.wrong {
  background: rgba(239, 68, 68, 0.4);
  border-color: #fb7185;
}

.dlg-opt-en {
  font-size: 1.06rem;
  font-weight: 800;
}

.dlg-opt-zh {
  font-size: 0.84rem;
  color: #cbd5e1;
  margin-top: 2px;
}

@media (max-width: 720px) {
  .subject-switcher, .english-dungeons-bar {
    grid-template-columns: 1fr;
  }
  .match-cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .dlg-npc-box {
    flex-direction: column;
    text-align: center;
  }
}


/* ==================== 百件裝備館系列橫幅與每日挑戰上限徽章 ==================== */
.shop-collection-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  margin-top: 6px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(49, 46, 129, 0.72), rgba(88, 28, 135, 0.52));
  border: 1.5px solid rgba(251, 191, 36, 0.48);
}

.shop-col-info {
  text-align: left;
  flex: 1;
  min-width: 200px;
}

.shop-col-title {
  font-size: 0.98rem;
  font-weight: 900;
  color: #fef08a;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.shop-col-desc {
  font-size: 0.8rem;
  color: #e2e8f0;
  margin-top: 2px;
}

.shop-col-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stage-daily-pill {
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.2);
  color: #bae6fd;
  border: 1px solid rgba(56, 189, 248, 0.45);
  display: inline-block;
}

.stage-daily-pill.capped {
  background: rgba(244, 63, 94, 0.24);
  color: #fecdd3;
  border-color: rgba(244, 63, 94, 0.65);
}


/* ✨ 黃金神秘彩蛋題（2 倍暴擊特效） */
.question-card.golden-bonus {
  border-color: #fde047 !important;
  background: linear-gradient(160deg, rgba(120, 53, 15, 0.55), rgba(30, 27, 75, 0.94));
  box-shadow: 0 0 26px rgba(250, 204, 21, 0.45);
}

.question-card.golden-bonus .question-label {
  color: #fef08a;
  font-weight: 900;
}


/* ==================== 🐾 星光靈寵系統與合體頭像樣式 ==================== */
@keyframes petBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.pet-companion-bob {
  animation: petBob 2.2s ease-in-out infinite;
}

.btn-pet {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  color: #fff;
  border-color: #f5d0fe;
}

.btn-pet.needs-care {
  background: linear-gradient(135deg, #f97316, #ef4444);
  border-color: #fef08a;
  animation: pulseGlow 1.5s infinite;
}

.pet-adopt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}

.pet-adopt-card {
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid rgba(251, 191, 36, 0.45);
  border-radius: 18px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.pet-adopt-sprite {
  width: 120px;
  height: 120px;
  margin: 0 auto;
}

.pet-layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 16px;
  align-items: start;
}

.pet-left-panel {
  background: rgba(15, 23, 42, 0.82);
  border: 1.5px solid var(--card-border);
  border-radius: 18px;
  padding: 12px;
}

.pet-name-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  margin-bottom: 6px;
}

.pet-showcase-stage {
  width: 224px;
  height: 176px;
  margin: 0 auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease;
}

.pet-showcase-stage:active {
  transform: scale(0.96);
}

.pet-speech-bubble {
  background: rgba(30, 41, 59, 0.92);
  border: 1.5px solid rgba(253, 224, 71, 0.55);
  border-radius: 12px;
  padding: 7px 10px;
  font-size: 0.84rem;
  color: #fef9c3;
  font-weight: 700;
  margin: 6px 0 8px;
}

.pet-bond-banner {
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 10px;
  padding: 6px 9px;
  font-size: 0.77rem;
  color: #bae6fd;
  text-align: left;
  margin-bottom: 8px;
}

.pet-bond-banner.active {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.28), rgba(236, 72, 153, 0.28));
  border-color: #fde047;
  color: #fef08a;
}

.pet-stat-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.pet-stat-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  font-size: 0.8rem;
  color: #cbd5e1;
  text-align: left;
}

.pet-stat-row strong {
  text-align: right;
  color: #fef08a;
}

.pet-stat-row .parent-bar {
  grid-column: 1 / -1;
  height: 8px;
}

.pet-buffs-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.pet-buff-pill {
  font-size: 0.77rem;
  font-weight: 800;
  padding: 5px 8px;
  border-radius: 9px;
  background: rgba(30, 41, 59, 0.75);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.25);
  text-align: left;
}

.pet-buff-pill.on {
  background: rgba(16, 185, 129, 0.2);
  color: #a7f3d0;
  border-color: #34d399;
}

.pet-evolve-box {
  background: rgba(49, 46, 129, 0.45);
  border: 1.5px solid rgba(192, 132, 252, 0.55);
  border-radius: 12px;
  padding: 9px;
}

.pet-subhead {
  grid-column: 1 / -1;
  text-align: left;
  font-size: 0.92rem;
  font-weight: 900;
  color: #fef08a;
  margin-top: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(251, 191, 36, 0.35);
}

@media (max-width: 780px) {
  .pet-layout {
    grid-template-columns: 1fr;
  }
}

/* ==================== 🎙️ 星光魔法口說殿與麥克風逐字評分樣式 ==================== */
@media (max-width: 960px) {
  .english-dungeons-bar {
    grid-template-columns: 1fr;
  }
}

.speak-word-pill {
  display: inline-block;
  padding: 2px 9px;
  margin: 2px 2px;
  border-radius: 10px;
  transition: transform 0.18s ease, background 0.18s ease;
}

.speak-word-pill.hit {
  background: rgba(16, 185, 129, 0.28);
  border: 1.5px solid #34d399;
  color: #a7f3d0;
}

.speak-word-pill.miss {
  background: rgba(245, 158, 11, 0.24);
  border: 1.5px dashed #fbbf24;
  color: #fde68a;
}

.speak-live-bubble {
  margin: 10px auto 4px;
  max-width: 560px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.18);
  border: 1.5px solid #38bdf8;
  color: #e0f2fe;
  font-size: 0.96rem;
  font-weight: 800;
  text-align: center;
}

.dlg-voice-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: rgba(88, 28, 135, 0.28);
  border: 1.5px solid rgba(240, 171, 252, 0.45);
}

.dlg-mic-btn {
  min-height: 44px;
  padding: 8px 22px;
  font-size: 0.96rem;
}

.dlg-mic-status {
  font-size: 0.85rem;
  color: #e9d5ff;
  text-align: center;
  font-weight: 700;
}

.speak-mode-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.speak-mode-btn {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1.5px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.78);
  color: #cbd5e1;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.16s ease;
}

.speak-mode-btn.active {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.55), rgba(236, 72, 153, 0.5));
  border-color: #fde047;
  color: #fef08a;
  box-shadow: 0 4px 14px rgba(168, 85, 247, 0.28);
}

.speak-studio-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.speak-challenge-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.55), rgba(88, 28, 135, 0.45));
  border: 1.5px solid rgba(251, 191, 36, 0.5);
}

.speak-echo-sprite {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}

.speak-echo-sprite svg {
  width: 100%;
  height: 100%;
}

.speak-challenge-info {
  text-align: left;
}

.speak-challenge-title {
  font-size: 0.95rem;
  font-weight: 900;
  color: #fef08a;
  margin-bottom: 6px;
}

.speak-challenge-dots {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.speak-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  background: rgba(15, 23, 42, 0.72);
  border: 1.5px solid rgba(148, 163, 184, 0.4);
  color: #94a3b8;
}

.speak-dot.current {
  border-color: #f472b6;
  background: rgba(236, 72, 153, 0.25);
  transform: scale(1.08);
}

.speak-dot.done {
  border-color: #fde047;
  background: rgba(250, 204, 21, 0.22);
  color: #fef08a;
}

.speak-prompt-card {
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid rgba(192, 132, 252, 0.65);
  border-radius: 18px;
  padding: 16px 18px;
  text-align: center;
}

.speak-card-meta {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.speak-unit-pill, .speak-kind-pill {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}

.speak-unit-pill {
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #bae6fd;
}

.speak-kind-pill {
  background: rgba(251, 191, 36, 0.18);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fef08a;
}

.speak-item-icon {
  font-size: 2.5rem;
  line-height: 1.1;
  margin-bottom: 6px;
}

.speak-target-words {
  font-size: 1.9rem;
  font-weight: 900;
  color: #fef08a;
  line-height: 1.45;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.speak-target-zh {
  font-size: 1.05rem;
  font-weight: 800;
  color: #e2e8f0;
}

.speak-target-guide {
  font-size: 0.88rem;
  color: #7dd3fc;
  margin-top: 4px;
}

.speak-demo-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.speak-mic-panel {
  background: rgba(30, 41, 59, 0.72);
  border: 1.5px solid rgba(244, 114, 182, 0.45);
  border-radius: 16px;
  padding: 14px 16px;
  text-align: center;
}

.speak-mic-btn-row {
  display: flex;
  justify-content: center;
}

.speak-mic-main-btn {
  min-width: 260px;
  min-height: 54px;
  font-size: 1.12rem;
  border-radius: 999px;
}

.speak-eval-box {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  text-align: left;
}

.speak-eval-box.pass {
  background: rgba(16, 185, 129, 0.18);
  border: 1.5px solid #34d399;
  color: #d1fae5;
}

.speak-eval-box.retry {
  background: rgba(245, 158, 11, 0.16);
  border: 1.5px solid #fbbf24;
  color: #fef3c7;
}

.speak-eval-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.speak-eval-stars {
  font-size: 1.15rem;
  font-weight: 900;
}

.speak-eval-score {
  font-size: 0.92rem;
}

.speak-eval-heard {
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.speak-eval-msg {
  font-size: 0.9rem;
  font-weight: 700;
}

.speak-self-record-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.speak-self-record-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.speak-rec-btn {
  min-height: 42px;
  padding: 8px 18px;
  font-size: 0.92rem;
}

.speak-rec-btn.recording {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: #fca5a5;
  color: #fff;
  animation: pulseGlow 1.1s infinite;
}

.speak-rec-status {
  font-size: 0.8rem;
  color: #94a3b8;
  text-align: center;
}

@media (max-width: 680px) {
  .speak-mode-bar {
    grid-template-columns: 1fr;
  }
  .speak-target-words {
    font-size: 1.48rem;
  }
  .speak-mic-main-btn {
    min-width: 100%;
  }
}

/* ==================== iPadOS / iOS 主畫面 App 安全區域自動避讓（避免頂部時間列擋住畫面） ==================== */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* iPad 加入主畫面獨立 App 模式：確保頂部至少保留足夠空間避開時間／狀態列 */
@media (display-mode: standalone) {
  :root {
    --safe-top: max(env(safe-area-inset-top, 0px), 30px);
  }
}

.top-hud {
  padding-top: calc(10px + var(--safe-top));
}

.battle-topbar {
  padding-top: calc(8px + var(--safe-top));
}

.enroll-container {
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}

.map-main {
  padding-bottom: calc(28px + var(--safe-bottom));
}

.modal-backdrop {
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}

.scratchpad-pane.is-fullscreen .fullscreen-question-bar {
  padding-top: calc(8px + var(--safe-top));
}

.eyecare-overlay {
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
}
