/* ============================================================
   LUMI 數學偵探社 · 動畫教學播放器
   2026-10-21 立項。全部 class 加 `lmd-` 前綴，避免與站內既有樣式衝突。

   角色：阿祈（Kei，男）· 阿澄（Ching，女）
   目標：每節課一部雙語（粵語 / 英文）偵探動畫，
        含 公式理論 → 如何應用 → 特點 → 技巧 四段完整結構。
   ============================================================ */

.lmd {
  --lmd-ink: #1f2937;
  --lmd-paper: #fffdf7;
  --lmd-accent: #c2410c;
  --lmd-accent2: #1d4ed8;
  --lmd-gold: #f59e0b;
  --lmd-stage: #0f172a;
  --lmd-mint: #10b981;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei",
    "Noto Sans HK", "Segoe UI", sans-serif;
  color: var(--lmd-ink);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.14);
  background: var(--lmd-paper);
  margin: 18px 0;
  border: 1px solid rgba(194, 65, 12, 0.16);
}

/* ── 標題列 ───────────────────────────────────────────── */
.lmd-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  background: linear-gradient(100deg, #7c2d12, #c2410c);
  color: #fff;
  flex-wrap: wrap;
}
.lmd-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.32);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.lmd-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.35;
  flex: 1 1 200px;
  min-width: 0;
}
.lmd-title small {
  display: block;
  font-size: 11px;
  font-weight: 500;
  opacity: 0.82;
  letter-spacing: 0.02em;
}
/* 語言切換 */
.lmd-lang {
  display: flex;
  gap: 0;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}
.lmd-lang button {
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 11px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.lmd-lang button[aria-pressed="true"] {
  background: #fff;
  color: #c2410c;
}

/* ── 舞台 ─────────────────────────────────────────────── */
.lmd-stage {
  position: relative;
  background: radial-gradient(120% 90% at 50% 0%, #1e293b 0%, #0b1220 70%);
  aspect-ratio: 16 / 9;
  min-height: 220px;
  overflow: hidden;
}
@media (max-width: 640px) {
  .lmd-stage { aspect-ratio: 4 / 3; }
}
/* 地板 */
.lmd-floor {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 22%;
  background: linear-gradient(180deg, #1e293b 0%, #0b1220 100%);
  border-top: 2px solid rgba(148, 163, 184, 0.22);
}
/* 聚光燈 */
.lmd-spot {
  position: absolute;
  left: 50%;
  top: -14%;
  width: 130%;
  height: 78%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 100%, rgba(245, 158, 11, 0.16), transparent 62%);
  pointer-events: none;
}

/* 角色：真卡通圖 + 光圈卡（2026-10-21 站長參考「張文暉滿分數學」3D 卡通風格） */
.lmd-actor {
  position: absolute;
  bottom: 16%;
  width: 24%;
  max-width: 175px;
  aspect-ratio: 2 / 3;
  transition: transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.35s, filter 0.35s;
}
.lmd-actor.a { left: 3%; }
.lmd-actor.b { right: 3%; }
.lmd-actor[data-active="0"] { opacity: 0.5; transform: translateY(11px) scale(0.92); filter: saturate(0.75); }
.lmd-actor[data-active="1"] { opacity: 1; transform: translateY(0) scale(1); }
.lmd-actor[data-active="1"].lmd-nod { animation: lmd-nod 1.1s ease-in-out infinite; }
@keyframes lmd-nod {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-9px) rotate(-1.8deg); }
}
/* 光圈卡：白底角色圖與暖色漸變自然融合，免去背工序 */
.lmd-portrait {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 30%, #fffaf0 0%, #ffe9c0 55%, #ffd28f 100%);
  border: 3px solid #f59e0b;
  box-shadow:
    0 12px 26px rgba(0, 0, 0, 0.38),
    0 0 0 5px rgba(245, 158, 11, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}
.lmd-actor.b .lmd-portrait {
  background:
    radial-gradient(120% 90% at 50% 30%, #fff5f6 0%, #ffd9df 55%, #ffb3c0 100%);
  border-color: #f43f5e;
  box-shadow:
    0 12px 26px rgba(0, 0, 0, 0.38),
    0 0 0 5px rgba(244, 63, 94, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}
.lmd-portrait img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* contain：完整顯示全身；白底與光圈卡漸變自然融合 */
  object-fit: contain;
  object-position: center bottom;
  opacity: 0;
  transition: opacity 0.28s ease;
}
.lmd-portrait img[data-on="1"] { opacity: 1; }
/* 角色名 */
.lmd-name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.28);
  padding: 3px 9px;
  border-radius: 999px;
  backdrop-filter: blur(2px);
}
/* 說話泡泡 */
.lmd-bubble {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  transform-origin: bottom center;
  min-width: 46px;
  padding: 5px 10px;
  border-radius: 14px;
  background: #fff;
  color: #1f2937;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  z-index: 3;
  white-space: nowrap;
}
.lmd-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
}
.lmd-bubble[data-on="1"] { transform: translateX(-50%) scale(1); }

