/* ============================================================
   豆苗AI海报设计助手 · Phase 1 MVP
   设计语言：晨光 + 纸感 + 抽芽
   ============================================================ */

@import url("https://fonts.googleapis.cn/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;600;700&family=Noto+Serif+SC:wght@500;700&display=swap");

/* --- Design Tokens --- */
:root {
  --brand-500: #10b981;
  --brand-600: #059669;
  --brand-700: #047857;
  --brand-400: #34d399;
  --brand-50: #ecfdf5;
  --brand-100: #d1fae5;
  --brand-200: #a7f3d0;

  --ink-900: #0f172a;
  --ink-800: #1e293b;
  --ink-700: #334155;
  --ink-600: #475569;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --ink-300: #cbd5e1;
  --ink-200: #e2e8f0;

  --paper: #fafaf7;
  --card: #ffffff;
  --line: #e5e7eb;

  --danger: #ef4444;

  --r-card: 16px;
  --r-item: 12px;
  --r-btn: 12px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 1px 2px rgba(15, 23, 42, 0.04),
    0 4px 12px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 4px 16px rgba(15, 23, 42, 0.06),
    0 12px 32px rgba(15, 23, 42, 0.08);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Sans SC", "Inter", -apple-system, BlinkMacSystemFont,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink-900);
  background: var(--paper);
  background-image: radial-gradient(
    rgba(15, 23, 42, 0.025) 1px,
    transparent 1px
  );
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button {
  font-family: inherit;
  color: inherit;
}

input,
textarea {
  font-family: inherit;
}

/* 让原生 hidden 一定生效，避免被后面 display 覆盖 */
[hidden] { display: none !important; pointer-events: none; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

@media (min-width: 768px) {
  #app {
    max-width: 720px;
    padding: 24px 24px 56px;
  }
}

/* ================ 品牌头部 ================ */
.brand-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 20px;
  border-radius: 20px;
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 55%, #a7f3d0 100%);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
}

.brand-header::before {
  content: "";
  position: absolute;
  top: -30px;
  right: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  filter: blur(20px);
  pointer-events: none;
}

.brand-logo-wrap {
  position: relative;
  width: 68px;
  height: 68px;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .brand-logo-wrap {
    width: 84px;
    height: 84px;
  }
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  border-radius: 18px;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  display: block;
}

.brand-logo-fallback {
  display: none;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: #fff;
  color: var(--brand-600);
  place-items: center;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.brand-text {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--ink-900);
  line-height: 1.3;
}

@media (min-width: 768px) {
  .brand-title {
    font-size: 24px;
  }
}

.brand-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--brand-700);
  font-weight: 500;
}

/* ================ 区块 ================ */
.main {
  display: flex;
  flex-direction: column;
}

.block {
  margin-top: 26px;
  animation: reveal 400ms var(--ease) both;
  animation-delay: calc(var(--reveal-index, 0) * 60ms);
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.block-head {
  margin-bottom: 12px;
  padding: 0 2px;
}

.block-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-900);
  letter-spacing: 0.3px;
}

.block-desc {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--ink-500);
}

/* ================ 通用选择卡片 ================ */
.opt {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-item);
  padding: 14px;
  cursor: pointer;
  transition: transform 160ms var(--ease), border-color 160ms var(--ease),
    background 160ms var(--ease), box-shadow 160ms var(--ease);
  user-select: none;
  overflow: hidden;
}

.opt:hover {
  border-color: var(--ink-300);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.opt:active {
  transform: translateY(0) scale(0.98);
}

.opt.is-active {
  border-color: var(--brand-500);
  border-width: 2px;
  padding: 13px;
  background: var(--brand-50);
}

.opt.is-active::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--brand-500)
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E")
    center / 12px 12px no-repeat;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
}

.opt-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-900);
  margin: 0;
}

.opt-desc {
  font-size: 11.5px;
  color: var(--ink-500);
  margin: 3px 0 0;
  line-height: 1.5;
}

