/* ==========================================================================
   CleanPlate —— 现代 AI 工具视觉系统 (Dark, Runway/Photoroom 取向)
   ========================================================================== */

:root {
  --bg-app: #0a0a0d;
  --bg-surface: #131318;
  --bg-elevated: #1a1a21;
  --bg-control: #202028;
  --bg-control-hover: #2a2a34;
  --bg-stage: radial-gradient(ellipse 80% 60% at 50% 0%, #17171f 0%, #08080a 72%);

  --border: #27272f;
  --border-soft: #1b1b21;
  --border-active: #14b8a6;

  --text-primary: #f2f2f5;
  --text-secondary: #9898a5;
  --text-tertiary: #5c5c68;

  --accent: #14b8a6;
  --accent-bright: #2dd4bf;
  --accent-soft: rgba(20, 184, 166, 0.14);
  --accent-2: #8b5cf6;
  --accent-2-soft: rgba(139, 92, 246, 0.16);

  --mask-color: rgba(251, 113, 133, 0.55);
  --danger: #f87171;
  --online: #34d399;
  --offline: #f87171;

  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 7px;

  --shadow-elevated: 0 24px 60px -24px rgba(0, 0, 0, 0.65), 0 4px 18px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 8px 24px -12px rgba(0, 0, 0, 0.5);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body.cp-theme {
  background-color: var(--bg-app);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.cp-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ==========================================================================
   顶栏
   ========================================================================== */
.cp-topbar {
  height: 60px;
  flex-shrink: 0;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

.cp-brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.cp-brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 14px;
  box-shadow: 0 4px 14px -4px rgba(20, 184, 166, 0.5);
}

.cp-brand-name {
  font-weight: 800;
  font-size: 15.5px;
  letter-spacing: -0.3px;
  color: #ffffff;
}

.cp-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 通用按钮 */
.cp-btn {
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.cp-btn-ghost {
  background-color: var(--bg-control);
  border-color: var(--border);
  color: var(--text-primary);
}

.cp-btn-ghost:hover {
  background-color: var(--bg-control-hover);
}

.cp-btn-icon {
  padding: 8px;
  width: 34px;
  height: 34px;
  justify-content: center;
}

.cp-btn-block {
  width: 100%;
  justify-content: center;
}

.cp-backend-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: 999px;
  background-color: var(--bg-control);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}

.cp-backend-pill:hover {
  background-color: var(--bg-control-hover);
}

.cp-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #6b7280;
  flex-shrink: 0;
}

.cp-status-dot.online { background-color: var(--online); box-shadow: 0 0 6px var(--online); }
.cp-status-dot.offline { background-color: var(--offline); }

/* ==========================================================================
   主体三栏
   ========================================================================== */
.cp-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---- 左侧图标工具栏 ---- */
.cp-rail {
  width: 60px;
  flex-shrink: 0;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 4px;
  z-index: 60;
}

.cp-rail-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cp-rail-group-relative {
  position: relative;
}

.cp-rail-sep {
  width: 26px;
  height: 1px;
  background-color: var(--border);
  margin: 8px 0;
}

.cp-rail-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background-color: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.cp-rail-btn:hover:not(:disabled) {
  background-color: var(--bg-control);
  color: var(--text-primary);
}

.cp-rail-btn.active {
  background-color: var(--accent-soft);
  color: var(--accent-bright);
}

.cp-rail-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.cp-popover {
  position: absolute;
  left: 52px;
  top: 0;
  width: 226px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  padding: 10px;
  z-index: 90;
}

.cp-popover-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  padding: 0 4px;
}

.cp-sample-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 320px;
  overflow-y: auto;
}

.cp-sample-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}

.cp-sample-row:hover {
  background-color: var(--bg-control);
}

.cp-sample-row.active {
  background-color: var(--accent-soft);
  border-color: var(--accent);
}

.cp-sample-thumb {
  width: 46px;
  height: 30px;
  border-radius: 5px;
  object-fit: cover;
  background-color: #000;
  flex-shrink: 0;
}

