* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e4e8f0;
  --text: #1f2937;
  --text-sub: #6b7280;
  --primary: #4f6bff;
  --primary-hover: #3b55e6;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  
  --site-header-height: 45px;
  
  --editor-header-height: 64px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.app {
  height: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  height: var(--editor-header-height);
  min-height: var(--editor-header-height);
  display: flex;
  align-items: center;
  padding: 0 22px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}
.app-header .header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: nowrap;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}
.app-header h1 { font-size: 19px; font-weight: 750; white-space: nowrap; }
.app-header h1 .logo-accent { color: var(--primary); }

html[lang="en"] .app-header h1 .logo-accent { margin-left: .22em; }
.subtitle { color: var(--text-sub); font-size: 13px; }
.app-header .subtitle { text-align: right; }

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  grid-template-rows: minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 10px;
  letter-spacing: .5px;
}


.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.panel-head .panel-title { margin-bottom: 0; }

.upload-mini {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--primary);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-mini:hover { border-color: var(--primary); background: #eef2ff; }
.upload-mini-icon { font-size: 13px; line-height: 1; }


.upload-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.list-toolbar {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-sub);
}
.image-count {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: #eef2ff;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.list-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  flex-shrink: 0;
}
.list-actions .btn {
  flex-shrink: 0;
  padding: 4px 7px;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.thumbs-hint {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--text-sub);
}

.thumbs {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
  min-height: 0;
  padding-right: 2px;
}
.thumbs-empty {
  grid-column: 1 / -1;
  align-self: center;
  text-align: center;
  color: var(--text-sub);
  font-size: 12px;
  padding: 24px 0;
}
.thumb {
  position: relative;
  width: 100%;
  padding-bottom: 100%; 
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: grab;
  background: #eee;
}
.thumb img {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.thumb .thumb-index {
  position: absolute; top: 2px; left: 3px;
  background: rgba(0,0,0,.5); color: #fff;
  font-size: 10px; padding: 1px 4px; border-radius: 3px;
}
.thumb .thumb-del {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px;
  border: none; border-radius: 50%;
  background: rgba(0,0,0,.55); cursor: pointer;
  padding: 0;
}
.thumb .thumb-del::before,
.thumb .thumb-del::after {
  content: "";
  display: block;
  position: absolute;
  width: 10px; height: 2px;
  background: #fff;
  border-radius: 2px;
  top: 8px;   
  left: 4px;  
}
.thumb .thumb-del::before { transform: rotate(45deg); }
.thumb .thumb-del::after  { transform: rotate(-45deg); }
.thumb .thumb-del:hover { background: var(--danger); }
.thumb.dragging { opacity: .35; }
.thumb.drag-over { outline: 2px solid var(--primary); }


.panel-center { align-items: stretch; }

.panel-title-wrap {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.panel-title-wrap .panel-title { margin-bottom: 0; justify-self: start; }

.btn.btn-shuffle {
  justify-self: end;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--primary);
  background: #eef2ff;
  border: 1px solid rgba(79, 107, 255, 0.35);
  box-shadow: 0 2px 8px rgba(79, 107, 255, 0.18);
  transition: background .15s, border-color .15s, box-shadow .15s, transform .15s;
}
.btn.btn-shuffle:hover {
  background: #e3e9ff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(79, 107, 255, 0.24);
  transform: translateY(-1px);
}
.btn.btn-shuffle:active { transform: translateY(0); }
.btn.btn-shuffle .shuffle-icon { font-size: 14px; }
.preview-zoom {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: center; 
}
.zoom-btn {
  width: 22px; height: 22px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.zoom-btn:hover { border-color: var(--primary); color: var(--primary); }
.zoom-btn.zoom-fit {
  width: auto;
  padding: 0 8px;
  font-size: 11px;
  justify-self: end; 
}
.preview-zoom input[type="range"] {
  width: 140px;
  height: 16px;
  margin: 0;
  align-self: center;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  outline: none;
  cursor: pointer;
}
.preview-zoom input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #e4e8f0;
}
.preview-zoom input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: #e4e8f0;
}
.preview-zoom input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.preview-zoom input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.zoom-val {
  font-size: 11px;
  color: var(--text-sub);
  min-width: 34px;
  text-align: right;
}

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #eef0f5 25%, transparent 25%),
    linear-gradient(-45deg, #eef0f5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef0f5 75%),
    linear-gradient(-45deg, transparent 75%, #eef0f5 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  min-height: 300px;
  overflow: hidden; 
}

.canvas-wrap.can-pan { cursor: grab; }
.canvas-wrap.is-panning { cursor: grabbing; }
#canvas {
  max-width: none;
  max-height: none;
  box-shadow: 0 4px 18px rgba(0,0,0,.18);
  border-radius: 4px;
  background: #fff;
  display: block;
}
.canvas-placeholder {
  position: absolute;
  inset: 0;
  color: var(--text-sub);
  font-size: 13px;
}