/* ================ 风格：横向滑动 ================ */
.hscroll-wrap {
  margin: 0 -16px;
  padding: 0 16px;
}
@media (min-width: 768px) {
  .hscroll-wrap {
    margin: 0 -24px;
    padding: 0 24px;
  }
}

.hscroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

.hscroll::-webkit-scrollbar {
  display: none;
}

.opt-style {
  flex: 0 0 132px;
  scroll-snap-align: start;
  padding: 14px 12px;
  text-align: left;
}

.opt-style.is-active {
  padding: 13px 11px;
}

.opt-style .style-emoji {
  font-size: 26px;
  line-height: 1;
  margin-bottom: 10px;
  display: inline-block;
}

.opt-style .opt-title {
  font-size: 14px;
}

/* ================ 比例：3x2 网格 ================ */
.grid {
  display: grid;
  gap: 10px;
}

.grid-ratio {
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 480px) {
  .grid-ratio {
    grid-template-columns: repeat(3, 1fr);
  }
}

.opt-ratio {
  text-align: center;
  padding: 14px 8px;
}

.opt-ratio .ratio-thumb {
  display: block;
  margin: 0 auto 10px;
  background: var(--brand-50);
  border: 1px dashed var(--brand-100);
  border-radius: 4px;
}

.opt-ratio.is-active .ratio-thumb {
  background: #fff;
  border-color: var(--brand-500);
  border-style: solid;
}

.opt-ratio .ratio-emoji {
  font-size: 14px;
  margin-right: 4px;
}

.opt-ratio .ratio-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-900);
  display: block;
}

.opt-ratio .ratio-size {
  font-size: 11px;
  color: var(--ink-500);
  display: block;
  margin-top: 2px;
}

/* ================ 配色：3列 / 4列 ================ */
.grid-palette {
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

@media (min-width: 480px) {
  .grid-palette {
    grid-template-columns: repeat(4, 1fr);
  }
}

.opt-palette {
  padding: 12px 10px;
  text-align: center;
}

.opt-palette.is-active {
  padding: 11px 9px;
}

.opt-palette .palette-swatches {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 8px;
  height: 24px;
  align-items: center;
}

.opt-palette .sw {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  transition: transform 200ms var(--ease);
}

.opt-palette .sw-main {
  width: 22px;
  height: 22px;
  margin-right: -6px;
  position: relative;
  z-index: 2;
}

.opt-palette.is-active .sw-main {
  transform: scale(1.1);
}

.opt-palette .opt-title {
  font-size: 12.5px;
}

.opt-palette .opt-hex {
  font-size: 10px;
  color: var(--ink-400);
  font-family: "Inter", monospace;
  margin-top: 2px;
  letter-spacing: 0;
}

/* ================ 表单 ================ */
.form-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 4px 20px;
  box-shadow: var(--shadow-sm);
}

.field {
  display: block;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.field:last-child {
  border-bottom: none;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--ink-500);
  margin-bottom: 8px;
  font-weight: 500;
}

.field-label .required {
  color: var(--danger);
  font-style: normal;
  margin-left: 2px;
  margin-right: auto;
}

.counter {
  font-size: 11px;
  color: var(--ink-400);
  font-family: "Inter", monospace;
  font-weight: 400;
}

.field-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 15px;
  color: var(--ink-900);
  padding: 4px 0;
  resize: none;
}

.field-input::placeholder {
  color: var(--ink-400);
}

.field-textarea {
  line-height: 1.6;
  min-height: 66px;
}

.field::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--brand-500);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 200ms var(--ease);
  border-radius: 2px;
}

.field:focus-within::after {
  transform: scaleX(1);
}

/* ================ 生成模式开关 ================ */
.toggle-opt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  cursor: pointer;
  user-select: none;
}

.toggle-opt input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--ink-300);
  transition: background 200ms var(--ease);
  flex-shrink: 0;
}

.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.15);
  transition: transform 200ms var(--ease);
}

