/* ============================================================
   Decompose page — fullscreen freeform canvas
   ============================================================ */

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: #18181b;
  -webkit-font-smoothing: antialiased;
}

.dc-page {
  background:
    radial-gradient(at 50% 40%, rgba(24, 24, 27, 0.025), transparent 70%),
    linear-gradient(180deg, #fdfcfa 0%, #f5f1ea 100%);
  background-image:
    radial-gradient(circle, rgba(24, 24, 27, 0.06) 1px, transparent 1px),
    radial-gradient(at 50% 40%, rgba(24, 24, 27, 0.025), transparent 70%),
    linear-gradient(180deg, #fdfcfa 0%, #f5f1ea 100%);
  background-size: 28px 28px, auto, auto;
}

/* ── Top toolbar ──────────────────────────────────────────── */
.dc-toolbar {
  position: fixed;
  top: 1rem;
  left: 1rem; right: 1rem;
  height: 58px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(24, 24, 27, 0.04);
  border-radius: 16px;
  /* layered shadow — a tight contact shadow + a soft ambient one */
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.04),
    0 12px 28px -10px rgba(24, 24, 27, 0.10);
  display: flex; align-items: center;
  padding: 0 0.85rem;
  gap: 1.1rem;
}
.dc-toolbar-left,
.dc-toolbar-right { display: flex; align-items: center; gap: 0.45rem; }
.dc-toolbar-center {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 1rem;
}

/* Back button — minimal ghost button, icon nudges left on hover */
.dc-back {
  display: inline-flex; align-items: center; gap: 0.42rem;
  padding: 0.48rem 0.85rem 0.48rem 0.62rem;
  border-radius: 10px;
  color: #44403c;
  text-decoration: none;
  font-size: 0.81rem; font-weight: 500;
  letter-spacing: 0.005em;
  transition: background 0.18s ease, color 0.18s ease;
}
.dc-back:hover  { background: rgba(24, 24, 27, 0.045); color: #0c0a09; }
.dc-back:active { background: rgba(24, 24, 27, 0.075); }
.dc-back svg    { transition: transform 0.22s cubic-bezier(.2,.8,.2,1); }
.dc-back:hover svg { transform: translateX(-2px); }

/* Character input — pill-shaped, premium feel. A dark-green leading
   "字" badge anchors the field; the input grows on focus and shows a
   refined indigo halo. The whole wrap is a single pill so the icon
   feels integrated rather than tacked on. */
.dc-char-input-wrap {
  display: inline-flex; align-items: center;
  gap: 0;
  background: #fff;
  border: 1px solid rgba(24, 24, 27, 0.10);
  border-radius: 999px;
  padding: 4px 6px 4px 4px;
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.04),
    0 8px 22px -10px rgba(24, 24, 27, 0.10);
  transition: border-color 0.22s ease, box-shadow 0.22s ease, transform 0.22s ease;
}
.dc-char-input-wrap:hover {
  border-color: rgba(24, 24, 27, 0.18);
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.05),
    0 10px 26px -10px rgba(24, 24, 27, 0.16);
}
.dc-char-input-wrap:focus-within {
  border-color: #4f46e5;
  box-shadow:
    0 0 0 4px rgba(79, 70, 229, 0.12),
    0 10px 26px -10px rgba(79, 70, 229, 0.30);
}
.dc-char-icon {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: #143c2a; color: #f7f1e8;
  font-family: 'Kaiti SC', 'STKaiti', 'KaiTi', '楷体', serif;
  font-size: 16px; font-weight: 600;
  user-select: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    0 4px 12px -4px rgba(20, 60, 42, 0.40);
}
.dc-char-input {
  flex: 1; min-width: 0;
  font-family: 'Kaiti SC', 'STKaiti', '楷体', serif;
  font-size: 1.05rem; color: #0c0a09;
  letter-spacing: 0.06em;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0 0.55rem;
  width: 10em;
  outline: none;
  transition: width 0.22s ease;
}
.dc-char-input-wrap:focus-within .dc-char-input { width: 14em; }
.dc-char-input::placeholder {
  color: #a8a29e; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 0.86em; font-weight: 500;
  letter-spacing: 0.01em;
}

