:root {
  --ink: #3d425c;
  --coral: #ff7a59;
  --coral-deep: #e25b3c;
  --cream: #fffdf8;
  --line: #ffd7a8;
  --shadow: #ffc27a;
  --sky: #d7f2ff;
  --mint: #e7f8ee;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: auto;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.9), transparent 28%),
    radial-gradient(circle at 86% 8%, rgba(255, 214, 170, 0.7), transparent 24%),
    linear-gradient(180deg, #d7f4ff 0%, #fff6ea 100%);
}

button, input { font: inherit; color: inherit; }

button {
  border: 3px solid var(--line);
  background: white;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
}

button:hover { transform: translateY(-1px); }

button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--shadow);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

button:focus-visible, input:focus-visible {
  outline: 3px solid #7ec8ff;
  outline-offset: 2px;
}

.back-site {
  align-self: center;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.primary {
  background: var(--coral);
  color: white;
  border-color: #ff6a46;
  box-shadow: 0 4px 0 var(--coral-deep);
}

.danger {
  width: 100%;
  background: #fff1f1;
  border-color: #ffb4b4;
  box-shadow: 0 4px 0 #f3b0b0;
  color: #c44b4b;
}

#app {
  height: 100%;
  min-width: 980px;
  min-height: 640px;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: rgba(255, 253, 248, 0.92);
  border: 3px solid #ffe3bf;
  border-radius: 22px;
  box-shadow: 0 8px 0 rgba(255, 186, 122, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
}

.brand h1 {
  margin: 0;
  font-family: "ZCOOL KuaiLe", "Microsoft YaHei", cursive;
  font-size: 40px;
  line-height: 1;
  font-weight: 400;
  color: #ff6b4a;
  letter-spacing: 1px;
}

.brand p {
  margin: 4px 0 0;
  color: #7b849c;
  font-size: 14px;
}

.logo {
  width: 54px;
  height: 54px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  transform: rotate(-8deg);
}

.logo i {
  display: block;
  border-radius: 6px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.08);
}

.logo i:nth-child(1) { background: #ffd93d; grid-column: 1 / 2; }
.logo i:nth-child(2) { background: #ff8ad4; }
.logo i:nth-child(3) { background: #4d96ff; grid-column: 1 / 3; }

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.layout {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(188px, 248px) minmax(420px, 1fr) minmax(210px, 276px);
  gap: 12px;
}

.panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: rgba(255, 253, 248, 0.94);
  border: 3px solid #ffe3bf;
  border-radius: 22px;
  padding: 14px;
  box-shadow: 0 8px 0 rgba(255, 186, 122, 0.28);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.panel section + section { margin-top: 16px; }

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  border: 3px solid rgba(80, 90, 120, 0.2);
  box-shadow: 0 3px 0 rgba(80, 90, 120, 0.16);
  padding: 0;
}

.swatch.is-on {
  border-color: #ff7a59;
  box-shadow: 0 0 0 3px #ffd3c4, 0 3px 0 rgba(80, 90, 120, 0.16);
}

.patterns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pattern {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 14px;
}

.pattern canvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: white;
}

.pattern span { font-size: 13px; }

.pattern.is-on {
  border-color: #ff7a59;
  background: #fff4ee;
}

.preview-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--mint);
  border-radius: 16px;
  padding: 10px;
}

.preview-box canvas {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  background: white;
  box-shadow: 0 4px 0 rgba(120, 170, 140, 0.25);
}

.preview-kicker {
  margin: 0 0 4px;
  color: #6d8b78;
  font-size: 13px;
}

#brush-label {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tools button.is-on {
  background: #ffe8c7;
  border-color: #ffb15a;
}

#tool-hint {
  margin: 10px 0 0;
  padding: 10px 12px;
  background: #fff6e8;
  border-radius: 12px;
  line-height: 1.5;
}

.stage {
  position: relative;
  min-width: 420px;
  min-height: 320px;
  border-radius: 24px;
  overflow: hidden;
  border: 3px solid #d7efff;
  box-shadow: 0 8px 0 rgba(150, 200, 230, 0.35);
  background: #c5ebff;
}

#view {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

body[data-tool="place"] #view { cursor: crosshair; }
body[data-tool="remove"] #view { cursor: pointer; }

.stage-tip, #empty-hint, .front-btn, #toast {
  position: absolute;
  z-index: 2;
}

.stage-tip, #empty-hint { pointer-events: none; }

.stage-tip {
  left: 14px;
  bottom: 14px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.88);
  color: #607089;
  font-size: 13px;
}

#empty-hint {
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.92);
  font-weight: 700;
}

.front-btn {
  right: 14px;
  bottom: 14px;
  background: #fffdf8;
}

#toast {
  left: 50%;
  top: 16px;
  transform: translate(-50%, -12px);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: #3d425c;
  color: white;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

input {
  width: 100%;
  border: 3px solid #ffe3bf;
  background: white;
  border-radius: 14px;
  padding: 10px 12px;
}

.count {
  margin: 0;
  font-size: 16px;
}

.count strong {
  font-size: 42px;
  line-height: 1;
  color: #ff7a59;
}

#select-label {
  margin: 6px 0 0;
  color: #7b849c;
}

.help {
  margin: 0;
  padding-left: 20px;
  line-height: 1.55;
}

.help li + li { margin-top: 4px; }

.template-list {
  display: grid;
  gap: 8px;
}

.template-list button {
  text-align: left;
  background: #fff8ee;
}

.muted {
  margin: 0;
  color: #8b93a7;
  line-height: 1.5;
}

.work {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 14px;
  background: #fff8ee;
  margin-bottom: 8px;
}

.work.is-active { outline: 3px solid #ffd3a8; }

.work-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.work-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-meta span {
  color: #8b93a7;
  font-size: 12px;
}

.work-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.work-actions button {
  padding: 6px 8px;
  border-radius: 10px;
  box-shadow: 0 3px 0 var(--shadow);
}

.tiny-danger {
  background: #fff1f1;
  border-color: #ffc1c1;
  color: #c44b4b;
  box-shadow: 0 3px 0 #f3b0b0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(80, 96, 120, 0.28);
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-card {
  width: min(420px, 100%);
  background: var(--cream);
  border-radius: 22px;
  border: 3px solid #ffe3bf;
  padding: 22px;
  box-shadow: 0 12px 0 rgba(255, 186, 122, 0.35);
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 26px;
  font-family: "ZCOOL KuaiLe", "Microsoft YaHei", cursive;
  font-weight: 400;
  color: #ff6b4a;
}

.modal-card p {
  margin: 0;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: #fff8ee;
  font-size: 20px;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .brand h1 { font-size: 32px; }
  .layout {
    grid-template-columns: minmax(176px, 220px) minmax(420px, 1fr) minmax(196px, 240px);
  }
}
