:root {
  --bg: #0b0d11;
  --stage: #12151c;
  --panel: #161a22;
  --panel-2: #1c212c;
  --line: #2a3140;
  --line-soft: #232836;
  --text: #e6eaf2;
  --muted: #8b93a7;
  --accent: #e8a87c;
  --accent-2: #6ea8fe;
  --ok: #3dd68c;
  --danger: #ff6b7a;
  --top-h: 48px;
  --film-w: 88px;
  --insp-w: 320px;
  font-family: "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.pc-app {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--top-h) 1fr;
  overflow: hidden;
}

/* —— 顶栏 —— */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: linear-gradient(180deg, #1a1f29 0%, #141820 100%);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.app-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: radial-gradient(circle at 35% 30%, #f0d0b0, var(--accent) 55%, #a86a40);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 4px 12px rgba(232,168,124,0.25);
}
.app-titles { display: flex; flex-direction: column; line-height: 1.15; }
.app-titles strong { font-size: 13px; font-weight: 650; letter-spacing: 0.02em; }
.app-titles span { font-size: 10px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.topbar-right { display: flex; justify-content: flex-end; }
.top-hint { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }

.tb-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.tb-btn:hover:not(:disabled) { border-color: #3d475c; background: #222836; }
.tb-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tb-btn.primary {
  background: linear-gradient(180deg, #f0b890, var(--accent));
  border-color: transparent; color: #1a1008;
}
.tb-btn.primary:hover:not(:disabled) { filter: brightness(1.05); }
.tb-btn.full { width: 100%; margin: 8px 0 12px; }

/* —— 工作区 —— */
.workspace {
  display: grid;
  grid-template-columns: var(--film-w) 1fr var(--insp-w);
  min-height: 0;
}

/* 胶片条 */
.filmstrip {
  background: #10131a;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 10px 8px; overflow: hidden;
}
.film-label { font-size: 10px; color: var(--muted); letter-spacing: 0.08em; }
.film-add {
  width: 56px; height: 36px; border-radius: 6px;
  border: 1px dashed #3a4458; background: transparent; color: var(--muted);
  font-size: 18px;
}
.film-add:hover { border-color: var(--accent); color: var(--accent); }
.film-list { flex: 1; overflow-y: auto; width: 100%; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.film-empty { font-size: 10px; color: #5c6578; text-align: center; margin-top: 12px; line-height: 1.4; }
.film-thumb {
  width: 64px; height: 64px; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--line); background: #0a0c10; padding: 0;
  position: relative;
}
.film-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.film-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(232,168,124,0.35); }
.film-thumb .badge {
  position: absolute; left: 3px; bottom: 3px; font-size: 9px;
  background: rgba(0,0,0,0.65); color: #ddd; padding: 1px 4px; border-radius: 3px;
}

/* 中央舞台 */
.stage {
  position: relative; background: var(--stage); min-width: 0;
  background-image:
    radial-gradient(ellipse at 50% 40%, #1a2030 0%, transparent 55%),
    linear-gradient(180deg, #10131a, #0b0d11);
}
#viewport { position: absolute; inset: 0 0 28px 0; }
#viewport canvas { display: block; width: 100% !important; height: 100% !important; }
.stage-footer {
  position: absolute; left: 0; right: 0; bottom: 0; height: 28px;
  display: flex; align-items: center; padding: 0 12px;
  border-top: 1px solid var(--line-soft); background: rgba(12,14,18,0.9);
  font-size: 11px; color: var(--muted);
}

.overlay {
  position: absolute; inset: 0 0 28px 0; display: grid; place-items: center;
  background: rgba(8,10,14,0.55); backdrop-filter: blur(6px); z-index: 5;
  transition: opacity 0.2s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 30px; max-width: 360px; text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,0.45);
}
.overlay-card h2 { margin: 0 0 8px; font-size: 18px; font-weight: 650; }
.overlay-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.busy {
  position: absolute; inset: 0 0 28px 0; z-index: 8;
  display: grid; place-items: center; background: rgba(8,10,14,0.5);
}
.busy.hidden { display: none; }
.busy-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px 24px; text-align: center; min-width: 200px;
}
.busy-card p { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; margin: 0 auto;
  border: 2px solid #2a3140; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 右侧检查器 */
.inspector {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.tabbar {
  display: grid; grid-template-columns: repeat(6, 1fr);
  border-bottom: 1px solid var(--line); background: #12161e;
}
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 10px 2px; font-size: 11px; font-weight: 600;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.02); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); background: rgba(232,168,124,0.06); }

.tab-panels { flex: 1; overflow-y: auto; min-height: 0; }
.tab-panel { display: none; padding: 0 0 16px; }
.tab-panel.on { display: block; }

.sec {
  padding: 12px 14px 6px;
  border-bottom: 1px solid var(--line-soft);
}
.sec h3 {
  margin: 0 0 8px; font-size: 11px; font-weight: 650;
  color: #aeb6c8; letter-spacing: 0.06em; text-transform: none;
}

.dropzone {
  border: 1px dashed #3a4458; border-radius: 8px; background: var(--panel-2);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover, .dropzone:focus-visible {
  border-color: var(--accent); background: #222836; outline: none;
}
.dropzone-inner { padding: 16px 10px; text-align: center; color: var(--muted); }
.dropzone-inner p { margin: 0; font-size: 12px; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.45; }
.hint.tight { margin: 0 0 8px; }
.status { min-height: 1.1em; margin: 6px 0 0; font-size: 11px; color: var(--accent-2); }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.ctrl {
  display: grid;
  grid-template-columns: 64px 1fr 42px;
  align-items: center; gap: 6px;
  margin-bottom: 7px; font-size: 11.5px;
}
.ctrl span { color: #c2c8d6; }
.ctrl em {
  font-style: normal; text-align: right; color: var(--muted);
  font-variant-numeric: tabular-nums; font-size: 10.5px; min-height: 1em;
}
.ctrl input[type="range"] { width: 100%; accent-color: var(--accent); height: 3px; }
.ctrl input[type="color"] {
  width: 100%; height: 26px; border: 1px solid var(--line);
  border-radius: 5px; background: transparent; padding: 1px; cursor: pointer;
}
.ctrl.check { grid-template-columns: 18px 1fr; gap: 8px; margin-bottom: 8px; }
.ctrl.check input { accent-color: var(--accent); width: 14px; height: 14px; }
.ctrl .select, .select {
  width: 100%; grid-column: 2 / 4;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 5px 7px; color: var(--text); font-size: 12px;
}

.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); border-radius: 999px; padding: 4px 9px;
  font-size: 11px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: #44506a; }
.chip.active {
  border-color: transparent; color: #1a1008; font-weight: 650;
  background: linear-gradient(180deg, #f0b890, var(--accent));
}

@media (max-width: 1100px) {
  :root { --insp-w: 280px; --film-w: 72px; }
  .top-hint { display: none; }
}
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr minmax(40vh, 48vh); }
  .filmstrip { display: none; }
  .inspector { border-left: none; border-top: 1px solid var(--line); }
}

.file-help .overlay-card code {
  background: #0c0e14; padding: 1px 6px; border-radius: 4px; color: var(--accent);
}
.file-help[hidden] { display: none !important; }

/* 抠图模式分段控件 */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
}
.seg-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 0;
  cursor: pointer;
  position: relative;
}
.seg-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.seg-item span {
  display: block;
  width: 100%;
  text-align: center;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-right: 1px solid var(--line);
  transition: background 0.12s, color 0.12s;
}
.seg-item:last-child span { border-right: none; }
.seg-item input:checked + span {
  color: #1a1008;
  background: linear-gradient(180deg, #f0b890, var(--accent));
}
.seg-item:hover input:not(:checked) + span { color: var(--text); background: #222836; }

/* —— 常用蒙版（致敬像素蛋糕布局，无品牌） —— */
.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.sec-head h3 { margin: 0; }
.sec-meta {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.mask-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 10px;
}
.mask-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: #c8cedc;
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
}
.mask-chip:hover:not(:disabled):not(.disabled) {
  color: var(--text);
  border-color: #44506a;
  background: #222836;
}
.mask-chip.on {
  border-color: rgba(232, 168, 124, 0.55);
  color: #1a1008;
  font-weight: 650;
  background: linear-gradient(180deg, #f0b890, var(--accent));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}
.mask-chip.on::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1a1008;
  opacity: 0.55;
  flex-shrink: 0;
}
.mask-chip.wide {
  grid-column: 1 / -1;
}
.mask-chip.disabled,
.mask-chip:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  color: #6a7388;
  background: #171b24;
  border-style: dashed;
}
.mask-chip .chip-tag {
  font-size: 9px;
  color: #8b93a7;
  margin-left: 2px;
  font-weight: 500;
}
.mask-chip.disabled .chip-tag,
.mask-chip:disabled .chip-tag {
  color: #5c6578;
}

.feather-ctrl {
  grid-template-columns: 40px 1fr 36px;
}
.feather-ctrl em {
  min-width: 28px;
  text-align: right;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 11px;
  color: var(--text);
}

.mask-sec .btn-row + .btn-row { margin-top: 0; }

/* —— 美化面板 —— */

.face-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}
.face-chip {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.face-chip:hover { color: var(--text); border-color: #44506a; }
.face-chip.on {
  color: #1a1008;
  border-color: transparent;
  background: linear-gradient(180deg, #f0b890, var(--accent));
}

.beauty-subtabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  margin-bottom: 4px;
}
.bsub {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 4px;
  font-size: 11.5px;
  font-weight: 650;
  border-right: 1px solid var(--line);
}
.bsub:last-child { border-right: none; }
.bsub:hover { color: var(--text); background: #222836; }
.bsub.on {
  color: #1a1008;
  background: linear-gradient(180deg, #f0b890, var(--accent));
}

.beauty-pane[hidden] { display: none !important; }

.filter-presets { margin-bottom: 4px; }
.filter-presets .chip { min-width: 4.5em; text-align: center; }

#filterInstantOpts .ctrl { margin-top: 4px; }

#btnClarityCompare:disabled { opacity: 0.45; cursor: not-allowed; }
#btnClarityCompare.comparing {
  border-color: var(--accent);
  color: #1a1008;
  background: linear-gradient(180deg, #f0b890, var(--accent));
  font-weight: 650;
}

.frame-dialog {
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}
.frame-dialog::backdrop { background: rgba(6, 8, 12, 0.72); }
.frame-dialog-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin: 0;
  padding: 16px 16px 8px;
}
.frame-dialog-bar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  max-width: 62ch;
}
.frame-dialog-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  padding: 8px 16px 16px;
  min-height: 0;
}
.frame-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
  max-height: min(68vh, 640px);
  overflow: auto;
  align-content: start;
}
.frame-pick {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  text-align: left;
}
.frame-pick img {
  width: 100%;
  aspect-ratio: 720 / 1120;
  object-fit: cover;
  border-radius: 4px;
  background: #fff;
}
.frame-pick span { font-size: 11px; color: var(--muted); }
.frame-pick.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.frame-pick.on span { color: var(--text); }
.frame-preview-col { display: flex; flex-direction: column; gap: 8px; }
.frame-preview-col canvas {
  width: 100%;
  height: auto;
  background: #0e1118;
  border-radius: 8px;
}
@media (max-width: 720px) {
  .frame-dialog-body { grid-template-columns: 1fr; }
  .frame-grid { max-height: 28vh; }
}


/* mobile-web phone */
@media (max-width: 860px) {
  :root { --top-h: 56px; }
  .pc-app {
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .topbar {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
    min-height: var(--top-h);
    padding: 8px 10px calc(8px + env(safe-area-inset-top, 0));
    gap: 8px;
  }
  .topbar-left { min-width: 0; }
  .topbar-actions { justify-content: flex-start; }
  .topbar-right { display: none; }
  .tb-btn {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 10px;
  }
  .tab {
    min-height: 40px;
    font-size: 13px;
  }
  .workspace {
    grid-template-rows: minmax(38vh, 46vh) minmax(42vh, 1fr);
  }
  .inspector {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .ctrl input[type="range"] {
    min-height: 28px;
  }
  .dropzone {
    min-height: 88px;
  }
  .film-add, .filmstrip button {
    min-height: 44px;
  }
}
