:root {
  --bg: #f3efe6;
  --ink: #172017;
  --muted: #6b756c;
  --line: #d8d2c4;
  --panel: #fffdf8;
  --wx: #07c160;
  --wx-dark: #059a4c;
  --danger: #d84a4a;
  --shadow: 0 18px 50px rgba(42, 51, 38, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(7, 193, 96, 0.16), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(214, 176, 90, 0.18), transparent 46%),
    var(--bg);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

.brand { display: flex; gap: 14px; align-items: center; }
.brand h1 { margin: 0; font-size: 30px; letter-spacing: 0.04em; }
.brand-kicker {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, #19d36e 0 50%, transparent 50% 100%),
    linear-gradient(315deg, #0a8f4a 0 50%, #d6b05a 50% 100%);
  box-shadow: 6px 6px 0 #12351c22;
  position: relative;
}
.brand.mini .brand-mark { width: 28px; height: 28px; border-radius: 9px; box-shadow: none; flex: none; }
.brand.mini strong { font-size: 16px; }
.brand-text { display: flex; flex-direction: column; gap: 1px; line-height: 1.15; }
.brand-text em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 16px;
  transition: 0.15s transform, 0.15s background;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
  background: var(--wx);
  border-color: var(--wx);
  color: #fff;
  font-weight: 650;
}
.btn.primary:disabled,
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 6px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.editor-topbar {
  height: 52px;
  padding: 0 16px 0 14px;
  background: #fffdf8;
  flex: none;
}
.topbar-meta { display: flex; align-items: center; gap: 10px; }
.editor-topbar .topbar-meta { gap: 8px; }
.pill {
  background: #e8f8ee;
  color: #0b7a3e;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}
.editor-topbar .pill {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
}
.card-code {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 13px;
}
.editor-topbar .card-code {
  background: #f4f1e8;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 11px;
  letter-spacing: 0.06em;
}
.editor-topbar .btn {
  padding: 6px 12px;
  border-radius: 10px;
  height: 32px;
}

.page-login { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid #efe8d8;
  border-radius: 28px;
  padding: 36px 36px 28px;
  box-shadow: var(--shadow);
}
.login-lead { color: var(--muted); line-height: 1.7; }
.login-form { display: grid; gap: 8px; margin-top: 8px; }
.login-form label { font-size: 13px; color: var(--muted); }
.login-form input {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  letter-spacing: 0.14em;
  background: #fff;
}
.login-form button {
  margin-top: 8px;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--wx);
  color: #fff;
  font-weight: 700;
}
.form-msg { min-height: 22px; color: var(--danger); font-size: 13px; margin: 0; }
.login-steps {
  margin: 8px 0 0;
  padding: 16px 0 0 18px;
  color: var(--muted);
  line-height: 1.8;
  border-top: 1px dashed var(--line);
}

.page-editor {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #ece8de;
}
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  flex: 1;
  min-height: 0;
}
.canvas-col {
  padding: 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #ece8de;
}
.stage-shell {
  flex: 1;
  min-height: 0;
  background: #ece8de;
  border-radius: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}
.stage-shell > * {
  grid-area: 1 / 1;
}
.stage-empty {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
  color: #6b756c;
  text-align: center;
  cursor: pointer;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #ece8de;
}
.stage-empty[hidden],
.stage[hidden],
.stage-shell.has-image .stage-empty {
  display: none !important;
}
.stage-empty p { margin: 0 0 6px; font-size: 18px; }
.stage-empty span { color: #8b988d; font-size: 13px; }
.stage {
  position: relative;
  margin: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  line-height: 0;
  flex: none;
}
.stage:not([hidden]) {
  display: block;
}
.stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  border-radius: 0;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
}
.stage #overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.avatar-box {
  position: absolute;
  border: 1.5px dashed #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.45);
  background: rgba(255, 255, 255, 0.06);
  pointer-events: auto;
  cursor: grab;
  border-radius: 3px;
  touch-action: none;
}
.avatar-box:hover { border-color: #ffe082; }
.avatar-box.is-drag { cursor: grabbing; border-color: #ffd54f; z-index: 3; }
.avatar-box-del {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: #d84a4a;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  padding: 0;
  cursor: pointer;
}
.hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 6;
  margin: 0;
  color: #fff;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(23, 32, 23, 0.72);
  pointer-events: none;
}

.side {
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; }
.step header { display: flex; align-items: baseline; gap: 10px; }
.step header span {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--wx-dark);
}
.step h2 { margin: 0; font-size: 16px; }
.step p { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.drop, .avatar-pick {
  margin-top: 10px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed #b9c3b6;
  border-radius: 16px;
  padding: 16px;
  background: #f7f4ec;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 3;
  cursor: pointer;
  font-size: 64px;
}
.drop strong { font-size: 14px; }
.drop em { color: var(--muted); font-style: normal; font-size: 12px; }
.drop.drag { border-color: var(--wx); background: #eefbf3; }
.stat {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}
.size-ctrl { display: flex; align-items: center; gap: 6px; }
.size-ctrl button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}
.avatar-pick { min-height: 110px; }
.avatar-pick img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 16px;
}
.avatar-pick span { color: var(--muted); font-size: 13px; line-height: 1.6; }
.side-actions { display: grid; gap: 8px; margin-top: auto; }
.side-actions .btn { width: 100%; height: 44px; }