.toggle-opt input:checked + .toggle-track {
  background: var(--brand-500);
}

.toggle-opt input:checked + .toggle-track .toggle-knob {
  transform: translateX(18px);
}

.toggle-label {
  font-size: 13px;
  color: var(--ink-500);
  font-weight: 500;
}

/* ================ 按钮 ================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-btn);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms var(--ease), background 160ms var(--ease),
    box-shadow 160ms var(--ease), color 160ms var(--ease),
    border-color 160ms var(--ease);
  white-space: nowrap;
  font-family: inherit;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.28);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-700));
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.36);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: #fff;
  color: var(--brand-600);
  border-color: var(--brand-100);
}

.btn-secondary:hover {
  border-color: var(--brand-500);
  background: var(--brand-50);
}

.btn-lg {
  width: 100%;
  padding: 15px 20px;
  font-size: 15.5px;
  border-radius: 14px;
}

/* 抽芽 loading */
.btn-loading {
  display: none;
  align-items: center;
  gap: 10px;
}

.btn-loading .loading-label {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.btn-loading i {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  transform-origin: bottom center;
  animation: sprout 1200ms var(--ease) infinite;
  display: inline-block;
}

.btn-loading i:nth-child(3) {
  animation-delay: 150ms;
}
.btn-loading i:nth-child(4) {
  animation-delay: 300ms;
}

@keyframes sprout {
  0%,
  100% {
    transform: scaleY(0.4);
    opacity: 0.5;
  }
  40% {
    transform: scaleY(1.6);
    opacity: 1;
  }
  70% {
    transform: scaleY(1);
    opacity: 0.85;
  }
}

.btn.is-loading .btn-text {
  display: none;
}

.btn.is-loading .btn-loading {
  display: inline-flex;
}

.btn.is-loading {
  cursor: wait;
}

/* ================ 实时预览 ================ */
#livePreviewBlock {
  scroll-margin-top: 16px;
}
.live-preview {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 16px;
  display: flex;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease);
}
.live-poster {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 14px 12px;
  transition: background 0.3s var(--ease);
}
.live-poster-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  transition: background 0.3s var(--ease);
}
.live-poster-deco {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}
.live-poster-body {
  position: relative;
  z-index: 2;
}
.live-poster-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  margin: 0 0 4px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-poster-sub {
  font-size: 10px;
  line-height: 1.3;
  margin: 0 0 3px;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-poster-info {
  font-size: 9px;
  line-height: 1.2;
  margin: 0;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-hint {
  text-align: center;
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-400);
}

/* ================ 结果卡片 ================ */
.result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 24px 20px;
  box-shadow: var(--shadow-md);
}

.result-empty {
  text-align: center;
  padding: 24px 12px 12px;
  color: var(--ink-400);
}

.result-empty svg {
  color: var(--ink-300);
  margin-bottom: 12px;
}

.result-empty p {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-500);
}

/* ---- 骨架屏 loading ---- */
.result-loading {
  text-align: center;
}

.skeleton-poster {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 3 / 4;
  margin: 0 auto 20px;
  border-radius: 12px;
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.skeleton-inner {
  position: absolute;
  inset: 0;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.7);
}

.skeleton-line.lg {
  height: 22px;
}

