/* LayerMagic — style.css v1 */
:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #1c2420;
  --muted: #6b7770;
  --line: #e3e8e2;
  --emerald: #10b981;
  --emerald-dark: #0b7a56;
  --emerald-soft: #e7f7f0;
  --danger: #d9534f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 30, 0.06), 0 6px 18px rgba(16, 40, 30, 0.05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- header ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 1.05rem; letter-spacing: 0.2px; }
.brand-text span { font-size: 0.72rem; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }

.chip-btn {
  font: inherit; font-size: 0.8rem; font-weight: 700;
  color: var(--emerald-dark);
  background: var(--emerald-soft);
  border: 1px solid #cdeeda;
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s;
}
.chip-btn:hover { background: #d9f2e6; }

/* ---------- layout ---------- */
#layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 14px;
  padding: 14px 18px;
  flex: 1;
  min-height: 0;
}
#panel { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.card.grow { flex: 1; display: flex; flex-direction: column; min-height: 120px; }
.card-title {
  font-weight: 800; font-size: 0.9rem; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.badge {
  background: var(--emerald-soft); color: var(--emerald-dark);
  font-size: 0.72rem; font-weight: 800;
  border-radius: 999px; padding: 1px 9px;
}

/* engine status */
.engine-status { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c2ccc5; flex-shrink: 0; }
.dot.loading { background: #f0b429; animation: pulse 1.1s infinite; }
.dot.ready { background: var(--emerald); }
.dot.error { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }
.progress-wrap { margin-top: 10px; }
.progress-label { font-size: 0.7rem; color: var(--muted); margin-bottom: 4px; }
.progress-track { height: 7px; background: #edf1ee; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #34d399, #10b981); transition: width 0.2s; }
.muted { color: var(--muted); }
.small { font-size: 0.72rem; }
#engine-note { margin-top: 10px; line-height: 1.6; }

/* layers list */
.layers-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.layer-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 9px; margin-bottom: 7px;
  background: #fbfdfb;
}
.layer-row.off { opacity: 0.45; }
.layer-chip { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.12); }
.layer-name { flex: 1; font-size: 0.78rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-meta { font-size: 0.66rem; color: var(--muted); flex-shrink: 0; }
.icon-btn {
  font: inherit; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; padding: 3px 7px; cursor: pointer; font-size: 0.75rem;
  color: var(--ink); line-height: 1.2; flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--emerald); color: var(--emerald-dark); }
.icon-btn.del:hover { border-color: var(--danger); color: var(--danger); }
#layers-empty { margin-top: 4px; line-height: 1.7; }

/* export */
.btn-col { display: flex; flex-direction: column; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 0.8rem; font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--emerald); color: var(--emerald-dark); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--emerald); border-color: var(--emerald); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--emerald-dark); color: #fff; }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.btn.toggle.active { background: var(--emerald-soft); border-color: var(--emerald); color: var(--emerald-dark); box-shadow: inset 0 0 0 1px var(--emerald); }

/* ---------- stage ---------- */
#stage { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
#toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow);
}
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; }

#canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 340px;
  border-radius: var(--radius);
  background: #171c19;
  background-image:
    linear-gradient(45deg, #1d231f 25%, transparent 25%, transparent 75%, #1d231f 75%),
    linear-gradient(45deg, #1d231f 25%, transparent 25%, transparent 75%, #1d231f 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#view { max-width: calc(100% - 24px); max-height: calc(100% - 24px); display: none; }
#view.on { display: block; }
#view.click-mode { cursor: crosshair; }
#view.edit-mode { cursor: grab; }
#view.edit-mode.dragging { cursor: grabbing; }

/* transform panel */
.tf-row {
  display: grid;
  grid-template-columns: 60px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.75rem;
}
.tf-row label { font-weight: 700; color: var(--ink); }
.tf-row input[type="range"] { width: 100%; accent-color: var(--emerald); cursor: pointer; }
.tf-val { font-size: 0.7rem; color: var(--muted); text-align: end; font-variant-numeric: tabular-nums; font-weight: 700; }
.tf-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.btn.small { padding: 6px 10px; font-size: 0.72rem; flex: 1; min-width: 0; }

/* selected layer highlight */
.layer-row.selected {
  border-color: var(--emerald);
  background: var(--emerald-soft);
  box-shadow: 0 0 0 1px var(--emerald);
}

#dropzone {
  position: absolute; inset: 14px;
  border: 2px dashed #3a4a41;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}
#dropzone.drag { border-color: var(--emerald); background: rgba(16, 185, 129, 0.08); }
.dz-inner { text-align: center; color: #cfd8d2; padding: 20px; }
.dz-inner h2 { margin: 12px 0 4px; font-size: 1.15rem; color: #fff; }
.dz-inner p { margin: 0 0 18px; font-size: 0.78rem; }
.dz-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

#busy {
  position: absolute; inset: 0;
  background: rgba(14, 20, 17, 0.72);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #fff; font-weight: 700; font-size: 0.9rem;
  z-index: 5;
}
.spinner {
  width: 42px; height: 42px;
  border: 4px solid rgba(255,255,255,0.25);
  border-top-color: var(--emerald);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#hintbar {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 0.7rem; color: var(--muted);
  padding: 2px 6px;
}

.hidden { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #layout { grid-template-columns: 1fr; padding: 10px; }
  #panel { order: 2; }
  #stage { order: 1; }
  .brand-text span { display: none; }
}
