:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #111111;
  --muted: #6a6a6a;
  --line: #e1dfd7;
  --accent: #1b5b5f;
  --accent-2: #e86f51;
  --toast: #0f0f0f;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 96px;

  --radius-1: 6px;
  --radius-2: 12px;

  --font-display: "Playfair Display", "Times New Roman", serif;
  --font-sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;

  --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
}

.app,
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 320px;
  min-height: 100vh;
  gap: var(--space-5);
  padding: var(--space-6);
}

.app.dragging {
  user-select: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-2);
  padding: var(--space-5);
  box-shadow: var(--shadow-soft);
}

.panel h2 {
  margin: 0 0 var(--space-4) 0;
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 0.5px;
}

.panel h3 {
  margin: var(--space-5) 0 var(--space-3) 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}

.panel .section {
  margin-bottom: var(--space-5);
}

.block-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-1);
  padding: var(--space-2);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  background: #fff;
  position: relative;
}

.block-item.dragging {
  opacity: 0.5;
}

.block-item.drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(27, 91, 95, 0.15);
}

.block-item.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(17, 17, 17, 0.08);
}

.block-select {
  width: 100%;
  text-align: left;
}

.block-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.inline {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.inline.space-between {
  justify-content: space-between;
  align-items: center;
}

button,
select,
input,
textarea {
  font-family: var(--font-sans);
  font-size: 14px;
}

button,
select,
input[type="text"],
input[type="number"],
textarea {
  border-radius: var(--radius-1);
  border: 1px solid var(--line);
  background: #fff;
  padding: var(--space-2) var(--space-3);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  min-height: 40px;
}

button {
  cursor: pointer;
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  min-height: 40px;
}

button.secondary {
  background: transparent;
  color: var(--ink);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

button.small {
  font-size: 12px;
  padding: 6px 10px;
  min-height: 32px;
}

.inline .button-compact {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
}

.block-list button {
  width: 100%;
}

button:focus,
select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 91, 95, 0.2);
}

button:active {
  transform: translateY(1px);
}

.toggle {
  display: inline-flex;
  background: #f2f2ee;
  border-radius: 999px;
  border: 1px solid var(--line);
  overflow: hidden;
}

.toggle button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 12px;
  min-height: auto;
}

.toggle button.active {
  background: var(--ink);
  color: #fff;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(232, 111, 81, 0.12);
  color: var(--accent-2);
  font-size: 12px;
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.canvas-shell {
  flex: 1;
  background: #efeee8;
  border-radius: var(--radius-2);
  border: 1px solid var(--line);
  padding: var(--space-6);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.artboard {
  position: relative;
  background: #ffffff;
  border-radius: var(--radius-2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
  overflow: visible;
}

.safe-area {
  position: absolute;
  inset: 0;
  border: 2px dashed rgba(232, 111, 81, 0.7);
  pointer-events: none;
  opacity: 0;
}

.app.overflowing .safe-area {
  opacity: 1;
}

.snap-indicator {
  position: absolute;
  border: 2px dashed rgba(27, 91, 95, 0.8);
  background: rgba(27, 91, 95, 0.12);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.app.dragging .snap-indicator {
  opacity: 1;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  pointer-events: none;
  opacity: 0.6;
}

.app.dragging .grid-overlay {
  opacity: 0.85;
}

.grid-overlay span {
  border-left: 1px solid rgba(27, 91, 95, 0.6);
  border-right: 1px solid rgba(27, 91, 95, 0.6);
  background: rgba(27, 91, 95, 0.08);
}

.canvas {
  position: absolute;
  inset: 0;
  display: grid;
}

.block {
  background: #f4f3ef;
  border: 1px solid #d9d6cc;
  border-radius: var(--radius-1);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.block:active {
  cursor: grabbing;
}


.block.image-resizable {
  overflow: visible;
}

.block .resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: rgba(17, 17, 17, 0.6);
  border-radius: 999px;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: auto;
}

.block.image-resizable:hover .resize-handle,
.block.text-only:hover .resize-handle {
  opacity: 1;
}

.resize-handle.ne {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.resize-handle.nw {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.resize-handle.se {
  bottom: -4px;
  right: -4px;
  cursor: nwse-resize;
}

.resize-handle.sw {
  bottom: -4px;
  left: -4px;
  cursor: nesw-resize;
}

.resize-handle.e {
  top: 50%;
  right: -4px;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.resize-handle.w {
  top: 50%;
  left: -4px;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.resize-handle.n {
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.resize-handle.s {
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.block.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.block .label {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  z-index: 2;
}

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

.block-inner {
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: var(--radius-1);
}

.placeholder {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.placeholder::before,
.placeholder::after {
  content: "";
  position: absolute;
  width: 120%;
  height: 1px;
  background: #c5c2b7;
}

.placeholder::before {
  transform: rotate(45deg);
}

.placeholder::after {
  transform: rotate(-45deg);
}

.text-block {
  padding: 0;
  align-items: flex-start;
  justify-content: flex-start;
  width: 100%;
}

.text-block p {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1.4;
  color: var(--ink);
}

.text-block.clamp p {
  display: -webkit-box;
  -webkit-line-clamp: var(--clamp-lines, 6);
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-block .more {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  cursor: pointer;
}

.preset-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-1);
  padding: var(--space-3);
  display: grid;
  gap: var(--space-2);
  background: #fafaf7;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.block-list {
  display: grid;
  gap: var(--space-2);
}

.block-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-1);
  padding: var(--space-2);
  display: grid;
  gap: var(--space-2);
  background: #fbfbf8;
}

.block-item.active {
  border-color: var(--accent);
}

.block-item .meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.editor-field {
  display: grid;
  gap: 6px;
  margin-bottom: var(--space-3);
}

.toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  background: var(--toast);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-1);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.why-panel {
  border-top: 1px solid var(--line);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
}

.why-panel ul {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: 13px;
}

.block.text-only {
  background: transparent;
  border: none;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0;
  min-height: 0;
  height: auto;
  align-self: start;
  justify-self: start;
}

.block.text-only .label {
  background: rgba(255, 255, 255, 0.6);
}

.block.text-only.selected {
  outline: none;
}

.block.text-only .block-inner {
  width: fit-content;
  height: fit-content;
  max-width: 100%;
}

.block.text-only.selected .block-inner {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

@media (max-width: 720px) {
  .app,
  .layout {
    padding: var(--space-4);
  }
  .canvas-shell {
    padding: var(--space-4);
  }
}
