/* ========================================
   拼豆小工坊 - 可爱像素风格 UI
   ======================================== */

/* CSS 变量 */
:root {
  /* 主色 - 柔和粉色系 */
  --primary-50: #FFF5F7;
  --primary-100: #FFE4EC;
  --primary-200: #FECDD6;
  --primary-300: #FDA4B8;
  --primary-400: #FB7A9C;
  --primary-500: #F43F6F;
  --primary-600: #E11D56;
  
  /* 辅助色 - 薰衣草紫 */
  --secondary-50: #F5F3FF;
  --secondary-100: #EDE9FE;
  --secondary-200: #DDD6FE;
  --secondary-300: #C4B5FD;
  --secondary-400: #A78BFA;
  --secondary-500: #8B5CF6;
  
  /* 强调色 */
  --accent-yellow: #FBBF24;
  --accent-mint: #6EE7B7;
  --accent-blue: #60A5FA;
  
  /* 中性色 */
  --neutral-50: #FAFAFA;
  --neutral-100: #F5F5F4;
  --neutral-200: #E7E5E4;
  --neutral-300: #D6D3D1;
  --neutral-400: #A8A29E;
  --neutral-500: #78716C;
  --neutral-600: #57534E;
  --neutral-700: #44403C;
  --neutral-900: #1C1917;
}

/* 基础重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Nunito', 'PingFang SC', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(180deg, #FFF5F7 0%, #F5F3FF 50%, #F0FDFA 100%);
  min-height: 100vh;
  color: var(--neutral-700);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* 容器 */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  padding-bottom: 100px;
}

/* ========== 头部 ========== */
.header {
  text-align: center;
  padding: 20px 0;
  position: relative;
}

.header h1 {
  font-size: 24px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-500), var(--secondary-500));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
  position: relative;
  display: inline-block;
}

/* 标题装饰 */
.header h1::before,
.header h1::after {
  content: '✨';
  position: absolute;
  font-size: 14px;
  -webkit-text-fill-color: initial;
}

.header h1::before {
  left: -24px;
  top: 0;
  animation: float 2s ease-in-out infinite;
}

.header h1::after {
  right: -24px;
  top: 0;
  animation: float 2s ease-in-out infinite 0.5s;
}

.account-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.account-name {
  font-size: 13px;
  color: var(--neutral-600);
  font-weight: 500;
}

.quota-badge {
  background: linear-gradient(135deg, var(--primary-100), var(--secondary-100));
  color: var(--primary-600);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--primary-200);
}

/* ========== 错误提示 ========== */
.error-banner {
  background: linear-gradient(135deg, #FEE2E2, #FECACA);
  color: #B91C1C;
  padding: 12px 16px;
  border-radius: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #FECACA;
  font-size: 14px;
}

.error-banner .close-btn {
  background: none;
  border: none;
  color: #B91C1C;
  font-size: 20px;
  cursor: pointer;
  padding: 0 5px;
  opacity: 0.7;
}

/* ========== 模式切换按钮 ========== */
.mode-switcher {
  display: flex;
  background: linear-gradient(135deg, var(--neutral-100), var(--neutral-200));
  border-radius: 24px;
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
  border: 2px solid var(--neutral-200);
  position: relative;
}

.mode-btn {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--neutral-500);
  z-index: 1;
}

.mode-btn.active {
  color: white;
}

.mode-btn.active.ai-mode {
  background: linear-gradient(135deg, var(--secondary-400), var(--secondary-500));
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.mode-btn.active.original-mode {
  background: linear-gradient(135deg, var(--primary-400), var(--primary-500));
  box-shadow: 0 4px 12px rgba(244, 63, 111, 0.4);
}

/* ========== 卡片样式 ========== */
.card {
  background: white;
  border-radius: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--neutral-200);
  overflow: hidden;
}

/* ========== 上传区域 ========== */
.upload-section {
  background: white;
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--neutral-200);
}

