*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --glass-bg: rgba(255, 255, 255, 0.12);
  --glass-border: rgba(255, 255, 255, 0.22);
  --glass-shadow: rgba(0, 0, 0, 0.18);
  --text-primary: #f8fafc;
  --text-secondary: rgba(248, 250, 252, 0.65);
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --panel-width: 320px;
}

html, body {
  height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text-primary);
  overflow: hidden;
}

body {
  position: relative;
  background: #0f0c29;
}

/* 流动渐变背景 */
.bg-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 40%, #24243e 100%);
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.7;
  animation: float 18s ease-in-out infinite;
}

.blob-1 {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, #667eea, #764ba2);
  top: -120px;
  left: -80px;
  animation-delay: 0s;
}

.blob-2 {
  width: 480px;
  height: 480px;
  background: radial-gradient(circle, #f093fb, #f5576c);
  top: 40%;
  right: -100px;
  animation-delay: -4s;
}

.blob-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #4facfe, #00f2fe);
  bottom: -80px;
  left: 30%;
  animation-delay: -8s;
}

.blob-4 {
  width: 360px;
  height: 360px;
  background: radial-gradient(circle, #a18cd1, #fbc2eb);
  top: 20%;
  left: 45%;
  animation-delay: -12s;
}

@keyframes float {
  0%, 100% {
    transform: translate(0, 0) scale(1);
  }
  25% {
    transform: translate(40px, -30px) scale(1.05);
  }
  50% {
    transform: translate(-20px, 40px) scale(0.95);
  }
  75% {
    transform: translate(30px, 20px) scale(1.02);
  }
}

.blur-overlay {
  position: fixed;
  inset: 0;
  backdrop-filter: blur(80px) saturate(1.4);
  -webkit-backdrop-filter: blur(80px) saturate(1.4);
  pointer-events: none;
}

/* 历史面板 */
.history-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--panel-width);
  height: 100%;
  background: rgba(15, 12, 41, 0.55);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-left: 1px solid var(--glass-border);
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.history-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.history-count {
  font-size: 12px;
  background: rgba(129, 140, 248, 0.25);
  color: #c7d2fe;
  padding: 2px 8px;
  border-radius: 999px;
}

.history-stats {
  padding: 0 18px 12px;
  font-size: 12px;
  color: rgba(248, 250, 252, 0.45);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.history-stats strong {
  color: #c7d2fe;
  font-weight: 600;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.history-empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 40px 16px;
  line-height: 1.6;
}

.history-item {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(129, 140, 248, 0.4);
  transform: translateX(-2px);
}

.history-item.active {
  border-color: var(--accent);
  background: rgba(129, 140, 248, 0.12);
}

.history-item-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.2);
  cursor: zoom-in;
  transition: transform 0.2s, box-shadow 0.2s;
}

.history-item-thumb:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.history-item-prompt {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item-time {
  font-size: 11px;
  color: rgba(248, 250, 252, 0.35);
  margin-top: 6px;
}

/* 主区域 */
.main {
  position: relative;
  z-index: 10;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px calc(var(--panel-width) + 32px) 24px 24px;
}

.dialog {
  width: 100%;
  max-width: 920px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  box-shadow: 0 24px 80px var(--glass-shadow);
  overflow: hidden;
  position: relative;
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px 28px 0;
  position: relative;
}

.balance-badge {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 12px;
  color: rgba(248, 250, 252, 0.7);
  background: rgba(129, 140, 248, 0.15);
  border: 1px solid rgba(129, 140, 248, 0.3);
  padding: 8px 14px;
  border-radius: 12px;
  min-width: 120px;
}

.balance-label {
  font-size: 11px;
  color: rgba(248, 250, 252, 0.45);
}

.balance-nums strong {
  color: #c7d2fe;
  font-size: 18px;
  font-weight: 700;
}

.balance-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 2px;
}

.balance-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #818cf8);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.balance-badge.low {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
}

