:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-border: #e6e9f2;
  --text: #2b2f3a;
  --muted: #8a90a2;
  --accent: #6c5ce7;
  --accent-soft: #efeaff;
  --shadow: 0 8px 24px rgba(40, 44, 80, 0.10);
  --radius: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 24px;
}

.app {
  width: 100%;
  max-width: 1100px;
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-areas:
    "header header"
    "workspace toolbar";
  gap: 20px;
}

/* ---------- Header ---------- */
.app-header {
  grid-area: header;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.app-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 1px;
}
.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Workspace / Canvas ---------- */
.workspace {
  grid-area: workspace;
}
.canvas-wrap {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
}
#board {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  background: #ffffff;
  border-radius: var(--radius-sm);
  border: 2px dashed #d7dbe8;
  cursor: crosshair;
  touch-action: none;
  display: block;
}

/* ---------- Toolbar ---------- */
.toolbar {
  grid-area: toolbar;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tool-group {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.tool-group h2 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 1px;
}

/* Colors */
.colors {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.color-dot {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.color-dot:hover { transform: scale(1.08); }
.color-dot.active {
  border-color: var(--accent);
  transform: scale(1.12);
}

/* Sizes */
.sizes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.size-dot {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 2px solid var(--panel-border);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.size-dot .dot {
  border-radius: 50%;
  background: var(--text);
  width: min(var(--size, 26px), 60%);
  height: min(var(--size, 26px), 60%);
  max-width: 26px;
  max-height: 26px;
}
.size-dot.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Magic */
.magic-btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
  background-size: 300% 300%;
  animation: magicflow 6s ease infinite;
  transition: transform 0.12s ease;
}
.magic-btn:hover { transform: translateY(-1px); }
.magic-btn.active {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.magic-icon { font-size: 18px; }
@keyframes magicflow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Actions */
.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.action-btn {
  width: 100%;
  border: 1px solid var(--panel-border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}
.action-btn:hover { background: var(--accent-soft); transform: translateY(-1px); }
.action-btn:active { transform: translateY(0); }
#clear:hover { background: #ffeaea; color: #e03131; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  body { padding: 14px; }
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "workspace"
      "toolbar";
  }
  .toolbar {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .tool-group {
    flex: 1 1 160px;
  }
}