.admin { padding: 22px; display: grid; gap: 18px; }
.panel {
  background: var(--panel);
  border: 1px solid #efe8d8;
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.panel h1 { margin: 0 0 16px; font-size: 20px; }
.gen-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}
.gen-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.gen-form input, .gen-form select {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
  background: #fff;
}
.gen-form .grow { flex: 1; min-width: 200px; }
.new-codes {
  margin-top: 16px;
  border-top: 1px dashed var(--line);
  padding-top: 14px;
}
.new-codes header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.new-codes textarea {
  width: 100%;
  min-height: 110px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 10px;
  letter-spacing: 0.08em;
  resize: vertical;
}
.panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}
.filters button.on { background: #12351c; color: #fff; border-color: #12351c; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 8px; border-bottom: 1px solid #efe8d8; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td code { letter-spacing: 0.06em; }
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}
.badge.unused { background: #eef2ff; color: #3b4cca; }
.badge.active { background: #e8f8ee; color: #0b7a3e; }
.badge.expired { background: #f4f1e8; color: #8a7a4a; }
.badge.disabled { background: #fdeeee; color: #b42318; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px !important; }
.row-actions { display: flex; gap: 6px; }

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #111;
  color: #fff;
}
.crop-modal[hidden] { display: none !important; }
.crop-bar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: #1a1a1a;
  flex: none;
}
.crop-bar h2 { margin: 0; font-size: 16px; font-weight: 650; }
.crop-text-btn {
  border: 0;
  background: transparent;
  color: #eee;
  padding: 8px 10px;
  font-size: 15px;
}
.crop-text-btn.save { color: #ff4d4f; font-weight: 700; }
.crop-tip {
  margin: 0;
  padding: 8px 14px 10px;
  font-size: 12px;
  line-height: 1.55;
  color: #d8d8d8;
  background: #1a1a1a;
}
.crop-viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background: #0d0d0d;
  cursor: grab;
}
.crop-viewport.is-drag { cursor: grabbing; }
.crop-viewport #cropShot {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.crop-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 180px;
  height: 180px;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
.crop-frame.circle { border-radius: 50%; }
.crop-frame img {
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: 50% 50%;
}
.crop-fab {
  position: absolute;
  z-index: 3;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: #222;
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.crop-fab.zoom-out { top: 16px; left: 50%; margin-left: -52px; }
.crop-fab.zoom-in { top: 16px; left: 50%; margin-left: 8px; }
.crop-fab.nudge-up { top: 50%; left: 50%; margin: -150px 0 0 -22px; }
.crop-fab.nudge-down { top: 50%; left: 50%; margin: 106px 0 0 -22px; }
.crop-fab.nudge-left { top: 50%; left: 50%; margin: -22px 0 0 -150px; }
.crop-fab.nudge-right { top: 50%; left: 50%; margin: -22px 0 0 106px; }
.crop-foot {
  flex: none;
  padding: 12px 14px 16px;
  background: #1a1a1a;
}
.crop-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}
.shape-btn {
  border: 1px solid #555;
  background: transparent;
  color: #ddd;
  border-radius: 8px;
  padding: 6px 10px;
}
.shape-btn.on { border-color: #ff4d4f; color: #ff4d4f; }
.radius-ctrl { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.radius-ctrl button {
  width: 28px;
  height: 28px;
  border: 1px solid #555;
  background: #2a2a2a;
  color: #fff;
  border-radius: 6px;
}
.radius-ctrl input {
  width: 52px;
  height: 28px;
  text-align: center;
  border: 1px solid #555;
  background: #111;
  color: #fff;
  border-radius: 6px;
}

@media (max-width: 960px) {
  .page-editor { height: auto; min-height: 100vh; overflow: auto; }
  .editor {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(50vh, 1fr) auto;
  }
  .canvas-col { min-height: 50vh; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .editor-topbar .brand-text em,
  .editor-topbar .card-code { display: none; }
  .hint {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 16px;
    z-index: 40;
  }
}