.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-50 { width: 50%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-70 { width: 70%; }

.skeleton-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 20%,
    rgba(255, 255, 255, 0.5) 45%,
    rgba(255, 255, 255, 0.6) 55%,
    transparent 80%
  );
  animation: shimmer 1600ms infinite linear;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.loading-text {
  margin: 0;
  color: var(--ink-600);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.loading-dots {
  display: inline-flex;
  align-items: flex-end;
  gap: 4px;
  height: 12px;
  color: var(--brand-500);
}

.loading-dots i {
  width: 5px;
  height: 5px;
  background: currentColor;
  border-radius: 50%;
  transform-origin: bottom center;
  animation: sprout 1200ms var(--ease) infinite;
}
.loading-dots i:nth-child(2) { animation-delay: 150ms; }
.loading-dots i:nth-child(3) { animation-delay: 300ms; }

.poster-frame {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* result actions */
.result-actions {
  margin-top: 22px;
  display: flex;
  gap: 8px;
  width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}

.result-actions .btn {
  flex: 1 1 100px;
  min-width: 100px;
  padding: 10px 8px;
  font-size: 13px;
}

/* ================ Stage Info (两阶段徽章 + 提示) ================ */
.stage-info {
  margin: 4px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.stage-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  letter-spacing: 0.2px;
}

.stage-badge.stage-preview {
  color: var(--brand-600);
  background: var(--brand-50);
  border-color: var(--brand-100);
}

.stage-badge.stage-final {
  color: #92400e;
  background: #fef3c7;
  border-color: #fde68a;
}

.stage-hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink-600);
}

.stage-hint b {
  color: var(--ink-900);
  font-weight: 600;
}

.result-empty:empty ~ .stage-info,
#resultEmpty:not([hidden]) ~ .stage-info {
  display: none;
}

/* 空态时隐藏 stage-info */
.result-card > .stage-info {
  display: flex;
}

/* ================ btn-ghost（第三级按钮） ================ */
.btn-ghost {
  background: transparent;
  color: var(--ink-600);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 160ms var(--ease);
}

.btn-ghost:hover {
  background: var(--paper);
  color: var(--ink-900);
  border-color: var(--ink-400);
}

/* ================ 最终图 ================ */
.poster-frame-final {
  padding: 0;
  background: transparent;
  box-shadow: none;
  border: none;
}

.final-image {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 6px 24px rgba(15, 23, 42, 0.08);
  background: linear-gradient(135deg, var(--brand-50), #f9f9f6);
  object-fit: contain;
}

/* btn-final (loading 状态复用主按钮的动画) */
.btn.btn-final {
  position: relative;
}
.btn.btn-final .btn-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: inherit;
}
.btn.btn-final.is-loading .btn-text { visibility: hidden; }
.btn.btn-final.is-loading .btn-loading { display: flex; }
.btn.btn-final .btn-loading i {
  display: inline-block;
  width: 5px; height: 5px;
  background: currentColor;
  border-radius: 999px;
  animation: sprout 900ms ease-in-out infinite;
}
.btn.btn-final .btn-loading i:nth-child(3) { animation-delay: .12s; }
.btn.btn-final .btn-loading i:nth-child(4) { animation-delay: .24s; }


/* ================ Drawer ================ */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--ease);
}

.drawer-mask.is-open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background: var(--card);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 260ms var(--ease);
  box-shadow: var(--shadow-lg);
  padding-bottom: env(safe-area-inset-bottom);
  pointer-events: none;
}

.drawer.is-open {
  transform: translateY(0);
  pointer-events: auto;
}

.drawer-handle {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: var(--ink-300);
  margin: 10px auto 0;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 8px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.drawer-close {
  background: none;
  border: none;
  color: var(--ink-500);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}

.drawer-close:hover {
  background: var(--paper);
  color: var(--ink-900);
}

.drawer-body {
  padding: 8px 20px 16px;
  overflow-y: auto;
  flex: 1;
}

.drawer-tip {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--ink-500);
  line-height: 1.6;
}

.drawer-textarea {
  border: 1px solid var(--line);
  border-radius: var(--r-item);
  padding: 12px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink-800);
  background: var(--paper);
  min-height: 220px;
}

.drawer-textarea:focus {
  border-color: var(--brand-500);
  background: #fff;
  outline: none;
}

.drawer-foot {
  display: flex;
  gap: 10px;
  padding: 12px 20px 20px;
  border-top: 1px solid var(--line);
}

.drawer-foot .btn {
  flex: 1;
}

@media (min-width: 768px) {
  .drawer {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.96);
    max-width: 520px;
    width: 92%;
    border-radius: 20px;
    opacity: 0;
  }
  .drawer.is-open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