.dc-char-clear {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #a8a29e;
  font-size: 1.05rem; line-height: 1; font-weight: 400;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.18s ease, color 0.18s ease, transform 0.08s ease;
  font-family: inherit;
}
.dc-char-clear:hover  { background: rgba(24, 24, 27, 0.06); color: #44403c; }
.dc-char-clear:active { transform: scale(0.92); }

/* Mode tabs — segmented control with floating active pill */
.dc-mode-tabs {
  display: inline-flex;
  background: rgba(245, 245, 244, 0.7);
  border: 1px solid rgba(24, 24, 27, 0.04);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}
.dc-tab {
  padding: 0.44rem 1rem;
  font-size: 0.785rem; font-weight: 500;
  color: #57534e;
  background: transparent; border: none; border-radius: 9px;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 0.18s ease, color 0.18s ease, transform 0.08s ease;
  font-family: inherit;
}
.dc-tab:hover  { color: #0c0a09; }
.dc-tab:active { transform: scale(0.97); }
.dc-tab.active {
  background: #fff; color: #0c0a09;
  box-shadow:
    0 0 0 0.5px rgba(24, 24, 27, 0.04),
    0 1px 2px rgba(24, 24, 27, 0.06),
    0 2px 6px -2px rgba(24, 24, 27, 0.06);
}

/* Char nav — kept in HTML for backward compat but now permanently hidden
   (`hidden` attr is set on the element). Use :not([hidden]) so the
   display:inline-flex rule does not override the native `hidden` semantic. */
.dc-char-nav:not([hidden]) {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding-left: 0.75rem;
  border-left: 1px solid rgba(24, 24, 27, 0.07);
}
.dc-nav-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(24, 24, 27, 0.08);
  background: #fff;
  color: #18181b;
  font-size: 1.05rem; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.08s ease;
}
.dc-nav-btn:hover:not(:disabled)  { background: #fafaf9; border-color: rgba(24, 24, 27, 0.18); }
.dc-nav-btn:active:not(:disabled) { transform: scale(0.94); }
.dc-nav-btn:disabled              { opacity: 0.3; cursor: not-allowed; }
.dc-nav-counter {
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem; color: #57534e;
  min-width: 36px; text-align: center;
}

/* Selection-count pill — discreet by default, glows indigo when active */
.dc-sel-count {
  font-size: 0.74rem;
  color: #a8a29e;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.015em;
  padding: 0.32rem 0.72rem;
  border-radius: 999px;
  transition: background 0.22s ease, color 0.22s ease;
}
.dc-sel-count.has-selection {
  color: #4f46e5; font-weight: 600;
  background: rgba(79, 70, 229, 0.08);
}

/* Generic toolbar button — white surface, subtle shadow, gentle lift on hover */
.dc-btn {
  background: #fff;
  border: 1px solid rgba(24, 24, 27, 0.08);
  border-radius: 10px;
  padding: 0.46rem 0.9rem;
  font-size: 0.765rem; color: #44403c;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.035);
  transition:
    background 0.18s ease, border-color 0.18s ease, color 0.18s ease,
    box-shadow 0.18s ease, transform 0.08s ease;
}
.dc-btn:hover {
  background: #fafaf9;
  border-color: rgba(24, 24, 27, 0.16);
  color: #0c0a09;
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.04),
    0 4px 12px -4px rgba(24, 24, 27, 0.08);
}
.dc-btn:active { transform: scale(0.97); }
.dc-btn-icon  { padding: 0.46rem 0.6rem; display: inline-flex; align-items: center; }

/* ── Canvas (everything else) ──────────────────────────────── */
.dc-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.dc-canvas svg.dc-canvas-svg {
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Welcome hint (shown until pieces render or if no data) */
.dc-hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #78716c;
  font-size: 0.95rem;
  line-height: 1.7;
  pointer-events: none;
  max-width: 560px;
  padding: 1rem;
}
.dc-hint strong { color: #18181b; font-weight: 600; }
.dc-hint-sub {
  display: inline-block; margin-top: 0.4rem;
  font-size: 0.78rem; color: #a8a29e;
}
.dc-hint kbd {
  display: inline-block; padding: 0 0.4em; min-width: 1.4em;
  border: 1px solid #d6d3d1; border-bottom-width: 2px;
  border-radius: 5px;
  background: #fff;
  font-family: -apple-system, monospace;
  font-size: 0.72rem;
  color: #18181b;
  margin: 0 0.1em;
}

/* ── Draggable pieces ──────────────────────────────────────── */
.dc-piece {
  cursor: grab;
  transition: filter 0.15s ease;
}
.dc-piece:hover {
  filter: drop-shadow(0 2px 5px rgba(24, 24, 27, 0.18));
}
.dc-piece.dc-selected {
  filter:
    drop-shadow( 0 0 1px #2563eb)
    drop-shadow( 0 0 4px rgba(37, 99, 235, 0.65))
    drop-shadow( 0 0 12px rgba(37, 99, 235, 0.35));
}
.dc-piece.dc-selected:hover {
  filter:
    drop-shadow( 0 0 1.5px #2563eb)
    drop-shadow( 0 0 7px rgba(37, 99, 235, 0.80))
    drop-shadow( 0 0 14px rgba(37, 99, 235, 0.45));
}
.dc-piece.dc-dragging {
  cursor: grabbing;
  filter:
    drop-shadow( 0 0 1.5px rgba(37, 99, 235, 0.85))
    drop-shadow( 0 12px 26px rgba(24, 24, 27, 0.30));
}

/* Marquee (box-select) rectangle */
.dc-marquee {
  fill: rgba(37, 99, 235, 0.08);
  stroke: #2563eb;
  stroke-width: 1;
  stroke-dasharray: 4 3;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

/* ── Bottom dock (color & size & BG tools — acts on current selection) ── */
.dc-dock {
  position: fixed;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(24, 24, 27, 0.04);
  border-radius: 16px;
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.04),
    0 12px 28px -10px rgba(24, 24, 27, 0.10);
  display: flex; align-items: center;
  padding: 0.55rem 0.85rem;
  gap: 0.75rem;
}
.dc-dock-section { display: flex; align-items: center; gap: 0.42rem; }
.dc-dock-divider { width: 1px; height: 22px; background: rgba(24, 24, 27, 0.07); }
.dc-dock-label   {
  font-size: 0.7rem; color: #78716c;
  font-weight: 500; letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dc-color {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow:
    0 0 0 1px rgba(24, 24, 27, 0.10),
    0 1px 2px rgba(24, 24, 27, 0.06);
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s cubic-bezier(.2,.8,.2,1), box-shadow 0.18s ease;
}
.dc-color:hover {
  transform: scale(1.15) translateY(-1px);
  box-shadow:
    0 0 0 1.5px #4f46e5,
    0 4px 10px -2px rgba(24, 24, 27, 0.18);
}
.dc-color:active { transform: scale(0.95); }

.dc-size-btn {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(24, 24, 27, 0.08);
  background: #fff;
  color: #18181b;
  font-size: 1.05rem; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.035);
  transition:
    background 0.18s ease, border-color 0.18s ease,
    box-shadow 0.18s ease, transform 0.08s ease;
  font-family: inherit;
}
.dc-size-btn:hover {
  background: #fafaf9; border-color: rgba(24, 24, 27, 0.16);
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.04),
    0 4px 12px -4px rgba(24, 24, 27, 0.08);
}
.dc-size-btn:active { transform: scale(0.94); }

/* Background color picker — native <input type="color"> styled as a swatch. */
.dc-bg-picker {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow:
    0 0 0 1px rgba(24, 24, 27, 0.10),
    0 1px 2px rgba(24, 24, 27, 0.06);
  cursor: pointer;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: transparent;
  transition: transform 0.15s cubic-bezier(.2,.8,.2,1), box-shadow 0.18s ease;
}
.dc-bg-picker::-webkit-color-swatch-wrapper { padding: 0; }
.dc-bg-picker::-webkit-color-swatch         { border: none; border-radius: 50%; }
.dc-bg-picker::-moz-color-swatch            { border: none; border-radius: 50%; }
.dc-bg-picker:hover {
  transform: scale(1.15) translateY(-1px);
  box-shadow:
    0 0 0 1.5px #4f46e5,
    0 4px 10px -2px rgba(24, 24, 27, 0.18);
}
.dc-bg-picker:active { transform: scale(0.95); }

.dc-bg-reset {
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(24, 24, 27, 0.08);
  background: #fff;
  color: #78716c;
  font-size: 0.9rem; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.035);
  transition:
    background 0.18s ease, border-color 0.18s ease, color 0.18s ease,
    box-shadow 0.18s ease, transform 0.08s ease;
  font-family: inherit;
}
.dc-bg-reset:hover {
  background: #fafaf9; border-color: rgba(24, 24, 27, 0.16); color: #0c0a09;
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.04),
    0 4px 12px -4px rgba(24, 24, 27, 0.08);
}
.dc-bg-reset:active { transform: scale(0.94); }

.dc-error {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #b45309;
  font-size: 1rem;
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 720px) {
  .dc-toolbar {
    height: auto; flex-wrap: wrap;
    padding: 0.5rem 0.6rem;
    gap: 0.5rem;
  }
  .dc-toolbar-center {
    width: 100%; order: 3;
    justify-content: flex-start; flex-wrap: wrap;
    gap: 0.55rem;
  }
  .dc-back span { display: none; }
  .dc-tab { padding: 0.32rem 0.55rem; font-size: 0.72rem; }
  .dc-sel-count { display: none; }
  .dc-btn { padding: 0.35rem 0.6rem; font-size: 0.72rem; }
  .dc-char-input-wrap { padding: 3px 4px 3px 3px; }
  .dc-char-icon  { width: 28px; height: 28px; font-size: 14px; }
  .dc-char-input { font-size: 0.95rem; width: 7em; padding: 0 0.45rem; }
  .dc-char-input-wrap:focus-within .dc-char-input { width: 10em; }
  .dc-char-clear { width: 24px; height: 24px; font-size: 0.95rem; }
  .dc-dock { padding: 0.4rem 0.55rem; gap: 0.45rem; bottom: 0.6rem; flex-wrap: wrap; max-width: calc(100vw - 1.2rem); }
  .dc-color { width: 20px; height: 20px; }
  .dc-bg-picker { width: 20px; height: 20px; }
  .dc-bg-reset { width: 22px; height: 22px; }
  .dc-size-btn { width: 24px; height: 24px; }
  .dc-dock-label { display: none; }
}
