:root {
  --mechanism-text: #443852;
  --mechanism-muted: #786d83;
  --mechanism-purple: #8565a2;
  --mechanism-purple-soft: #f4edf9;
  --mechanism-teal: #619d99;
  --mechanism-line: rgba(130, 96, 157, 0.2);
  --mechanism-surface: rgba(255, 255, 255, 0.97);
  --mechanism-shadow: 0 24px 64px rgba(69, 48, 84, 0.2);
  --mechanism-font: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.mechanism-video-task-toggle,
.mechanism-video-task-panel,
.mechanism-video-confirm,
.mechanism-video-player {
  box-sizing: border-box;
  font-family: var(--mechanism-font);
}

/* 常驻入口与历史侧栏：页面加载后即可恢复上次的生成任务和机制解释。 */
.mechanism-video-task-toggle {
  position: fixed;
  z-index: 930;
  top: 176px;
  left: 0;
  right: auto;
  display: flex;
  width: 44px;
  min-height: 166px;
  padding: 12px 8px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(126, 91, 154, 0.28);
  border-left: 0;
  border-radius: 0 16px 16px 0;
  color: #fff;
  background: linear-gradient(165deg, #9c79b9 0%, #8669aa 48%, #69a7a2 100%);
  box-shadow: -10px 16px 34px rgba(85, 58, 104, 0.2);
  font: 800 12px/1.25 var(--mechanism-font);
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, filter 180ms ease, box-shadow 180ms ease;
}

.mechanism-video-task-toggle:hover,
.mechanism-video-task-toggle:focus-visible {
  transform: translateX(3px);
  filter: saturate(1.06) brightness(1.03);
  box-shadow: -14px 18px 38px rgba(85, 58, 104, 0.26);
  outline: none;
}
.mechanism-video-task-toggle.is-active {
  opacity: 0;
  transform: translateX(-100%);
  pointer-events: none;
}

.mechanism-video-task-icon {
  display: grid;
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #76528f;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 5px 14px rgba(63, 45, 78, 0.18);
}

.mechanism-video-task-icon svg,
.mechanism-video-player-mark svg,
.mechanism-video-task-panel header button svg,
.mechanism-video-player header button svg {
  display: block;
  width: 16px;
  height: 16px;
}

.mechanism-video-task-label { writing-mode: vertical-rl; letter-spacing: 0.13em; }

.mechanism-video-task-toggle b {
  display: grid;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  place-items: center;
  border-radius: 999px;
  color: #725187;
  background: #fff;
  font-size: 11px;
  line-height: 20px;
}
.mechanism-video-task-toggle b[hidden] { display: none; }

.mechanism-video-task-panel {
  position: fixed;
  z-index: 940;
  top: 92px;
  bottom: auto;
  left: 0;
  right: auto;
  display: flex;
  width: min(400px, calc(100vw - 58px));
  max-height: calc(100dvh - 116px);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--mechanism-line);
  border-left: 0;
  border-radius: 0 20px 20px 0;
  color: var(--mechanism-text);
  background: rgba(252, 250, 253, 0.985);
  box-shadow: 18px 0 52px rgba(69, 48, 84, 0.16);
  backdrop-filter: blur(16px);
  animation: mechanism-panel-enter 180ms ease-out both;
}
.mechanism-video-task-panel[hidden] { display: none; }

.mechanism-video-task-panel > header,
.mechanism-video-player > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.mechanism-video-task-panel > header {
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(130, 96, 157, 0.14);
  background: linear-gradient(90deg, rgba(239, 230, 245, 0.5), rgba(236, 246, 244, 0.36));
}
.mechanism-video-task-panel h2 { margin: 0; color: #51405d; font-size: 19px; letter-spacing: -0.02em; }
.mechanism-video-task-panel header button,
.mechanism-video-player header button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(128, 99, 151, 0.16);
  border-radius: 50%;
  color: #765f85;
  background: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.mechanism-video-task-panel header button:hover,
.mechanism-video-task-panel header button:focus-visible,
.mechanism-video-player header button:hover,
.mechanism-video-player header button:focus-visible {
  color: #fff;
  background: #8667a0;
  transform: translateY(-1px);
  outline: none;
}

.mechanism-video-job-list {
  min-height: 0;
  flex: 1;
  max-height: calc(100dvh - 188px);
  overflow: auto;
  padding: 0 22px 16px;
  scrollbar-color: rgba(135, 102, 160, 0.34) transparent;
}
.mechanism-video-empty { padding: 34px 18px; color: #92879b; text-align: center; }
.mechanism-video-job {
  margin: 0;
  padding: 18px 0;
  border: 0;
  border-bottom: 1px solid rgba(128, 96, 153, 0.14);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.mechanism-video-job:last-child { border-bottom: 0; }
.mechanism-video-job[data-status="queued"],
.mechanism-video-job[data-status="generating"] {
  margin-inline: -10px;
  padding-inline: 10px;
  border-radius: 12px;
  background: rgba(241, 235, 246, 0.62);
}
.mechanism-video-job[data-status="failed"],
.mechanism-video-job[data-status="rejected"] {
  padding-left: 10px;
  box-shadow: inset 2px 0 0 rgba(181, 102, 108, 0.7);
}
.mechanism-video-job-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mechanism-video-job-top strong { color: #4f405a; font-size: 14px; line-height: 1.5; }
.mechanism-video-job-top span { color: var(--mechanism-purple); font-size: 11px; font-weight: 800; }
.mechanism-video-job[data-status="completed"] .mechanism-video-job-top span { color: var(--mechanism-teal); }
.mechanism-video-job[data-status="failed"] .mechanism-video-job-top span,
.mechanism-video-job[data-status="rejected"] .mechanism-video-job-top span { color: #b5666c; }
.mechanism-video-progress { height: 5px; margin-top: 11px; overflow: hidden; border-radius: 999px; background: #eee8f1; }
.mechanism-video-progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #a77cc2, #6daba6); transition: width 300ms ease; }
.mechanism-video-job-explanation {
  margin-top: 12px;
  padding-left: 12px;
  border-left: 2px solid rgba(97, 157, 153, 0.42);
  color: #6b5b75;
  font-size: 12px;
  line-height: 1.7;
}
.mechanism-video-job-explanation summary { color: #675474; font-weight: 800; cursor: pointer; }
.mechanism-video-job-explanation p { margin: 7px 0 0; }
.mechanism-video-timeline {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.mechanism-video-timeline li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 7px 9px;
  border-radius: 9px;
  color: #716579;
  background: rgba(245, 239, 248, 0.66);
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.mechanism-video-timeline li > span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #9a83aa;
  font-size: 11px;
  font-weight: 800;
}
.mechanism-video-timeline li > p { margin: 0; line-height: 1.65; }
.mechanism-video-timeline li.is-active {
  color: #503b5c;
  background: linear-gradient(90deg, #f3e8f8, #e7f5f2);
  box-shadow: inset 3px 0 #8b69a2;
}
.mechanism-video-job-action { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.mechanism-video-job-action button {
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid rgba(119, 88, 143, 0.28);
  border-radius: 8px;
  color: #694d80;
  background: rgba(255, 255, 255, 0.66);
  font: 800 12px/1.2 var(--mechanism-font);
  cursor: pointer;
  transition: transform 150ms ease, color 150ms ease, background 150ms ease;
}
.mechanism-video-job-action button:hover,
.mechanism-video-job-action button:focus-visible { color: #fff; background: #8768a1; outline: none; }
.mechanism-video-job-action button:active { transform: translateY(1px); }

.mechanism-video-confirm-backdrop {
  position: fixed;
  z-index: 1200;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(52, 42, 61, 0.32);
  backdrop-filter: blur(8px);
}
.mechanism-video-confirm {
  width: 440px;
  max-width: calc(100vw - 40px);
  padding: 27px;
  border: 1px solid var(--mechanism-line);
  border-radius: 22px;
  color: var(--mechanism-text);
  background: radial-gradient(circle at 100% 0%, rgba(190, 224, 219, 0.52), transparent 38%), radial-gradient(circle at 0 0, rgba(232, 211, 243, 0.62), transparent 42%), #fff;
  box-shadow: 0 28px 78px rgba(55, 40, 66, 0.28);
}
.mechanism-video-confirm h2 { margin: 0 0 8px; color: #564265; font-size: 24px; }
.mechanism-video-confirm p { color: var(--mechanism-muted); line-height: 1.7; }
.mechanism-video-confirm-topic { color: #5c476b !important; font-weight: 850; }
.mechanism-video-resolution {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0 0;
  padding: 0;
  border: 0;
}
.mechanism-video-resolution legend {
  margin-bottom: 9px;
  color: #5c4c67;
  font-size: 13px;
  font-weight: 800;
}
.mechanism-video-resolution label { position: relative; display: block; cursor: pointer; }
.mechanism-video-resolution input { position: absolute; opacity: 0; pointer-events: none; }
.mechanism-video-resolution span {
  display: grid;
  min-height: 68px;
  padding: 11px 13px;
  align-content: center;
  gap: 3px;
  border: 1px solid rgba(119, 88, 143, 0.22);
  border-radius: 12px;
  color: #66566f;
  background: rgba(255, 255, 255, 0.72);
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.mechanism-video-resolution strong { color: #54405f; font-size: 15px; }
.mechanism-video-resolution small { color: #85798c; font-size: 12px; }
.mechanism-video-resolution input:checked + span {
  border-color: rgba(116, 83, 143, 0.62);
  background: #f1eaf6;
  box-shadow: inset 0 0 0 1px rgba(116, 83, 143, 0.12);
}
.mechanism-video-resolution input:focus-visible + span { outline: 2px solid #80619a; outline-offset: 2px; }
.mechanism-video-resolution label:active span { transform: translateY(1px); }
.mechanism-video-estimate {
  min-height: 46px;
  margin: 14px 0 0;
  padding: 11px 13px;
  border-left: 2px solid rgba(97, 157, 153, 0.58);
  color: #665a6d !important;
  background: rgba(239, 246, 245, 0.58);
  font-size: 13px;
}
.mechanism-video-estimate[data-state="loading"] { color: #7b6f82 !important; }
.mechanism-video-estimate[data-state="error"] {
  border-left-color: rgba(181, 102, 108, 0.72);
  color: #985d64 !important;
  background: rgba(250, 238, 239, 0.64);
}
.mechanism-video-confirm > div { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.mechanism-video-confirm button {
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid rgba(122, 91, 145, 0.2);
  border-radius: 11px;
  color: #685673;
  background: rgba(255, 255, 255, 0.78);
  font: 800 13px/1.2 var(--mechanism-font);
  cursor: pointer;
}
.mechanism-video-confirm button.is-primary { border-color: transparent; color: #fff; background: linear-gradient(135deg, #9874b3, #6ca5a1); box-shadow: 0 9px 20px rgba(112, 82, 135, 0.22); }
.mechanism-video-confirm button:disabled { opacity: 0.52; cursor: wait; }

.mechanism-video-player {
  --player-cascade-y: 0px;
  --player-cascade-x: 0px;
  position: fixed;
  z-index: 1100;
  top: calc(90px + var(--player-cascade-y));
  left: calc(24px + var(--player-cascade-x));
  width: 760px;
  max-width: calc(100vw - 40px);
  overflow: hidden;
  border: 1px solid rgba(131, 96, 158, 0.22);
  border-radius: 22px;
  color: var(--mechanism-text);
  background: #fff;
  box-shadow: 0 30px 86px rgba(54, 39, 66, 0.28);
  animation: mechanism-player-enter 220ms cubic-bezier(.22, .8, .25, 1) both;
}
.mechanism-video-player > header {
  justify-content: flex-start;
  padding: 13px 14px 12px 17px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: linear-gradient(110deg, #f4eafa 0%, #f8f4fb 54%, #ebf7f5 100%);
}
.mechanism-video-player-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #9872b4, #6fa7a3);
  box-shadow: 0 7px 16px rgba(111, 80, 133, 0.2);
}
.mechanism-video-player header div { min-width: 0; flex: 1; }
.mechanism-video-player header strong { display: block; overflow: hidden; color: #4e4058; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.mechanism-video-player video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #151219; object-fit: contain; }
.mechanism-video-current-sentence {
  display: grid;
  min-height: 58px;
  padding: 13px 25px;
  place-items: center;
  border-bottom: 1px solid rgba(131, 96, 158, 0.12);
  color: #574463;
  background: linear-gradient(90deg, #f7f0fa, #edf8f6);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.65;
  text-align: center;
}
.mechanism-video-current-sentence small { color: #8a7296; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }
.mechanism-video-current-sentence p { margin: 2px 0 0; }
.mechanism-video-player details { padding: 11px 18px 15px; color: var(--mechanism-muted); font-size: 12px; }
.mechanism-video-player summary { color: #76568d; font-weight: 700; cursor: pointer; }
.mechanism-video-player details p { max-height: 110px; overflow: auto; line-height: 1.75; }
.mechanism-video-player-timeline { max-height: 210px; overflow: auto; }

@keyframes mechanism-panel-enter {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes mechanism-player-enter {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 680px) {
  .mechanism-video-task-toggle {
    top: 132px;
    width: 44px;
    min-height: 146px;
    padding: 10px 7px;
  }
  .mechanism-video-task-panel {
    top: 70px;
    bottom: auto;
    left: 0;
    right: 50px;
    width: auto;
    max-height: calc(100dvh - 82px);
    border-radius: 0 18px 18px 0;
  }
  .mechanism-video-task-panel > header { padding: 18px 18px 15px; }
  .mechanism-video-job-list {
    max-height: calc(100dvh - 150px);
    padding-inline: 18px;
  }
  .mechanism-video-player {
    top: 76px;
    left: 10px;
    width: calc(100vw - 20px);
    max-width: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .mechanism-video-task-panel,
  .mechanism-video-player { animation: none; }
  .mechanism-video-task-toggle,
  .mechanism-video-progress i { transition: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .mechanism-video-task-panel {
    background: #fcfafd;
    backdrop-filter: none;
  }
}
