: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;
}

.hero {
  padding: 24px 4px 10px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--text);
  color: #17202a;
  font-weight: 900;
}

.brand {
  font-size: 18px;
  font-weight: 900;
}

.sub {
  color: var(--muted);
  font-size: 13px;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.16;
  letter-spacing: 0;
  white-space: nowrap;
}

.hero p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.75;
}

.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 {
  position: fixed;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));
  right: 14px;
  width: auto;
  margin: 0;
  padding: 0;
  border-color: rgba(134, 183, 255, .34);
  background: rgba(30, 36, 43, .88);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .24);
}

.auth-card.compact-auth .auth-title {
  min-height: 42px;
  gap: 8px;
  margin: 0;
  padding: 0 12px;
}

.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 {
  color: #dce8ff;
  font-size: 13px;
}

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

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

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

.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);
}

.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;
}

#useEditBtn {
  display: none !important;
}

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

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

.pay-hint {
  color: #c9d6ef;
}

.status {
  min-height: 24px;
}

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

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

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

.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);
}

.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 {
  margin-top: 12px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c1014;
}

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

.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;
}

.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 {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #151a1f;
}

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

.hidden { display: none !important; }

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