.upload-area {
  border: 3px dashed var(--primary-200);
  border-radius: 20px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: linear-gradient(135deg, rgba(255,255,255,0.9), rgba(255,245,247,0.5));
  position: relative;
  overflow: hidden;
}

.upload-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(to right, var(--primary-200) 1px, transparent 1px),
    linear-gradient(to bottom, var(--primary-200) 1px, transparent 1px);
  background-size: 12px 12px;
  opacity: 0.05;
  pointer-events: none;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--primary-400);
  background: var(--primary-50);
  transform: scale(1.01);
}

.upload-icon {
  font-size: 56px;
  margin-bottom: 16px;
  display: block;
  animation: float 3s ease-in-out infinite;
}

.upload-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--neutral-700);
  margin-bottom: 8px;
}

.upload-hint {
  font-size: 13px;
  color: var(--neutral-400);
}

/* 上传按钮提示 */
.upload-btn-hint {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--primary-400), var(--primary-500));
  color: white;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(244, 63, 111, 0.3);
}

/* ========== 预览容器 ========== */
.preview-container {
  position: relative;
  margin-top: 16px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.preview-container img {
  width: 100%;
  display: block;
  border-radius: 20px;
}

.remove-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  color: white;
  border: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.remove-btn:active {
  transform: scale(0.9);
}

/* ========== 选项面板 ========== */
.options-panel {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--neutral-200);
}

.options-panel h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--neutral-700);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.options-panel h3::before {
  content: '⚙️';
}

.option-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 4px 0;
}

.option-group label {
  font-size: 14px;
  color: var(--neutral-600);
  font-weight: 500;
}

.option-group select {
  padding: 10px 16px;
  border: 2px solid var(--neutral-200);
  border-radius: 12px;
  font-size: 14px;
  background: white;
  min-width: 140px;
  color: var(--neutral-700);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.option-group select:focus {
  outline: none;
  border-color: var(--primary-400);
  box-shadow: 0 0 0 3px var(--primary-100);
}

/* ========== 生成按钮 ========== */
.generate-btn {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary-400), var(--primary-500));
  color: white;
  border: none;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 16px rgba(244, 63, 111, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.generate-btn:disabled {
  background: var(--neutral-300);
  box-shadow: none;
  cursor: not-allowed;
}

.generate-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(244, 63, 111, 0.4);
}

.generate-btn:not(:disabled):active {
  transform: scale(0.98);
}

/* ========== 进度区域 ========== */
.progress-section {
  background: white;
  border-radius: 24px;
  padding: 48px 24px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--neutral-200);
}

/* 拼豆风格加载动画 */
.progress-spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto 24px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  animation: spin-beads 1.2s linear infinite;
}

.progress-spinner::before,
.progress-spinner::after {
  content: '';
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: 
    inset 0 -3px 6px rgba(0,0,0,0.15),
    inset 0 3px 6px rgba(255,255,255,0.4);
}

.progress-spinner::before {
  background: var(--primary-400);
}

.progress-spinner::after {
  background: var(--secondary-400);
}

.bead-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: 
    inset 0 -3px 6px rgba(0,0,0,0.15),
    inset 0 3px 6px rgba(255,255,255,0.4);
}

.bead-spinner:nth-child(1) { background: #FB7A9C; }
.bead-spinner:nth-child(2) { background: #60A5FA; }
.bead-spinner:nth-child(3) { background: #FBBF24; }
.bead-spinner:nth-child(4) { background: #6EE7B7; }

@keyframes spin-beads {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.progress-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--neutral-700);
  margin-bottom: 8px;
}

.progress-hint {
  font-size: 13px;
  color: var(--neutral-400);
}

/* ========== 结果区域 ========== */
.result-section {
  background: white;
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--neutral-200);
}

.result-section h2 {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 20px;
  color: var(--neutral-800);
}

.result-section h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--neutral-600);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* AI 图片网格 */
.ai-images h3::before {
  content: '🤖';
}

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

.ai-image-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.3s ease;
  border: 3px solid transparent;
}

