/* photo2kb · 在线图片编辑器 —— Photopea 风格深色工作区（v2 分层编辑器）
   模板：_editor.html；逻辑：static/js/ps/*.js（core/filters/tools/ui）
   命名空间 .psapp；菜单/工具/图层列表/历史/选项栏内容由 JS 构建，这里负责全部样式。
   v1 的浅色 ps-stage/ps-pane 样式已随模板重写移除。 */

.psapp {
  --ps-bg: #1e1e1e;            /* 工作区底 */
  --ps-panel: #2b2b2b;         /* 面板/菜单栏 */
  --ps-panel2: #333333;        /* 选项栏/输入件 */
  --ps-line: #3f3f3f;
  --ps-text: #d8d8d8;
  --ps-dim: #9a9a9a;
  --ps-accent: #3b82f6;
  --ps-accent-soft: rgba(59, 130, 246, .18);
  --ps-radius: 10px;
  color-scheme: dark;
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ps-text);
  background: var(--ps-bg);
  border: 1px solid #000;
  border-radius: var(--ps-radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

.psapp *, .psapp *::before, .psapp *::after { box-sizing: border-box; }
.psapp button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.psapp h3 { margin: 0; }
.psapp output { font-variant-numeric: tabular-nums; color: var(--ps-dim); font-size: 12px; }

/* ── 菜单栏 ─────────────────────────────────────────────── */
.ps-menubar {
  display: flex; align-items: center; gap: 2px;
  background: var(--ps-panel);
  border-bottom: 1px solid var(--ps-line);
  padding: 0 8px; height: 38px; user-select: none;
}
.ps-brand {
  font-weight: 700; font-size: 11px; letter-spacing: .08em;
  color: #fff; background: var(--ps-accent);
  border-radius: 4px; padding: 2px 6px; margin-right: 8px;
}
.ps-menubar-items { display: flex; align-items: center; flex: 1; min-width: 0; }
.ps-menu { position: relative; }
.ps-menu > span {
  display: block; padding: 4px 9px; border-radius: 5px; cursor: pointer; white-space: nowrap;
}
.ps-menu > span:hover, .ps-menu.open > span { background: var(--ps-panel2); }
.ps-dropdown {
  display: none; position: absolute; top: 100%; left: 0; z-index: 60;
  min-width: 220px; padding: 5px;
  background: #262626; border: 1px solid var(--ps-line); border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .45);
}
.ps-menu.open .ps-dropdown { display: block; }
.ps-dropdown button {
  display: flex; align-items: center; width: 100%;
  padding: 6px 9px; border-radius: 5px; text-align: left;
}
.ps-dropdown button:hover { background: var(--ps-accent); color: #fff; }
.ps-dd-label { flex: 1; }
.ps-dd-key { color: var(--ps-dim); font-size: 11px; margin-left: 22px; }
.ps-dropdown hr { border: 0; border-top: 1px solid var(--ps-line); margin: 5px 4px; }
.ps-menubar-actions { display: flex; gap: 4px; }
.ps-mb-btn {
  width: 28px; height: 26px; border-radius: 5px;
  display: grid; place-items: center; font-size: 14px;
}
.ps-mb-btn:hover:not(:disabled) { background: var(--ps-panel2); }
.ps-mb-btn:disabled { opacity: .32; cursor: default; }

/* ── 选项栏 ─────────────────────────────────────────────── */
.ps-optionbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px;
  min-height: 42px; padding: 4px 12px;
  background: var(--ps-panel2); border-bottom: 1px solid var(--ps-line);
}
.ps-opt { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 12px; color: var(--ps-dim); }
.ps-opt input[type="number"] { width: 66px; }
.ps-opt select { min-width: 90px; }
.ps-opt-hint { color: var(--ps-dim); font-size: 12px; }
.ps-opt-btn {
  padding: 4px 10px; border: 1px solid var(--ps-line); border-radius: 5px;
  background: var(--ps-panel); font-size: 12px;
}
.ps-opt-btn:hover { border-color: var(--ps-accent); color: #fff; }

/* 深色输入件 */
.psapp input[type="number"], .psapp select, .psapp .ps-dialog input, .psapp .ps-dialog select {
  font: inherit; font-size: 12px; color: var(--ps-text);
  background: #242424; border: 1px solid var(--ps-line); border-radius: 5px;
  padding: 3px 6px; color-scheme: dark;
}
.psapp input[type="color"] {
  width: 26px; height: 22px; padding: 1px 2px;
  background: #242424; border: 1px solid var(--ps-line); border-radius: 5px;
}
.psapp input[type="checkbox"] { accent-color: var(--ps-accent); }
.psapp input[type="range"] { accent-color: var(--ps-accent); width: 130px; }

/* ── 三栏工作区 ─────────────────────────────────────────── */
.ps-workbench {
  display: flex; align-items: stretch;
  height: clamp(480px, 62vh, 780px);
}

/* 工具箱（左列） */
.ps-toolbox {
  display: flex; flex-direction: column; gap: 2px; flex: none;
  width: 46px; padding: 6px 5px;
  background: var(--ps-panel); border-right: 1px solid var(--ps-line);
  overflow-y: auto;
}
.ps-tool {
  width: 36px; height: 34px; border-radius: 6px;
  display: grid; place-items: center; color: var(--ps-dim);
}
.ps-tool svg { width: 19px; height: 19px; }
.ps-tool:hover { background: var(--ps-panel2); color: var(--ps-text); }
.ps-tool.active { background: var(--ps-accent-soft); color: #fff; box-shadow: inset 0 0 0 1px var(--ps-accent); }
.ps-tool-colors { position: relative; width: 36px; height: 36px; margin-top: 8px; flex: none; }
.ps-color-chip {
  position: absolute; width: 22px; height: 22px;
  border: 2px solid #fff; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
  cursor: pointer;
}
.ps-color-chip input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.ps-color-chip#ps-chip-fg { left: 0; top: 0; z-index: 2; }
.ps-color-chip#ps-chip-bg { right: 0; bottom: 0; z-index: 1; }

/* 画布区（中列） */
.ps-canvasarea { position: relative; flex: 1; min-width: 0; background: #262626; }
.ps-scroll { position: absolute; inset: 0; overflow: auto; display: flex; }
.ps-canvas-holder {
  position: relative; flex: none; margin: auto;   /* margin:auto：小于视口居中、超出可滚动不裁顶 */
  background:
    repeating-conic-gradient(#cfcfcf 0 25%, #efefef 0 50%) 0 0 / 16px 16px; /* 透明棋盘 */
  box-shadow: 0 4px 18px rgba(0, 0, 0, .5);
}
#ps-main { display: block; }
.ps-ants { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#ps-ants-rect {
  fill: rgba(59, 130, 246, .06);
  stroke: #4cc2ff; stroke-width: 1.5; stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
  animation: ps-ants-move .5s linear infinite;
}
@keyframes ps-ants-move { to { stroke-dashoffset: -10; } }

/* 工具光标 */
.tool-move #ps-main { cursor: move; }
.tool-select #ps-main, .tool-crop #ps-main, .tool-brush #ps-main,
.tool-eraser #ps-main, .tool-fill #ps-main, .tool-shape #ps-main,
.tool-eyedropper #ps-main { cursor: crosshair; }
.tool-text #ps-main { cursor: text; }
.tool-zoom #ps-main { cursor: zoom-in; }
.tool-pan #ps-main { cursor: grab; }

.ps-canvas-hint {
  position: absolute; left: 0; right: 0; bottom: 6px;
  text-align: center; font-size: 11px; color: rgba(255, 255, 255, .38);
  pointer-events: none; user-select: none;
}

/* 文字浮层编辑器 */
.ps-text-editor {
  position: absolute; z-index: 40; display: flex; align-items: center; gap: 6px;
  background: #fff; color: #111;
  border: 2px solid var(--ps-accent); border-radius: 6px;
  padding: 4px 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
}
.ps-text-editor input {
  border: 0; outline: 0; font-weight: 600; min-width: 160px; color: inherit;
}
.ps-text-actions { display: flex; gap: 4px; }
.ps-text-actions button {
  font-size: 11px; padding: 2px 8px; border-radius: 4px;
  background: #111; color: #fff;
}
.ps-text-actions button#ps-text-cancel { background: #e5e5e5; color: #111; }

/* 侧面板（右列） */
.ps-side {
  width: 268px; flex: none; overflow-y: auto;
  background: var(--ps-panel); border-left: 1px solid var(--ps-line);
  scrollbar-width: thin; scrollbar-color: #4a4a4a transparent;
}
.ps-panel { border-bottom: 1px solid var(--ps-line); }
.ps-panel h3 {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ps-dim); padding: 9px 12px 7px;
}
.ps-panel-body { padding: 2px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.ps-panel.highlight { box-shadow: inset 0 0 0 2px var(--ps-accent); }
.ps-panel-hint { margin: 0; font-size: 11px; color: var(--ps-dim); }
.ps-panel-btn {
  padding: 6px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: var(--ps-accent); color: #fff;
}
.ps-panel-btn:hover { filter: brightness(1.1); }

/* 调整滑杆行 */
.ps-adj-row {
  display: grid; grid-template-columns: 76px 1fr 34px;
  align-items: center; gap: 8px; font-size: 12px; color: var(--ps-dim);
}
.ps-adj-row input[type="range"] { width: 100%; }
.ps-adj-row output { text-align: right; }

/* 滤镜网格 */
.ps-filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ps-filter-grid button {
  padding: 6px 4px; border-radius: 6px; font-size: 12px;
  background: var(--ps-panel2); border: 1px solid var(--ps-line);
}
.ps-filter-grid button:hover { border-color: var(--ps-accent); color: #fff; }

/* 图层面板 */
.ps-layer-props { display: flex; align-items: center; gap: 8px; }
.ps-layer-props select { flex: 1; min-width: 0; }
.ps-layer-props input[type="range"] { width: 64px; }
.ps-layer-list { display: flex; flex-direction: column; gap: 3px; min-height: 46px; }
.ps-layer {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; background: var(--ps-panel2);
}
.ps-layer:hover { border-color: var(--ps-line); }
.ps-layer.active { border-color: var(--ps-accent); background: var(--ps-accent-soft); }
.ps-layer-thumb {
  width: 36px; height: 36px; flex: none; border-radius: 4px;
  border: 1px solid var(--ps-line); background:
    repeating-conic-gradient(#bbb 0 25%, #ddd 0 50%) 0 0 / 10px 10px;
}
.ps-layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.ps-layer-rename {
  flex: 1; min-width: 0; font: inherit; font-size: 12px;
  background: #1a1a1a; color: #fff; border: 1px solid var(--ps-accent); border-radius: 4px; padding: 1px 5px;
}
.ps-layer-eye { color: var(--ps-dim); font-size: 13px; width: 22px; }
.ps-layer-eye.off { opacity: .35; }
.ps-layer-btns { display: flex; gap: 4px; }
.ps-layer-btns button {
  flex: 1; padding: 5px 0; border-radius: 5px; font-size: 13px;
  background: var(--ps-panel2); border: 1px solid var(--ps-line);
}
.ps-layer-btns button:hover { border-color: var(--ps-accent); color: #fff; }

/* 历史面板 */
.ps-history-list {
  max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: #4a4a4a transparent;
}
.ps-hist { padding: 4px 8px; border-radius: 5px; font-size: 12px; cursor: pointer; color: var(--ps-dim); }
.ps-hist:hover { background: var(--ps-panel2); }
.ps-hist.active { background: var(--ps-accent-soft); color: #fff; }

/* ── 状态栏 ─────────────────────────────────────────────── */
.ps-statusbar {
  display: flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 10px;
  background: var(--ps-panel); border-top: 1px solid var(--ps-line);
  font-size: 11.5px; color: var(--ps-dim); user-select: none;
}
.ps-zbtn {
  min-width: 24px; height: 20px; padding: 0 5px; border-radius: 4px;
  display: grid; place-items: center; font-size: 12px;
  background: var(--ps-panel2); border: 1px solid var(--ps-line);
}
.ps-zbtn:hover { color: #fff; border-color: var(--ps-accent); }
.ps-status-zoom { min-width: 42px; color: var(--ps-text); font-variant-numeric: tabular-nums; }
.ps-status-doc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-status-spacer, .psapp .spacer { flex: 1; }
.ps-status-sel { color: var(--ps-dim); font-variant-numeric: tabular-nums; }
.ps-privacy { color: rgba(255, 255, 255, .35); font-size: 11px; white-space: nowrap; }

/* ── 对话框 ─────────────────────────────────────────────── */
.psapp .ps-dialog {
  color: var(--ps-text); background: #2b2b2b;
  border: 1px solid var(--ps-line); border-radius: 12px;
  padding: 18px 20px; min-width: 320px; max-width: min(92vw, 460px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .55);
  color-scheme: dark;
}
.ps-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.ps-dialog h3 { font-size: 15px; margin-bottom: 14px; color: #fff; }
.ps-dlg-row { display: flex; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 12px; }
.ps-dlg-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ps-dim); }
.ps-dlg-row input[type="number"] { width: 96px; }
.ps-dlg-row input[type="range"] { width: 130px; }
.ps-dlg-check { flex-direction: row !important; align-items: center; gap: 6px !important; padding-top: 18px; }
.ps-dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.ps-btn-solid {
  padding: 7px 16px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
  background: var(--ps-accent); color: #fff;
}
.ps-btn-solid:hover { filter: brightness(1.12); }
.ps-btn-solid:disabled { opacity: .5; cursor: default; }
.ps-btn-ghost {
  padding: 7px 14px; border-radius: 7px; font-size: 12.5px;
  border: 1px solid var(--ps-line); color: var(--ps-dim);
}
.ps-btn-ghost:hover { color: #fff; border-color: var(--ps-dim); }
.ps-dlg-hr { border: 0; border-top: 1px solid var(--ps-line); margin: 14px 0; }
.ps-exp-status { margin: 10px 0 0; font-size: 12px; color: #7ee787; min-height: 16px; }

/* ── 编辑器下方的本地隐私提示条 ─────────────────────────── */
.privacy-strip { display: flex; align-items: center; gap: 10px; justify-content: center; margin: 14px 0 6px; flex-wrap: wrap; }

/* ── 窄屏适配：三栏改纵向堆叠 ───────────────────────────── */
@media (max-width: 900px) {
  .ps-workbench { flex-direction: column; height: auto; }
  .ps-toolbox {
    flex-direction: row; width: auto; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-bottom: 1px solid var(--ps-line); padding: 6px;
  }
  .ps-tool-colors { margin: 0 0 0 8px; }
  .ps-canvasarea { height: 58vh; min-height: 340px; flex: none; }
  .ps-side { width: 100%; max-height: 300px; border-left: 0; border-top: 1px solid var(--ps-line); }
  .ps-canvas-hint { display: none; }
  .ps-menubar-items { overflow-x: auto; }
}

/* ── 嵌入模式引导区（openbar）：站点浅色语境下的上传入口 ── */
.ps-openbar {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin: 0 0 14px; padding: 26px 16px;
  border: 2px dashed #b6c2d4; border-radius: 12px;
  background: #f6f9fd; color: #334155;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: center; cursor: pointer; user-select: none;
  transition: border-color .15s, background .15s;
}
.ps-openbar strong { font-size: 15px; color: #0f172a; }
.ps-openbar .ps-openbar-sub { font-size: 12px; color: #64748b; }
.ps-openbar:hover, .ps-openbar.drag { border-color: #3b82f6; background: #eef4ff; }
.ps-openbar:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }

/* 拖放悬停高亮（画布区） */
.ps-canvasarea.drag::after {
  content: ""; position: absolute; inset: 8px; z-index: 30;
  border: 2px dashed var(--ps-accent); border-radius: 8px;
  background: rgba(59, 130, 246, .08); pointer-events: none;
}

/* ── 全屏应用模式（?full=1）：编辑器独占视口，站点外框全部隐藏 ── */
body.ps-fullscreen { overflow: hidden; }
body.ps-fullscreen .site-header,
body.ps-fullscreen .site-footer,
body.ps-fullscreen .app-tabs,
body.ps-fullscreen .ps-openbar,
body.ps-fullscreen .privacy-strip { display: none !important; }
body.ps-fullscreen main,
body.ps-fullscreen main > .wrap { max-width: none; margin: 0; padding: 0; }
body.ps-fullscreen .wrap > :not(.psapp):not(script):not(style) { display: none !important; }
body.ps-fullscreen .psapp {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  border: 0; border-radius: 0; box-shadow: none;
}
body.ps-fullscreen .ps-workbench { flex: 1; min-height: 0; height: auto; }
body.ps-fullscreen .ps-menubar, body.ps-fullscreen .ps-optionbar,
body.ps-fullscreen .ps-statusbar { flex: none; }

/* ── Export 弹框：label 左 / 控件右 两列对齐（左列定宽，两组共享列位）── */
.ps-exp-grid {
  display: grid;
  grid-template-columns: 132px 1fr;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 12px;
}
.ps-exp-grid > label { font-size: 12px; color: var(--ps-dim); }
.ps-exp-grid select,
.ps-exp-grid input[type="range"] { width: 100%; }
.ps-exp-kb { display: flex; align-items: center; gap: 8px; }
.ps-exp-kb input[type="number"] { flex: 1; min-width: 0; }
.ps-exp-kb span { font-size: 12px; color: var(--ps-dim); }

/* ── 落地页（body.ps-landing，由 ui.js 在嵌入模式加）：不展示内嵌编辑器，
      上传引导区加高为主视觉入口 ── */
body.ps-landing .psapp { display: none !important; }
body.ps-landing .ps-openbar {
  min-height: 340px;
  padding: 64px 28px;
  justify-content: center;
  gap: 10px;
  font-size: 15px;
}
body.ps-landing .ps-openbar strong { font-size: 22px; }
body.ps-landing .ps-openbar .ps-openbar-sub { font-size: 13px; }

/* ── 变换框（移动工具四角旋转手柄）────────────────────────── */
#ps-tf-box {
  stroke: var(--ps-accent); stroke-width: 1; stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}
/* 手柄单独开放指针事件（父 SVG 是 pointer-events:none）；
   白底蓝边，尺寸由 JS 按 10/zoom 设置 —— 屏幕大小恒定不随缩放 */
.ps-tf-handle {
  fill: #fff; stroke: var(--ps-accent); stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
  pointer-events: all; cursor: grab;
}
.ps-tf-handle:hover { fill: var(--ps-accent); }

/* ── 侧面板横向拖宽条 ───────────────────────────────────── */
.ps-side-resizer {
  flex: none; width: 6px; cursor: col-resize;
  background: transparent; touch-action: none; user-select: none;
  transition: background .15s;
}
.ps-side-resizer:hover { background: var(--ps-accent-soft); }

@media (max-width: 900px) {
  .ps-side-resizer { display: none; }   /* 纵向堆叠布局无需横向拉宽 */
}
