:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --paper: #f8fafc;
  --panel: rgba(255, 255, 255, 0.95);
  --input-bg: #ffffff;
  --accent: #4f46e5;
  --accent-bright: #6366f1;
  --accent-soft: #e0e7ff;
  --gradient: linear-gradient(135deg, #4f46e5 0%, #a855f7 100%);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  background: #f8fafc;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  border-color: transparent;
  background: var(--gradient);
  color: white;
  box-shadow: 0 10px 24px rgba(127, 0, 185, 0.24);
}

.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #4338ca 0%, #9333ea 100%);
  box-shadow: 0 12px 28px rgba(79, 70, 229, 0.3);
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  min-height: calc(100vh - 48px);
}

.panel,
.editor {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 12px;
}

/* Accordion Styles */
.accordion-trigger {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0 0 4px 0;
  min-height: auto;
  color: var(--accent);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.2s ease;
}

.accordion-trigger:hover {
  background: transparent !important;
  box-shadow: none !important;
  transform: none !important;
  color: var(--accent-bright);
}

.accordion-trigger .caret {
  transition: transform 0.2s ease;
}

.accordion-trigger[aria-expanded="false"] .caret {
  transform: rotate(-90deg);
}

.accordion-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.accordion-trigger[aria-expanded="false"] + .accordion-content {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

@keyframes breathe {
  0%, 100% { border-color: #cbd5e1; box-shadow: 0 0 0 rgba(79, 70, 229, 0); }
  50% { border-color: var(--accent-bright); box-shadow: 0 0 10px rgba(79, 70, 229, 0.15); }
}

.drop-zone {
  display: grid;
  min-height: 170px;
  place-items: center;
  gap: 6px;
  border: 1.5px dashed #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  animation: breathe 4s ease-in-out infinite;
}

.drop-zone:hover {
  animation: none;
  border-color: var(--accent);
  background: white;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.02);
  transition: all 0.2s ease;
}

.drop-zone input {
  display: none;
}

.upload-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--gradient);
  color: white;
  font-size: 28px;
  line-height: 1;
}

small {
  color: var(--muted);
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

input[type="number"],
select,
input[type="color"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 0 12px;
  transition: all 0.2s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="color"] {
  padding: 4px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field-grid,
.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.size-grid {
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
}

.aspect-lock {
  width: 32px;
  height: 42px;
  min-height: 42px;
  background: transparent;
  border: none;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 0;
}

.aspect-lock:hover {
  background: rgba(0,0,0,0.05) !important;
  box-shadow: none !important;
  transform: none !important;
  color: var(--ink);
}

.aspect-lock[aria-pressed="true"] {
  color: var(--accent);
}

.aspect-lock .lock-icon { display: none; }
.aspect-lock[aria-pressed="true"] .lock-icon { display: block; }
.aspect-lock .unlock-icon { display: block; }
.aspect-lock[aria-pressed="true"] .unlock-icon { display: none; }

.editor {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto auto;
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.toolbar div {
  display: grid;
  gap: 2px;
}

.toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.toolbar-actions button {
  padding: 0 14px;
}

.toolbar-actions button:not(:disabled) {
  border-color: transparent;
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 8px 20px rgba(127, 0, 185, 0.18);
}

.preview-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
  background:
    linear-gradient(45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2f7 75%),
    linear-gradient(-45deg, transparent 75%, #eef2f7 75%);
  background-color: #fff;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  overflow: hidden;
  border-radius: 8px;
}

canvas {
  max-width: min(92%, 900px);
  max-height: 68vh;
  border: 1px solid #cfd7e6;
  border-radius: 8px;
  background: white;
  box-shadow: 0 12px 34px rgba(22, 25, 31, 0.18);
  cursor: grab;
  user-select: none;
}

canvas.dragging {
  cursor: grabbing;
}

.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 40px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.08);
  text-align: center;
  pointer-events: none;
  animation: float-card 4s ease-in-out infinite;
  transition: border-color 0.3s ease, background 0.3s ease;
}

@keyframes float-card {
  0% { transform: translate(-50%, -50%) translateY(0px); }
  50% { transform: translate(-50%, -50%) translateY(-8px); box-shadow: 0 22px 45px rgba(0, 0, 0, 0.12); }
  100% { transform: translate(-50%, -50%) translateY(0px); }
}

.animated-icon {
  margin-bottom: 8px;
}

.animated-icon .arrow {
  animation: bounce-arrow 2s ease-in-out infinite;
  transform-origin: center;
}

@keyframes bounce-arrow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.empty-state[hidden] {
  display: none !important;
}

.empty-state strong {
  font-size: 22px;
  color: var(--ink);
}

.empty-state span {
  color: var(--muted);
  font-size: 14px;
  max-width: 250px;
}

.preview-wrap.dragging-over {
  border: 2px dashed var(--accent);
  background: var(--accent-soft);
}

.preview-wrap.dragging-over .empty-state {
  display: flex !important;
  border-color: var(--accent);
  background: white;
  animation: none;
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 20px 45px rgba(79, 70, 229, 0.2);
}

.preview-wrap.dragging-over canvas {
  opacity: 0.2;
}

.focus-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 14px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-row button {
  min-height: 36px;
  padding: 0 12px;
}

.preset-row button:hover:not(:disabled) {
  border-color: transparent;
  background: var(--gradient);
  color: #fff;
}

.image-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 180px;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  overflow-x: auto;
  cursor: grab;
  user-select: none;
}

