* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 1400px;
  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; }

.topbar {
  height: 72px;
  background: linear-gradient(135deg,#ffebf5,#ece6fb);
  border: 1px solid #d9dae6;
  border-radius: 0 0 14px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  margin: -18px -18px 16px;
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  border-bottom: 1px solid rgba(236,72,153,.2);
}

.brand { display: flex; align-items: center; gap: 10px; }
.banana {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #ffb48a, #f6d0ff);
  display: grid; place-items: center;
}
.brand h1 { margin: 0; color: #d65adf; }
.brand p { margin: 0; font-size: 12px; color: #5c6077; }
.top-actions { display: flex; gap: 10px; }

.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: 20;
}
.panel {
  width: min(520px, 92vw);
  background: #fff;
  border-radius: 16px;
  padding: 16px;
}
.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);
}
  /* 顶部布局：在原有基础上支持中间导航区 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap; /* 小屏自动换行，避免挤压 */
}

/* 新增导航区 */
.top-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;                 /* 占据中间弹性空间 */
  min-width: 260px;
  justify-content: center; /* 菜单居中更大方 */
}

/* 导航链接：轻量胶囊风格，贴合你现有按钮体系 */
.top-nav a {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  color: #374151;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid #e5e7eb;
  transition: all .2s ease;
  white-space: nowrap;
}

.top-nav a:hover {
  color: #111827;
  background: #ffffff;
  border-color: #d1d5db;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

.top-nav a:active {
  transform: translateY(1px);
}

/* 当前页高亮（可选：给当前a加 class="active"） */
.top-nav a.active {
  color: #166534;
  background: #ecfdf3;
  border-color: #86efac;
}

/* 保持右侧按钮不被压缩 */
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 响应式：小屏让导航换到下一行并左对齐更好读 */
@media (max-width: 1100px) {
  .top-nav {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .top-nav::-webkit-scrollbar {
    height: 6px;
  }

  .top-nav::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 999px;
  }
}