/* 证件照换背景 */

.page-idbg {
  max-width: 1100px;
}

.page-idbg.is-editing {
  max-width: 1180px;
  padding-top: 12px;
  padding-bottom: 16px;
}

.page-idbg.is-editing .header,
.page-idbg.is-editing .seo-content,
.page-idbg.is-editing .footer {
  display: none !important;
}

.page-idbg.is-editing .panel {
  padding: 14px;
}

.idbg-workspace[hidden] {
  display: none !important;
}

.idbg-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  margin-top: 4px;
}

.idbg-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.idbg-stage {
  position: relative;
  height: min(58vh, 560px);
  min-height: 280px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background-color: #dce3eb;
  background-image:
    linear-gradient(45deg, #c8d0da 25%, transparent 25%),
    linear-gradient(-45deg, #c8d0da 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #c8d0da 75%),
    linear-gradient(-45deg, transparent 75%, #c8d0da 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: none;
}

.idbg-viewport {
  position: relative;
  flex: 0 0 auto;
  line-height: 0;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 8px 28px rgba(24, 33, 43, 0.18);
}

.idbg-viewport canvas {
  display: block;
  max-width: none;
  max-height: none;
  pointer-events: none;
}

.idbg-crop-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.idbg-crop-layer[hidden] {
  display: none !important;
}

.idbg-crop-box {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(24, 33, 43, 0.48);
  cursor: move;
  touch-action: none;
}

.idbg-crop-grid {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to right, transparent 33.33%, rgba(255,255,255,0.35) 33.33%, rgba(255,255,255,0.35) calc(33.33% + 1px), transparent calc(33.33% + 1px), transparent 66.66%, rgba(255,255,255,0.35) 66.66%, rgba(255,255,255,0.35) calc(66.66% + 1px), transparent calc(66.66% + 1px)),
    linear-gradient(to bottom, transparent 33.33%, rgba(255,255,255,0.35) 33.33%, rgba(255,255,255,0.35) calc(33.33% + 1px), transparent calc(33.33% + 1px), transparent 66.66%, rgba(255,255,255,0.35) 66.66%, rgba(255,255,255,0.35) calc(66.66% + 1px), transparent calc(66.66% + 1px));
  pointer-events: none;
}

.idbg-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  box-sizing: border-box;
  z-index: 1;
}

.idbg-handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.idbg-handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.idbg-handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.idbg-handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.idbg-handle.n { top: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
.idbg-handle.s { bottom: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
.idbg-handle.w { left: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }
.idbg-handle.e { right: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }

@media (max-width: 860px) {
  .idbg-handle {
    width: 16px;
    height: 16px;
  }
  .idbg-handle.nw { top: -8px; left: -8px; }
  .idbg-handle.ne { top: -8px; right: -8px; }
  .idbg-handle.sw { bottom: -8px; left: -8px; }
  .idbg-handle.se { bottom: -8px; right: -8px; }
  .idbg-handle.n { top: -8px; margin-left: -8px; }
  .idbg-handle.s { bottom: -8px; margin-left: -8px; }
  .idbg-handle.w { left: -8px; margin-top: -8px; }
  .idbg-handle.e { right: -8px; margin-top: -8px; }
}

.idbg-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  background: rgba(24, 33, 43, 0.48);
  color: #fff;
  text-align: center;
  z-index: 3;
}

.idbg-overlay[hidden] {
  display: none !important;
}

.idbg-overlay .progress-wrap {
  width: min(320px, 80%);
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.idbg-overlay .progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5eead4, #14b8a6, #5eead4);
  background-size: 200% 100%;
  transition: width 0.25s linear;
  animation: idbg-bar-shine 1.4s linear infinite;
}

.idbg-overlay .progress-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #5eead4;
  animation: idbg-spin 0.8s linear infinite;
}

.idbg-overlay .progress-text {
  font-size: 0.92rem;
  font-weight: 600;
  min-height: 1.4em;
}

.idbg-overlay .progress-elapsed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: #99f6e4;
  text-shadow: 0 1px 8px rgba(15, 118, 110, 0.35);
}

.idbg-overlay.is-running .progress-elapsed {
  animation: idbg-pulse 1.6s ease-in-out infinite;
}

/* CSS 计时：主线程被 ONNX 占满时 setInterval 也会停，用动画保证秒数仍在走 */
.elapsed-roller {
  display: inline-block;
  height: 1.2em;
  overflow: hidden;
  vertical-align: -0.15em;
  min-width: 1.6em;
  text-align: center;
}

.elapsed-strip {
  display: block;
  will-change: transform;
}

.elapsed-strip span {
  display: block;
  height: 1.2em;
  line-height: 1.2em;
  text-align: center;
}

