/**
 * Manim Blackboard Teaching Player — chalk-on-board animation system
 *
 * Dark board + chalk text + step-by-step reveal + compact subtitle-style narration.
 * Narration appears BELOW the board (never overlaps content).
 */

/* ── Root Container ── */
.manim-root {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  overflow: hidden;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  user-select: none;
}

/* ── Top Bar ── */
.manim-topbar {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  z-index: 10;
  gap: 10px;
  min-height: 40px;
}

.manim-back {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #c9d1d9;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: background 0.2s;
  white-space: nowrap;
}
.manim-back:hover { background: rgba(255, 255, 255, 0.15); }

.manim-topbar-title {
  flex: 1;
  color: #e6edf3;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manim-phase-badge {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.3);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.manim-topbar-time {
  color: #8b949e;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  min-width: 54px;
  text-align: right;
}

/* ── Board Area (takes all remaining space) ── */
.manim-board-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #1b3a1b;
  min-height: 0;
}

/* Chalkboard grain overlay */
.manim-board-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E");
  opacity: 0.15;
  pointer-events: none;
  z-index: 1;
}

/* Board canvas */
.manim-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

/* Chalkboard border accent */
.manim-board-wrap::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(139, 119, 70, 0.2);
  border-radius: 4px;
  pointer-events: none;
  z-index: 3;
}

/* Chalk tray at board bottom */
.manim-chalk-tray {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(to bottom, rgba(139, 119, 70, 0.12), transparent);
  z-index: 3;
  pointer-events: none;
}

/* ── Narration Bar (BELOW board, never overlaps) ── */
.manim-narration-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 16px;
  min-height: 48px;
  max-height: 90px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  transition: opacity 0.6s ease, max-height 0.4s ease;
  opacity: 0;
  max-height: 0;
  padding: 0 16px;
}
.manim-narration-bar.visible {
  opacity: 1;
  max-height: 90px;
  padding: 8px 16px;
}

.manim-narration-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  margin-top: 2px;
}

.manim-narration-content {
  flex: 1;
  min-width: 0;
}

.manim-narration-name {
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 1px;
  line-height: 1.3;
}
.manim-narration-name.narrator { color: #94a3b8; }
.manim-narration-name.xiaowen { color: #fbbf24; }
.manim-narration-name.xiaozhi { color: #60a5fa; }

.manim-narration-text {
  color: #d1d5db;
  font-size: 0.82rem;
  line-height: 1.55;
}
.manim-narration-text p { margin: 0 0 4px 0; }
.manim-narration-text p:last-child { margin: 0; }
.manim-narration-text .katex { font-size: 1em; }

/* ── Narration toggle button ── */
.manim-narration-toggle {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-top: 1px;
}
.manim-narration-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #e6edf3;
}

/* ── Progress Bar ── */
.manim-progress {
  flex-shrink: 0;
  padding: 3px 16px 0;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  align-items: center;
  gap: 6px;
}

.manim-progress-track {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  position: relative;
  cursor: pointer;
}

.manim-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
  border-radius: 2px;
  transition: width 0.4s ease;
  width: 0%;
}

.manim-progress-dots {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.manim-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  transition: all 0.3s ease;
  cursor: pointer;
}
.manim-dot.active { background: #fbbf24; box-shadow: 0 0 6px rgba(251, 191, 36, 0.5); }
.manim-dot.done { background: rgba(255, 255, 255, 0.35); }
.manim-dot:hover { transform: scale(1.3); }

.manim-progress-label {
  color: #8b949e;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}

/* ── Controls ── */
.manim-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px 8px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.manim-ctrl {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #c9d1d9;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.manim-ctrl:hover { background: rgba(255, 255, 255, 0.14); }
.manim-ctrl:disabled { opacity: 0.25; cursor: default; }
.manim-ctrl.manim-play-btn {
  width: 38px;
  height: 38px;
  background: rgba(251, 191, 36, 0.18);
  border-color: rgba(251, 191, 36, 0.25);
  font-size: 1rem;
}
.manim-ctrl.manim-play-btn:hover { background: rgba(251, 191, 36, 0.28); }

.manim-speed {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #c9d1d9;
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 0.75rem;
  cursor: pointer;
  margin-left: 6px;
}
.manim-speed option { background: #1a1a2e; color: #c9d1d9; }

.manim-step-num {
  color: #8b949e;
  font-size: 0.75rem;
  margin-left: 10px;
}

.manim-keyhint {
  color: rgba(255, 255, 255, 0.18);
  font-size: 0.62rem;
  margin-left: auto;
}
@media (max-width: 600px) {
  .manim-keyhint { display: none; }
}

/* ── Floating control button (bottom-right corner) ── */
.manim-float-ctrl {
  position: absolute;
  bottom: 8px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #c9d1d9;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}
.manim-float-ctrl:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* ── Bottom drawer (slides up from bottom) ── */
.manim-bottom-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9;
  background: rgba(26, 26, 46, 0.92);
  backdrop-filter: blur(6px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.manim-drawer-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.manim-drawer-close {
  margin-left: auto;
  color: #8b949e;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 8px;
}
.manim-drawer-close:hover { color: #c9d1d9; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .manim-narration-bar.visible {
    max-height: 70px;
    padding: 6px 12px;
  }
  .manim-narration-text { font-size: 0.78rem; }
  .manim-topbar-title { font-size: 0.82rem; }
}
