:root {
  --bg: #FFF6F1;
  --panel: #FFFFFF;
  --ink: #27130D;
  --muted: #9A8578;
  --line: #F2E0D3;
  --accent: #FF2E4D;
  --accent-deep: #C81B36;
  --accent-soft: #FFF0EE;
  --yellow: #FFD84D;
  --radius: 20px;
  --shadow-hard: 0 5px 0;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html { touch-action: manipulation; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.page-pad {
  padding-left: max(16px, var(--safe-area-inset-left, env(safe-area-inset-left, 0px)));
  padding-right: max(16px, var(--safe-area-inset-right, env(safe-area-inset-right, 0px)));
}

.masthead {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 1020px;
  margin: 0 auto;
  padding: 22px 16px 16px;
  padding-top: calc(22px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
}

.logo {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: var(--shadow-hard) var(--line);
  flex: none;
}

.masthead h1 {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.tagline {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.tagline mark {
  background: linear-gradient(transparent 58%, var(--yellow) 58%, var(--yellow) 94%, transparent 94%);
  color: var(--ink);
  padding: 0 2px;
}

.app {
  max-width: 1020px;
  margin: 0 auto;
  padding: 0 16px 32px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.col { display: grid; gap: 16px; align-content: start; min-width: 0; }

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
}

.step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.step-chip {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--ink);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  transform: rotate(-4deg);
  box-shadow: 0 3px 0 rgba(39, 19, 13, 0.18);
}

.chip-accent {
  background: var(--accent);
  box-shadow: 0 3px 0 var(--accent-deep);
}

.step-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin: 6px 0 14px 44px;
}

.dropzone {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
  padding: 26px 16px;
  border: 2.5px dashed #E8CBB8;
  border-radius: 16px;
  background: #FFFBF8;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.dropzone:active { transform: scale(0.99); }

.dropzone.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.dropzone.is-drag .dz-main { color: var(--accent); }

.dz-main {
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  margin-top: 4px;
}

.dz-sub { font-size: 12px; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--line);
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
    linear-gradient(45deg, #eee 25%, #fafafa 25%, #fafafa 75%, #eee 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  touch-action: none;
  cursor: grab;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.thumb.is-dragging {
  opacity: 0.85;
  cursor: grabbing;
  box-shadow: 0 0 0 3px var(--accent), 0 10px 24px rgba(39, 19, 13, 0.25);
  z-index: 5;
}

.thumb.is-target { box-shadow: 0 0 0 3px var(--yellow); }

.thumb-idx {
  position: absolute;
  left: 6px;
  bottom: 6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 7px;
  background: rgba(39, 19, 13, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.thumb-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  height: 20px;
  padding: 0 6px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.5px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.thumb-del {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(39, 19, 13, 0.72);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.thumb-del:active { background: var(--accent); }

.thumb-cap {
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(39, 19, 13, 0.72);
  color: #fff;
  font-size: 12.5px;
  font-weight: 900;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 1;
}

.thumb-cap:active { background: #E50113; }

.thumb-captag {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #E50113;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  padding: 4px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  pointer-events: none;
}

.cap-preview {
  display: block;
  width: 100%;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: #fff;
}

.cap-input {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  background: #fff;
  color: inherit;
}

.cap-input:focus {
  outline: none;
  border-color: #E50113;
}

.pick-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  min-height: 32px;
}

.count-label { font-size: 13px; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }

.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  padding: 8px;
}

.ctrl-block { margin-bottom: 14px; }

.layout-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.layout-chip {
  border: 2px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 5px;
  width: 52px;
  height: 52px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.layout-chip:active { transform: scale(0.94); }

.layout-chip.is-active {
  border-color: var(--accent);
  background: #FFF0F2;
}

.layout-mini {
  width: 32px;
  height: 32px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lm-row {
  flex: 1;
  display: flex;
  gap: 3px;
  min-height: 0;
}

.lm-cell {
  flex: 1;
  min-width: 0;
  border-radius: 3px;
  background: rgba(39, 19, 13, 0.22);
}

.layout-chip.is-active .lm-cell { background: var(--accent); }

.fine-tune {
  margin-top: 12px;
  border: 2px solid var(--line);
  border-radius: 13px;
  background: #FDF8F3;
}

.fine-tune summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fine-tune summary::-webkit-details-marker { display: none; }

.fine-tune summary::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2.5px solid var(--muted);
  border-bottom: 2.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  margin-right: 2px;
}

.fine-tune[open] summary::after { transform: rotate(225deg); }

.fine-tune-body { padding: 0 12px 12px; }

.fine-tune-body .ctrl-row { margin-top: 4px; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: #F7ECE3;
  border-radius: 13px;
  padding: 4px;
}

.seg-btn {
  border: 0;
  border-radius: 10px;
  background: transparent;
  padding: 10px 0;
  font-size: 14.5px;
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(39, 19, 13, 0.12);
}

.seg-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.ctrl-row {
  display: grid;
  grid-template-columns: 52px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.ctrl-label { font-size: 13.5px; font-weight: 800; }

.ctrl-out {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

.bg-row { grid-template-columns: 52px 1fr; }

.fit-row { grid-template-columns: 52px 1fr; }

.bg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bg-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 7px 13px 7px 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.bg-chip.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 46, 77, 0.18);
}

.swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(39, 19, 13, 0.15);
  flex: none;
}

.swatch-checker {
  background:
    linear-gradient(45deg, #c9c9c9 25%, transparent 25%, transparent 75%, #c9c9c9 75%),
    linear-gradient(45deg, #c9c9c9 25%, #fff 25%, #fff 75%, #c9c9c9 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
}

#bgColor {
  position: absolute;
  inset: 0;
  opacity: 0;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.preview-panel { display: grid; gap: 14px; }

.preview-panel .step { margin-bottom: 0; }

.preview-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--line);
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
    linear-gradient(45deg, #eee 25%, #fafafa 25%, #fafafa 75%, #eee 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

#preview {
  display: block;
  width: 100%;
  height: auto;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel);
}

.pe-icon { color: #D8C3B4; }

.preview-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  justify-items: center;
  background: rgba(255, 251, 248, 0.82);
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3.5px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.format-note, .privacy {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.action-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.btn {
  border: 2px solid transparent;
  border-radius: 15px;
  font-family: inherit;
  font-size: 16.5px;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 14px 18px;
  min-height: 52px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-hard) var(--accent-deep);
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--accent-deep);
}

.btn-ghost {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow-hard) var(--line);
}

.btn-ghost:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--line);
}

.btn[disabled] { opacity: 0.55; pointer-events: none; }

.web-only.xhs-only { display: none; }

body.env-xhs .web-only { display: none; }
body.env-web .xhs-only { display: none; }

.foot {
  text-align: center;
  font-size: 11.5px;
  color: #C4AE9F;
  padding: 0 16px 28px;
  padding-bottom: calc(28px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
}

.toast {
  position: fixed;
  top: calc(14px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
  left: 50%;
  transform: translateX(-50%) translateY(-160%);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border-radius: 999px;
  padding: 10px 20px;
  box-shadow: 0 8px 24px rgba(39, 19, 13, 0.3);
  max-width: min(86vw, 420px);
  text-align: center;
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  z-index: 60;
  pointer-events: none;
}

.toast.is-visible { transform: translateX(-50%) translateY(0); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(31, 15, 9, 0.58);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  padding-top: max(20px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
  padding-bottom: max(20px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  z-index: 50;
}

.modal-card {
  background: var(--panel);
  border-radius: 22px;
  padding: 16px;
  width: min(92vw, 400px);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  gap: 12px;
}

.modal-title { font-size: 17px; font-weight: 900; text-align: center; }

.modal-img-wrap {
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--line);
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
    linear-gradient(45deg, #eee 25%, #fafafa 25%, #fafafa 75%, #eee 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}

.modal-img-wrap img { display: block; width: 100%; }

.modal-hint { font-size: 12px; color: var(--muted); text-align: center; }

.modal-actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }

.modal-actions .btn { font-size: 14.5px; padding: 11px 8px; min-height: 46px; }

.modal-close { width: 100%; }

:focus-visible {
  outline: 3px solid rgba(255, 46, 77, 0.5);
  outline-offset: 2px;
}

@media (min-width: 980px) {
  .app { grid-template-columns: minmax(0, 1.06fr) minmax(0, 0.94fr); align-items: start; }
  .col-right { position: sticky; top: 18px; }
  .masthead { padding-top: 34px; }
  .masthead h1 { font-size: 30px; }
  .panel { padding: 22px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
