:root {
  --bg: #0a0e16;
  --bg-elevated: #111827;
  --bg-panel: #141b2b;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text: #eef2ff;
  --text-muted: #8b97b3;
  --primary: #5b8cff;
  --primary-hover: #7aa3ff;
  --primary-soft: rgba(91, 140, 255, 0.14);
  --danger: #ff6b7a;
  --success: #3ecf8e;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  --font: "Noto Sans SC", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --panel-w: 372px;
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  font-family: var(--font);
  background:
    radial-gradient(1100px 560px at 8% -12%, rgba(91, 140, 255, 0.2), transparent 55%),
    radial-gradient(800px 420px at 100% 0%, rgba(62, 207, 142, 0.08), transparent 48%),
    radial-gradient(600px 400px at 50% 100%, rgba(91, 140, 255, 0.05), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}

/* Custom scrollbar */
.panel-left,
.file-list,
.preview-stage {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.panel-left::-webkit-scrollbar,
.file-list::-webkit-scrollbar,
.preview-stage::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.panel-left::-webkit-scrollbar-thumb,
.file-list::-webkit-scrollbar-thumb,
.preview-stage::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.drop-zone:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.hidden {
  display: none !important;
}

/* —— Layout —— */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px 18px 10px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  animation: fadeSlideIn 0.45s var(--ease) both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #5b8cff 0%, #4a7af0 45%, #3ecf8e 120%);
  color: #0a0e16;
  box-shadow: 0 8px 28px rgba(91, 140, 255, 0.38);
  flex-shrink: 0;
}

.logo svg {
  width: 22px;
  height: 22px;
}

.header h1 {
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.2;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 3px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.main {
  flex: 1;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  gap: 16px;
  min-height: 0;
  animation: fadeSlideIn 0.5s var(--ease) 0.05s both;
}

/* —— Left panel —— */
.panel-left {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 120px), var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  overflow-y: auto;
  max-height: calc(100dvh - 120px);
  box-shadow: var(--shadow);
}

.section {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head h2 {
  margin-bottom: 0;
}

.section h2 {
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary-hover);
  border: 1px solid rgba(91, 140, 255, 0.25);
  font-variant-numeric: tabular-nums;
}

/* —— Drop zone —— */
.drop-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 22px 14px;
  text-align: center;
  background: rgba(255, 255, 255, 0.015);
  transition: border-color 0.2s, background 0.2s, transform 0.2s var(--ease), box-shadow 0.2s;
  cursor: pointer;
  user-select: none;
}

.drop-zone:hover {
  border-color: rgba(91, 140, 255, 0.45);
  background: var(--primary-soft);
}

.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.12);
  transform: scale(1.01);
}

.drop-zone-sm {
  padding: 16px 12px;
}

.drop-visual {
  margin-bottom: 10px;
  color: var(--primary-hover);
}

.drop-svg {
  width: 48px;
  height: 48px;
}

.drop-title {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.drop-hint {
  color: var(--text-muted);
  font-size: 0.76rem;
}

/* —— File list —— */
.file-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 168px;
  overflow-y: auto;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s var(--ease);
  animation: fadeSlideIn 0.3s var(--ease) both;
}

.file-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.file-item.active {
  border-color: rgba(91, 140, 255, 0.45);
  background: var(--primary-soft);
}

.file-item img {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  flex-shrink: 0;
}

.file-meta {
  flex: 1;
  min-width: 0;
}

.file-meta .name {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta .size {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.file-item .remove {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.file-item .remove:hover {
  background: rgba(255, 107, 122, 0.15);
  color: var(--danger);
}

/* —— Tabs —— */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.tab {
  padding: 9px 8px;
  border-radius: 9px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.86rem;
  transition: all 0.18s var(--ease);
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.28), rgba(91, 140, 255, 0.12));
  color: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* —— Fields —— */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field > span {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field > span em {
  font-style: normal;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 7px;
  border-radius: 6px;
}

.field-hint {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--primary-hover);
  opacity: 0.85;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.field input[type="text"],
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.28);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input[type="text"]:hover,
.field select:hover {
  border-color: var(--border-strong);
}

.field input[type="text"]:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.15);
}

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b97b3' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Range sliders */
.field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), rgba(91, 140, 255, 0.35));
  background-color: rgba(255, 255, 255, 0.08);
  outline: none;
  cursor: pointer;
}

.field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s var(--ease);
}

.field input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

.field input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.field input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.field-color {
  flex: 0 0 72px;
}

.field-color input[type="color"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 3px;
  cursor: pointer;
}

.field-color input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.field-color input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

.row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 12px;
  align-items: end;
}

