:root {
  --bg: #11161b;
  --panel: #1e242b;
  --panel-2: #262d35;
  --line: rgba(255, 255, 255, .10);
  --text: #f4f0e8;
  --muted: #aeb8c2;
  --blue: #86b7ff;
  --green: #35b466;
  --danger: #ff8b82;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(134,183,255,.13), rgba(17,22,27,0) 280px),
    var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

button, input, textarea {
  font: inherit;
}

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px 28px;
}

.card {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(30, 36, 43, .94);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-weight: 900;
  color: #dce8ff;
}

.section-title small {
  color: var(--muted);
  font-weight: 600;
}

.auth-title {
  cursor: pointer;
  margin-bottom: 0;
}

.auth-card.open .auth-title {
  margin-bottom: 12px;
}

.auth-card.needs-recharge {
  border-color: rgba(255, 139, 130, .42);
  background: rgba(49, 28, 31, .88);
}

.auth-body.collapsed {
  display: none;
}

.auth-actions-row {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

.auth-fold-btn {
  min-height: 46px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(53, 180, 102, .16);
  color: var(--green);
  font-size: 28px;
  line-height: 1;
}

.auth-card.compact-auth .auth-actions-row {
  display: none;
}

.auth-card.compact-auth {
  width: 100%;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
  border-color: rgba(134, 183, 255, .34);
  background: rgba(30, 36, 43, .88);
}

.auth-card.compact-auth .auth-title {
  width: 48px;
  min-height: 48px;
  display: grid;
  place-items: center;
  gap: 0;
  margin: 0;
  padding: 0;
}

.auth-card.compact-auth .auth-title span {
  font-size: 0;
}

.auth-card.compact-auth .auth-title span::before {
  content: "☰";
  font-size: 20px;
  line-height: 1;
  color: var(--blue);
}

.auth-card.compact-auth .auth-title small {
  display: none;
}

.config-toggle-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(54px, .5fr);
  gap: 8px;
}

.config-toggle-row .reference-title,
.config-toggle-row .prompt-title,
.config-toggle-row .advanced-toggle {
  position: relative;
  width: 100%;
  min-height: 44px;
  display: block;
  margin: 0;
  padding: 0 22px 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(134, 183, 255, .06);
  color: #dce8ff;
  text-align: left;
}

.config-toggle-row .reference-title[aria-expanded="true"],
.config-toggle-row .prompt-title[aria-expanded="true"] {
  margin-bottom: 0;
}

.config-toggle-row .reference-title span,
.config-toggle-row .prompt-title span,
.config-toggle-row .advanced-toggle span {
  display: block;
  overflow: hidden;
  color: #dce8ff;
  font-size: 14px;
  font-weight: 900;
  line-height: 44px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.config-toggle-row .advanced-toggle {
  padding: 0 20px 0 8px;
}

.config-toggle-row .advanced-toggle span {
  text-align: center;
}

.config-toggle-row .reference-title small,
.config-toggle-row .prompt-title small,
.config-toggle-row .advanced-toggle small {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.config-toggle-row .reference-title::after,
.config-toggle-row .prompt-title::after,
.config-toggle-row .advanced-toggle::after {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%) rotate(90deg);
}

.config-toggle-row .reference-title[aria-expanded="true"]::after,
.config-toggle-row .prompt-title[aria-expanded="true"]::after,
.config-toggle-row .advanced-toggle[aria-expanded="true"]::after {
  transform: translateY(-50%) rotate(-90deg);
}

.config-card .reference-body,
.config-card .prompt-body,
.config-card .advanced-body {
  margin-top: 12px;
}

.contact-tip {
  display: none;
}

.auth-card.compact-auth .contact-tip {
  display: block;
  color: #dce8ff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}

.edit-title,
.history-title {
  cursor: pointer;
  margin-bottom: 0;
}

.edit-title > span,
.history-title > span {
  position: relative;
  padding-right: 22px;
}

.edit-title > span::after,
.history-title > span::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid var(--blue);
  transform: translateY(-35%);
}

.edit-title[aria-expanded="true"] > span::after,
.history-title[aria-expanded="true"] > span::after {
  border-top: 0;
  border-bottom: 7px solid var(--blue);
  transform: translateY(-55%);
}

.history-card.open .history-title {
  margin-bottom: 12px;
}

.history-list.collapsed {
  display: none;
}

.edit-card.open .edit-title {
  margin-bottom: 12px;
}

.edit-body.collapsed {
  display: none;
}

.reference-title,
.prompt-title {
  width: 100%;
  margin-bottom: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #dce8ff;
  cursor: pointer;
  text-align: left;
}

.reference-title[aria-expanded="true"],
.prompt-title[aria-expanded="true"] {
  margin-bottom: 12px;
}

.reference-title small,
.prompt-title small {
  color: var(--blue);
  font-weight: 700;
}

.reference-title::after,
.prompt-title::after {
  content: "›";
  color: var(--blue);
  font-size: 22px;
  line-height: 1;
  transform: rotate(90deg);
}

.reference-title[aria-expanded="true"]::after,
.prompt-title[aria-expanded="true"]::after {
  transform: rotate(-90deg);
}

.prompt-body.collapsed {
  display: none;
}

.style-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.style-chip {
  width: auto;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid rgba(134, 183, 255, .30);
  border-radius: 6px;
  background: rgba(134, 183, 255, .08);
  color: #dce8ff;
  font-size: 12px;
  font-weight: 700;
}

.style-chip.active {
  border-color: rgba(134, 183, 255, .82);
  background: var(--blue);
  color: #101820;
}

.reference-body.collapsed {
  display: none;
}

.reference-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 94px;
  gap: 10px;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}

