/* ===================================================
   贴贴 TieTie — Design System
   Color: White + Vibrant Lavender Purple + Peach
   =================================================== */

/* --- Design Tokens --- */
:root {
  /* Purple spectrum */
  --purple-50: #F5F3FF;
  --purple-100: #EDE9FE;
  --purple-200: #DDD6FE;
  --purple-300: #C4B5FD;
  --purple-400: #A78BFA;
  --purple-500: #7C5CFF;
  /* ★ Primary — vibrant, distinctive */
  --purple-600: #6A4FE8;
  /* Hover */
  --purple-700: #5B43CC;
  /* Active / pressed */

  /* Peach accent */
  --peach-100: #FFE8E0;
  --peach-200: #FFCDB8;
  --peach-400: #FFAB91;

  /* Neutrals */
  --white: #FFFFFF;
  --gray-50: #FAFAFA;
  --gray-100: #F4F4F5;
  --gray-200: #E4E4E7;
  --gray-300: #D4D4D8;
  --gray-400: #A1A1AA;
  --gray-500: #71717A;
  --gray-600: #52525B;
  --gray-800: #27272A;
  --gray-900: #18181B;

  /* Semantic */
  --bg: var(--white);
  --bg-subtle: #FAFAFC;
  --text: var(--gray-900);
  --text-sub: var(--gray-500);
  --text-hint: var(--gray-400);
  --border: var(--gray-200);
  --border-focus: var(--purple-300);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.09);
  --shadow-purple: 0 4px 20px rgba(124, 92, 255, 0.18);

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 9999px;

  /* Fonts */
  --font: 'Outfit', 'PingFang SC', 'Noto Sans SC', system-ui, sans-serif;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.2s;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* --- Decorative background --- */
body::before {
  content: '';
  position: fixed;
  top: -120px;
  right: -80px;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--purple-100) 0%, transparent 70%);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: -100px;
  left: -60px;
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, var(--peach-100) 0%, transparent 70%);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

/* --- Header --- */
.header {
  position: relative;
  z-index: 1;
  padding: 20px 24px 12px;
  animation: fadeSlideIn 0.5s var(--ease) both;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-paw {
  font-size: 22px;
  animation: gentleBounce 2s ease-in-out infinite;
}

.brand-name {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  color: var(--purple-500);
  letter-spacing: -0.5px;
}

.brand-en {
  font-weight: 500;
  font-size: 18px;
  color: var(--purple-400);
  margin-left: 2px;
}

.slogan {
  margin: 0;
  font-size: 13px;
  color: var(--text-hint);
  letter-spacing: 0.3px;
}

.header-links {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.header-links-weak .header-nav-link {
  opacity: 0.8;
  font-weight: 500;
}

.header-nav-link {
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--purple-500);
  border: 1px solid var(--purple-200);
  border-radius: var(--r-full);
  padding: 6px 12px;
  transition: all var(--duration) var(--ease);
}

.header-nav-link:hover {
  background: var(--purple-50);
  border-color: var(--purple-300);
  opacity: 1;
}

/* --- App Layout --- */
.app-layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 24px 40px;
  min-height: calc(100vh - 140px);
}

/* --- Control Panel (left) --- */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeSlideIn 0.5s var(--ease) 0.1s both;
}

.ctrl-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--duration) var(--ease);
}

.ctrl-section:hover {
  box-shadow: var(--shadow-sm);
}

.ctrl-title {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--r-full);
  background: var(--purple-500);
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* --- Upload Zone --- */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--r-md);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  background: var(--gray-50);
  outline: none;
}

.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--purple-400);
  background: var(--purple-50);
}

.upload-zone.drag-over {
  border-color: var(--purple-500);
  background: var(--purple-50);
  box-shadow: var(--shadow-purple);
}

.upload-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 8px;
  color: var(--gray-400);
  transition: color var(--duration) var(--ease);
}

.upload-zone:hover .upload-icon {
  color: var(--purple-400);
}

.upload-text {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sub);
}

.upload-subtext {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-hint);
}

.upload-link {
  color: var(--purple-500);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.upload-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-hint);
  opacity: 0.8;
}

/* Upload Preview */
.upload-preview-box[hidden] {
  display: none !important;
}

.upload-preview-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.upload-thumb {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--r-md);
  border: 2px solid var(--purple-200);
  box-shadow: var(--shadow-sm);
}

.upload-meta {
  text-align: center;
  line-height: 1.5;
}

