:root {
  --bg: #0b0c0f;
  --panel: #121419;
  --panel-2: #181b21;
  --line: #242832;
  --text: #eceef2;
  --muted: #8b93a3;
  --accent: #c6ff3d;
  --accent-ink: #0b0c0f;
  --danger: #ff5d6c;
  --radius: 14px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, textarea, select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none; transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 44px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.end { justify-content: flex-end; }
.row > button, .row > .primary, .row > .ghost { white-space: nowrap; flex-shrink: 0; }

.primary {
  background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: 12px;
  padding: 10px 16px; transition: transform .08s, filter .15s;
}
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.primary.big { width: 100%; padding: 14px; font-size: 16px; }
.ghost { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--panel); }
.ghost:hover { border-color: #3a404d; }
.ghost.small { padding: 6px 10px; font-size: 13px; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login-view { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 70% -10%, #1d2a0a 0%, transparent 60%), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; font-size: 17px; }
.brand.big { font-size: 24px; }
.logo { width: 22px; height: 22px; background: url("/static/favicon.svg") center/contain no-repeat; display: inline-block; }
.brand.big .logo { width: 30px; height: 30px; }

/* ---------- app shell ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 12px 20px; background: rgba(11,12,15,.85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab { padding: 6px 16px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--accent); border-color: #3b4a14; }
.pill.bad { color: var(--danger); border-color: #4a1d23; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px; display: grid; min-width: 150px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.menu button { text-align: left; padding: 8px 10px; border-radius: 8px; }
.menu button:hover { background: var(--panel-2); }

.layout { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
.composer { border-right: 1px solid var(--line); padding: 18px; display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; }
.block { display: grid; gap: 8px; }
.label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: none; letter-spacing: .02em; }
.note { margin: 0; }

.tool-list { display: grid; gap: 8px; }
.tool { text-align: left; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: grid; gap: 2px; transition: border-color .15s, background .15s; }
.tool:hover { border-color: #3a404d; }
.tool.active { border-color: var(--accent); background: linear-gradient(180deg, rgba(198,255,61,.07), transparent); }
.tool.off { opacity: .55; }
.tool-title { font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool-sub { color: var(--muted); font-size: 12px; }
.badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: #20252e; color: #c9d1dc; }
.badge.hot { background: var(--accent); color: var(--accent-ink); }

.image-inputs { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.image-inputs:empty { display: none; }
.drop { position: relative; border: 1.5px dashed #343a46; border-radius: var(--radius); min-height: 120px;
  display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 12px; padding: 10px;
  overflow: hidden; background: var(--panel); transition: border-color .15s; }
.drop:hover, .drop.over { border-color: var(--accent); color: var(--text); }
.drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.drop .drop-label { position: relative; z-index: 1; background: rgba(11,12,15,.6); padding: 2px 8px; border-radius: 6px; }
.drop .drop-clear { position: absolute; z-index: 2; top: 6px; right: 6px; background: rgba(11,12,15,.8);
  border-radius: 8px; padding: 2px 8px; color: var(--text); }
.drop.busy::after { content: ""; position: absolute; inset: 0; background: rgba(11,12,15,.55); }

.options { gap: 12px; }
.opt { display: grid; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 11px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
.chip.active { border-color: var(--accent); color: var(--accent); }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.advanced .field { display: grid; gap: 6px; margin-top: 10px; }

/* ---------- gallery ---------- */
.gallery-wrap { padding: 18px 22px 40px; min-width: 0; }
.gallery-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.gallery-head h2 { margin: 0; font-size: 16px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--panel);
  border: 1px solid var(--line); aspect-ratio: 1 / 1; cursor: zoom-in; }
.card.wide { aspect-ratio: 16 / 10; }
.card img, .card video { width: 100%; height: 100%; object-fit: cover; display: block; background: #07080a; }
.card .overlay { position: absolute; inset: auto 0 0 0; padding: 28px 10px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.85)); opacity: 0; transition: opacity .15s; }
.card:hover .overlay, .card:focus-within .overlay { opacity: 1; }
.card .ov-title { font-size: 12px; font-weight: 700; }
.card .ov-prompt { font-size: 12px; color: #c8ced8; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .ov-actions { display: flex; gap: 6px; margin-top: 6px; }
.icon-btn { background: rgba(20,22,27,.85); border: 1px solid #2d323c; border-radius: 8px; padding: 4px 8px; font-size: 12px; }
.icon-btn:hover { border-color: var(--accent); }
.card .kind { position: absolute; top: 8px; left: 8px; font-size: 11px; background: rgba(11,12,15,.75); padding: 2px 7px; border-radius: 6px; }
.card.pending { cursor: default; display: grid; place-items: center; text-align: center; padding: 16px;
  background: radial-gradient(400px 200px at 50% 0%, rgba(198,255,61,.06), transparent), var(--panel); }
.pending .p-title { font-weight: 700; margin-bottom: 4px; }
.pending .p-stage { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.bar { width: 80%; height: 6px; border-radius: 99px; background: #232832; overflow: hidden; margin: 0 auto 10px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.bar.indeterminate > i { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
.card.failed { cursor: default; display: grid; place-items: center; padding: 16px; text-align: center; }
.card.failed .p-stage { color: var(--danger); font-size: 12px; margin: 6px 0 10px; word-break: break-word; }
.empty { text-align: center; color: var(--muted); padding: 80px 20px; }
.empty-art { width: 64px; height: 64px; margin: 0 auto 12px; background: url("/static/favicon.svg") center/contain no-repeat; opacity: .5; }
.more-wrap { display: grid; place-items: center; margin-top: 16px; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(5,6,8,.92); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 24px; }
.lb-close { position: absolute; top: 16px; right: 16px; }
.lb-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; width: min(1400px, 100%); max-height: 100%; }
.lb-media { display: grid; place-items: center; min-height: 0; }
.lb-media img, .lb-media video { max-width: 100%; max-height: calc(100vh - 80px); border-radius: 12px; }
.lb-info { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; overflow-y: auto;
  max-height: calc(100vh - 80px); display: grid; gap: 12px; align-content: start; }
.lb-tool { font-weight: 800; }
.lb-prompt { white-space: pre-wrap; word-break: break-word; margin: 0; color: #d7dce4; }
.lb-params { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 12px; }
.lb-params dt { color: var(--muted); }
.lb-params dd { margin: 0; word-break: break-all; }
.lb-actions { display: grid; gap: 8px; }

dialog { border: 0; padding: 0; background: transparent; color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: min(360px, 92vw); display: grid; gap: 12px; }
.dialog-card h3 { margin: 0; }
.dialog-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

.dialog-card.wide { width: min(780px, 94vw); max-height: 86vh; overflow-y: auto; }
.admin-sec { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.admin-invite { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center; }
.admin-invite select { width: auto; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.check input { width: auto; }
.inv-result { display: grid; gap: 6px; }
.inv-result input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.admin-list { display: grid; gap: 6px; }
.admin-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.admin-row .grow { flex: 1; min-width: 160px; }
.admin-row .tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #262b35; }
.admin-row .tag.warn { background: #4a1d23; color: #ffd6db; }
.admin-row .tag.ok { background: #2a3a10; color: var(--accent); }
@media (max-width: 640px) { .admin-invite { grid-template-columns: 1fr 1fr; } }

.guide ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.code { margin: 0; background: #0a0b0e; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; color: #d5f7a0; }
code { font-family: ui-monospace, Consolas, monospace; background: #20252e; padding: 1px 5px; border-radius: 5px; }

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; }
.toast { background: #1d2129; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 90vw; }
.toast.err { border-color: #5a222b; color: #ffd6db; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .composer { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar { gap: 10px; padding: 10px 12px; }
  .brand { font-size: 15px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .lb-body { grid-template-columns: 1fr; overflow-y: auto; }
  .card .overlay { opacity: 1; }
  #engine-pill { display: none; }
}