.cp-sample-meta {
  overflow: hidden;
}

.cp-sample-name {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cp-sample-desc {
  font-size: 10px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- 中央舞台 ---- */
.cp-stage-area {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  background: var(--bg-stage);
  overflow: hidden;
}

.cp-view-tabs {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow-soft);
  z-index: 40;
}

.cp-view-tab {
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.cp-view-tab:hover:not(:disabled):not(.active) {
  color: var(--text-primary);
}

.cp-view-tab.active {
  background-color: var(--accent);
  color: #052420;
}

.cp-view-tab:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.cp-compare-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 7px 14px;
  border-radius: 999px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  z-index: 40;
  box-shadow: var(--shadow-soft);
}

.cp-compare-toggle:hover {
  color: var(--text-primary);
}

.cp-compare-toggle.active {
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-bright);
}

.cp-canvas-shell {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-elevated);
  background-color: #000000;
  max-width: 100%;
  max-height: 100%;
}

.cp-layer {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

video.cp-layer {
  object-fit: fill;
}

.cp-layer-checker {
  background-image:
    linear-gradient(45deg, #3a3a3a 25%, transparent 25%),
    linear-gradient(-45deg, #3a3a3a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a3a3a 75%),
    linear-gradient(-45deg, transparent 75%, #3a3a3a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #232323;
}

#mask-canvas {
  z-index: 5;
  cursor: none;
}

.cp-empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.cp-empty-hint i {
  font-size: 32px;
}

.cp-empty-hint p {
  font-size: 13px;
}

/* 卷帘对比分割器 */
.split-slider {
  position: absolute;
  top: 0;
  left: 50%;
  height: 100%;
  z-index: 20;
  pointer-events: none;
}

.split-line {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.85);
  transform: translateX(-1px);
}

.split-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #ffffff;
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  cursor: ew-resize;
  pointer-events: all;
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-soft);
  font-size: 12px;
}

.tag-label {
  position: absolute;
  bottom: 12px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background-color: rgba(10, 10, 13, 0.72);
  color: #fff;
  backdrop-filter: blur(4px);
  z-index: 21;
  pointer-events: none;
}

.label-left { left: 12px; }
.label-right { right: 12px; }

/* 画笔光标 */
.brush-cursor {
  position: absolute;
  border: 1.5px solid var(--accent-bright);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 30;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

/* 简化播放条 */
.cp-scrub-bar {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 640px;
}

.cp-scrub-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-color: var(--bg-control);
  border: 1px solid var(--border);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.cp-scrub-play:hover {
  background-color: var(--bg-control-hover);
}

.cp-scrub-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--text-secondary);
  min-width: 38px;
  text-align: center;
}

.cp-scrub-track {
  flex: 1;
  height: 4px;
  background-color: var(--bg-control);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
}

.cp-scrub-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background-color: var(--accent);
  border-radius: 999px;
}

.cp-scrub-handle {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #ffffff;
  box-shadow: 0 0 0 3px var(--accent-soft);
  transform: translate(-50%, -50%);
}

/* ==========================================================================
   Loading 遮罩
   ========================================================================== */
.loading-shade {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(4, 4, 6, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.loading-box {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 22px 28px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  text-align: center;
  box-shadow: var(--shadow-elevated);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--bg-control);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-title {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
}

.loading-detail {
  font-size: 10.5px;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
  max-width: 320px;
}

/* 轻量 toast（不阻塞画面，剪映式的完成提示） */
.cp-toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-elevated);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in-out 2.6s ease forwards;
}

@keyframes toast-in-out {
  0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0); }
  85% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(8px); }
}

/* ==========================================================================
   右侧参数抽屉
   ========================================================================== */
.cp-inspector {
  width: 320px;
  flex-shrink: 0;
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border-soft);
  overflow: hidden;
  transition: width 0.2s ease, opacity 0.15s ease;
}

.cp-inspector.collapsed {
  width: 0;
  opacity: 0;
  border-left: none;
}

.cp-inspector-scroll {
  width: 320px;
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cp-card {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
}

.cp-card-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 11px;
}

