/* ==========================================================================
   Text to Image Studio — OLED Dark Modern AI Workbench Style
   ========================================================================== */

:root {
  --bg-app: #090a0f;
  --bg-card: #12131a;
  --bg-card-hover: #161822;
  --bg-input: #181a24;
  --bg-input-focus: #1f2230;
  --bg-badge: #1f2232;
  --bg-tag: #1c1e2b;
  --bg-tag-hover: #282c3f;

  --border-subtle: #1e202c;
  --border-hover: #2e3245;
  --border-focus: #3b82f6;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #090a0f;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  --accent-gradient-hover: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px -2px rgba(59, 130, 246, 0.25);

  --font-heading: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* 顶部导航栏 */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: rgba(9, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.75rem 1.5rem;
}

.nav-container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  overflow-wrap: break-word;
  word-break: break-word;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.user-avatar {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
}

.user-avatar svg {
  width: 16px;
  height: 16px;
}

.username {
  font-weight: 500;
  color: var(--text-primary);
}

/* 主布局 */
.main-layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  flex: 1;
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* 面板通用样式 */
.panel-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.card-header-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-badge);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
}

.card-header-icon svg {
  width: 16px;
  height: 16px;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow-wrap: break-word;
  word-break: break-word;
}

/* 表单组件 */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-sublabel {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  background-color: var(--bg-badge);
  border: 1px solid var(--border-subtle);
  color: var(--accent-primary);
}

.select-wrapper {
  position: relative;
}