/* Color presets */
.color-presets {
  display: flex;
  gap: 8px;
  margin: -4px 0 12px;
  flex-wrap: wrap;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  transition: transform 0.15s var(--ease), box-shadow 0.15s;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch.active {
  box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 4px var(--primary);
}

/* Chips / checkboxes */
.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.84rem;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.chip:hover {
  border-color: var(--border-strong);
}

.chip:has(input:checked) {
  background: var(--primary-soft);
  border-color: rgba(91, 140, 255, 0.4);
  color: var(--primary-hover);
}

.chip input {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  margin: 0;
}

.chip-block {
  width: 100%;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
}

/* Position grid */
.position-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.position-grid button {
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  position: relative;
  transition: all 0.15s var(--ease);
}

.position-grid button::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.45;
  display: block;
  margin: 0 auto;
  transition: all 0.15s;
}

.position-grid button:hover {
  background: rgba(255, 255, 255, 0.05);
}

.position-grid button:hover::after {
  opacity: 0.85;
  background: var(--text);
}

.position-grid button.active {
  background: var(--primary-soft);
  border-color: rgba(91, 140, 255, 0.4);
}

.position-grid button.active::after {
  width: 10px;
  height: 10px;
  opacity: 1;
  background: var(--primary-hover);
  box-shadow: 0 0 8px rgba(91, 140, 255, 0.6);
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  transition: all 0.18s var(--ease);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, #6b96ff, #4a7af0);
  color: white;
  box-shadow: 0 6px 20px rgba(91, 140, 255, 0.32);
}

.btn-primary:not(:disabled):hover {
  background: linear-gradient(135deg, #7aa3ff, #5b8cff);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(91, 140, 255, 0.42);
}

.btn-primary:not(:disabled):active {
  transform: translateY(0);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-ghost:not(:disabled):hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.btn-block {
  width: 100%;
  margin-top: 4px;
  padding: 12px 16px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

.btn-icon:not(:disabled):hover {
  background: var(--primary-soft);
  border-color: rgba(91, 140, 255, 0.4);
  color: var(--primary-hover);
}

/* —— Preview —— */
.preview-area {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 120px);
  max-height: calc(100dvh - 120px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}

.preview-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#previewIndex {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.preview-name {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  text-align: center;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#zoomLabel {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 40px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.preview-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 20px;
  position: relative;
  overflow: auto;
  background-color: #0c101a;
  background-image:
    linear-gradient(45deg, #161c2a 25%, transparent 25%),
    linear-gradient(-45deg, #161c2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #161c2a 75%),
    linear-gradient(-45deg, transparent 75%, #161c2a 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.canvas-wrap {
  display: grid;
  place-items: center;
  transition: transform 0.2s var(--ease);
  transform-origin: center center;
}

#previewCanvas {
  max-width: 100%;
  max-height: calc(100dvh - 200px);
  border-radius: 6px;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.55);
  background: #fff;
  image-rendering: auto;
  transition: opacity 0.15s;
  touch-action: none;
}

#previewCanvas.draggable-wm {
  cursor: grab;
}

#previewCanvas.dragging-wm {
  cursor: grabbing;
}

#previewCanvas.rendering {
  opacity: 0.7;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  max-width: 340px;
  padding: 20px;
  animation: fadeSlideIn 0.5s var(--ease) both;
}

.empty-visual {
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
  color: var(--primary-hover);
  opacity: 0.7;
}

.empty-visual svg {
  width: 100%;
  height: 100%;
}

.empty-title {
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 6px;
}

.muted {
  font-size: 0.8rem;
  opacity: 0.75;
  line-height: 1.55;
}

.wm-image-preview {
  margin-bottom: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  text-align: center;
  position: relative;
  animation: fadeSlideIn 0.3s var(--ease) both;
}

.wm-image-preview img {
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}

.wm-image-preview .clear-wm {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--text-muted);
  font-size: 0.9rem;
  display: grid;
  place-items: center;
}

.wm-image-preview .clear-wm:hover {
  color: var(--danger);
}

/* Progress */
.progress-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  z-index: 5;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.2s var(--ease);
}

/* —— Footer —— */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 0 2px;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.footer-sep {
  opacity: 0.4;
}

.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* —— Toast —— */
.toast-host {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  align-items: center;
}

.toast {
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(20, 27, 43, 0.92);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  animation: toastIn 0.35s var(--ease) both;
  max-width: min(90vw, 360px);
  text-align: center;
}

.toast.success {
  border-color: rgba(62, 207, 142, 0.35);
}

.toast.error {
  border-color: rgba(255, 107, 122, 0.4);
}

.toast.out {
  animation: toastOut 0.3s var(--ease) both;
}

/* —— Animations —— */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
}

/* —— Responsive —— */
@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
  }

  .panel-left {
    max-height: none;
    order: 2;
  }

  .preview-area {
    order: 1;
    min-height: 48vh;
    max-height: 52vh;
  }

  #previewCanvas {
    max-height: 40vh;
  }

  .header {
    flex-wrap: wrap;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1;
  }

  .preview-toolbar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .preview-name {
    order: 3;
    width: 100%;
    text-align: center;
    max-width: none;
  }

  .kbd-hint {
    display: none;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 12px 10px 8px;
  }

  .logo {
    width: 40px;
    height: 40px;
  }

  .header h1 {
    font-size: 1.1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