.upload-filename {
  display: block;
  font-size: 13px;
  color: var(--text-sub);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-check {
  display: block;
  font-size: 12px;
  color: #22c55e;
  font-weight: 500;
}

.btn-remove {
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-sm);
  padding: 4px 14px;
  font-size: 12px;
  color: var(--text-sub);
  transition: all var(--duration) var(--ease);
}

.btn-remove:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: #fef2f2;
}

/* --- Template Strip (horizontal scroll) --- */
.template-strip-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.template-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-behavior: smooth;
  padding: 4px 2px;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
}

.template-strip::-webkit-scrollbar {
  display: none;
}

.strip-arrow {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-full);
  background: var(--white);
  font-size: 18px;
  line-height: 1;
  color: var(--text-hint);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration) var(--ease);
  padding: 0;
}

.strip-arrow:hover {
  border-color: var(--purple-300);
  color: var(--purple-500);
  background: var(--purple-50);
}

/* Strip thumbnails */
.strip-thumb {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border: 2px solid var(--gray-200);
  border-radius: var(--r-sm);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  padding: 2px;
  background: var(--white);
}

.strip-thumb:hover {
  border-color: var(--purple-300);
  transform: scale(1.06);
  box-shadow: var(--shadow-sm);
}

.strip-thumb.selected {
  border-color: var(--purple-500);
  box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.18);
}

.strip-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

/* Selected template info row */
.template-selected-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 8px;
}

.selected-tpl-name {
  font-size: 13px;
  color: var(--text-sub);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* View all button */
.btn-view-all {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--purple-500);
  font-size: 12px;
  font-weight: 500;
  padding: 2px 4px;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
}

.btn-view-all:hover {
  color: var(--purple-600);
  text-decoration: underline;
}

/* Dice button */
.btn-dice {
  flex-shrink: 0;
  background: var(--purple-50);
  border: 1px solid var(--purple-200);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  font-size: 16px;
  line-height: 1;
  transition: all var(--duration) var(--ease);
}

.btn-dice:hover {
  background: var(--purple-100);
  transform: rotate(15deg) scale(1.1);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.2s var(--ease);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: min(680px, 92vw);
  max-height: 80vh;
  background: var(--white);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.25s var(--ease);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-full);
  background: var(--white);
  font-size: 13px;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration) var(--ease);
}

.modal-close:hover {
  border-color: var(--gray-400);
  color: var(--text);
  background: var(--gray-50);
}

.modal-body {
  padding: 20px 24px 24px;
  overflow-y: auto;
}

.modal-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

/* Modal template card */
.modal-tpl-card {
  position: relative;
  border: 2px solid var(--gray-200);
  border-radius: var(--r-md);
  padding: 6px;
  cursor: pointer;
  background: var(--white);
  transition: all var(--duration) var(--ease);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  appearance: none;
  font: inherit;
  color: inherit;
}

.modal-tpl-card:hover {
  border-color: var(--purple-300);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

.modal-tpl-card.selected {
  border-color: var(--purple-500);
  box-shadow: var(--shadow-purple);
}

.modal-tpl-card.selected::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: var(--r-full);
  background: var(--purple-500);
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: popIn 0.2s var(--ease);
}

.modal-tpl-card img {
  border-radius: var(--r-sm);
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--gray-100);
}

.modal-tpl-card-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
}

.modal-tpl-card.selected .modal-tpl-card-name {
  color: var(--purple-500);
  font-weight: 600;
}

.editor-modal-card {
  width: min(860px, 94vw);
  max-height: 88vh;
}

.editor-meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-sub);
}

.editor-body {
  display: grid;
  gap: 12px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.editor-brush-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-sub);
}

.editor-brush-label input[type="range"] {
  width: 180px;
}

.editor-brush-label span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  min-width: 40px;
}

.editor-dirty {
  margin: 0;
  font-size: 12px;
  color: var(--text-hint);
}

.editor-dirty.dirty {
  color: var(--purple-600);
  font-weight: 600;
}