.balance-badge.low .balance-bar-fill {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.balance-badge.low .balance-nums strong {
  color: #fca5a5;
}

.logo {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 14px;
  color: white;
  flex-shrink: 0;
}

.dialog-header h1 {
  font-size: 20px;
  font-weight: 600;
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.dialog-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 24px 28px 28px;
}

.input-section label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  color: rgba(248, 250, 252, 0.85);
}

textarea {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  min-height: 140px;
  font-family: inherit;
  transition: border-color 0.2s;
}

textarea:focus {
  outline: none;
  border-color: rgba(129, 140, 248, 0.6);
}

textarea::placeholder {
  color: rgba(248, 250, 252, 0.3);
}

.size-options {
  margin-top: 14px;
}

.size-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  color: rgba(248, 250, 252, 0.85);
}

.size-group {
  display: flex;
  gap: 10px;
}

.size-option {
  flex: 1;
  cursor: pointer;
}

.size-option input {
  display: none;
}

.size-option span {
  display: block;
  text-align: center;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  color: rgba(248, 250, 252, 0.65);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.size-option input:checked + span {
  color: #c7d2fe;
  background: rgba(129, 140, 248, 0.18);
  border-color: rgba(129, 140, 248, 0.55);
}

.size-option span:hover {
  border-color: rgba(129, 140, 248, 0.35);
}

.btn-generate {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-generate:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 全屏生成蒙版 */
.loading-mask[hidden] {
  display: none !important;
}

.loading-mask {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 6, 24, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: maskIn 0.4s ease;
}

.loading-content {
  text-align: center;
  padding: 40px;
  max-width: 420px;
}

.loading-ring {
  width: 64px;
  height: 64px;
  margin: 0 auto 28px;
  border: 3px solid rgba(129, 140, 248, 0.15);
  border-top-color: #818cf8;
  border-right-color: #a78bfa;
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
}

.loading-text {
  font-size: 20px;
  font-weight: 600;
  color: #f8fafc;
  min-height: 30px;
  letter-spacing: 0.02em;
  transition: opacity 0.35s, transform 0.35s;
}

.loading-text.fade {
  opacity: 0;
  transform: translateY(6px);
}

.loading-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0 12px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #818cf8;
  animation: dotPulse 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

.loading-sub {
  font-size: 13px;
  color: rgba(248, 250, 252, 0.4);
}

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes maskIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes imageReveal {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.result-image-wrap.reveal img {
  animation: imageReveal 0.5s ease;
}

/* 结果区域 */
.result-section {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.result-placeholder {
  text-align: center;
  color: var(--text-secondary);
}

.result-placeholder svg {
  opacity: 0.3;
  margin-bottom: 12px;
}

.result-placeholder p {
  font-size: 13px;
}

.result-image-wrap {
  width: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.result-image-wrap img {
  max-width: 100%;
  max-height: 360px;
  border-radius: 10px;
  object-fit: contain;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  cursor: zoom-in;
  transition: transform 0.2s, box-shadow 0.2s;
}

.result-image-wrap img:hover {
  transform: scale(1.02);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.image-hint {
  font-size: 12px;
  color: rgba(248, 250, 252, 0.35);
}

.result-actions {
  display: flex;
  gap: 10px;
}

.btn-action {
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: none;
  background: var(--accent);
  color: white;
  transition: background 0.2s;
}

.btn-action:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* 图片放大预览 */
.lightbox[hidden] {
  display: none !important;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: maskIn 0.25s ease;
  padding: 40px;
}

.lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: imageReveal 0.3s ease;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Toast */
.toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
  white-space: nowrap;
  animation: fadeInUp 0.3s ease;
}

.toast.error {
  background: rgba(220, 38, 38, 0.85);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@media (max-width: 900px) {
  .history-panel {
    width: 100%;
    height: auto;
    max-height: 200px;
    top: auto;
    bottom: 0;
    border-left: none;
    border-top: 1px solid var(--glass-border);
  }

  .main {
    padding: 16px 16px 220px;
  }

  .dialog-body {
    grid-template-columns: 1fr;
  }
}