input {
  height: 46px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  line-height: 1.6;
  resize: vertical;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 7px;
  background: #4c5663;
  color: var(--text);
  font-weight: 900;
}

button:disabled {
  opacity: .45;
}

.primary-btn {
  width: 100%;
  color: #07140c;
  background: var(--green);
}

.config-card #renderBtn {
  margin-top: 12px;
}

.buy-code-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0 54px;
  margin-top: 0;
  border-radius: 7px;
}

.buy-code-btn .btn-arrow {
  position: absolute;
  right: 18px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(7, 20, 12, .16);
  color: #07140c;
  font-size: 18px;
  line-height: 1;
}

.secondary-btn {
  width: 100%;
  margin-top: 12px;
  color: var(--text);
  background: #4c5663;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.text-btn {
  min-height: 0;
  padding: 5px 0;
  background: transparent;
  color: var(--blue);
  font-size: 14px;
}

.text-btn:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: .55;
}

.hint, .status {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.pay-hint {
  color: #c9d6ef;
}

.status {
  min-height: 24px;
}

.file-input-hidden {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.upload-box {
  min-height: 190px;
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 20px 16px;
  border: 1px dashed rgba(134, 183, 255, .45);
  border-radius: 8px;
  background: rgba(134, 183, 255, .08);
  text-align: center;
}

.upload-icon {
  margin-top: 8px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--blue);
  color: #101820;
  font-size: 28px;
  font-weight: 900;
}

/* 上传框主视觉：主标题 + 副标题 */
.upload-lead {
  max-width: 100%;
  color: var(--text);
  font-size: 27px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 1px;
}

.upload-sub {
  max-width: 100%;
  margin-top: -4px;
  color: #c9d6ef;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 3px;
  text-indent: 3px;
}

.upload-desc {
  max-width: 100%;
  color: #c9d6ef;
  font-size: 14px;
  line-height: 1.55;
}

.upload-box small {
  color: var(--muted);
}

.compact-upload {
  min-height: 78px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 14px;
  border: 1px dashed rgba(134, 183, 255, .38);
  border-radius: 8px;
  background: rgba(134, 183, 255, .06);
  color: var(--text);
}

.compact-upload input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.compact-upload span {
  font-weight: 900;
}

.compact-upload small {
  color: var(--muted);
}

.reference-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.local-ref-panel {
  margin-top: 12px;
}

.mini-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #dce8ff;
  font-weight: 900;
  font-size: 14px;
}

.local-ref-upload {
  min-height: 70px;
}

.local-reference-list {
  grid-template-columns: repeat(3, 1fr);
}