.editor-canvas-wrap {
  border: 1px solid var(--gray-200);
  border-radius: var(--r-md);
  overflow: auto;
  padding: 12px;
  max-height: 62vh;
  touch-action: none;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #f2f4fb 25%, transparent 25%),
    linear-gradient(-45deg, #f2f4fb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f2f4fb 75%),
    linear-gradient(-45deg, transparent 75%, #f2f4fb 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.editor-canvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-xs);
  touch-action: none;
  cursor: crosshair;
}

.editor-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* --- Generate Button --- */
.btn-generate {
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: var(--r-md);
  background: var(--purple-500);
  color: var(--white);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  box-shadow: var(--shadow-purple);
  transition: all var(--duration) var(--ease);
}

.btn-generate:hover:not(:disabled) {
  background: var(--purple-600);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(124, 92, 255, 0.25);
}

.btn-generate:active:not(:disabled) {
  transform: translateY(0);
  background: var(--purple-700);
}

.btn-generate:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.generate-timing {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-hint);
  text-align: center;
}

.status-msg {
  margin: 6px 0 0;
  font-size: 13px;
  text-align: center;
  min-height: 20px;
  color: var(--text-sub);
}

.status-msg.error {
  color: #ef4444;
}

/* --- Preview Panel (right) --- */
.preview-panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 32px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  animation: fadeSlideIn 0.5s var(--ease) 0.2s both;
  overflow: hidden;
}

/* Empty state */
.state-empty {
  text-align: center;
  padding: 40px 20px;
}

.empty-deco {
  font-size: 48px;
  color: var(--purple-300);
  margin-bottom: 16px;
  animation: gentleSpin 8s linear infinite;
}

.empty-text {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-sub);
}

.empty-sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-hint);
}

/* Loading state */
.state-loading {
  text-align: center;
  padding: 40px 20px;
  width: 100%;
  max-width: 360px;
}

.loader {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
}

.loader-ring {
  position: absolute;
  inset: 0;
  border: 3px solid var(--purple-100);
  border-top-color: var(--purple-500);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loader-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--purple-500);
}

.loading-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--gray-100);
  border-radius: var(--r-full);
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--purple-500);
  border-radius: var(--r-full);
  transition: width 0.5s var(--ease);
}

.loading-tip {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-sub);
  min-height: 20px;
  animation: fadeInUp 0.4s var(--ease);
}

.loading-timer {
  margin: 0;
  font-size: 12px;
  color: var(--text-hint);
}

/* Result state */
.state-result {
  width: 100%;
  animation: fadeInUp 0.4s var(--ease);
}

.result-header {
  text-align: center;
  margin-bottom: 16px;
}

.result-title {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
}

.result-meta {
  margin: 0;
  font-size: 13px;
  color: var(--text-sub);
}

/* Tabs */
.result-tabs {
  display: flex;
  gap: 4px;
  background: var(--gray-100);
  border-radius: var(--r-sm);
  padding: 3px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  transition: all var(--duration) var(--ease);
}

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

.tab-btn.active {
  background: var(--white);
  color: var(--purple-500);
  box-shadow: var(--shadow-xs);
  font-weight: 600;
}

/* Tab panels */
.tab-panel[hidden] {
  display: none;
}

/* Grid slices */
.slices-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.slice-item {
  position: relative;
  border: 2px solid var(--gray-200);
  border-radius: var(--r-sm);
  padding: 3px;
  cursor: pointer;
  background: var(--white);
  transition: all var(--duration) var(--ease);
  appearance: none;
  font: inherit;
  color: inherit;
  text-align: center;
}

.slice-edit-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  border: 1px solid var(--purple-300);
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.95);
  color: var(--purple-600);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(-2px);
  transition: all var(--duration) var(--ease);
  z-index: 2;
  padding: 0;
}

.slice-video-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 1px solid #9bc6ff;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.96);
  color: #2f74d0;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(-2px);
  transition: all var(--duration) var(--ease);
  z-index: 2;
  padding: 0;
}

.slice-gif-btn {
  position: absolute;
  top: 36px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 1px solid #8ecf9d;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.96);
  color: #2f9a4a;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(-2px);
  transition: all var(--duration) var(--ease);
  z-index: 2;
  padding: 0;
}

.slice-item:hover .slice-edit-btn,
.slice-item:focus-within .slice-edit-btn,
.slice-item:hover .slice-video-btn,
.slice-item:focus-within .slice-video-btn,
.slice-item:hover .slice-gif-btn,
.slice-item:focus-within .slice-gif-btn,
.slice-edit-btn:focus-visible,
.slice-video-btn:focus-visible,
.slice-gif-btn:focus-visible {
  opacity: 1;
  transform: translateY(0);
}

.slice-edit-btn:hover {
  background: var(--purple-50);
  border-color: var(--purple-400);
}

.slice-video-btn:hover:not(:disabled) {
  background: #edf5ff;
  border-color: #6fa9f7;
}

.slice-video-btn:disabled {
  opacity: 1;
  cursor: progress;
}

.slice-gif-btn:hover:not(:disabled) {
  background: #e9f8ee;
  border-color: #70c786;
}