.idbg-overlay.is-running .elapsed-strip.is-ticking {
  animation: idbg-sec-roll 180s steps(180) forwards;
}

.elapsed-fallback {
  display: none;
  min-width: 1.2em;
  text-align: center;
}

.idbg-overlay:not(.is-running) .elapsed-roller {
  display: none;
}

.idbg-overlay:not(.is-running) .elapsed-fallback {
  display: inline;
}

@keyframes idbg-sec-roll {
  from { transform: translateY(0); }
  to { transform: translateY(calc(-1.2em * 180)); }
}

.idbg-overlay .progress-hint {
  font-size: 0.78rem;
  opacity: 0.82;
  max-width: 280px;
  line-height: 1.4;
}

@keyframes idbg-spin {
  to { transform: rotate(360deg); }
}

@keyframes idbg-bar-shine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes idbg-pulse {
  0%, 100% { opacity: 0.78; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.03); }
}

.idbg-stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.idbg-meta {
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.idbg-meta strong {
  color: var(--ink);
  font-weight: 600;
}

.idbg-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  max-height: calc(min(58vh, 560px) + 40px);
}

.idbg-sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}

.idbg-sidebar .side-block {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.idbg-sidebar .side-block h3 {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 600;
}

.idbg-sidebar .hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}

.idbg-sidebar .seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.idbg-sidebar .seg-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}

.idbg-sidebar .seg-btn:hover {
  border-color: rgba(15, 118, 110, 0.3);
  color: var(--ink);
}

.idbg-sidebar .seg-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.bg-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bg-option {
  appearance: none;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.bg-option:hover {
  border-color: rgba(15, 118, 110, 0.3);
  background: #fff;
}

.bg-option.active {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.bg-option-dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(24, 33, 43, 0.12);
  flex-shrink: 0;
}

.bg-option-dot.is-white {
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(24, 33, 43, 0.18);
}

.bg-option-dot.is-transparent {
  background-color: #dce3eb;
  background-image:
    linear-gradient(45deg, #c8d0da 25%, transparent 25%),
    linear-gradient(-45deg, #c8d0da 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #c8d0da 75%),
    linear-gradient(-45deg, transparent 75%, #c8d0da 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.bg-option-text {
  min-width: 0;
}

.bg-option-text strong {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.bg-option-text em {
  display: block;
  margin-top: 2px;
  font-style: normal;
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.35;
}

.bg-custom-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px dashed rgba(24, 33, 43, 0.16);
  background: #fff;
  cursor: pointer;
}

.bg-custom-row.active {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.bg-custom-swatch {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(24, 33, 43, 0.12);
}

.bg-custom-swatch input {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  border: none;
  padding: 0;
  cursor: pointer;
}

.bg-custom-text strong {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
}

.bg-custom-text em {
  display: block;
  margin-top: 2px;
  font-style: normal;
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.35;
}

.bg-list.is-ready .bg-option {
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}

.bg-list.is-ready .bg-option:hover {
  transform: translateY(-1px);
}

.size-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.size-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 10px;
  padding: 8px 8px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}

.size-btn:hover {
  border-color: rgba(15, 118, 110, 0.3);
}

.size-btn.active {
  background: rgba(15, 118, 110, 0.08);
  border-color: var(--accent);
}

.size-btn .lbl {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
}

.size-btn .sub {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

.field:last-child { margin-bottom: 0; }

.field > span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.field > span em {
  font-style: normal;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.field select,
.field input[type="range"] {
  width: 100%;
}

.field select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.88rem;
  color: var(--ink);
  background: #fff;
  font-family: inherit;
}

.field select:focus {
  outline: none;
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.field input[type="range"] {
  accent-color: var(--accent);
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.status-tip {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 118, 110, 0.1);
  border: 1px solid rgba(15, 118, 110, 0.22);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.45;
}

.status-tip[hidden] {
  display: none !important;
}

.status-tip.is-flash {
  animation: idbg-tip-flash 0.9s ease;
}

.btn-link {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 4px 0;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-link:hover {
  color: var(--accent);
}

.btn-link[hidden] {
  display: none !important;
}

.side-actions.is-done #btn-run {
  display: none;
}

@keyframes idbg-tip-flash {
  0% { background: rgba(15, 118, 110, 0.22); }
  100% { background: rgba(15, 118, 110, 0.1); }
}

.side-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-block { width: 100%; }

.dropzone.is-dragover {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.06);
}

@media (max-width: 860px) {
  .idbg-layout {
    grid-template-columns: 1fr;
  }

  .idbg-sidebar {
    max-height: none;
  }

  .idbg-stage {
    height: min(48vh, 420px);
  }
}
