:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --border: #262b33;
  --text: #e8eaed;
  --text-dim: #7d8590;
  --accent: #5ee6c8;
  --accent-ink: #06211c;
  --danger: #ff6b6b;
  --radius: 4px;
  --mono: 'JetBrains Mono', 'SFMono-Regular', Menlo, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

body { display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; letter-spacing: .01em; }

.brand-mark {
  width: 8px; height: 8px;
  background: var(--accent);
  flex-shrink: 0;
}

.brand-name { color: var(--text); }

.topnav { display: flex; gap: 4px; }

.topnav-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius);
}

.topnav-link:hover { color: var(--text); }
.topnav-link.active { color: var(--text); background: var(--bg); }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-text {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}

.export-group { display: flex; gap: 6px; }

.format-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-family: var(--mono);
  padding: 7px 8px;
  border-radius: var(--radius);
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--sans);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}

.btn:hover:not(:disabled) { border-color: var(--text-dim); }
.btn:disabled { opacity: .35; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #7cecd3; }

.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

.icon-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  width: 28px; height: 28px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}

.icon-btn:hover { border-color: var(--text-dim); }
.icon-btn-wide { width: auto; padding: 0 12px; font-size: 12px; }

/* ---------- Layout ---------- */
.workspace { flex: 1; display: grid; grid-template-columns: 250px 1fr 270px; min-height: 0; }

.panel {
  background: var(--panel);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }
.panel-section.grow { flex: 1; }

.panel-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}

/* ---------- Upload ---------- */
.upload-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px 10px;
  cursor: pointer;
  color: var(--text-dim);
  transition: border-color .15s, color .15s;
}

.upload-drop:hover, .upload-drop.dragover { border-color: var(--accent); color: var(--accent); }
.upload-icon { font-size: 20px; }
.upload-text { font-size: 12px; text-align: center; }

/* ---------- Class chips ---------- */
.class-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.class-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-dim);
}

.class-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.class-chip.active { border-color: currentColor; color: var(--text); background: #1a1e24; }

.class-add { display: flex; gap: 6px; }

/* ---------- Inputs ---------- */
.text-input {
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: var(--sans);
}

.text-input:focus { outline: none; border-color: var(--accent); }
.text-input-sm { padding: 7px 9px; font-size: 12px; }

.hint { font-size: 11px; color: var(--text-dim); margin-top: 8px; line-height: 1.6; }

.help-list { margin: 0; padding-left: 16px; font-size: 12px; color: var(--text-dim); line-height: 2; }

kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: var(--mono);
}

/* ---------- Canvas ---------- */
.canvas-area { display: flex; flex-direction: column; min-height: 0; }

.canvas-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.zoom-level { font-family: var(--mono); font-size: 12px; color: var(--text-dim); width: 40px; text-align: center; }

.toolbar-divider { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }

.canvas-scroll {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(45deg, #14171b 25%, transparent 25%),
    linear-gradient(-45deg, #14171b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #14171b 75%),
    linear-gradient(-45deg, transparent 75%, #14171b 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0px;
  background-color: var(--bg);
}

.canvas-wrap { position: relative; box-shadow: 0 0 0 1px var(--border); flex-shrink: 0; }

#canvas { display: block; cursor: crosshair; }

.canvas-placeholder {
  color: var(--text-dim);
  font-size: 13px;
  padding: 70px 110px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin: 60px;
}

/* ---------- Box list ---------- */
.box-list { display: flex; flex-direction: column; gap: 8px; }
.empty-note { font-size: 12px; color: var(--text-dim); }

.box-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
}

.box-item.selected { border-color: var(--accent); }
.box-item .swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.box-item .box-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-item .box-coords { color: var(--text-dim); font-size: 10px; font-family: var(--mono); }
.box-item .remove-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; }

/* ---------- Gallery ---------- */
.gallery-main { flex: 1; padding: 28px; overflow-y: auto; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.gallery-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.gallery-card img { width: 100%; height: 150px; object-fit: cover; display: block; background: var(--bg); }

.gallery-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }

.gallery-card-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.gallery-card-meta { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

.gallery-card-actions { display: flex; gap: 6px; margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .panel-left, .panel-right { border: none; border-top: 1px solid var(--border); }
}
