:root {
  --bg: #0d0d0d;
  --surface: #171717;
  --surface-2: #1f1f1f;
  --line: #2a2a2a;
  --text: #f2f2f2;
  --text-2: #9a9a9a;
  --text-3: #6a6a6a;
  --accent: #3ecf8e;
  --accent-dim: rgba(62, 207, 142, 0.14);
  --danger: #e5484d;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

button { font-family: inherit; color: inherit; }

#app { height: 100%; }

.view {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
.view.is-active { display: flex; }

/* ---------------- 首页 ---------------- */

.home-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: calc(28px + var(--safe-t)) 20px 20px;
  overflow-y: auto;
}

.home-head h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.4px;
}
.home-head .sub {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 13px;
}

.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 28px;
}

.action-card {
  background: var(--surface);
  border: 0.5px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.action-card:active { background: var(--surface-2); border-color: #3a3a3a; }
.action-label { font-size: 16px; font-weight: 500; }
.action-hint { font-size: 12px; color: var(--text-3); }
.action-icon {
  width: 26px;
  height: 26px;
  margin-bottom: 10px;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  position: relative;
}
.icon-photo::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.5;
}
.icon-video::after {
  content: "";
  position: absolute;
  top: 8px; left: 5px;
  border-left: 9px solid var(--accent);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.home-filters { margin-top: 32px; }
.home-filter-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.home-filter-list .manage-item {
  cursor: pointer;
  background: var(--surface);
  border: 0.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.home-filter-list .manage-item:active { background: var(--surface-2); }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 13px;
  padding: 4px 2px;
  cursor: pointer;
}
.text-btn.accent { color: var(--accent); }

/* ---------------- 编辑页顶栏 ---------------- */

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  border-bottom: 0.5px solid var(--line);
  background: var(--bg);
  flex: none;
}
.editor-title { font-size: 15px; font-weight: 500; }

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------------- 预览区 ---------------- */

.stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #080808;
  min-height: 0;
  touch-action: none;
}

.stage canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
}

#photo-base,
#photo-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.stage-filter {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.stage-filter canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.compare-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  left: 50%;
  transform: translateX(-1px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.compare-line.is-visible { opacity: 0.9; }
.compare-grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
}
.compare-grip::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 0; height: 0;
  border-left: 5px solid #111;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  box-shadow: 9px 0 0 -1px #111, -9px 0 0 0 #111;
  margin-left: -8px;
}

.stage-tip {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: var(--text-2);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
  pointer-events: none;
  transition: opacity 0.4s;
  white-space: nowrap;
}
.stage-tip.is-hidden { opacity: 0; }

.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
}
.play-overlay.is-hidden { display: none; }
.play-icon {
  width: 0; height: 0;
  border-left: 22px solid rgba(255, 255, 255, 0.9);
  border-top: 14px solid transparent;
  border-bottom: 14px solid transparent;
  margin-left: 6px;
}

/* ---------------- 底部控制区 ---------------- */

.controls {
  flex: none;
  padding: 12px 0 calc(10px + var(--safe-b));
  border-top: 0.5px solid var(--line);
  background: var(--bg);
}

.filter-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 16px 12px;
  scrollbar-width: none;
}
.filter-strip::-webkit-scrollbar { display: none; }

.filter-item {
  flex: none;
  width: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
.filter-thumb {
  width: 62px;
  height: 62px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.filter-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.filter-item.is-active .filter-thumb { border-color: var(--accent); }
.filter-name {
  font-size: 11px;
  color: var(--text-2);
  text-align: center;
  line-height: 1.25;
  max-width: 62px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filter-item.is-active .filter-name { color: var(--accent); }

.strength-row { padding: 4px 20px 10px; }
.strength-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.strength-val { color: var(--text); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -8.5px;
  border: none;
}
input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

.control-actions {
  display: flex;
  gap: 10px;
  padding: 0 20px;
}
.ghost-btn,
.primary-btn {
  flex: 1;
  padding: 11px 14px;
  border-radius: 11px;
  font-size: 14px;
  cursor: pointer;
  border: 0.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.ghost-btn:active,
.primary-btn:active { background: var(--surface-2); }
.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #06281a;
  font-weight: 500;
}
.ghost-btn.danger { color: var(--danger); border-color: rgba(229, 72, 77, 0.35); }

.hint {
  margin: 0;
  padding: 8px 20px 2px;
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
}

/* ---------------- 视频传输控制 ---------------- */

.transport {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 0.5px solid var(--line);
  background: var(--bg);
}
.transport input[type="range"] { flex: 1; }
.time {
  font-size: 11.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  min-width: 78px;
  text-align: right;
}

/* ---------------- 批量 ---------------- */

.batch-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.batch-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  min-height: 0;
}
.batch-cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface);
  overflow: hidden;
}
.batch-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.batch-cell .cell-check {
  position: absolute;
  top: 6px; right: 6px;
  width: 21px; height: 21px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.3);
}
.batch-cell.is-on .cell-check {
  background: var(--accent);
  border-color: var(--accent);
}
.batch-cell.is-on .cell-check::after {
  content: "";
  position: absolute;
  top: 4px; left: 7px;
  width: 5px; height: 9px;
  border-right: 2px solid #06281a;
  border-bottom: 2px solid #06281a;
  transform: rotate(40deg);
}
.batch-body .controls { padding-top: 12px; }
.batch-body .primary-btn { margin: 4px 20px calc(6px + var(--safe-b)); flex: none; }

/* ---------------- 滤镜管理 ---------------- */

.manage-body,
.filter-edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(24px + var(--safe-b));
}

.manage-list { display: flex; flex-direction: column; gap: 8px; }

.manage-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 0.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.manage-item .mi-main { flex: 1; min-width: 0; }
.manage-item .mi-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.manage-item .mi-meta { font-size: 11.5px; color: var(--text-3); }
.manage-item .mi-actions { display: flex; gap: 2px; }
.manage-item .mi-actions .icon-btn { width: 32px; height: 32px; font-size: 15px; color: var(--text-2); }

.manage-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 40px 20px;
}

.name-field { margin-bottom: 18px; }
.name-field label {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.name-field input,
.param-list input[type="number"] {
  width: 100%;
  background: var(--surface);
  border: 0.5px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
}
.param-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }
.param-group-title {
  font-size: 12px;
  color: var(--text-3);
  margin: 6px 0 -4px;
  letter-spacing: 0.3px;
}
.param-row { display: flex; align-items: center; gap: 12px; }
.param-row .p-label { width: 88px; font-size: 13px; color: var(--text-2); flex: none; }
.param-row input[type="range"] { flex: 1; }
.param-row .p-val {
  width: 46px;
  text-align: right;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  flex: none;
}

/* ---------------- 提示 / 遮罩 ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-b));
  transform: translateX(-50%) translateY(10px);
  background: rgba(28, 28, 28, 0.96);
  color: var(--text);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 0.5px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  max-width: 82vw;
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.busy {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 70;
}
.busy.is-visible { display: flex; }
.busy-inner {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-2);
}
.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