.cp-field {
  margin-bottom: 11px;
}

.cp-field:last-child {
  margin-bottom: 0;
}

.cp-field-label {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.cp-field-val {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-bright);
  font-weight: 600;
}

.cp-field input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 3px;
  background-color: var(--bg-control);
  border-radius: 999px;
  outline: none;
}

.cp-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background-color: var(--accent-bright);
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.cp-input {
  width: 100%;
  background-color: var(--bg-control);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  outline: none;
}

.cp-input:focus {
  border-color: var(--border-active);
}

.cp-input::placeholder {
  color: var(--text-tertiary);
}

.cp-backend-status-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  color: var(--text-secondary);
  margin: 10px 0 8px;
}

.cp-backend-status-row-top {
  margin: 0;
}

/* 连接设置默认收起——日常用不着盯着它，尤其桌面 App 里地址是自动连的 */
.cp-collapsible-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.cp-collapsible-toggle:hover {
  color: var(--text-secondary);
}

.cp-collapsible-toggle i {
  transition: transform 0.2s ease;
  font-size: 9px;
}

.cp-collapsible-toggle.expanded i {
  transform: rotate(180deg);
}

.cp-collapsible-body {
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--border);
}

.cp-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-primary);
  padding: 5px 0;
  cursor: pointer;
}

.cp-check input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
}

.cp-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cp-btn-primary {
  position: relative;
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 130%);
  border: none;
  color: #ffffff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 10px 28px -10px rgba(20, 184, 166, 0.55);
  transition: filter 0.15s ease, transform 0.1s ease;
  overflow: hidden;
}

.cp-btn-primary:hover {
  filter: brightness(1.08);
}

.cp-btn-primary:active {
  transform: translateY(1px);
}

.cp-btn-primary:disabled {
  cursor: default;
  opacity: 0.4;
  filter: grayscale(0.4);
  box-shadow: none;
}

/* 在线引擎按钮：换个渐变方向区分开，别跟本地引擎那个撞脸 */
.cp-btn-primary-alt {
  background: linear-gradient(135deg, var(--accent-2) 0%, #3b82f6 130%);
  box-shadow: 0 10px 28px -10px rgba(139, 92, 246, 0.55);
}

/* 剪映式内联进度：不弹遮罩，进度条从按钮底色里"长出来" */
.cp-btn-primary-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background-color: rgba(255, 255, 255, 0.22);
  transition: width 0.25s ease;
  pointer-events: none;
}

.cp-btn-primary-label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.01em;
}

.cp-btn-primary-label i {
  font-family: 'Font Awesome 6 Free';
}

.cp-actions-row {
  display: flex;
  gap: 8px;
}

.cp-actions-row .cp-btn {
  flex: 1;
  justify-content: center;
}

.cp-card-title-note {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--text-tertiary);
}

.cp-hint-text {
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--text-tertiary);
  margin: 0 0 11px;
}

.cp-input-row {
  display: flex;
  gap: 6px;
}

.cp-input-row .cp-input {
  flex: 1;
}

.cp-input-row .cp-btn-icon {
  flex-shrink: 0;
  padding: 8px 10px;
}

.cp-console-card {
  padding: 0;
  overflow: hidden;
}

.cp-console-card .cp-card-title {
  padding: 12px 14px 0;
  margin-bottom: 8px;
}

.cp-console-logs {
  max-height: 320px; /* 连接设置默认收起腾出来的空间给日志，之前 160px 太挤 */
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  line-height: 1.7;
  color: var(--text-secondary);
  padding: 0 14px 12px;
}

.cp-console-logs::-webkit-scrollbar,
.cp-sample-list::-webkit-scrollbar,
.cp-inspector-scroll::-webkit-scrollbar {
  width: 6px;
}

.cp-console-logs::-webkit-scrollbar-thumb,
.cp-sample-list::-webkit-scrollbar-thumb,
.cp-inspector-scroll::-webkit-scrollbar-thumb {
  background-color: var(--bg-control-hover);
  border-radius: 999px;
}
