:root {
  --bg: #0e0e0f;
  --surface: #161618;
  --surface2: #1e1e21;
  --border: #2a2a2e;
  --accent: #e8342a;
  --accent-glow: rgba(232,52,42,0.3);
  --accent-hover: #ff5a51;
  --text: #f0f0f0;
  --text-dim: #666;
  --text-muted: #999;
  --radius: 6px;
  --sidebar-w: 280px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 28px;
  letter-spacing: 4px;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
}

.header-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
  letter-spacing: 0.5px;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }

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

.btn:disabled { opacity: .35; cursor: default; pointer-events: none; }

.btn.danger { background: none; }

.btn.danger:hover { border-color: #ff4444; color: #ff4444; }

.app-body { display: flex; flex: 1; overflow: hidden; height: calc(100vh - 53px); }

.sidebar.drop-target { box-shadow: inset 0 0 0 2px var(--accent); background: rgba(232,52,42,0.04); }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: box-shadow .15s, background .15s;
}

.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); flex-wrap: wrap; }

.stab {
  flex: 1;
  padding: 9px 4px;
  font-size: 9px;
  letter-spacing: 0.8px;
  text-align: center;
  cursor: pointer;
  color: var(--text-dim);
  border: none;
  background: none;
  font-family: 'DM Mono', monospace;
  transition: all .15s;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.stab:hover { color: var(--text-muted); }

.stab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sidebar-panel { display: none; flex-direction: column; flex: 1; overflow: hidden; }

.sidebar-panel.active { display: flex; }

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-section h3 {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 10px;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
}

.image-pool {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}

.pool-img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 4px;
  cursor: grab;
  border: 2px solid transparent;
  transition: all .15s;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-drag: none;
}

.pool-img:hover { border-color: var(--accent); transform: scale(1.05); }

.pool-img.dragging { opacity: .4; }

.pool-empty {
  width: 100%;
  text-align: center;
  padding: 30px 10px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.6;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.6;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(232,52,42,0.05);
}

.sep-library { flex: 1; overflow-y: auto; padding: 10px; }

.sep-category { margin-bottom: 16px; }

.sep-category-title {
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
}

.sep-grid { display: flex; flex-wrap: wrap; gap: 6px; }

.sep-item {
  cursor: grab;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  padding: 4px 10px;
  font-size: 13px;
  transition: all .15s;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
}

.sep-item:hover { border-color: var(--accent); background: rgba(232,52,42,0.08); }

.trash-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.trash-pool {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}

.trash-item {
  width: 72px;
  height: 72px;
  border-radius: 4px;
  border: 2px solid #444;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: border-color .15s;
}

.trash-item:hover { border-color: var(--accent); }

.trash-item img { width: 100%; height: 100%; object-fit: cover; display: block; filter: grayscale(40%); }

.trash-item.sep-trash {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: var(--surface2);
}

.trash-restore-hint {
  position: absolute;
  inset: 0;
  background: rgba(232,52,42,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.trash-item:hover .trash-restore-hint { display: flex; }

.trash-empty {
  width: 100%;
  text-align: center;
  padding: 30px 10px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.6;
}

.trash-clear-btn {
  margin: 10px;
  flex-shrink: 0;
}

.main-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tier-row {
  display: flex;
  align-items: stretch;
  height: 80px;
  border-radius: var(--radius);
  overflow: visible;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: box-shadow .15s;
}

.tier-row.drag-target { box-shadow: 0 0 0 2px var(--accent); }

.tier-label {
  width: 80px;
  min-width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  gap: 2px;
  align-self: stretch;
}

.tier-label:hover .tier-label-edit { opacity: 1; }

.tier-label.drop-target { box-shadow: inset 0 0 0 3px var(--accent); filter: brightness(1.15); }

.tier-label-img { cursor: zoom-in; }

.tier-label-text {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 22px;
  letter-spacing: 1px;
  text-align: center;
  color: #000;
  word-break: break-all;
  line-height: 1;
  max-width: 100%;
  overflow: hidden;
}

.tier-label-img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
}

.tier-label-edit {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: rgba(0,0,0,0.6);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s;
  font-size: 10px;
}

.tier-items {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  align-content: flex-start;
  gap: 3px;
  padding: 4px 6px;
  border-left: 1px solid rgba(255,255,255,0.05);
  align-self: stretch;
  overflow-x: auto;
  overflow-y: hidden;
}

.tier-items.drag-over { background: rgba(232,52,42,0.04); }

.tier-item {
  height: 100%;
  aspect-ratio: 1 / 1;
  width: auto;
  position: relative;
  flex-shrink: 0;
  cursor: grab;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color .15s;
}

.tier-item:hover { border-color: rgba(255,255,255,0.25); }

.tier-item.dragging { opacity: .3; }

.tier-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.tier-item.sep-type {
  width: 28px;
  height: auto;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.04);
  border: 1px dashed var(--border);
  border-radius: 3px;
  font-size: 15px;
  overflow: hidden;
  flex-direction: column;
  padding: 4px 0;
  gap: 2px;
}

