:root {
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-muted: #6B7280;
  --handle: #6366F1;
  --radius: 8px;
  --space: 4px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  padding: calc(var(--space) * 5) calc(var(--space) * 6) calc(var(--space) * 3);
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-header .hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--space) * 8) calc(var(--space) * 10) calc(var(--space) * 12);
  overflow: auto;
}

.collage-wrapper {
  position: relative;
  width: min(90vw, 1100px);
  padding: 0 24px 24px 0;
}

.grid-container {
  display: grid;
  width: 100%;
  aspect-ratio: var(--aspect, 16 / 9);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
}

.grid-cell {
  position: relative;
  overflow: hidden;
  background: #F3F4F6;
  cursor: grab;
}

.grid-cell.dragover {
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
  background: #EEF2FF;
}

.grid-cell.panning {
  cursor: grabbing;
}

.grid-cell .cell-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.grid-cell img {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.col-handles, .row-handles {
  position: absolute;
  pointer-events: none;
}

.col-handles {
  left: 0;
  right: 24px;
  bottom: 10px;
  height: 20px;
}

.row-handles {
  top: 0;
  bottom: 24px;
  right: 10px;
  width: 20px;
}

.handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--handle);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.25);
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.col-handles .handle {
  top: 50%;
  cursor: ew-resize;
}

.row-handles .handle {
  left: 50%;
  cursor: ns-resize;
}

.handle:hover, .handle:active {
  background: var(--primary-hover);
}

.toolbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: calc(var(--space) * 6);
  padding: calc(var(--space) * 4) calc(var(--space) * 6);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.field input, .field select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  min-width: 90px;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.btn-primary {
  margin-left: auto;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: var(--primary-hover);
}
