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

:root {
  --color-primary: #1aad19;
  --color-primary-dark: #179b16;
  --color-primary-light: #e8f5e9;
  --color-bg: #f5f6fa;
  --color-card: #ffffff;
  --color-text: #333333;
  --color-text-secondary: #888888;
  --color-border: #e8e8e8;
  --color-tag-bg: #f0f0f0;
  --radius-card: 16px;
  --radius-btn: 24px;
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-card-hover: 0 4px 20px rgba(0, 0, 0, 0.1);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial,
    sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 40px;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  padding: 22px 16px 14px;
  background: linear-gradient(135deg, #2ecc71 0%, #00bcd4 50%, #03a9f4 100%);
  color: #fff;
  border-radius: 0 0 24px 24px;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.header-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
}

.header-texts {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 0;
  letter-spacing: 1px;
  line-height: 1.3;
}

.header-subtitle {
  font-size: 13px;
  opacity: 0.9;
  font-weight: 400;
  line-height: 1.4;
}

.header-menu {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  touch-action: manipulation;
  flex-shrink: 0;
}

.header-menu:active {
  background: rgba(255,255,255,0.2);
}

/* ===== Promo Banner ===== */
.promo-banner {
  margin: 6px 12px 8px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 3px 15px rgba(238,90,158,0.25);
}

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

/* ===== Main Content ===== */
.main-content {
  padding: 0 16px;
}

/* ===== Card ===== */
.card {
  background: var(--color-card);
  border-radius: var(--radius-card);
  padding: 20px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}

.card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
}

.label-icon {
  flex-shrink: 0;
  color: var(--color-primary);
}

/* ===== Prompt Textarea ===== */
.prompt-card {
  padding-bottom: 12px;
}

.textarea-wrapper {
  position: relative;
}

.prompt-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border: 1.5px solid var(--color-border);
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: #fafafa;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.prompt-textarea::placeholder {
  color: #bbb;
  font-size: 14px;
}

.prompt-textarea:focus {
  border-color: var(--color-primary);
  background: #fff;
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 6px;
  padding-right: 4px;
}

.char-count.warning {
  color: #e74c3c;
}

/* ===== Tag Group ===== */
.tag-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 44px;
  padding: 4px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: 18px;
  background: var(--color-tag-bg);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  flex-direction: column;
  gap: 3px;
}

.tag-btn:active {
  transform: scale(0.96);
}

.tag-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* 比例图框 */
.ratio-frame {
  display: block;
  height: 20px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  aspect-ratio: calc(var(--rw) / var(--rh));
}

/* ===== Generate Button ===== */
.generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  border: none;
  border-radius: var(--radius-btn);
  background: linear-gradient(135deg, var(--color-primary) 0%, #2ed573 100%);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(26, 173, 25, 0.3);
  margin-top: 4px;
  margin-bottom: 14px;
  touch-action: manipulation;
}

.generate-btn:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(26, 173, 25, 0.3);
}

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

.generate-btn .btn-text {
  pointer-events: none;
}

.generate-btn .btn-icon {
  pointer-events: none;
  margin-right: 6px;
}

/* ===== Generate Wrapper & Quota ===== */
.generate-wrapper {
  margin-top: 4px;
  margin-bottom: 14px;
}

.quota-hint {
  text-align: center;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 8px;
}

.quota-hint.warning {
  color: #e67e22;
}

.quota-hint.exhausted {
  color: #e74c3c;
  font-weight: 500;
}

/* ===== Disclaimer ===== */
.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 12px 14px;
  background: #fff8e1;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 12px;
  color: #8d6e00;
  line-height: 1.6;
}

.disclaimer svg {
  flex-shrink: 0;
  margin-top: 2px;
  color: #f9a825;
}

/* ===== Background Generating Float ===== */
.bg-generating {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
}

.bg-generating-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 24px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}

.bg-generating-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.loading-overlay.active {
  display: flex;
}

.loading-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 32px;
  text-align: center;
  max-width: 300px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-primary-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

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

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

.loading-tip {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  min-height: 40px;
  transition: opacity 0.3s ease;
}

.loading-bg-btn {
  margin-top: 16px;
  padding: 8px 20px;
  border: 1.5px solid var(--color-primary);
  border-radius: 20px;
  background: #fff;
  color: var(--color-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.loading-bg-btn:active {
  background: var(--color-primary-light);
  transform: scale(0.96);
}

/* ===== Result Card ===== */
.result-image-wrapper {
  border-radius: 12px;
  overflow: hidden;
  background: #f0f0f0;
  margin-bottom: 16px;
}

.result-image {
  width: 100%;
  display: block;
  border-radius: 12px;
}

.result-actions {
  display: flex;
  gap: 12px;
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  border: 1.5px solid var(--color-border);
  border-radius: 22px;
  background: #fff;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.action-btn:active {
  transform: scale(0.96);
}

.save-btn {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.save-btn:active {
  background: var(--color-primary-light);
}

.share-btn:active {
  background: var(--color-tag-bg);
}

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

/* ===== Inspiration Grid ===== */
.inspiration-card {
  padding-bottom: 12px;
}

.card-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-label-row .card-label {
  margin-bottom: 0;
}

.shuffle-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border: 1.5px solid var(--color-primary);
  border-radius: 16px;
  background: #fff;
  color: var(--color-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.shuffle-btn:active {
  background: var(--color-primary-light);
  transform: scale(0.96);
}

.shuffle-icon {
  flex-shrink: 0;
}

.inspiration-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.inspiration-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: #f0f0f0;
  transition: transform 0.2s;
}

.inspiration-item:active {
  transform: scale(0.96);
}

.inspiration-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.inspiration-item .inspiration-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  color: #fff;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== History Grid ===== */
.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.history-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: #f0f0f0;
  transition: transform 0.2s;
}

.history-item:active {
  transform: scale(0.96);
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ===== Preview Overlay ===== */
.preview-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  flex-direction: column;
}

.preview-overlay.active {
  display: flex;
}

.preview-header {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px;
}

.preview-close {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.preview-close:active {
  background: rgba(255, 255, 255, 0.3);
}

.preview-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
}

.preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  text-align: center;
  max-width: 80%;
  line-height: 1.5;
}

.toast.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ===== Responsive ===== */
@media (min-width: 481px) {
  #app {
    max-width: 480px;
  }

  .header {
    border-radius: 0 0 32px 32px;
    padding: 40px 20px 24px;
  }
}

/* ===== Scrollbar (Desktop) ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 2px;
}

/* ===== Selection ===== */
::selection {
  background: var(--color-primary);
  color: #fff;
}