.tier-item.sep-type.sep-text {
  width: 28px;
  writing-mode: vertical-rl;
  font-size: 13px;
  padding: 4px 0;
}

.tier-item.sep-type.sep-vbar {
  width: 20px;
  height: auto;
  align-self: stretch;
  flex-direction: column;
  padding: 4px 0;
  writing-mode: horizontal-tb;
}

.sep-vbar .sep-type-line {
  width: 2px;
  height: 60%;
  background: currentColor;
  border-radius: 1px;
  opacity: 0.5;
  flex-shrink: 0;
}

.trash-zone-indicator {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 90px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  pointer-events: none;
  flex-direction: column;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 1px;
  color: #fff;
  font-family: 'DM Mono', monospace;
}

.trash-zone-indicator.left { left: 0; background: linear-gradient(to right, rgba(220,50,50,0.55), transparent); }

.trash-zone-indicator.right { right: 0; background: linear-gradient(to left, rgba(220,50,50,0.55), transparent); }

.trash-zone-indicator .trash-icon { font-size: 28px; }

body.is-dragging .trash-zone-indicator { display: flex; }

.trash-zone-indicator.active { background: rgba(220,50,50,0.75); }

.trash-zone-indicator.right.active { background: rgba(220,50,50,0.75); }

.tier-controls {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px;
  gap: 3px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
}

.tier-ctrl-btn {
  width: 24px;
  height: 24px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  padding: 0;
}

.tier-ctrl-btn:hover { color: var(--text); border-color: var(--text-muted); }

.tier-ctrl-btn.del:hover { color: #ff4444; border-color: #ff4444; }

.add-tier-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  letter-spacing: 1px;
  transition: all .15s;
  width: 100%;
}

.add-tier-btn:hover { border-color: var(--accent); color: var(--accent); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: 400px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal h2 {
  font-family: 'Syne', sans-serif;
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 20px;
  letter-spacing: 1px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}

.modal-close:hover { color: var(--text); }

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
  resize: vertical;
}

.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }

.field input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  background: var(--surface2);
  cursor: pointer;
}

.field-row { display: flex; gap: 10px; }

.field-row .field { flex: 1; }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

.font-preview {
  margin-top: 8px;
  padding: 10px;
  background: var(--surface2);
  border-radius: var(--radius);
  text-align: center;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.txt-img-canvas-wrap {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}

#txt-img-preview-canvas {
  border-radius: 6px;
  border: 1px solid var(--border);
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
}

#zoom-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 800;
  cursor: zoom-out;
}

#zoom-overlay.open { display: flex; }

#zoom-img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 0 60px rgba(0,0,0,.8);
  image-rendering: auto;
}

::-webkit-scrollbar { width: 6px; height: 6px; }

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: .85;
  transform: translate(-50%, -50%) rotate(2deg) scale(1.08);
  display: none;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid var(--accent);
  box-shadow: 0 4px 20px rgba(232,52,42,0.4);
}

#drag-ghost img { width: 72px; height: 72px; object-fit: cover; display: block; }

#drag-ghost .ghost-sep {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  font-size: 24px;
}