.slice-gif-btn:disabled {
  opacity: 1;
  cursor: progress;
}

.slice-item:hover {
  border-color: var(--purple-300);
  transform: scale(1.04);
  box-shadow: var(--shadow-sm);
  z-index: 1;
}

.slice-item.selected {
  border-color: var(--purple-500);
  box-shadow: var(--shadow-purple);
}

.slice-item.processing {
  border-style: dashed;
}

.slice-item.video-processing {
  border-color: #75a9ea;
}

.slice-item.gif-processing {
  border-color: #7bc58c;
}

.slice-item.selected::after {
  content: attr(data-index);
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--purple-500);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: popIn 0.2s var(--ease);
}

.slice-media-wrap {
  position: relative;
}

.slice-media-img,
.slice-media-video {
  aspect-ratio: 1;
  border-radius: 5px;
  object-fit: cover;
  width: 100%;
  display: block;
}

.slice-media-img {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #f2f4fb 25%, transparent 25%),
    linear-gradient(-45deg, #f2f4fb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f2f4fb 75%),
    linear-gradient(-45deg, transparent 75%, #f2f4fb 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.slice-media-video {
  background: #000;
}

.slice-media-img[hidden],
.slice-media-video[hidden] {
  display: none !important;
}

.slice-video-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  max-width: calc(100% - 12px);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  line-height: 1.3;
  font-weight: 600;
  color: #fff;
  background: rgba(38, 126, 230, 0.9);
  z-index: 2;
}

.slice-video-badge.generating {
  background: rgba(33, 104, 201, 0.88);
}

.slice-video-badge.error {
  background: rgba(201, 65, 85, 0.9);
}

.slice-gif-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  max-width: calc(100% - 12px);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  line-height: 1.3;
  font-weight: 600;
  color: #fff;
  background: rgba(46, 153, 75, 0.9);
  z-index: 2;
}

.slice-gif-badge.generating {
  background: rgba(50, 133, 71, 0.9);
}

.slice-gif-badge.error {
  background: rgba(201, 65, 85, 0.9);
}

.slice-item:focus-visible {
  outline: 2px solid var(--purple-500);
  outline-offset: 2px;
}

/* Full result image */
.result-full-img {
  max-width: 480px;
  margin: 0 auto;
  border-radius: var(--r-md);
  border: 1px solid var(--gray-200);
}

/* Result actions */
.result-actions {
  margin-top: 16px;
  text-align: center;
}

.cutout-controls {
  margin: 0 0 10px;
}

.cutout-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-sub);
  user-select: none;
}

.cutout-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--purple-500);
}

.cutout-note {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-hint);
}

.video-controls {
  margin: 0 0 12px;
}

.video-model-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-sub);
}

.video-model-label select {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  background: var(--white);
}

.video-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-hint);
}

.select-hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-sub);
}

.action-bar {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.advanced-wrap {
  margin-top: 14px;
}

.advanced-toggle {
  border: none;
  background: transparent;
  color: var(--text-hint);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 2px 6px;
}

.advanced-toggle:hover {
  color: var(--purple-500);
}

.advanced-panel {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-md);
  background: var(--gray-50);
}

.advanced-actions {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.btn-primary {
  padding: 10px 24px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--purple-500);
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-purple);
  transition: all var(--duration) var(--ease);
}

.btn-primary:hover:not(:disabled) {
  background: var(--purple-600);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-outline {
  padding: 10px 24px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--r-sm);
  background: var(--white);
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--duration) var(--ease);
}

.btn-outline:hover {
  border-color: var(--purple-300);
  color: var(--purple-500);
  background: var(--purple-50);
}

.btn-outline:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --- Footer --- */
.footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--text-hint);
}

/* --- Animations --- */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes gentleSpin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes gentleBounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3px);
  }
}

@keyframes popIn {
  from {
    transform: scale(0);
  }

  to {
    transform: scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --- Responsive --- */
@media (max-width: 860px) {
  .app-layout {
    grid-template-columns: 1fr;
    padding: 8px 16px 32px;
  }

  .preview-panel {
    min-height: 400px;
  }

  .slices-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .header-inner {
    flex-direction: column;
    gap: 4px;
  }

  .header-links {
    margin-left: 0;
  }

  .editor-toolbar {
    align-items: flex-start;
  }

  .editor-brush-label input[type="range"] {
    width: 140px;
  }

  .editor-actions {
    justify-content: center;
  }
}

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

  .result-full-img {
    max-width: 100%;
  }
}