/* ================ Toast ================ */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--ink-900);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--r-pill);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease), transform 240ms var(--ease);
  z-index: 200;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.is-error {
  background: var(--danger);
}

/* ================ Footer ================ */
.foot {
  margin-top: 40px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-400);
  padding: 12px 0;
}

.foot p {
  margin: 0;
}

/* ================ 微调抽屉 ================ */
.refine-image-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
  max-height: 200px;
}

.refine-image {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
}

/* ========== 场景类别 ========== */
.grid-scene {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.opt-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 8px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  transition: all 150ms var(--ease);
  text-align: center;
}
.opt-scene .scene-emoji { font-size: 22px; line-height: 1.2; }
.opt-scene .scene-name { font-size: 13px; font-weight: 500; color: var(--ink-900); line-height: 1.3; }
.opt-scene:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.opt-scene.is-active { border-color: var(--brand-500); border-width: 2px; background: var(--brand-50); }

/* 其他场景手动输入 */
.other-scene-input { margin-top: 10px; }
.other-scene-input .input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  color: var(--ink-900);
  background: var(--card);
  outline: none;
  transition: border-color 150ms var(--ease);
  box-sizing: border-box;
}
.other-scene-input .input:focus { border-color: var(--brand-500); }
.other-scene-input .input::placeholder { color: var(--ink-400); }

/* ========== 风格来源 ========== */
.grid-source {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.opt-source {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  transition: all 150ms var(--ease);
  text-align: center;
}
.opt-source .source-emoji { font-size: 28px; line-height: 1; }
.opt-source .source-name { font-size: 15px; font-weight: 600; color: var(--ink-900); }
.opt-source .source-desc { font-size: 12px; color: var(--ink-400); line-height: 1.4; }
.opt-source:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.opt-source.is-active { border-color: var(--brand-500); border-width: 2px; background: var(--brand-50); }

/* ========== 来源子选项 ========== */
.source-sub {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.sub-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-900);
  margin-bottom: 14px;
}

/* ========== 大师选择 ========== */
.grid-master {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}
.opt-master {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  transition: all 150ms var(--ease);
}
.opt-master .master-name { font-size: 14px; font-weight: 600; color: var(--ink-900); }
.opt-master .master-cat { font-size: 11px; color: var(--ink-400); }
.opt-master .master-desc { font-size: 12px; color: var(--ink-600); line-height: 1.4; margin-top: 2px; }
.opt-master:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.opt-master.is-active { border-color: var(--brand-500); border-width: 2px; background: var(--brand-50); }

/* ========== 五维组合 ========== */
.dimension-group { display: flex; flex-direction: column; gap: 20px; }
.dimension-block { display: flex; flex-direction: column; gap: 8px; }
.dim-title { font-size: 13px; font-weight: 600; color: var(--ink-600); margin: 0; }
.dim-title::before { content: "· "; color: var(--brand-500); }
.grid-dim {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}
.opt-dim {
  padding: 10px 8px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  transition: all 150ms var(--ease);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  text-align: center;
}
.opt-dim .dim-name {
  font-size: 12.5px;
  color: var(--ink-900);
  line-height: 1.3;
  margin: 0;
}
.opt-dim:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.opt-dim:hover .dim-name { color: var(--brand-600); }
.opt-dim.is-active {
  border-color: var(--brand-500);
  border-width: 2px;
  background: var(--brand-50);
  padding: 9px 7px;
}
.opt-dim.is-active .dim-name { color: var(--brand-600); font-weight: 600; }

/* 五维配色卡片 */
.opt-dim-palette .dim-swatches {
  display: flex;
  gap: 3px;
  margin-bottom: 2px;
}
.opt-dim-palette .dim-sw {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.08);
  display: inline-block;
}
.opt-dim-palette.is-active .dim-sw {
  border-color: rgba(0,0,0,0.12);
  transform: scale(1.05);
}