.local-reference-list .hint {
  grid-column: 1 / -1;
  white-space: nowrap;
}

.annotation-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.annotation-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.annotation-ref-upload {
  min-height: 70px;
  margin-top: 10px;
  border-color: rgba(255, 139, 130, .42);
  background: rgba(255, 139, 130, .08);
}

.annotation-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.annotation-list button {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(134, 183, 255, .06);
  color: #dce8ff;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.annotation-list button.active {
  border-color: rgba(255, 139, 130, .72);
  background: rgba(255, 139, 130, .14);
  color: #fff;
}

.reference-item {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #151a1f;
}

.reference-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.reference-item button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  min-height: 24px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  font-size: 15px;
  line-height: 1;
}

.preview-wrap {
  position: relative;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c1014;
}

.annotation-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: auto;
}

.annotation-box {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: move;
  touch-action: none;
  user-select: none;
  pointer-events: none;
}

.annotation-shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.annotation-shape polygon {
  fill: rgba(255, 59, 48, .12);
  stroke: #ff3b30;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: visiblePainted;
}

.annotation-box span {
  position: absolute;
  transform: translate(4px, 4px);
  z-index: 2;
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  background: #ff3b30;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  pointer-events: auto;
  cursor: pointer;
}

.annotation-box .handle {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  background: #ff3b30;
  pointer-events: auto;
}

.annotation-box.selected .annotation-shape polygon {
  fill: rgba(255, 59, 48, .18);
  stroke-width: 1.4;
}

.preview-wrap img,
.result-image {
  display: block;
  width: 100%;
  height: auto;
}

.preview-wrap.only-preview {
  margin-top: 0;
}

.reupload-corner {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  width: 58px;
  height: 58px;
  cursor: pointer;
}

.reupload-corner::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-top: 58px solid rgba(134, 183, 255, .96);
  border-left: 58px solid transparent;
}

.reupload-corner::after {
  content: "+";
  position: absolute;
  top: 6px;
  right: 10px;
  color: #101820;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.result-image {
  cursor: pointer;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.grid-2 label,
.range-label {
  color: var(--muted);
  font-size: 13px;
}

.range-label {
  display: block;
  margin-top: 12px;
}

.range-label input {
  height: 34px;
  padding: 0;
}

.advanced-toggle {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: rgba(134, 183, 255, .06);
  color: #dce8ff;
  text-align: left;
}

.advanced-toggle::after {
  content: "›";
  color: var(--blue);
  font-size: 22px;
  line-height: 1;
  transform: rotate(90deg);
}

.advanced-toggle[aria-expanded="true"]::after {
  transform: rotate(-90deg);
}

.advanced-body {
  margin-top: 10px;
}

.advanced-body.collapsed {
  display: none;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  border-radius: 8px;
  color: var(--muted);
  background: #151a1f;
  border: 1px solid var(--line);
}

.edit-stage-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c1014;
  touch-action: none;
}

.edit-stage-wrap:not(.ready) {
  display: none;
}

.edit-stage-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

#maskCanvas {
  position: absolute;
  inset: 0;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.tool-btn {
  min-height: 42px;
  font-size: 14px;
}

.tool-btn.active {
  background: var(--blue);
  color: #101820;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.history-item {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #151a1f;
}

.history-item.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(134, 183, 255, .24);
}

.history-item.selected::after {
  content: "已选";
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(134, 183, 255, .92);
  color: #101820;
  font-size: 12px;
  font-weight: 900;
}

.history-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.edit-source-panel {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid rgba(134, 183, 255, .34);
  border-radius: 8px;
  background: rgba(134, 183, 255, .08);
}

.edit-source-panel img {
  width: 76px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 7px;
  background: #151a1f;
}

.edit-source-info {
  display: grid;
  gap: 4px;
}

.edit-source-info strong {
  color: #dce8ff;
}

.edit-source-info span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.edit-source-panel .secondary-btn {
  grid-column: 1 / -1;
  margin-top: 0;
  background: var(--blue);
  color: #101820;
}

.hidden { display: none !important; }

@media (max-width: 360px) {
  .input-row { grid-template-columns: 1fr; }
}