.canvas-dropzone {
  position: absolute;
  top: calc(50% - 32px);
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px));
  padding: 28px 20px;
  text-align: center;
  border: 1px dashed #cfd6e4;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(31, 41, 55, .08);
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
.canvas-dropzone:hover,
.canvas-placeholder.drag-over .canvas-dropzone {
  border-color: var(--primary);
  box-shadow: 0 10px 32px rgba(79, 107, 255, .16);
}
.canvas-dropzone-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: #eef2ff;
  color: var(--primary);
  font-size: 30px;
  line-height: 1;
  transition: transform .2s;
}
.canvas-dropzone:hover .canvas-dropzone-icon { transform: scale(1.06); }
.canvas-dropzone-title { display: block; font-size: 15px; font-weight: 600; color: var(--text); }
.canvas-dropzone-hint { display: block; margin-top: 5px; font-size: 11px; color: var(--text-sub); }


.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  
  max-height: 370px;
  overflow-y: auto;
}
.tpl-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 5px 6px;
  text-align: center;
  cursor: pointer;
  font-size: 11px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s, background .15s, color .15s;
  user-select: none;
  line-height: 1.2;
}
.tpl-card:hover { border-color: var(--primary); color: var(--primary); box-shadow: 0 2px 8px rgba(79, 107, 255, .12); }
.tpl-card.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.tpl-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 64px;
  height: 42px;
  margin: 0 auto 5px;
  padding: 4px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-sub);
  line-height: 0;
  transition: background .15s, color .15s;
}
.tpl-icon svg { width: 100%; height: 100%; display: block; }
.tpl-card:hover .tpl-icon { background: #eef2ff; color: var(--primary); }
.tpl-card.active .tpl-icon { background: rgba(255, 255, 255, 0.18); color: #fff; }


.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.settings { display: flex; flex-direction: column; gap: 8px; }
.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.setting-row label {
  width: 72px;
  color: var(--text-sub);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}


.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
  transition: transform .15s ease, color .15s ease;
}
.info-icon svg { width: 100%; height: 100%; display: block; }
.info-icon:hover {
  color: var(--primary-hover);
  transform: scale(1.12);
}
.info-pop {
  position: fixed;
  z-index: 10000;
  max-width: 230px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  opacity: 0;
  transform: translateY(-4px) scale(.98);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.info-pop.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.setting-row input[type="number"],
.setting-row select {
  flex: 1; min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
}
.setting-row input[type="color"] {
  flex: 1; min-width: 0; height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; background: none; padding: 2px;
}
.setting-row input[type="range"] {
  flex: 1;
  height: 16px;
  margin: 0;
  align-self: center;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  outline: none;
  cursor: pointer;
}
.setting-row input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #e4e8f0;
}
.setting-row input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: #e4e8f0;
}
.setting-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
}
.setting-row input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
}
.range-val, #qualityVal {
  width: 34px; text-align: right; font-size: 11px; color: var(--text-sub);
}


.btn {
  border: none; border-radius: 6px;
  padding: 7px 12px; font-size: 12px;
  cursor: pointer; transition: background .15s;
}
.btn-ghost { background: #f0f2f7; color: var(--text); }
.btn-ghost:hover { background: #e4e8f0; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-download {
  margin-top: 14px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
}

.app-footer {
  text-align: center;
  padding: 12px;
  font-size: 11px;
  color: var(--text-sub);
}


.thumbs::-webkit-scrollbar,
.panel-scroll::-webkit-scrollbar { width: 6px; }
.thumbs::-webkit-scrollbar-thumb,
.panel-scroll::-webkit-scrollbar-thumb { background: #c6cdda; border-radius: 3px; }


.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -20px);
  min-width: 220px;
  max-width: 80vw;
  padding: 11px 18px;
  border-radius: 8px;
  background: rgba(31, 41, 55, 0.92);
  color: #fff;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.warn { background: rgba(217, 119, 6, 0.95); }
.toast.error { background: rgba(220, 38, 38, 0.95); }


.thumbs-hint {
  margin: 0 0 8px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-sub);
  background: #f4f6fb;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  line-height: 1.5;
}


