* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 1380px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f7f3cf;
  color: #3f3f56;
  padding: 18px;
}

.dot { position: fixed; border-radius: 50%; opacity: .25; z-index: 0; pointer-events: none; }
.dot1 { width: 90px; height: 90px; background: #ffb8c6; left: 22px; top: 52px; }
.dot2 { width: 100px; height: 100px; background: #cdb4ff; left: 220px; bottom: 80px; }
.dot3 { width: 90px; height: 90px; background: #a0d8ff; right: 160px; top: 280px; }

.topbar, .grid-main, .card { position: relative; z-index: 1; }

.banana {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #ffb48a, #f6d0ff);
  display: grid; place-items: center;
}

.btn { border: none; border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.btn.soft { background: #dceee8; color: #2f7968; }
.btn.icon {
  background: #e8ddff; color: #7959df;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0;
}
.btn.icon svg { width: 18px; height: 18px; fill: currentColor; }
.btn.green { background: #c9f0da; color: #2c8b5a; }
.btn.gray { background: #ececf0; color: #666; }
.btn.orange { background: linear-gradient(90deg, #ff8b2c, #ff5db1); color: #fff; }
.btn.purple { background: linear-gradient(90deg, #d044c0, #7a53f2); color: #fff; }
.btn.cyan { background: #14b8b0; color: #fff; }

.grid-main {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 16px;
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

.card {
  background: linear-gradient(135deg, #f7e9f2, #edf6ef);
  border: 1px solid #efdce9;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .05);
}

.title-row { display: flex; justify-content: space-between; align-items: center; }
.title-row h2 { margin: 0; color: #6a55ff; }

.switch {
  background: #fff;
  border: 1px solid #eed4e9;
  border-radius: 16px;
  padding: 4px;
  display: flex;
  gap: 4px;
}
.switch button {
  border: none;
  border-radius: 12px;
  padding: 8px 16px;
  background: transparent;
  cursor: pointer;
}
.switch .active { background: #5d7cff; color: #fff; }

label { display: block; margin: 14px 0 8px; font-weight: 600; color: #666b82; }
textarea {
  width: 100%;
  height: 120px;
  border: 2px solid #f1c7e2;
  border-radius: 14px;
  padding: 12px;
  font-size: 16px;
}
.counter { text-align: right; color: #9196ad; margin-top: 4px; }
.row { display: flex; gap: 10px; margin-top: 12px; }

.image-panel { margin-top: 14px; }
.ref-row { display: flex; justify-content: space-between; align-items: center; }
.upload-box {
  margin-top: 8px;
  border: 2px dashed #f0b9dc;
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  background: rgba(255, 255, 255, .4);
}
.upload-box input { display: none; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.thumbs img { width: 100%; height: 70px; object-fit: cover; border-radius: 8px; }

.hidden { display: none !important; }

/* ===== 顶部工具栏：一排靠左，生成按钮紧邻右侧 ===== */
.toolbar {
  display: inline-grid;
  grid-template-columns: 220px 130px 220px 140px;
  gap: 12px;
  align-items: end;
  justify-content: start;
}

.toolbar > div {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.toolbar p { margin: 0 0 6px; font-weight: 600; }

.num-group { display: flex; gap: 6px; }
.num-group button {
  border: 1px solid #d9ced8;
  background: #efeef0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.num-group .active {
  background: linear-gradient(90deg, #ff8731, #ff57b6);
  color: #fff;
  border: none;
}

select {
  width: 100%;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #d8d8de;
  background: #f4f4f6;
}

.quality-group { display: flex; gap: 8px; }
.quality-group button {
  border: 1px solid #d8dbe4;
  background: #fff;
  color: #4a4f5c;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s ease;
}
.quality-group button.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(90deg, #7b4dff, #ff5ca8);
  box-shadow: 0 6px 16px rgba(123, 77, 255, .25);
}

.toolbar .gen-wrap {
  margin: 0;
  align-self: end;
  text-align: initial !important;
}
.toolbar .gen-wrap .btn { width: 100%; }

.result-head { display: flex; justify-content: space-between; align-items: center; }
.result h2 { margin: 0; color: #c950ea; }
#status { color: #666c87; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  min-height: 240px;
}
.result-grid img { width: 100%; border-radius: 12px; cursor: zoom-in; }

.samples {
  margin-top: 16px;
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

.samples-grid.one-line {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 175px;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  padding-bottom: 4px;
  font-size: .875rem;
  text-align: center;
}
.sample-item img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: grid;
  place-items: center;
  z-index: 310;
}
.panel {
  width: min(520px, 92vw);
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  z-index: 370;
}
.panel input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  margin-bottom: 10px;
}
.test-msg { margin: 8px 0 0; font-size: 14px; color: #333; }
.test-msg.ok { color: #13a165; }
.test-msg.err { color: #d43b3b; }

.preview { width: min(1000px, 94vw); position: relative; }
.preview img { width: 100%; max-height: 90vh; object-fit: contain; border-radius: 12px; }
#btn-close-preview {
  position: absolute;
  top: 8px; right: 8px;
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  cursor: pointer;
}

/* 历史记录 */
.history-wrap {
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 10px 12px;
}
.history-wrap #history-list {
  margin: 0;
  padding-left: 18px;
  max-height: 220px;
  overflow: auto;
}
.history-wrap #history-list li,
.history-item {
  margin: 6px 0;
  color: #3f3f56;
  cursor: pointer;
  line-height: 1.45;
  word-break: break-word;
  font-size: .875rem;
}
.history-wrap #history-list li:hover,
.history-item:hover {
  color: #f1894f;
  text-decoration: underline;
}
.history-empty { color: #aab4c3; margin: 6px 0; }

/* 响应式 */
@media (max-width: 1440px) {
  body {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 1200px) {
  .toolbar {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(180px, 1fr) 120px 210px 140px;
  }
}

@media (max-width: 980px) {
  .grid-main { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
}

/* 右侧卡片内边距一致，避免视觉错位 */
.card.right { padding: 18px; }

/* 工具栏宽度跟随右卡片，保持上下同宽 */
.card.right .toolbar {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(180px,1.2fr) minmax(110px,.7fr) minmax(220px,1.1fr) auto auto;
  gap: 12px;
  align-items: end;
}

/* 每列允许收缩，不把父容器撑宽 */
.card.right .toolbar > div { min-width: 0; }

.card.right .toolbar p {
  margin: 0 0 6px;
  font-weight: 600;
  line-height: 1.2;
}

/* 下拉框和质量区始终不溢出 */
.card.right .toolbar select {
  width: 100%;
  min-width: 0;
}

.card.right .quality-group {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}
.card.right .quality-group button {
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
}

/* 右侧两个按钮固定高度+不换行，基线对齐 */
.card.right .gen-wrap .btn,
.card.right .history-wrap-btn .btn {
  height: 40px;
  padding: 0 14px;
  white-space: nowrap;
}

/* 结果区域与工具栏拉齐 */
.card.right .result { margin-top: 14px; }
.card.right .result-head { margin: 0 0 10px; }

/* 中等屏：按钮可能拥挤时，改为两行但总宽仍一致 */
@media (max-width: 1280px) {
  .card.right .toolbar {
    grid-template-columns: minmax(180px,1fr) minmax(110px,.8fr) minmax(200px,1fr) auto;
  }
  .card.right .history-wrap-btn { grid-column: 4; }
}

/* 小屏：两列布局 */
@media (max-width: 900px) {
  .card.right .toolbar { grid-template-columns: 1fr 1fr; }
}

.dropzone { cursor: pointer; }
.dropzone.is-dragover {
  border-color: #7c5cff;
  background: rgba(124, 92, 255, 0.08);
}
#image-panel .upload-box.is-dragover {
  border-color: #7c5cff;
  background: rgba(124, 92, 255, 0.08);
}

.action-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-generate,
.btn-history {
  min-width: 108px;
  height: 36px;
  padding: 0 14px;
  white-space: nowrap;
}

/* ===== Header (clean version) ===== */
.topbar {
  min-height: 72px;
  background: linear-gradient(135deg, #ffebf5, #ece6fb);
  border: 1px solid #d9dae6;
  border-bottom: 1px solid rgba(236, 72, 153, 0.2);
  border-radius: 0 0 14px 14px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;

  padding: 10px 16px;
  margin: -18px 0px 16px;
  width: auto;

  position: relative;
  z-index: 300;
  overflow: visible;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 0 1 auto;
}
.brand h1 {
  margin: 0;
  color: #d65adf;
  line-height: 1.05;
}
.brand p {
  margin: 0;
  font-size: 12px;
  color: #5c6077;
  line-height: 1.2;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  flex: 1 1 420px;
  min-width: 0;
  overflow: visible;
}

.nav-item {
  position: relative;
  overflow: visible;
}

.top-nav .nav-link,
.top-nav .nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid #d6d9e3;
  background: #f2f3f7;
  color: #303546;
  font-size: 14px;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.top-nav .nav-btn {
  appearance: none;
  -webkit-appearance: none;
}
.top-nav .nav-link:hover,
.top-nav .nav-btn:hover {
  background: #e9ecf5;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 190px;
  padding: 8px;
  margin-top: 0;
  border: 1px solid #dcdfea;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(34, 42, 73, 0.14);
  display: none;
  z-index: 2000;
}
.dropdown-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: #2f3445;
  text-decoration: none;
  font-size: 14px;
}
.dropdown-menu a:hover {
  background: #f2f5ff;
  color: #4f46e5;
}

.has-dropdown:hover .dropdown-menu,
.has-dropdown:focus-within .dropdown-menu,
.has-dropdown.open .dropdown-menu {
  display: block;
}

.nav-item.has-dropdown::after {
  content: "";
  position: absolute;
  left: 0;
  top: 100%;
  width: 100%;
  height: 10px;
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

@media (max-width: 1024px) {
  .topbar { align-items: flex-start; }

  .brand { flex: 1 1 100%; }

  .top-nav {
    order: 3;
    flex: 1 1 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .top-actions {
    order: 2;
    margin-left: 0;
  }
}

@media (max-width: 768px) {
  .topbar {
    padding: 10px 12px;
    gap: 10px;
    margin: -18px -18px 12px;
    border-radius: 0 0 12px 12px;
  }

  .brand { flex: 1 1 auto; }

  .brand h1 { font-size: clamp(24px, 6vw, 32px); }

  .top-actions { margin-left: auto; }

  .top-nav {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    gap: 8px;
  }

  .has-dropdown,
  .top-nav .nav-link {
    width: 100%;
  }

  .has-dropdown .nav-btn {
    width: 100%;
    justify-content: flex-start;
  }

  .top-nav .nav-link {
    height: 34px;
    justify-content: flex-start;
    padding: 0 12px;
    font-size: 13px;
  }

  .dropdown-menu {
    position: static;
    width: 100%;
    min-width: 0;
    margin-top: 6px;
    box-shadow: none;
    border-radius: 10px;
    z-index: 1;
  }

  .nav-item.has-dropdown::after { display: none; }
}

/* 防止内容层盖住导航 */
.grid-main,
.card,
.toolbar,
.result,
.samples {
  position: relative;
  z-index: 1;
}