/* PickIt · 图片裁剪 · 工具专属样式  author: ruan
 * 公共部分见 /shared/base.css */

/* 比例芯片 */
.ratio-chips .chip { font-family: var(--mono); }
.ratio-chips .chip[data-ratio="free"],
.ratio-chips .chip[data-ratio="source"],
.ratio-chips .chip[data-ratio="id1"],
.ratio-chips .chip[data-ratio="id2"],
.ratio-chips .chip[data-ratio="avatar"],
.ratio-chips .chip[data-ratio="mpcover"],
.ratio-chips .chip[data-ratio="custom"] { font-family: var(--font); }

.ratio-custom {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.ratio-custom .colon { color: var(--ink-3); font-family: var(--mono); text-align: center; }

/* 数字输入（X / Y / 宽 / 高、自定义比例、输出宽度） */
.num-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.num-grid label { display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.num-input, .ratio-custom input, .field input.num-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 14px;
}
.num-input:focus-visible, .ratio-custom input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* 操作按钮：居中 / 全图 / 旋转 / 翻转 */
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}
.tool-row .btn svg { width: 16px; height: 16px; }

.check-row { display: flex; align-items: flex-start; gap: 8px; margin-top: 12px; }
.check-row input { margin-top: 4px; accent-color: var(--accent); }
.check-row label { font-size: 13px; color: var(--ink-2); cursor: pointer; }

/* ---------- 裁剪舞台 ---------- */
.crop-frame {
  position: relative;
  display: inline-block;
  line-height: 0;
  overflow: hidden;
  /* 画布本身把纵向滑动交回浏览器滚动页面。裁剪框与把手是 touch-action: none，
     按规范取从命中元素往上的交集，所以拖它们仍是完整的二维控制。
     不这么分的话，画布是块占屏四成的滚动死区，随手一滑还会把裁剪框改坏。 */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.35);
}
.crop-frame canvas { display: block; max-width: none; max-height: none; box-shadow: none; }

.crop-box {
  position: absolute;
  box-sizing: border-box;
  border: 1.5px solid #fff;
  outline: 1px solid rgba(0, 0, 0, 0.45);
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.5);
  cursor: move;
  touch-action: none;
}
.crop-box:focus-visible { outline: 2px solid var(--accent-2); }
.crop-box.has-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.55) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.55) 1px, transparent 1px);
  background-size: 100% 33.34%, 33.34% 100%;
  background-position: 0 -1px, -1px 0;
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.45);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  touch-action: none;
}
.crop-handle[data-handle="nw"] { top: -7px; left: -7px; cursor: nwse-resize; }
.crop-handle[data-handle="ne"] { top: -7px; right: -7px; cursor: nesw-resize; }
.crop-handle[data-handle="sw"] { bottom: -7px; left: -7px; cursor: nesw-resize; }
.crop-handle[data-handle="se"] { bottom: -7px; right: -7px; cursor: nwse-resize; }
.crop-handle[data-handle="n"] { top: -7px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.crop-handle[data-handle="s"] { bottom: -7px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.crop-handle[data-handle="w"] { left: -7px; top: 50%; margin-top: -7px; cursor: ew-resize; }
.crop-handle[data-handle="e"] { right: -7px; top: 50%; margin-top: -7px; cursor: ew-resize; }

.crop-size {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(29, 27, 23, 0.75);
  color: #fff;
  font-size: 11px;
  font-family: var(--mono);
  line-height: 1.4;
  pointer-events: none;
  white-space: nowrap;
}
.crop-box.is-small .crop-size { bottom: -22px; right: 0; }

@media (pointer: coarse) {
  .crop-handle { width: 22px; height: 22px; }
  .crop-handle[data-handle="nw"], .crop-handle[data-handle="ne"], .crop-handle[data-handle="sw"], .crop-handle[data-handle="se"] { margin: 0; }
  .crop-handle[data-handle="nw"] { top: -11px; left: -11px; }
  .crop-handle[data-handle="ne"] { top: -11px; right: -11px; }
  .crop-handle[data-handle="sw"] { bottom: -11px; left: -11px; }
  .crop-handle[data-handle="se"] { bottom: -11px; right: -11px; }
  .crop-handle[data-handle="n"] { top: -11px; margin-left: -11px; }
  .crop-handle[data-handle="s"] { bottom: -11px; margin-left: -11px; }
  .crop-handle[data-handle="w"] { left: -11px; margin-top: -11px; }
  .crop-handle[data-handle="e"] { right: -11px; margin-top: -11px; }
  .num-input, .ratio-custom input { min-height: 44px; }
}

/* 舞台留出把手的空间 */
.stage.has-crop { padding: 20px; }

/* 双指放大后：画布接管全部手势（页面因此滚不动），靠这个按钮或双击退出 */
.crop-frame.is-pinched { touch-action: none; }
.zoom-reset {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.export-actions-batch { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) {
  .export-actions-batch { grid-template-columns: 1fr; }
  .num-input, .ratio-custom input { font-size: 16px; }
}
