:root {
  color-scheme: light;
  --accent: #3d7eff;
  --bg: #f7f8fb;
  --border: #d5d9e2;
  --text: #1f2a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

header h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

header p {
  margin: 0 0 24px;
  color: #5c6470;
}

.main-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
}

@media (max-width: 980px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

.template-shell {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-shell img {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  pointer-events: none;
}

.placeholder {
  position: absolute;
  border: 2px dashed var(--accent);
  background: rgba(61, 126, 255, 0.12);
  color: var(--text);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  cursor: grab;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.placeholder.dragging {
  cursor: grabbing;
  background: rgba(61, 126, 255, 0.18);
}

.placeholder.locked {
  border-style: dotted;
  background: rgba(96, 112, 134, 0.08);
  color: #4b5563;
  cursor: not-allowed;
  pointer-events: none;
}

.controls-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.stack-text {
  margin: 0 0 16px;
  color: #526078;
  font-size: 14px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  position: relative;
  user-select: none;
  margin-bottom: 18px;
  font-weight: 600;
  font-size: 14px;
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle .track {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #cdd6f4;
  position: relative;
  transition: background 0.18s ease;
}

.toggle .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.18);
  transition: transform 0.18s ease;
}

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

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

.toggle-label {
  color: var(--text);
}

.toggle.disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.toggle.disabled .toggle-label {
  color: #94a3b8;
}

.toggle.disabled .track {
  cursor: not-allowed;
}

.placement-settings {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.placement-settings.collapsed {
  display: none;
}

.controls-card h2 {
  font-size: 18px;
  margin: 0 0 12px;
}

.controls-card h3 {
  font-size: 15px;
  margin: 20px 0 8px;
  color: #526078;
}

label {
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
  font-weight: 600;
}

select,
input[type="text"],
input[type="number"],
input[type="color"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

input[type="range"] {
  width: 100%;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

button {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

button.secondary {
  background: #e6ecff;
  color: var(--accent);
}

button:active {
  transform: scale(0.98);
}

small.helper {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-top: 6px;
}

.preview-panel {
  margin-top: 16px;
  text-align: center;
}

.preview-panel canvas {
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.generated-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.generated-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.generated-card img {
  width: 100%;
  border-radius: 8px;
  display: block;
}

.generated-card .name {
  font-weight: 600;
  font-size: 15px;
  text-align: center;
}

.generated-card .actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.generated-card .actions a {
  text-decoration: none;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #edf2ff;
  color: var(--accent);
  font-weight: 600;
}

@media (max-width: 720px) {
  .app {
    padding: 20px 12px 36px;
  }

  header h1 {
    font-size: 24px;
  }

  header p {
    font-size: 14px;
  }

  .controls-card {
    padding: 18px;
  }

  .template-shell {
    min-height: 260px;
  }

  .button-row {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .generated-card .actions {
    flex-direction: column;
  }

  .generated-card .actions a {
    width: 100%;
    text-align: center;
  }
}

@media (max-width: 540px) {
  .controls-card {
    padding: 16px 14px;
  }

  .template-shell {
    min-height: 220px;
  }

  textarea {
    min-height: 120px;
  }

  .preview-panel canvas {
    max-height: 260px;
  }
}
