/* ============================================================
 * cropper.css — 图片裁剪组件样式（Prompt 13a，零依赖）
 * 覆盖 image-cropper.js 生成的 DOM。
 * 移动端 <768：全屏 + 底部按钮堆叠 + 手柄触摸区 44px
 * 平板 768-1024：弹窗宽 90%
 * 桌面 ≥1024：弹窗最大宽 1000px
 * ============================================================ */

/* ---------- 遮罩与骨架 ---------- */
.ic-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-cropper);
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  -webkit-tap-highlight-color: transparent;
}

body.ic-open {
  overflow: hidden;
}

/* ---------- 顶部 ---------- */
.ic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex: 0 0 auto;
}

.ic-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ic-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Prompt 33：副提示语（如「框选图形区域，只保留这部分」） */
.ic-hint {
  font-size: 12px;
  color: rgba(248, 250, 252, 0.72);
  line-height: 1.4;
}

.ic-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  font-size: 16px;
  cursor: pointer;
  position: relative;
}

.ic-close::after {
  /* 触摸区扩大到 44px（视觉保持 36px） */
  content: '';
  position: absolute;
  inset: -4px;
}

.ic-close:active {
  background: rgba(255, 255, 255, 0.24);
}

/* ---------- 中部舞台 ---------- */
.ic-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0 16px;
  touch-action: none; /* 手势全由 JS 接管，浏览器不滚动/不缩放 */
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.ic-stage.is-preparing .ic-zoomer {
  visibility: hidden;
}

.ic-zoomer {
  will-change: transform;
  transform-origin: center center;
}

.ic-canvas-wrap {
  position: relative;
  margin: 0 auto;
  /* P28：手势全部交给 JS（Touch Events）接管，浏览器不得滚动 / 缩放 */
  touch-action: none;
}

.ic-canvas {
  display: block;
  border-radius: 4px;
  touch-action: none;
  -webkit-user-drag: none; /* 防长按拖动图片幽灵 */
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- 裁剪框 ---------- */
.ic-box {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5); /* 框外暗色遮罩 */
  cursor: move;
  touch-action: none;
}

/* 三分法网格：2 横 2 竖，1px 白色 50% */
.ic-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent calc(33.33% - 0.5px), rgba(255, 255, 255, 0.5) 33.33%, transparent calc(33.33% + 0.5px)),
    linear-gradient(to right, transparent calc(66.66% - 0.5px), rgba(255, 255, 255, 0.5) 66.66%, transparent calc(66.66% + 0.5px)),
    linear-gradient(to bottom, transparent calc(33.33% - 0.5px), rgba(255, 255, 255, 0.5) 33.33%, transparent calc(33.33% + 0.5px)),
    linear-gradient(to bottom, transparent calc(66.66% - 0.5px), rgba(255, 255, 255, 0.5) 66.66%, transparent calc(66.66% + 0.5px));
}

/* ---------- 手柄：视觉 8x8，触摸区 44x44（伪元素） ---------- */
.ic-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #ffffff;
  border: 2px solid var(--brand-500, #f97316);
  border-radius: 2px;
  box-sizing: border-box;
  touch-action: none;
}

.ic-handle::after {
  content: '';
  position: absolute;
  inset: -18px; /* 8px + 18px*2 = 44px 触摸区 */
}

.ic-h-nw { left: -5px; top: -5px; cursor: nwse-resize; }
.ic-h-n  { left: 50%; top: -5px; margin-left: -4px; cursor: ns-resize; }
.ic-h-ne { right: -5px; top: -5px; cursor: nesw-resize; }
.ic-h-e  { right: -5px; top: 50%; margin-top: -4px; cursor: ew-resize; }
.ic-h-se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.ic-h-s  { left: 50%; bottom: -5px; margin-left: -4px; cursor: ns-resize; }
.ic-h-sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.ic-h-w  { left: -5px; top: 50%; margin-top: -4px; cursor: ew-resize; }

/* ---------- loading / 错误 ---------- */
.ic-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.6);
  font-size: 15px;
  z-index: 3;
}

.ic-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.85);
  z-index: 4;
  padding: 24px;
  text-align: center;
}

.ic-error.is-hidden { display: none; }

.ic-error-icon { font-size: 40px; }

.ic-error-text {
  font-size: 15px;
  color: #fecaca;
  max-width: 320px;
}

/* ---------- 缩放指示器 ---------- */
.ic-zoom-badge {
  position: absolute;
  right: 16px;
  bottom: 16px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transition: opacity 0.3s;
}

.ic-zoom-badge.is-hidden {
  opacity: 0;
  visibility: hidden;
}

/* ---------- 底部按钮 ---------- */
.ic-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
}

.ic-footer .btn {
  min-height: 44px;
}

/* ---------- 响应式 ---------- */

/* 手机 <768：全屏（遮罩本身已是全屏），底部按钮堆叠 */
@media (max-width: 767px) {
  .ic-footer {
    flex-direction: column-reverse; /* 主按钮「确认裁剪」在最上/最顺手的位置 */
    gap: 10px;
  }

  .ic-footer .btn {
    width: 100%;
  }
}

/* 平板 768-1024：弹窗宽 90%，居中显示 */
@media (min-width: 768px) and (max-width: 1023px) {
  .ic-overlay {
    width: 90%;
    height: 90%;
    left: 5%;
    top: 5%;
    border-radius: 16px;
    overflow: hidden;
  }
}

/* 桌面 ≥1024：最大宽 1000px，居中 */
@media (min-width: 1024px) {
  .ic-overlay {
    width: 1000px;
    max-width: calc(100vw - 48px);
    height: calc(100vh - 48px);
    left: 50%;
    top: 24px;
    transform: translateX(-50%);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  }
}