.form-select {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 2.5rem 0.65rem 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.form-select:hover {
  border-color: var(--border-hover);
}

.form-select:focus {
  border-color: var(--border-focus);
  background-color: var(--bg-input-focus);
}

.select-arrow {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
}

.select-arrow svg {
  width: 16px;
  height: 16px;
}

.form-help {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* 提示词多行文本框 */
.prompt-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.char-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.textarea-wrapper {
  position: relative;
}

.form-textarea {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 110px;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.form-textarea:hover {
  border-color: var(--border-hover);
}

.form-textarea:focus {
  border-color: var(--border-focus);
  background-color: var(--bg-input-focus);
}

.form-textarea::placeholder {
  color: var(--text-muted);
}

/* 灵感标签库 */
.tags-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background-color: rgba(24, 26, 36, 0.4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem;
}

.tag-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.tag-group-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-chip {
  background-color: var(--bg-tag);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.tag-chip:hover {
  background-color: var(--bg-tag-hover);
  border-color: var(--border-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.tag-chip:active {
  transform: translateY(0);
}

/* 参考图上传 Dropzone */
.dropzone {
  position: relative;
  background-color: var(--bg-input);
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent-primary);
  background-color: rgba(59, 130, 246, 0.04);
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  pointer-events: none;
}

.dropzone-icon {
  width: 32px;
  height: 32px;
  color: var(--text-muted);
}

.dropzone-icon svg {
  width: 100%;
  height: 100%;
}

.dropzone-text {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.dropzone-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* 参考图缩略预览列表 */
.ref-previews {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.ref-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-app);
}

.ref-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ref-thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.75);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s;
}

.ref-thumb-remove::after {
  content: "";
  position: absolute;
  inset: -6px;
}

.ref-thumb-remove:hover {
  background-color: var(--danger);
}

.ref-thumb-remove svg {
  width: 14px;
  height: 14px;
}

/* 按钮系统 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.6rem 1.15rem;
  min-height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  outline: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: var(--accent-gradient-hover);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.45);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

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

.btn-outline {
  background-color: transparent;
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.btn-outline:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background-color: var(--bg-input);
  color: var(--text-primary);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.15s;
  padding: 0.25rem 0.5rem;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-text::after {
  content: "";
  position: absolute;
  inset: -6px;
}

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

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  min-height: 32px;
}

.btn-generate {
  width: 100%;
  padding: 0.85rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* 右侧画布与展示面板 */
.canvas-card {
  min-height: 600px;
}

.canvas-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.canvas-title-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.canvas-stage {
  min-height: 400px;
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* 空状态 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: 0.75rem;
}

.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background-color: var(--bg-badge);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-icon svg {
  width: 32px;
  height: 32px;
}

.empty-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 340px;
}

/* 加载状态 */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 3rem;
}

.spinner-ring {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(59, 130, 246, 0.15);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.loading-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* 图片查看器 */
.image-viewer {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
}

.image-wrapper {
  position: relative;
  width: 100%;
  max-width: 512px;
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: #000000;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-subtle);
}

.rendered-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.image-overlay-actions {
  position: absolute;
  bottom: 10px;
  right: 10px;
  opacity: 0;
  transition: opacity 0.2s;
}

.image-wrapper:hover .image-overlay-actions {
  opacity: 1;
}

.btn-icon-overlay {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background-color: rgba(9, 10, 15, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-subtle);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s;
  position: relative;
}

.btn-icon-overlay::after {
  content: "";
  position: absolute;
  inset: -6px;
}

.btn-icon-overlay:hover {
  background-color: var(--accent-primary);
}

.btn-icon-overlay svg {
  width: 18px;
  height: 18px;
}

/* 结果工具栏 */
.result-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.meta-tag {
  background-color: var(--bg-badge);
  border: 1px solid var(--border-subtle);
  color: var(--accent-primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.meta-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toolbar-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.result-prompt-box {
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
}

.prompt-box-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.25rem;
}

.prompt-box-content {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
  word-break: break-word;
}

/* 历史画廊 */
.history-gallery-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gallery-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.gallery-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.gallery-strip {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.gallery-strip::-webkit-scrollbar {
  height: 4px;
}

.gallery-strip::-webkit-scrollbar-thumb {
  background-color: var(--border-subtle);
  border-radius: 2px;
}

.gallery-empty-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.75rem 0;
}

.gallery-item {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  background-color: #000000;
  cursor: pointer;
  transition: all 0.2s ease;
}

.gallery-item:hover {
  transform: translateY(-2px);
  border-color: var(--border-hover);
}

.gallery-item.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 大图 Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.modal-close {
  position: absolute;
  top: -44px;
  right: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s;
}

.modal-close::after {
  content: "";
  position: absolute;
  inset: -6px;
}

.modal-close:hover {
  background-color: var(--danger);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-preview-img {
  max-width: 80vw;
  max-height: 80vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  object-fit: contain;
}

/* Toast 组件 */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.75rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-error {
  border-left: 3px solid var(--danger);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* 图片尺寸 Size 输入区 */
.size-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.size-preset-chip {
  background-color: var(--bg-tag);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

.size-preset-chip:hover {
  background-color: var(--bg-tag-hover);
  border-color: var(--border-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.size-preset-chip:active {
  transform: translateY(0);
}

.size-preset-chip.active {
  background-color: var(--accent-bg-soft);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.size-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.size-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.form-input {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 2.25rem 0.65rem 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.form-input::-webkit-outer-spin-button,
.form-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:hover {
  border-color: var(--border-hover);
}

.form-input:focus {
  border-color: var(--border-focus);
  background-color: var(--bg-input-focus);
}

.form-input.invalid {
  border-color: var(--danger);
  background-color: rgba(239, 68, 68, 0.06);
}

.size-field-label {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
  user-select: none;
}

.size-x {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  user-select: none;
}

.form-help.error {
  color: var(--danger);
}

/* ==========================================================================
   Responsive Breakpoints (4.9.1 规范三档适配：桌面 >1024px / 平板 768-1024px / 手机 <768px + 极窄 <480px)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. 平板端适配 (768px ~ 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 1.25rem 1.5rem 3rem;
  }

  .panel-card {
    padding: 1.25rem;
  }
}

/* --------------------------------------------------------------------------
   2. 手机端适配 (< 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* 顶部导航栏 */
  .navbar {
    padding: 0.65rem 1rem;
  }

  .brand-subtitle {
    display: none; /* 手机端隐藏副标题防止折行 */
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .nav-actions {
    gap: 0.5rem;
  }

  .user-badge {
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-badge .username {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* 主布局与面板卡片 */
  .main-layout {
    grid-template-columns: 1fr;
    gap: 1.25rem;
    padding: 1rem 0.85rem 3rem;
  }

  .panel-card {
    padding: 1.15rem 1rem;
    border-radius: var(--radius-lg);
    gap: 1rem;
  }

  /* 表单与交互 */
  .form-group {
    gap: 0.4rem;
  }

  .form-select {
    padding: 0.65rem 2.25rem 0.65rem 0.75rem;
    font-size: 0.875rem;
  }

  .form-textarea {
    min-height: 90px;
    padding: 0.75rem;
    font-size: 0.875rem;
  }

  .size-presets {
    gap: 0.4rem;
  }

  .size-preset-chip {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
    min-height: 32px;
  }

  .tag-chips {
    gap: 0.4rem;
  }

  .tag-chip {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }

  .ref-previews {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
  }

  /* 按钮与触控保障 (≥ 44×44px / 40px sm) */
  .btn {
    min-height: 44px;
    padding: 0.65rem 1.15rem;
    font-size: 0.925rem;
  }

  .btn-sm {
    min-height: 40px;
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
  }

  .btn-generate {
    min-height: 48px;
    font-size: 1rem;
  }

  /* 画布展示与图片视图 */
  .canvas-card {
    min-height: auto;
  }

  .canvas-stage {
    min-height: 320px;
  }

  .image-viewer {
    padding: 0.75rem;
    gap: 0.85rem;
  }

  .image-wrapper {
    max-width: 100%;
  }

  /* 触屏移动端放大按钮常驻，移除 hover 依赖 */
  .image-overlay-actions {
    opacity: 1;
    bottom: 8px;
    right: 8px;
  }

  .result-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .result-meta {
    justify-content: space-between;
    width: 100%;
  }

  .toolbar-buttons {
    display: flex;
    width: 100%;
    gap: 0.5rem;
  }

  .toolbar-buttons .btn {
    flex: 1 1 50%;
  }

  /* 历史画廊 */
  .gallery-item {
    width: 64px;
    height: 64px;
  }

  /* 大图 Modal 适配手机屏幕 */
  .modal-backdrop {
    padding: 1rem;
  }

  .modal-content {
    max-width: 96vw;
    max-height: 90vh;
  }

  .modal-close {
    top: 8px;
    right: 8px;
    background-color: rgba(0, 0, 0, 0.75);
    width: 36px;
    height: 36px;
    z-index: 10;
  }

  .modal-preview-img {
    max-width: 94vw;
    max-height: 82vh;
  }

  /* Toast 浮层在手机端通栏沉底 */
  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }

  .toast {
    max-width: 100%;
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   3. 超窄手机端适配 (< 480px)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .navbar {
    padding: 0.5rem 0.75rem;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
  }

  .brand-title {
    font-size: 0.95rem;
  }

  .toolbar-buttons {
    flex-direction: column;
  }

  .toolbar-buttons .btn {
    width: 100%;
  }

  .size-input-row {
    flex-wrap: wrap;
  }

  .size-field {
    flex: 1 1 calc(50% - 1rem);
  }
}
