:root {
  --bg: #f4efe7;
  --panel: #fffaf3;
  --panel-strong: #fff;
  --text: #1f2721;
  --muted: #5d695f;
  --line: #d7cebf;
  --accent: #1c7c54;
  --accent-strong: #0e5b3d;
  --danger: #b44332;
  --shadow: 0 16px 32px rgba(50, 41, 26, 0.12);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 232, 184, 0.5), transparent 22%),
    linear-gradient(135deg, #efe7da 0%, #f7f3eb 55%, #e5efe5 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
}

.sidebar,
.workspace {
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
  padding-right: 4px;
}

.panel {
  background: rgba(255, 250, 243, 0.92);
  border: 1px solid rgba(215, 206, 191, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel h1,
.panel h2,
.workspace h2 {
  margin: 0 0 8px;
}

.panel-header,
.workspace-header,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.button-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 12px;
}

.toggle-row {
  margin-top: 0;
}

.toggle-row .ghost-button.active {
  background: rgba(28, 124, 84, 0.14);
  border-color: rgba(28, 124, 84, 0.55);
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-strong);
  padding: 10px 12px;
  color: var(--text);
}

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

textarea {
  min-height: 220px;
  resize: vertical;
  margin-top: 12px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-strong);
}

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

.ghost-button {
  background: transparent;
  color: var(--accent-strong);
  border: 1px solid rgba(28, 124, 84, 0.25);
}

.ghost-button:hover {
  background: rgba(28, 124, 84, 0.08);
}

.danger {
  color: var(--danger);
  border-color: rgba(180, 67, 50, 0.25);
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.stats,
.workspace-meta {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.item-library {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  max-height: 340px;
  overflow: auto;
}

.item-library.horizontal {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  max-height: none;
  width: 100%;
  min-width: 0;
  overflow: visible;
  padding-bottom: 0;
}

.library-item {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  padding: 6px;
  display: grid;
  gap: 4px;
  cursor: pointer;
  min-width: 0;
  min-height: 104px;
}

.library-item:hover {
  border-color: rgba(28, 124, 84, 0.6);
}

.library-item img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.025) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.025) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.025) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border-radius: 10px;
}

.library-item strong,
.library-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-item strong {
  font-size: 12px;
  text-align: center;
}

.library-count {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(31, 39, 33, 0.85);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
}

.library-count.empty {
  background: rgba(93, 105, 95, 0.22);
  color: var(--muted);
}

.library-usage {
  display: block;
  text-align: center;
  font-style: normal;
  font-size: 11px;
  line-height: 1.2;
  color: var(--accent-strong);
  font-weight: 700;
}

.library-usage.empty {
  color: var(--muted);
  font-weight: 500;
}

.item-library.horizontal .library-item span {
  display: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  min-width: 0;
}

.library-panel {
  padding-bottom: 12px;
  min-width: 0;
  overflow: hidden;
}

.stage-viewport {
  position: relative;
  min-height: 0;
  border-radius: 24px;
  border: 1px solid rgba(78, 92, 82, 0.15);
  background:
    linear-gradient(rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.35)),
    repeating-linear-gradient(
      45deg,
      rgba(31, 39, 33, 0.035),
      rgba(31, 39, 33, 0.035) 14px,
      transparent 14px,
      transparent 28px
    );
  box-shadow: var(--shadow);
  overflow: auto;
  padding: 20px;
}

.stage-canvas {
  position: relative;
  margin: 0 auto;
  transform-origin: top center;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border-radius: 18px;
  box-shadow: 0 22px 40px rgba(21, 34, 31, 0.24);
}

.placement {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 12px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  cursor: grab;
  transition: box-shadow 120ms ease, border-color 120ms ease;
}

.placement:hover {
  border-color: rgba(28, 124, 84, 0.6);
}

.placement.selected {
  border-color: #f2a93b;
  box-shadow: 0 0 0 3px rgba(242, 169, 59, 0.28);
}

.placement::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(31, 39, 33, 0.8);
  color: white;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.placement:hover::after,
.placement.selected::after {
  opacity: 1;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
}

.hidden {
  display: none;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
}

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

  .panel,
  .stage-viewport {
    padding: 14px;
  }

  .item-library.horizontal {
    grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
    gap: 8px;
  }
}