/* 中央視覺板 */
.lmd-board {
  position: absolute;
  left: 50%;
  top: 8%;
  transform: translateX(-50%);
  width: 54%;
  max-width: 400px;
  background: rgba(255, 253, 247, 0.97);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  text-align: center;
  transition: opacity 0.3s, transform 0.3s;
}
.lmd-board[data-show="0"] { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(0.96); pointer-events: none; }
.lmd-board[data-show="1"] { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
.lmd-board-cap {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #94a3b8;
  margin-bottom: 5px;
}
.lmd-formula {
  font-size: clamp(15px, 3.4vw, 23px);
  font-weight: 800;
  color: #c2410c;
  line-height: 1.35;
  font-family: "Cambria Math", "Times New Roman", Georgia, serif;
  word-break: break-word;
}
.lmd-formula .lmd-fnote {
  display: block;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  margin-top: 5px;
}

/* 視覺化容器 */
.lmd-viz { width: 100%; }
.lmd-viz svg { display: block; width: 100%; height: auto; max-height: 165px; margin: 0 auto; }
.lmd-pie-slice { transition: opacity 0.5s, transform 0.5s; transform-origin: center; }
.lmd-pie-slice[data-on="0"] { opacity: 0.2; }
.lmd-pie-slice[data-on="1"] { opacity: 1; }
.lmd-fill { transition: width 0.6s ease, height 0.6s ease, opacity 0.5s; }
.lmd-seq-item {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s, transform 0.4s;
}
.lmd-seq-item[data-on="1"] { opacity: 1; transform: translateY(0); }

/* 字幕 */
.lmd-subs {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 10px 16px 12px;
  background: linear-gradient(0deg, rgba(11, 18, 32, 0.94), rgba(11, 18, 32, 0.55) 70%, transparent);
  color: #fff;
  font-size: clamp(12.5px, 2.5vw, 15px);
  line-height: 1.6;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 1px;
}
.lmd-say {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.28s, transform 0.28s;
}
.lmd-say[data-on="1"] { opacity: 1; transform: translateY(0); }
.lmd-who {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 5px;
  flex-shrink: 0;
  margin-top: 2px;
  white-space: nowrap;
}
.lmd-who.kei { background: #1d4ed8; color: #fff; }
.lmd-who.ching { background: #be123c; color: #fff; }
.lmd-who.both { background: #64748b; color: #fff; }
.lmd-who.narr { background: #f59e0b; color: #422006; }
.lmd-txt { flex: 1; min-width: 0; }
.lmd-txt-en { font-size: 0.87em; color: #cbd5e1; }

/* 幕類型標記 */
.lmd-tag {
  position: absolute;
  right: 10px;
  top: 10px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.09em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
}
.lmd-tag.t-formula { background: rgba(194, 65, 12, 0.88); border-color: #fdba74; color: #fff7ed; }
.lmd-tag.t-apply { background: rgba(16, 185, 129, 0.88); border-color: #6ee7b7; color: #022c22; }
.lmd-tag.t-feature { background: rgba(29, 78, 216, 0.88); border-color: #93c5fd; color: #eff6ff; }
.lmd-tag.t-tip { background: rgba(245, 158, 11, 0.92); border-color: #fde68a; color: #422006; }
.lmd-tag.t-solve { background: rgba(190, 18, 60, 0.88); border-color: #fda4af; color: #fff1f2; }

/* ── 控制條 ───────────────────────────────────────────── */
.lmd-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #fffdf7;
  border-top: 1px solid rgba(194, 65, 12, 0.14);
  flex-wrap: wrap;
}
.lmd-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  min-width: 34px;
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid rgba(194, 65, 12, 0.3);
  background: #fff;
  color: #c2410c;
  cursor: pointer;
  transition: background 0.14s, color 0.14s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.lmd-btn:hover { background: #fff7ed; }
.lmd-btn:active { transform: scale(0.94); }
.lmd-btn.primary {
  background: #c2410c;
  border-color: #c2410c;
  color: #fff;
  min-width: 62px;
}
.lmd-btn.primary:hover { background: #9a3412; }
.lmd-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 進度條 */
.lmd-prog {
  flex: 1 1 120px;
  min-width: 80px;
  height: 6px;
  background: #fed7aa;
  border-radius: 999px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.lmd-prog-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #f59e0b, #c2410c);
  border-radius: 999px;
  transition: width 0.25s linear;
}
.lmd-meta {
  font-size: 11px;
  font-weight: 700;
  color: #78716c;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
/* 速度 */
.lmd-speed {
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  height: 30px;
  padding: 0 4px;
  border-radius: 8px;
  border: 1px solid rgba(194, 65, 12, 0.3);
  background: #fff;
  color: #c2410c;
  cursor: pointer;
}

/* ── 知識卡（特點 / 技巧 / 應用）───────────────────────── */
.lmd-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  padding: 12px 14px;
  background: #fffaf3;
  border-top: 1px solid rgba(194, 65, 12, 0.14);
}
.lmd-card {
  background: #fff;
  border: 1px solid rgba(194, 65, 12, 0.16);
  border-radius: 11px;
  padding: 9px 11px;
}
.lmd-card h4 {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 5px;
}
.lmd-card.feature h4 { color: #1d4ed8; }
.lmd-card.tip h4 { color: #b45309; }
.lmd-card.apply h4 { color: #047857; }
.lmd-card ul { margin: 0; padding-left: 16px; }
.lmd-card li {
  font-size: 12.2px;
  line-height: 1.55;
  margin-bottom: 3px;
}
.lmd-card li .en { display: block; font-size: 10.8px; color: #64748b; }

/* ── 破案橫幅 ─────────────────────────────────────────── */
.lmd-solved {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(11, 18, 32, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s;
  text-align: center;
  padding: 20px;
}
.lmd-solved[data-on="1"] { opacity: 1; }
.lmd-solved .lmd-sbig {
  font-size: clamp(18px, 4.6vw, 30px);
  font-weight: 900;
  color: #fcd34d;
  letter-spacing: 0.04em;
}
.lmd-solved .lmd-ssub {
  font-size: clamp(11px, 2.4vw, 13.5px);
  color: #e2e8f0;
  max-width: 90%;
  line-height: 1.6;
}

/* 無障礙 */
@media (prefers-reduced-motion: reduce) {
  .lmd-actor, .lmd-actor[data-active="1"].lmd-nod, .lmd-eye { animation: none !important; }
  .lmd-board, .lmd-say, .lmd-seq-item { transition: none; }
}
.lmd .lmd-sr {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.lmd-btn:focus-visible, .lmd-lang button:focus-visible {
  outline: 2px solid #c2410c;
  outline-offset: 2px;
}

/* ============================================================
   v2 真動畫層（2026-10-21 站長指令：唔好似 PPT，要似動畫片）
   - 角色呼吸浮動 + 講嘢彈跳
   - 換幕場景淡入 + 元素滑入
   - 打字機字幕游標
   - SVG 圖解逐格彈入（stagger）
   ============================================================ */

/* 角色呼吸浮動（常駐） */
@keyframes lmdFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.lmd-actor .lmd-portrait { animation: lmdFloat 3.2s ease-in-out infinite; }
.lmd-actor.b .lmd-portrait { animation-delay: 1.6s; }

/* 講嘢時彈跳 + 微微前傾 */
@keyframes lmdTalk {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-7px) rotate(-1.2deg); }
  50% { transform: translateY(0) rotate(0deg); }
  75% { transform: translateY(-4px) rotate(1.2deg); }
}
.lmd-actor.lmd-nod .lmd-portrait { animation: lmdTalk 0.9s ease-in-out infinite, lmdFloat 3.2s ease-in-out infinite; }

/* 換幕整體淡入 */
@keyframes lmdSceneIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.lmd-stage[data-fresh="1"] .lmd-tag,
.lmd-stage[data-fresh="1"] .lmd-board,
.lmd-stage[data-fresh="1"] .lmd-subs { animation: lmdSceneIn 0.4s ease-out both; }
.lmd-stage[data-fresh="1"] .lmd-board { animation-delay: 0.08s; }
.lmd-stage[data-fresh="1"] .lmd-subs { animation-delay: 0.12s; }

/* 聚光燈慢慢掃動 */
@keyframes lmdSpotSweep {
  0%, 100% { transform: translateX(-6%) scale(1); opacity: 0.85; }
  50% { transform: translateX(6%) scale(1.04); opacity: 1; }
}
.lmd-spot { animation: lmdSpotSweep 9s ease-in-out infinite; }

/* 打字機游標 */
.lmd-caret {
  display: inline-block; width: 2px; height: 1em;
  background: #f59e0b; margin-left: 1px; vertical-align: -0.12em;
  animation: lmdCaretBlink 0.7s steps(1) infinite;
}
@keyframes lmdCaretBlink { 50% { opacity: 0; } }

/* SVG 元素逐格彈入（stagger）——所有 viz 共用 */
@keyframes lmdPop {
  0% { opacity: 0; transform: scale(0.3); }
  60% { opacity: 1; transform: scale(1.12); }
  100% { opacity: 1; transform: scale(1); }
}
.lmd-viz .lmd-pop {
  transform-box: fill-box;
  transform-origin: center;
  animation: lmdPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 140ms);
}

/* 追及/相遇：距離虛線縮短動畫 */
@keyframes lmdDashShrink {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -40; }
}
.lmd-viz .lmd-chase-line {
  stroke-dasharray: 6 5;
  animation: lmdDashShrink 1.2s linear infinite;
}

/* 相遇爆炸字 */
@keyframes lmdMeetBoom {
  0% { opacity: 0; transform: scale(0.4); }
  55% { opacity: 1; transform: scale(1.25); }
  100% { opacity: 1; transform: scale(1); }
}
.lmd-viz .lmd-meet {
  transform-box: fill-box; transform-origin: center;
  animation: lmdMeetBoom 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 2.1s both;
}

/* 破案彩帶 */
@keyframes lmdConfettiFall {
  0% { transform: translateY(-14px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(70px) rotate(300deg); opacity: 0; }
}
.lmd-solved .lmd-confetti {
  position: absolute; width: 6px; height: 10px; border-radius: 1.5px;
  animation: lmdConfettiFall 1.6s ease-in infinite;
  animation-delay: calc(var(--i, 0) * 0.12s);
}

@media (prefers-reduced-motion: reduce) {
  .lmd-actor .lmd-portrait, .lmd-actor.lmd-nod .lmd-portrait,
  .lmd-spot, .lmd-viz .lmd-pop, .lmd-chase-line, .lmd-meet,
  .lmd-solved .lmd-confetti { animation: none !important; }
}
