:root {
  --bg: #0c0d0f;
  --surface: #12141a;
  --surface-2: #191c24;
  --line: #252730;
  --line-strong: #3d404e;
  --text: #f2f2ec;
  --muted: #8f94a3;
  --accent: #f2f2ec;
  --accent-ink: #171a18;
  --ok: #afddd1;
  --font-display: 'LeanLab Compact', 'Bricolage Grotesque', Geist, sans-serif;
  --font-ui: Geist, system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; min-width: 0; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(12, 13, 15, 0.94); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1400px; margin: 0 auto; height: 56px; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.top-left { display: flex; align-items: center; gap: 12px; }
.back-btn {
  font-size: 12px; color: var(--muted); padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px;
}
.back-btn:hover { color: var(--text); border-color: var(--line-strong); }
.top-title { font-size: 14px; font-weight: 700; }
.nav-links { display: flex; gap: 8px; }
.nav-btn {
  padding: 7px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface);
}
.nav-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* 3-Column Modular Studio: Left Template Sidebar | Center Canvas | Right Controls */
.workspace {
  max-width: 1400px; margin: 0 auto; padding: 20px;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 304px;
  gap: 16px;
  align-items: start;
}

/* Left Modular Template Sidebar */
.sidebar {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
  position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow-y: auto;
}
.side-head { display: flex; align-items: baseline; justify-content: space-between; }
.side-head h2 { margin: 0; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.side-head span { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

.filter-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.flt-btn {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 4px; font-size: 10.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.flt-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.cat-label {
  font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 6px 2px 2px;
}

.lib-card {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; display: flex; align-items: center; gap: 10px;
}
.lib-thumb { width: 42px; height: 52px; border-radius: 6px; object-fit: cover; flex: none; background: #000; }
.lib-info { min-width: 0; flex: 1; }
.lib-info strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-info span { display: block; font-size: 10px; color: var(--muted); }
.lib-acts { display: flex; gap: 4px; flex: none; }
.lib-mini {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 7px; font-size: 10.5px; cursor: pointer;
}
.lib-mini:hover { border-color: var(--line-strong); }
.lib-empty { font-size: 11.5px; color: var(--muted); padding: 12px 6px; text-align: center; }

.tpl-list { display: flex; flex-direction: column; gap: 6px; }
.tpl-btn {
  width: 100%; text-align: left; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 3px;
  transition: border-color 140ms ease, background 140ms ease;
}
.tpl-btn:hover { border-color: var(--line-strong); }
.tpl-btn[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.tpl-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tpl-name { font-size: 13px; font-weight: 700; }
.tpl-ratio { font-family: var(--font-mono); font-size: 10px; opacity: 0.7; }
.tpl-desc { font-size: 11px; opacity: 0.72; }

/* Center Poster Stage */
.poster-frame {
  background: #08090b; border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; min-height: 640px;
  display: flex; justify-content: center; align-items: center;
}
.poster-frame canvas {
  max-width: 100%; max-height: 760px; height: auto; width: auto;
  border-radius: 10px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

/* Right Controls */
.controls {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 72px;
}
.ctrl-title {
  margin: 0; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }
.inp {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font-size: 13px; width: 100%;
}
.inp:focus { outline: none; border-color: var(--line-strong); }

.upload-box {
  border: 1px dashed var(--line-strong); border-radius: 10px; padding: 12px;
  text-align: center; font-size: 12px; color: var(--muted); cursor: pointer;
  background: var(--surface-2);
}
.upload-box:hover { color: var(--text); border-color: var(--ok); }
.upload-box input { display: none; }

.btn-pri, .btn-sec {
  width: 100%; padding: 11px 14px; border-radius: 9px; font-size: 13px; font-weight: 700;
  cursor: pointer; border: 1px solid var(--line);
}
.btn-pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-sec { background: var(--surface-2); color: var(--text); }
.status { font-size: 12px; color: var(--ok); min-height: 16px; }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr); }
  .controls { grid-column: 1 / -1; position: static; }
}
@media (max-width: 720px) {
  .workspace { grid-template-columns: 1fr; padding: 12px; }
  .sidebar, .controls { position: static; max-height: none; }
  .tpl-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