.image-list.dragging {
  cursor: grabbing;
}

.thumb {
  position: relative;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  padding: 8px;
  text-align: left;
}

.thumb.active {
  border-color: var(--accent-bright);
  box-shadow: inset 0 0 0 1px var(--accent-bright), 0 8px 18px rgba(127, 0, 185, 0.12);
}

.thumb img {
  width: 54px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
}

.thumb span {
  display: block;
  overflow: hidden;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
}

.thumb-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  min-height: 20px;
  border-radius: 50%;
  background: #ff4757;
  color: white;
  border: none;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 4px rgba(255, 71, 87, 0.4);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.2s, transform 0.2s, background 0.2s;
  z-index: 10;
}

.thumb:hover .thumb-delete {
  opacity: 1;
  transform: scale(1);
}

.thumb-delete:hover {
  background: #ff6b81;
}

button.processing {
  cursor: wait;
  opacity: 0.7;
  pointer-events: none;
}

@media (max-width: 920px) {
  .app-shell {
    padding: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .focus-controls {
    grid-template-columns: 1fr;
  }
}

.sortable-ghost {
  opacity: 0.4;
  background: var(--paper);
}

.sortable-drag {
  opacity: 1 !important;
  box-shadow: 0 15px 30px rgba(0,0,0,0.15) !important;
  cursor: grabbing !important;
  z-index: 100;
  transform: scale(1.05);
}

/* Toast Notification Styles */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  min-width: 300px;
  max-width: 450px;
  padding: 16px 20px;
  border-radius: 12px;
  background: #1e293b;
  backdrop-filter: blur(10px);
  color: #f8fafc;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0,0,0,0.05);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
  pointer-events: auto;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-success {
  border-left: 6px solid #10b981;
}

.toast-error {
  border-left: 6px solid #ef4444;
}
opacity: 0.2;
}

.focus-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 14px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-row button {
  min-height: 36px;
  padding: 0 12px;
}

.preset-row button:hover:not(:disabled) {
  border-color: transparent;
  background: var(--gradient);
  color: #fff;
}

.image-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 180px;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  overflow-x: auto;
  cursor: grab;
  user-select: none;
}

.image-list.dragging {
  cursor: grabbing;
}

.thumb {
  position: relative;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  padding: 8px;
  text-align: left;
}

.thumb.active {
  border-color: var(--accent-bright);
  box-shadow: inset 0 0 0 1px var(--accent-bright), 0 8px 18px rgba(127, 0, 185, 0.12);
}

.thumb img {
  width: 54px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
}

.thumb span {
  display: block;
  overflow: hidden;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
}

.thumb-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  min-height: 20px;
  border-radius: 50%;
  background: #ff4757;
  color: white;
  border: none;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 4px rgba(255, 71, 87, 0.4);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.2s, transform 0.2s, background 0.2s;
  z-index: 10;
}

.thumb:hover .thumb-delete {
  opacity: 1;
  transform: scale(1);
}

.thumb-delete:hover {
  background: #ff6b81;
}

button.processing {
  cursor: wait;
  opacity: 0.7;
  pointer-events: none;
}

@media (max-width: 920px) {
  .app-shell {
    padding: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .focus-controls {
    grid-template-columns: 1fr;
  }
}

.sortable-ghost {
  opacity: 0.4;
  background: var(--paper);
}

.sortable-drag {
  opacity: 1 !important;
  box-shadow: 0 15px 30px rgba(0,0,0,0.15) !important;
  cursor: grabbing !important;
  z-index: 100;
  transform: scale(1.05);
}

/* Toast Notification Styles */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  min-width: 300px;
  max-width: 450px;
  padding: 16px 20px;
  border-radius: 12px;
  background: #1e293b;
  backdrop-filter: blur(10px);
  color: #f8fafc;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0,0,0,0.05);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
  pointer-events: auto;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-success {
  border-left: 6px solid #10b981;
}

.toast-error {
  border-left: 6px solid #ef4444;
}

.toast-warning {
  border-left: 6px solid #f59e0b;
}

.toast-icon {
  font-size: 20px;
}

.preset-row button {
  background: white;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.preset-row button:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.15);
}

.preset-row button:active {
  transform: translateY(0) scale(0.95);
}

#autoCropBtn {
  background: linear-gradient(135deg, #f0ebff, #ffffff);
  border: 1px solid var(--accent);
  color: var(--accent);
  position: relative;
  overflow: hidden;
}

#autoCropBtn::before {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.8), transparent);
  animation: shine 3s infinite;
}

@keyframes shine {
  0% { left: -100%; }
  20% { left: 200%; }
  100% { left: 200%; }
}

.dl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.dl-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.dl-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.15);
}

.dl-btn:not(:disabled):active {
  transform: translateY(1px);
}

.dl-icon {
  transition: transform 0.2s ease;
}

.dl-btn:not(:disabled):hover .dl-icon {
  transform: translateY(3px);
  color: var(--accent);
}

#downloadAllBtn {
  background: var(--gradient);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

#downloadAllBtn:not(:disabled):hover {
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
  filter: brightness(1.1);
}

#downloadAllBtn:not(:disabled):hover .dl-icon {
  color: white;
  animation: bounce-arrow 1s infinite;
}