:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1b1f2a;
  --muted: #6c7588;
  --accent: #4c6fff;
  --accent-2: #8ad3c7;
  --border: #e6eaf2;
  --shadow: 0 20px 60px rgba(25, 40, 80, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #f3f6fb 0%, #eef2f7 100%);
  color: var(--ink);
}

.ph { font-size: 40px; color: #8a94a8; }

.app {
  min-height: 100vh;
}

.main {
  padding: 28px 32px 40px;
}

.pill {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
}

.pill.small { padding: 8px 12px; font-size: 12px; }

.pill.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.pill.danger { border-color: #f2c6c6; color: #a82323; }
.pill.disabled {
  opacity: 0.5;
  background: #f1f3f7;
  border-color: #e1e6ef;
  color: #8a94a8;
  pointer-events: none;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 18px;
  align-items: start;
}

.dropzone {
  min-height: 560px;
  background: linear-gradient(180deg, #f9fafc 0%, #f0f3f9 100%);
  border: 1px dashed #d7ddeb;
  border-radius: 18px;
  position: relative;
  overflow: hidden;
}

.drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  gap: 18px;
}

.drop-icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  color: var(--ink);
}

.control-group {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.control-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-head h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.muted { color: var(--muted); font-size: 12px; }

label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
input[type="range"] { width: 100%; margin: 6px 0 12px; }
.file-input {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-upload-row { display: none; }

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.control-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
}

details.shape-detection > summary::-webkit-details-marker {
  display: none;
}

.shape-detection {
  padding: 0;
  overflow: hidden;
}

.shape-detection .control-title-row {
  padding: 14px;
  margin: 0;
  cursor: default;
}

.shape-detection .control-title {
  margin: 0;
}

.shape-detection[open] .caret {
  transform: rotate(180deg);
}

.shape-detection .caret {
  transition: transform 0.2s ease;
  font-size: 12px;
  color: var(--muted);
}

.shape-detection .caret {
  display: none;
}

.shape-detection-body {
  padding: 12px 14px 14px;
  display: grid;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.toggle-switch {
  position: relative;
  width: 42px;
  height: 22px;
  display: inline-flex;
  align-items: center;
}

.toggle-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.toggle-track {
  width: 100%;
  height: 100%;
  background: #e4e9f2;
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(30, 40, 80, 0.2);
  transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(20px);
}

.shape-options {
  display: grid;
  gap: 8px;
}

.control-subtitle {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.shape-warning {
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff6e5;
  color: #8a5a1f;
  font-size: 12px;
  border: 1px solid #f1d7a8;
}

.shape-legend {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  align-items: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px dashed currentColor;
}

.legend-item.rect {
  color: #2563eb;
}

.legend-item.ellipse {
  color: #f97316;
}

.legend-item.path {
  color: #94a3b8;
  border-style: solid;
}

.preview-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  box-shadow: var(--shadow);
}

.preview-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 12px;
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  box-shadow: var(--shadow);
}

.preview {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px;
  min-height: 460px;
  background: rgba(250, 251, 255, 0.92);
  color: var(--muted);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.preview-in-canvas {
  position: absolute;
  inset: 24px;
  background: rgba(250, 251, 255, 0.9);
  backdrop-filter: blur(6px);
  display: none;
}

.preview.pending {
  display: grid;
}

.pending-wrap {
  display: grid;
  gap: 10px;
  align-items: center;
  justify-items: center;
  color: var(--muted);
  font-size: 14px;
}

.splash {
  display: flex;
  gap: 6px;
  align-items: center;
}

.splash span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9aa3b6;
  display: inline-block;
  animation: splash 0.9s ease-in-out infinite;
}

.splash span:nth-child(2) { animation-delay: 0.15s; }
.splash span:nth-child(3) { animation-delay: 0.3s; }

@keyframes splash {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-6px); opacity: 1; }
}

.preview-viewport {
  width: 100%;
  height: 100%;
  cursor: grab;
  overflow: hidden;
  position: relative;
}

.preview-viewport.grabbing {
  cursor: grabbing;
}

.preview-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center;
}

.preview-content svg {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.preview svg { width: 100%; height: auto; }

.preview-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
  width: 100%;
}

.preview-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.preview-actions a { color: var(--ink); text-decoration: none; }


.dropzone img.draggable {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: center;
  cursor: grab;
  user-select: none;
}

.dropzone img.draggable.selected {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 6px rgba(76, 111, 255, 0.15);
}

@media (max-width: 980px) {
  .main { padding: 20px; }
  .workspace { grid-template-columns: 1fr; }
  .mobile-upload-row { display: flex; }
  .dropzone { min-height: clamp(280px, 35vh, 520px); }
  .preview-in-canvas { inset: 12px; }
}
