:root {
  --bg: #0e0f13;
  --panel: #161821;
  --panel-2: #1d2030;
  --border: #2a2d40;
  --text: #e8eaf6;
  --text-dim: #9ba1b6;
  --accent: #6b8afd;
  --accent-2: #8b5cf6;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); }
button.small { padding: 4px 10px; font-size: 12px; }

input, textarea, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
textarea { resize: vertical; min-height: 60px; }

label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar .backend {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text-dim);
  margin-left: 12px;
}
.topbar .backend.fal { color: var(--ok); }

.container { max-width: 1280px; margin: 0 auto; padding: 24px; }

/* ── Project list ─────────────────────────────────────────────── */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.project-card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.project-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.project-card h3 { margin: 0 0 6px; font-size: 16px; }
.project-card .meta { font-size: 12px; color: var(--text-dim); }

.empty { color: var(--text-dim); text-align: center; padding: 60px 20px; }

/* ── Editor layout ─────────────────────────────────────────────── */
.editor {
  display: grid;
  grid-template-columns: clamp(200px, 22vw, 320px) 1fr clamp(200px, 22vw, 320px);
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 56px);
  min-width: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-y: auto;
}
.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.panel h3 {
  font-size: 12px;
  color: var(--text-dim);
  margin: 16px 0 6px;
}

.field { margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > button { flex: 0 0 auto; }

/* ── Gallery ─────────────────────────────────────────────────── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.thumb {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--panel-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.active { border-color: var(--accent); }
.thumb.keyframe { border-color: var(--accent-2); box-shadow: 0 0 0 2px var(--accent-2); }
.thumb .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent-2);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
}
.thumb .key-order {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--accent-2);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
}

/* ── Canvas area ─────────────────────────────────────────────── */
.canvas-wrap {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.canvas-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}
.canvas-toolbar .spacer { flex: 1; }
.canvas-stage {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #07080c;
}
.canvas-stage .stage-inner { position: relative; }
.canvas-stage img.base { display: block; max-width: 100%; max-height: calc(100vh - 200px); }
.canvas-stage canvas { position: absolute; top: 0; left: 0; cursor: crosshair; }

.annotation-list { font-size: 12px; }
.annotation-list .ann {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 4px;
}
.annotation-list .ann select { flex: 1; padding: 3px 6px; font-size: 11px; }
.annotation-list .ann .swatch { width: 10px; height: 10px; border-radius: 50%; }

/* ── Job progress ─────────────────────────────────────────────── */
.progress {
  margin-top: 10px;
  background: var(--panel-2);
  border-radius: 6px;
  height: 6px;
  overflow: hidden;
}
.progress .bar { height: 100%; background: var(--accent); transition: width 0.2s; }
.status-line { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.status-line.ok { color: var(--ok); }
.status-line.err { color: var(--danger); }

video.preview { width: 100%; border-radius: 8px; margin-top: 8px; background: black; }
audio.preview { width: 100%; margin-top: 8px; }

.divider { height: 1px; background: var(--border); margin: 14px 0; }
