@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=DM+Sans:wght@400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a1e;
  --surface: #232328;
  --surface2: #2c2c32;
  --border: #3a3a42;
  --text: #e0e0e4;
  --text-dim: #88888e;
  --accent: #4a9eff;
  --accent-dim: #4a9eff33;
  --danger: #ff4a6a;
  --success: #4aff8a;
  --handle: #4a9eff;
}

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: 1fr 240px;
  grid-template-rows: 48px 1fr 40px;
  height: 100vh;
  gap: 1px;
  background: var(--border);
}

/* ── Toolbar ── */
.toolbar {
  grid-column: 1 / -1;
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}

.toolbar .logo {
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--accent);
  margin-right: 16px;
  font-size: 14px;
}

.toolbar .sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 8px;
}

.toolbar .info {
  color: var(--text-dim);
  font-size: 11px;
  margin-left: auto;
}

button {
  font-family: 'DM Sans', sans-serif;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: var(--border); border-color: var(--text-dim); }
button.primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #6ab4ff; }
button.danger { color: var(--danger); }
button.danger:hover { background: #ff4a6a22; }
button.sm { padding: 2px 6px; font-size: 11px; }

/* ── Workspace ── */
.workspace-wrap {
  background: var(--bg);
  overflow: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.workspace {
  position: relative;
  background:
    repeating-conic-gradient(#2a2a30 0% 25%, #222228 0% 50%) 0 0 / 20px 20px;
  min-width: 200px;
  min-height: 200px;
  box-shadow: 0 0 0 1px var(--border);
  overflow: hidden;
}

.workspace.drop-active {
  box-shadow: 0 0 0 2px var(--accent), 0 0 30px var(--accent-dim);
}

/* ── Drop overlay ── */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(26,26,30,0.85);
  z-index: 9999;
  pointer-events: none;
}
.drop-overlay.visible { display: flex; }
.drop-overlay span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--accent);
  border: 2px dashed var(--accent);
  padding: 24px 40px;
  border-radius: 8px;
}

/* ── Image layers ── */
.layer-img {
  position: absolute;
  cursor: move;
  image-rendering: auto;
}
.layer-img.selected {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* ── Text layers ── */
.layer-text {
  position: absolute;
  cursor: move;
  word-wrap: break-word;
  overflow: hidden;
  white-space: pre-wrap;
  line-height: 1.2;
}
.layer-text.selected {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.layer-text[contenteditable="true"] {
  cursor: text;
  outline: 2px dashed var(--accent);
  outline-offset: -1px;
  user-select: text;
}

/* ── Resize handles ── */
.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--handle);
  border: 2px solid #000;
  border-radius: 2px;
  z-index: 10000;
  /* Invisible hit area expansion */
  box-shadow: 0 0 0 6px transparent;
}
.resize-handle::after {
  content: '';
  position: absolute;
  inset: -8px;
}

.resize-handle.nw { cursor: nw-resize; }
.resize-handle.ne { cursor: ne-resize; }
.resize-handle.sw { cursor: sw-resize; }
.resize-handle.se { cursor: se-resize; }

/* ── Color picker for bg layer ── */
.bg-layer-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
.bg-layer-row input[type="color"] {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface2);
  cursor: pointer;
  padding: 2px;
}

/* ── Solid color layer in workspace ── */
.layer-solid {
  position: absolute;
  cursor: move;
}
.layer-solid.selected {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

/* ── Layer Properties panel ── */
#layerProps {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
  max-height: 220px;
  flex-shrink: 0;
}

#layerProps .sidebar-section {
  border-bottom: none;
}

.prop-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 5px;
}

.prop-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  min-width: 26px;
}

.prop-num {
  width: 48px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 5px;
  border-radius: 3px;
  font-size: 11px;
  text-align: center;
}

.prop-color {
  width: 28px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface2);
  cursor: pointer;
  padding: 2px;
}

.prop-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
}

.prop-sep {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.layer-btn.active {
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
}

/* ── Layer list ── */
.layer-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.layer-item:hover { background: var(--surface2); }
.layer-item.selected { background: var(--accent-dim); border-color: var(--accent); }

.layer-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--bg);
  flex-shrink: 0;
}

.text-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 2px;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

.layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.layer-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.layer-item:hover .layer-actions,
.layer-item.selected .layer-actions { opacity: 1; }

.layer-btn {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 2px;
  font-size: 12px;
  padding: 0;
}
.layer-btn:hover { color: var(--text); background: var(--surface2); }
.layer-btn.del:hover { color: var(--danger); }

/* ── Export panel ── */
.export-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

select {
  font-family: 'DM Sans', sans-serif;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.quality-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
}

/* ── Canvas size inputs ── */
.size-inputs {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
}

.size-inputs input {
  width: 60px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 11px;
  text-align: center;
}

.size-inputs span { color: var(--text-dim); }

/* ── Statusbar ── */
.statusbar {
  grid-column: 1 / -1;
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-dim);
  gap: 16px;
}

.statusbar .hint {
  margin-left: auto;
}

/* ── Empty state ── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: var(--text-dim);
  gap: 8px;
}
.empty-state .icon { font-size: 40px; opacity: 0.3; }
.empty-state p { font-size: 13px; }
.empty-state kbd {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