.ai-image-card:hover {
  transform: scale(1.03);
}

.ai-image-card:active {
  transform: scale(0.98);
}

.ai-image-card img {
  width: 100%;
  display: block;
}

.ai-image-card.selected {
  border-color: var(--secondary-500);
  box-shadow: 0 0 0 3px var(--secondary-200), 0 4px 16px rgba(139, 92, 246, 0.3);
}

.ai-image-card .select-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--secondary-500);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
}

.ai-image-card.selected .select-badge {
  display: flex;
}

.pixelate-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  background: linear-gradient(135deg, var(--secondary-400), var(--secondary-500));
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.pixelate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}

.pixelate-btn:disabled {
  background: var(--neutral-300);
  box-shadow: none;
  cursor: not-allowed;
}

/* ========== 像素图结果 ========== */
.pixel-result {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--neutral-200);
}

.pixel-result h3::before {
  content: '🎨';
}

.pixel-image-container {
  text-align: center;
  margin-bottom: 16px;
}

.pixel-image-container img {
  max-width: 100%;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.pixel-stats {
  background: linear-gradient(135deg, var(--primary-50), var(--secondary-50));
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--neutral-200);
}

.pixel-stats p {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px dashed var(--neutral-200);
}

.pixel-stats p:last-child {
  border-bottom: none;
}

.pixel-stats p span:first-child {
  color: var(--neutral-500);
}

.pixel-stats p span:last-child {
  font-weight: 700;
  color: var(--neutral-800);
}

.download-btn {
  display: block;
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
  text-align: center;
  text-decoration: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.restart-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  background: var(--neutral-100);
  color: var(--neutral-600);
  border: 2px solid var(--neutral-200);
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.restart-btn:hover {
  background: var(--neutral-200);
}

.restart-btn:active {
  transform: scale(0.98);
}

/* ========== 动画 ========== */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ========== 触摸反馈 ========== */
.touch-feedback {
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.touch-feedback:active {
  transform: scale(0.96);
  opacity: 0.9;
}

/* ========== 响应式 ========== */
@media (max-width: 380px) {
  .container {
    padding: 12px;
  }
  
  .header h1 {
    font-size: 20px;
  }
  
  .header h1::before,
  .header h1::after {
    display: none;
  }
  
  .upload-area {
    padding: 32px 16px;
  }
  
  .upload-icon {
    font-size: 48px;
  }
  
  .image-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  
  .mode-btn {
    padding: 10px 12px;
    font-size: 13px;
  }
}

/* ========================================
   图片放大预览模态框
   ======================================== */

.image-modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.9);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  margin: auto;
  display: block;
  max-width: 90%;
  max-height: 90vh;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: zoomIn 0.3s ease;
  cursor: zoom-out;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
}

@keyframes zoomIn {
  from {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
  }
  to {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

.modal-close {
  position: absolute;
  top: 20px;
  right: 35px;
  color: #ffffff;
  font-size: 48px;
  font-weight: bold;
  transition: 0.3s;
  cursor: pointer;
  z-index: 10000;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  line-height: 1;
}

.modal-close:hover,
.modal-close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

.modal-caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ffffff;
  padding: 16px 0;
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* 图片容器添加可点击样式 */
.pixel-image-container img {
  cursor: zoom-in;
  transition: transform 0.2s ease;
}

.pixel-image-container img:hover {
  transform: scale(1.02);
}

.ai-image-card img {
  cursor: zoom-in;
}

/* 移动端优化 */
@media (max-width: 768px) {
  .modal-content {
    max-width: 95%;
    max-height: 85vh;
  }
  
  .modal-close {
    top: 10px;
    right: 15px;
    font-size: 36px;
  }
  
  .modal-caption {
    width: 90%;
    font-size: 14px;
    bottom: 10px;
  }
}