/* ========== 设计哲学 ========== */
.grid-philosophy {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.opt-philosophy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  transition: all 150ms var(--ease);
}
.opt-philosophy .ph-name { font-size: 14px; font-weight: 600; color: var(--ink-900); }
.opt-philosophy .ph-desc { font-size: 12px; color: var(--ink-600); line-height: 1.4; }
.opt-philosophy:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.opt-philosophy.is-active { border-color: var(--brand-500); border-width: 2px; background: var(--brand-50); }

/* ========== 场景模板 ========== */
.grid-template {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}
.opt-template {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  transition: all 150ms var(--ease);
}
.opt-template .tpl-name { font-size: 14px; font-weight: 600; color: var(--ink-900); }
.opt-template .tpl-desc { font-size: 12px; color: var(--ink-600); line-height: 1.4; }
.opt-template:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.opt-template.is-active { border-color: var(--brand-500); border-width: 2px; background: var(--brand-50); }

/* ========== 素材上传 ========== */
.material-upload {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.material-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.material-list:empty { display: none; }
.material-item {
  display: flex;
  gap: 12px;
  padding: 10px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  align-items: stretch;
}
.material-thumb {
  position: relative;
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper);
}
.material-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.material-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.7);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms var(--ease);
}
.material-remove:hover { background: var(--danger); }
.material-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.material-name {
  font-size: 12px;
  color: var(--ink-400);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.material-purpose {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-900);
  background: var(--paper);
  outline: none;
  transition: border-color 150ms var(--ease);
  box-sizing: border-box;
}
.material-purpose:focus { border-color: var(--brand-500); background: var(--card); }
.material-purpose::placeholder { color: var(--ink-400); font-size: 12.5px; }

.material-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--brand-600);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms var(--ease);
}
.material-add-btn:hover {
  border-color: var(--brand-500);
  background: var(--brand-50);
}
.material-add-btn svg { stroke: currentColor; }

.material-hint {
  font-size: 12px;
  color: var(--ink-400);
  margin: 0;
  line-height: 1.5;
}

/* ========== 参考图上传 & 分析 ========== */
.ref-upload {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ref-upload-drop {
  position: relative;
  display: block;
  min-height: 140px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  overflow: hidden;
  transition: all 150ms var(--ease);
}
.ref-upload-drop:hover { border-color: var(--brand-500); background: var(--brand-50); }
.ref-upload-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  color: var(--ink-600);
  min-height: 140px;
}
.ref-upload-empty svg { color: var(--brand-500); }
.ref-upload-empty p {
  font-size: 13.5px;
  text-align: center;
  line-height: 1.6;
  margin: 0;
}
.ref-upload-empty small { color: var(--ink-400); font-size: 12px; }
.ref-upload-preview {
  position: relative;
  padding: 12px;
}
.ref-upload-preview img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--paper);
  display: block;
}
.ref-remove {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.7);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms var(--ease);
}
.ref-remove:hover { background: var(--danger); }

.btn-sm {
  padding: 10px 16px;
  font-size: 14px;
  min-height: 40px;
}
.btn.is-loading .btn-text { display: none; }
.btn.is-loading .btn-loading { display: inline-flex; }
.btn:not(.is-loading) .btn-loading { display: none; }

.ref-result {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--brand-50);
  border: 1.5px solid var(--brand-100);
  border-radius: 12px;
}
.ref-result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-600);
  margin: 0;
}
.ref-result textarea {
  background: var(--card);
  border-color: var(--brand-100);
  font-size: 13px;
  line-height: 1.6;
}
.ref-result-hint {
  font-size: 12px;
  color: var(--ink-600);
  margin: 0;
  line-height: 1.5;
}

/* ========== 微调结果区 ========== */
.result-image-block {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1.5px dashed var(--line);
}
.result-image-block .poster-frame-final {
  max-width: 100%;
}
.result-refine-loading {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1.5px dashed var(--line);
}
.stage-badge.stage-original {
  background: var(--ink-600);
  color: #fff;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.poster-frame.img-error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--danger);
  font-size: 14px;
}
