:root {
  --blue: #0078d4;
  --blue-hover: #106ebe;
  --blue-disabled: #bfd6f3;
  --text: #242424;
  --text-2: #666;
  --text-3: #767676;
  --border: #e6e6e6;
  --border-2: #dfe1e5;
  --hover: #f3f3f3;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .07);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #fff;
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ================= 登录闸门 ================= */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #e8f2fd 0%, #ffffff 55%, #f7f9fc 100%);
  z-index: 50;
}

.gate-card {
  width: 380px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .10);
  padding: 40px 36px 28px;
  text-align: center;
}

.gate-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.gate-title { font-size: 26px; font-weight: 600; margin: 0 0 6px; letter-spacing: -.2px; }
.gate-sub { color: var(--text-2); font-size: 13px; margin: 0 0 24px; line-height: 1.6; }
.gate-input-wrap { margin-bottom: 12px; }

.gate input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 0 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fff;
}
.gate input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 120, 212, .12); }

.gate-btn {
  width: 100%;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.gate-btn:hover { background: var(--blue-hover); }
.gate-btn:disabled { background: var(--blue-disabled); cursor: default; }

.gate-error { color: #c42b1c; font-size: 12.5px; min-height: 18px; margin: 10px 0 0; }
.gate-foot { color: #9b9b9b; font-size: 11.5px; margin: 18px 0 0; }

/* ================= 顶栏（极简） ================= */
.appbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid #ededed;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-b { font-size: 26px; font-weight: 700; color: var(--blue); line-height: 1; letter-spacing: -.5px; }
.brand-name { font-size: 15px; font-weight: 600; color: #333; }

.signout {
  height: 32px;
  padding: 0 14px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.signout:hover { background: var(--hover); }

/* ================= 主体 ================= */
.main { max-width: 860px; margin: 0 auto; padding: 0 24px 80px; }

.hero {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  margin: 40px 0 24px;
  letter-spacing: -.2px;
}

/* ================= 输入卡片 ================= */
.composer {
  position: relative;
  background: #fff;
  border: 1px solid #ececec;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px 14px;
  transition: box-shadow .2s;
}
.composer:focus-within { box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 12px 32px rgba(0,0,0,.10); }

.composer-main { display: flex; }

.prompt {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  padding: 8px 2px 4px;
  min-height: 84px;
  max-height: 260px;
  background: transparent;
}
.prompt::placeholder { color: var(--text-3); }

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.ratio-wrap { position: relative; }

.ratio-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.ratio-btn:hover { background: var(--hover); }

.ratio-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  min-width: 190px;
  background: #fff;
  border: 1px solid #eaeaea;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .16);
  padding: 6px;
  z-index: 20;
}
.ratio-item {
  display: flex;
  width: 100%;
  gap: 6px;
  align-items: center;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.ratio-item span { color: var(--text-2); }
.ratio-item:hover { background: var(--hover); }
.ratio-item.selected { background: #eef5fd; font-weight: 600; }
.ratio-item.selected::after { content: "✓"; margin-left: auto; color: var(--blue); font-weight: 700; }

.generate {
  min-width: 86px;
  height: 40px;
  border: none;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.generate:hover:not(:disabled) { background: var(--blue-hover); }
.generate:disabled { background: var(--blue-disabled); cursor: default; }

/* ================= 生成等待：粒子波场 ================= */
.generating {
  position: relative;
  overflow: hidden;
  border: 1px solid #eef0e7;
  border-radius: 12px;
  background: #fcfdf9;
  opacity: 1;
  transform: translateY(0);
  transition: opacity .26s ease, transform .26s ease;
}
.generating.is-leaving { opacity: 0; transform: translateY(-4px); }

.particle-stage {
  position: relative;
  height: clamp(238px, 37vw, 310px);
  background:
    radial-gradient(ellipse 58% 66% at 50% 44%, rgba(181, 210, 78, .055), transparent 72%),
    linear-gradient(180deg, #fdfdfa 0%, #fbfcf7 100%);
}
#loadingParticles {
  display: block;
  width: 100%;
  height: 100%;
}

.gen-status {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 0 22px 15px;
}
.gen-copy { min-width: 0; }
.gen-stage {
  color: #29331e;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: .01em;
}
.gen-stage::after {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 7px;
  border-radius: 50%;
  background: #adcb47;
  vertical-align: 2px;
  animation: gen-breathe 1.8s ease-in-out infinite;
}
@keyframes gen-breathe { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.gen-note {
  margin-top: 4px;
  color: #8b9380;
  font-size: 11.5px;
  letter-spacing: .015em;
}
.gen-actions { display: flex; align-items: center; gap: 14px; flex: none; }
.gen-percent {
  min-width: 58px;
  color: #53622d;
  font-variant-numeric: tabular-nums;
  font-size: 23px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.04em;
  text-align: right;
}
.pct-sign { margin-left: 1px; color: #8b966e; font-size: 12px; font-weight: 500; letter-spacing: 0; }
.gen-cancel {
  height: 30px;
  padding: 0 11px;
  border: 1px solid #dfe4d3;
  border-radius: 6px;
  background: rgba(255, 255, 255, .7);
  color: #626a59;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.gen-cancel:hover { background: #fff; border-color: #c9d2b8; }
.gen-bar { height: 2px; background: #edf0e5; overflow: hidden; }
.gen-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 0 2px 2px 0;
  background: #aacb43;
  transition: width .35s ease-out;
}

.gen-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 112px;
  padding: 20px 22px;
  border: 1px solid #efdbd7;
  border-radius: 12px;
  background: #fffdfc;
}
.gen-error-main { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.gen-error-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 50%;
  background: #f7e2de;
  color: #a44336;
  font-size: 13px;
  font-weight: 700;
}
.gen-error-title { color: #6d3028; font-size: 14px; font-weight: 600; }
.gen-error-text { margin-top: 4px; color: #81635e; font-size: 12.5px; line-height: 1.55; }
.gen-error-actions { display: flex; gap: 8px; flex: none; }
.gen-retry, .gen-back {
  height: 33px;
  padding: 0 15px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.gen-retry { border: none; background: var(--blue); color: #fff; }
.gen-retry:hover { background: var(--blue-hover); }
.gen-back { border: 1px solid #dedede; background: #fff; color: #555; font-weight: 500; }
.gen-back:hover { background: var(--hover); }

/* ================= 结果 ================= */
.results { margin-top: 30px; animation: results-in .3s ease-out both; }
@keyframes results-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.results-title { font-size: 16px; font-weight: 600; }
.results-meta { font-weight: 400; color: var(--text-2); font-size: 12.5px; margin-left: 8px; }

.ghost-btn {
  height: 34px; padding: 0 14px;
  border: 1px solid #d9d9d9; border-radius: 6px;
  background: #fff; font-family: inherit; font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { background: var(--hover); }

.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.result-tile {
  position: relative; border-radius: 12px; overflow: hidden;
  background: #f3f3f3; aspect-ratio: var(--ar, 3 / 2);
}
.result-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

.result-actions {
  position: absolute; inset: auto 0 0 0;
  display: flex; gap: 8px; justify-content: flex-end; padding: 10px;
  background: linear-gradient(to top, rgba(0,0,0,.45), rgba(0,0,0,0));
  opacity: 0; transition: opacity .15s;
}
.result-tile:hover .result-actions { opacity: 1; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.94); display: grid; place-items: center;
  cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.icon-btn:hover { background: #fff; }

.results-prompt { margin-top: 12px; color: var(--text-2); font-size: 13px; line-height: 1.6; word-break: break-word; }

/* ================= Toast ================= */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 12px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 60; max-width: 80vw;
}

/* ================= 响应式 ================= */
@media (max-width: 720px) {
  .appbar { padding: 0 14px; }
  .main { padding: 0 14px 60px; }
  .hero { font-size: 18px; margin: 24px 0 16px; }
  .composer { padding: 14px 14px 10px; }
  .result-grid { grid-template-columns: 1fr; }

  .particle-stage { height: 238px; }
  .gen-status { padding: 0 15px 14px; gap: 10px; }
  .gen-percent { min-width: 48px; font-size: 20px; }
  .gen-actions { gap: 8px; }
  .gen-cancel { padding: 0 9px; }
  .gen-error { flex-direction: column; align-items: stretch; padding: 16px; gap: 14px; }
  .gen-error-actions { justify-content: flex-end; }
}

@media (max-width: 390px) {
  .gen-note { max-width: 150px; }
  .gen-percent { font-size: 18px; min-width: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .generating { transition: none; }
  .results { animation: none; }
  .gen-stage::after { animation: none; opacity: .7; }
  .gen-bar i { transition: none; }
  .result-actions, .toast { transition: none; }
  html { scroll-behavior: auto; }
}
