.cm-root {
  --cm-bg: #fff;
  --cm-bg-muted: #f8fafc;
  --cm-border: #e2e8f0;
  --cm-text: #0f172a;
  --cm-text-muted: #64748b;
  --cm-primary: #6366f1;
  --cm-primary-light: #eef2ff;
  --cm-shadow: rgba(0,0,0,0.07);
  --cm-radius: 1rem;

  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

.theme-dark .cm-root {
  --cm-bg: #1e293b;
  --cm-bg-muted: #0f172a;
  --cm-border: #334155;
  --cm-text: #f1f5f9;
  --cm-text-muted: #94a3b8;
  --cm-primary: #818cf8;
  --cm-primary-light: #1e1b4b;
  --cm-shadow: rgba(0,0,0,0.4);
}

.cm-card {
  background: var(--cm-bg);
  border: 1px solid var(--cm-border);
  border-radius: var(--cm-radius);
  box-shadow: 0 4px 24px var(--cm-shadow);
  overflow: hidden;
}

.cm-top-row {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
}

@media (max-width: 700px) {
  .cm-top-row {
    grid-template-columns: 1fr;
  }
}

.cm-left-col {
  padding: 1.25rem;
  border-right: 1px solid var(--cm-border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (max-width: 700px) {
  .cm-left-col {
    border-right: none;
    border-bottom: 1px solid var(--cm-border);
  }
}

.cm-drop-zone {
  position: relative;
  background: var(--cm-bg-muted);
  border: 2px dashed var(--cm-border);
  border-radius: 0.75rem;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  color: var(--cm-primary);
}

.cm-drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.cm-drop-zone:hover,
.cm-drop-zone-over {
  border-color: var(--cm-primary);
  background: var(--cm-primary-light);
}

.cm-drop-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--cm-text);
  margin: 0;
}

.cm-drop-sub {
  font-size: 0.75rem;
  color: var(--cm-text-muted);
  margin: 0;
}

.cm-drop-link {
  color: var(--cm-primary);
  font-weight: 600;
  cursor: pointer;
}

.cm-section-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cm-text-muted);
}

.cm-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cm-badge {
  background: var(--cm-primary-light);
  color: var(--cm-primary);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
}

.cm-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.cm-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 0.4rem;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.cm-thumb:hover {
  border-color: var(--cm-primary);
}

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

.cm-thumb-num {
  position: absolute;
  bottom: 2px;
  left: 3px;
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--cm-bg);
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  line-height: 1;
}

.cm-thumb-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background: rgba(239,68,68,0.9);
  color: var(--cm-bg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s;
}

.cm-thumb:hover .cm-thumb-del {
  display: flex;
}

.cm-thumb-del:hover {
  background: #dc2626;
}

.cm-preview-col {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 260px;
}

.cm-preview-placeholder {
  flex: 1;
  background: var(--cm-bg-muted);
  border: 2px dashed var(--cm-border);
  border-radius: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--cm-text-muted);
}

.cm-preview-placeholder p {
  font-size: 0.8rem;
  margin: 0;
}

.cm-canvas {
  width: 100%;
  height: auto;
  border-radius: 0.75rem;
  border: 1px solid var(--cm-border);
  display: block;
}

.cm-dims-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--cm-text-muted);
  background: var(--cm-bg-muted);
  border: 1px solid var(--cm-border);
  border-radius: 9999px;
  padding: 0.15rem 0.5rem;
}

.cm-section-divider {
  border-top: 1px solid var(--cm-border);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cm-layouts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 0.4rem;
}

.cm-layout-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.25rem;
  background: var(--cm-bg-muted);
  border: 2px solid var(--cm-border);
  border-radius: 0.625rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
  color: var(--cm-text-muted);
  position: relative;
}

.cm-layout-btn span {
  font-size: 0.55rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.cm-layout-btn:hover:not(:disabled) {
  border-color: var(--cm-primary);
  color: var(--cm-primary);
  background: var(--cm-primary-light);
}

.cm-layout-btn-active {
  border-color: var(--cm-primary);
  background: var(--cm-primary-light);
  color: var(--cm-primary);
}

.cm-layout-btn-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cm-layout-need {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--cm-text-muted);
  background: var(--cm-bg);
  border: 1px solid var(--cm-border);
  border-radius: 9999px;
  padding: 0 3px;
  line-height: 1.4;
}

.cm-settings-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.cm-setting {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.cm-setting-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--cm-text-muted);
}

.cm-slider {
  accent-color: var(--cm-primary);
  width: 120px;
}

.cm-color-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cm-color-swatch {
  width: 32px;
  height: 32px;
  border: 2px solid var(--cm-border);
  border-radius: 0.4rem;
  cursor: pointer;
  padding: 2px;
  background: transparent;
}

.cm-color-code {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--cm-text-muted);
  font-variant-numeric: tabular-nums;
}

.cm-download-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  background: linear-gradient(135deg, var(--cm-primary), #8b5cf6);
  color: var(--cm-bg);
  border: none;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
  white-space: nowrap;
  margin-left: auto;
}

.cm-download-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.cm-download-btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99,102,241,0.4);
}