.thumb .thumb-edit {
  position: absolute;
  bottom: 3px;
  left: 3px;
  width: 20px; height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s;
  padding: 0;
}
.thumb .thumb-edit:hover { background: var(--primary); }
.thumb:hover .thumb-edit { opacity: 1; }

@media (hover: none) {
  .thumb .thumb-edit { opacity: 1; }
}


.editor-modal {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
}
.editor-modal[hidden] { display: none; }
.editor-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 35, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.editor-box {
  position: relative;
  width: 560px;
  max-width: 94vw;
  max-height: 90vh;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  
  line-height: 22px;
}
.editor-title { font-size: 14px; font-weight: 600; }
.editor-x {
  position: relative;
  width: 22px; height: 22px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.editor-x::before,
.editor-x::after {
  content: "";
  display: block;
  box-sizing: border-box;
  position: absolute;
  width: 12px;
  height: 2px;
  background: var(--text-sub);
  border-radius: 2px;
  top: 10px;   
  left: 5px;   
  transform-origin: center;
}
.editor-x::before { transform: rotate(45deg); }
.editor-x::after  { transform: rotate(-45deg); }
.editor-x:hover { background: #f0f2f7; }
.editor-x:hover::before,
.editor-x:hover::after { background: var(--text); }
.editor-stage {
  position: relative;
  flex: 1;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1b1d24;
  padding: 16px;
  overflow: hidden;
}
.editor-img {
  max-width: 100%;
  max-height: 62vh;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.crop-box {
  position: absolute;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
  cursor: move;
  z-index: 2;
}
.crop-box[hidden] { display: none; }
.crop-handle {
  position: absolute;
  width: 12px; height: 12px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 50%;
  z-index: 3;
}
.crop-handle[data-dir="nw"] { left: 0; top: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
.crop-handle[data-dir="ne"] { right: 0; top: 0; transform: translate(50%, -50%); cursor: nesw-resize; }
.crop-handle[data-dir="sw"] { left: 0; bottom: 0; transform: translate(-50%, 50%); cursor: nesw-resize; }
.crop-handle[data-dir="se"] { right: 0; bottom: 0; transform: translate(50%, 50%); cursor: nwse-resize; }
.editor-tools {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.editor-tools button {
  flex: 1;
  min-width: 90px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  color: var(--text);
}
.editor-tools button:hover { border-color: var(--primary); color: var(--primary); }
.editor-tools button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.editor-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #fafbff;
}


@media (max-width: 360px) {
  .list-toolbar { gap: 4px; }
  .image-count { padding: 2px 6px; font-size: 10px; }
  .list-actions { gap: 3px; }
  .list-actions .btn { padding: 4px 6px; font-size: 10px; }
  .preview-zoom input[type="range"] { width: 100px; }
  .app-header h1 { font-size: 16px; }
  .btn.btn-shuffle { padding: 6px 11px; font-size: 12px; }
}


@media (max-width: 1100px) {
  .app { height: auto; overflow: visible; }
  .app-main { grid-template-columns: 1fr; }
  .panel-center { min-height: 420px; }
  .panel-left .upload-list { flex: 0 0 auto; }
  .panel-left .thumbs { flex: 0 0 auto; max-height: 240px; }

  
  .app-header {
    height: auto;
    min-height: 0;
    align-items: flex-start;
    padding: 10px 16px;
  }
  .app-header .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
  }
  .app-header .subtitle {
    text-align: left;
    font-size: 12px;
    line-height: 1.45;
  }

  
  .panel-center .panel-title-wrap {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px;
  }
  .panel-center .preview-zoom {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    justify-self: auto;
  }
  .btn-shuffle { order: 2; margin-left: auto; }
}



body > header:not(.app-header) {
  height: var(--site-header-height);
  min-height: var(--site-header-height);
}


body > header:not(.app-header) .header-inner {
  align-items: center;
}
body > header:not(.app-header) .lang {
  align-self: center;
  margin: 0;
}
body > header:not(.app-header) .lang-select {
  line-height: 1.2;
}


.app {
  height: calc(100vh - var(--site-header-height));
  height: calc(100dvh - var(--site-header-height));
  min-height: 0;
}

@media (max-width: 1100px) {
  .app {
    height: auto;
    min-height: 0;
  }
}
