:root {
  --bg: #0b0c10;
  --bg-elev: #111218;
  --card: #14151c;
  --text: #e9ecf1;
  --text-dim: #a7aebd;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --pink: #ec4899;
  --pink-2: #db2777;
  --border: #242736;
  --ring: #4f46e5;
  --good: #10b981;
  --warn: #f59e0b;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --bg-elev: #ffffff;
    --card: #ffffff;
    --text: #0e1116;
    --text-dim: #61708a;
    --primary: #2563eb;
    --primary-2: #1d4ed8;
    --border: #e6e8ef;
    --ring: #4f46e5;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at 20% -10%, #1f2433 0%, transparent 60%),
              radial-gradient(1000px 600px at 110% 10%, #1a1f2c 0%, transparent 50%),
              var(--bg);
}

.site-header, .site-footer {
  text-align: center;
  padding: 1.25rem 1rem;
}
.title { margin: 0; font-size: 1.75rem; letter-spacing: 0.2px; }
.subtitle { margin: 0.25rem 0 0; color: var(--text-dim); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.02);
}

.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 14px;
  background: var(--bg-elev);
  padding: 28px 16px;
  text-align: center;
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
  outline: none;
}
.dropzone.has-image .dz-icon,
.dropzone.has-image .dz-title,
.dropzone.has-image .dz-subtitle { display: none; }
/* 允许在有图时继续点击/拖拽替换 */
.dropzone.has-image .file-input { pointer-events: auto; }
.dropzone.has-image .img-frame { border: none; background: transparent; }
.dropzone:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 40%, transparent); }
.dropzone.dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, var(--bg-elev));
}
.dz-icon { font-size: 2rem; margin-bottom: .25rem; }
.dz-title { margin: .25rem 0; font-weight: 600; }
.dz-subtitle { margin: 0; color: var(--text-dim); font-size: .95rem; }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-input { z-index: 1; }

.controls {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px 16px;
  margin-top: 16px;
  align-items: stretch;
}
.control { grid-column: span 12; display: grid; grid-template-rows: auto 1fr; gap: 12px; align-items: center; justify-items: center; text-align: center; }
.control > span { color: var(--text-dim); font-size: .95rem; margin-top: 4px; }
.select, .btn {
  appearance: none;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}
.select { max-width: 220px; width: 100%; min-height: 40px; align-self: center; }
#cropMode.select { max-width: 220px; }
.segmented { display: inline-flex; gap: 14px; flex-direction: column; align-items: stretch; align-self: center; }
.segmented .seg { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; cursor: pointer; background: var(--bg-elev); width: 100%; }
.segmented .seg input { appearance: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); display: inline-block; position: relative; }
.segmented .seg input:checked { border-color: var(--pink); box-shadow: inset 0 0 0 4px var(--pink); }
.segmented .seg:hover { border-color: var(--primary); }
.range-wrap { display: flex; align-items: center; gap: 10px; }
input[type="range"] { width: 100%; }
output { min-width: 3ch; text-align: right; color: var(--text-dim); }

.actions { grid-column: span 12; display: flex; gap: 10px; justify-content: flex-start; align-items: center; }
.btn { cursor: pointer; user-select: none; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, var(--pink), var(--pink-2)); color: white; border: none; }
.btn-primary:hover { filter: brightness(1.02); }

.preview {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 16px;
}
.preview-col h3 { display: none; }
.img-frame { position: relative; border: 2px dashed var(--border); border-radius: 12px; background: var(--bg-elev); min-height: 220px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.img-frame img { width: 100%; max-height: 380px; object-fit: contain; image-orientation: from-image; border: none; background: transparent; border-radius: 12px; }
.img-frame.has-image { border: none; background: transparent; }
/* 结果区即使有图也保留虚线框 */
#outputFrame.has-image { border: none; background: transparent; }
/* 输入区域不显示任何边框/背景 */
#inputFrame { border: none; background: transparent; min-height: 0; }
.meta { margin-top: 6px; color: var(--pink); font-size: .9rem; text-align: center; }
#outputMeta { text-align: center; }
#inputFrame .meta-inside, #outputFrame .meta-inside {
  position: absolute;
  left: 0; right: 0; bottom: 8px;
  text-align: center;
  padding: 2px 8px;
  pointer-events: none;
  color: var(--pink);
}

.message { margin-top: 10px; color: var(--text-dim); }
.message.error { color: #ef4444; }
.message.success { color: var(--good); }
.message.warn { color: var(--warn); }

@media (min-width: 720px) {
  .controls { grid-template-columns: repeat(3, 1fr); }
  .control { grid-column: span 1; min-height: 220px; }
  .actions { grid-column: span 3; }
}

@media (max-width: 720px) {
  .preview { grid-template-columns: 1fr; }
}

/* Center actions and tweak spacing */
.actions { justify-content: center; }

/* Crop overlay */
.crop-container { position: relative; }
.crop-overlay { position: absolute; inset: 0; pointer-events: auto; touch-action: none; z-index: 2; }
.crop-rect { position: absolute; border: 2px solid rgba(255,255,255,0.9); box-shadow: 0 0 0 9999px rgba(0,0,0,0.35); pointer-events: auto; cursor: move; touch-action: none; }
.applied-rect { position: absolute; border: 2px solid var(--pink); box-shadow: 0 0 0 1px color-mix(in srgb, var(--pink) 50%, transparent); pointer-events: none; border-radius: 2px; }
.handle { position: absolute; width: 12px; height: 12px; background: var(--pink); border: 2px solid white; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.handle.tl { top: -6px; left: -6px; cursor: nwse-resize; }
.handle.tr { top: -6px; right: -6px; cursor: nesw-resize; }
.handle.bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle.br { bottom: -6px; right: -6px; cursor: nwse-resize; }
.crop-confirm { position: absolute; right: 8px; bottom: 8px; border: none; border-radius: 8px; background: linear-gradient(180deg, var(--pink), var(--pink-2)); color: #fff; padding: 6px 10px; font-size: 12px; cursor: pointer; }
.crop-confirm:active { transform: translateY(1px); }

/* 输出占位：无图时使用较小的虚线框和居中文字 */
#outputFrame:not(.has-image) {
  width: auto;
  min-height: 220px;
  margin: 0;
}
#outputFrame .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.95rem;
}
#outputFrame.has-image .placeholder { display: none; }
