:root {
  --bg: #0a0b0f;
  --panel: #111319;
  --panel-2: #161922;
  --line: #232734;
  --line-soft: #1b1f29;
  --text: #e9ebf2;
  --muted: #8a92a6;
  --accent: #7c5cff;
  --accent-soft: #2a2350;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 45px rgba(0, 0, 0, .45);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(124, 92, 255, .16), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(34, 211, 238, .08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

.hidden { display: none !important; }

/* Author rules like .field { display:block } would otherwise defeat the
   [hidden] attribute the JS toggles. */
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -.01em;
  font-size: 15px;
}
.brand-lg { font-size: 21px; gap: 12px; }
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--accent), #4b2fd6 65%, var(--accent-2));
  box-shadow: 0 6px 18px rgba(124, 92, 255, .35);
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 6px;
  border: 2px solid rgba(255, 255, 255, .92);
  border-radius: 3px;
  border-bottom-color: transparent;
  border-right-color: transparent;
  transform: rotate(45deg) scale(.82);
}
.brand-lg .brand-mark { width: 34px; height: 34px; border-radius: 10px; }

/* ------------------------------------------------------------------- auth */
.auth {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 28px;
}
.auth-card {
  width: min(420px, 92vw);
  background: linear-gradient(180deg, rgba(24, 27, 36, .96), rgba(16, 18, 25, .96));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px 28px 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.auth-sub { color: var(--muted); font-size: 14px; margin: 10px 0 22px; }
.auth-foot {
  text-align: center;
  color: #5c6478;
  font-size: 12.5px;
  letter-spacing: .02em;
}
.auth-switch {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13.5px;
  color: var(--muted);
}

.linklike {
  background: none; border: 0; padding: 0 0 0 6px;
  color: var(--accent-2); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}

/* ----------------------------------------------------------------- fields */
.field { display: block; margin-bottom: 14px; }
.field > span,
.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
textarea, select {
  width: 100%;
  background: #0d0f15;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font: inherit;
  font-size: 14.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.55; }
input:focus, textarea:focus, select:focus {
  border-color: #4b3fa8;
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .18);
  background: #0f1118;
}
input::placeholder, textarea::placeholder { color: #4e5568; }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

/* ------------------------------------------------------------------ buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font: inherit;
  font-weight: 550;
  font-size: 14px;
  cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: #1d212c; border-color: #2e3444; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, #8566ff, #6b4bf0);
  border-color: #7a5cff;
  color: #fff;
  box-shadow: 0 8px 22px rgba(124, 92, 255, .28);
}
.btn-primary:hover { background: linear-gradient(180deg, #9074ff, #7558f5); border-color: #8f78ff; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255, 255, 255, .05); color: var(--text); border-color: transparent; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; margin-top: 6px; }

kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: rgba(0, 0, 0, .25);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 5px;
  padding: 1px 5px;
  margin-left: 6px;
  opacity: .8;
}

.form-error {
  color: var(--err);
  font-size: 13.5px;
  min-height: 18px;
  margin: 4px 0 8px;
}

/* -------------------------------------------------------------------- app */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(10, 11, 15, .82);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(16px);
}
.topbar-right { display: flex; align-items: center; gap: 6px; }

.backend {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--muted);
  padding: 5px 10px; border: 1px solid var(--line-soft);
  border-radius: 999px; margin-right: 8px;
}
.backend i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn); box-shadow: 0 0 0 3px rgba(251, 191, 36, .12);
}
.backend.ok i { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .14); }
.backend.bad i { background: var(--err); box-shadow: 0 0 0 3px rgba(248, 113, 113, .14); }

.user-chip {
  display: flex; align-items: center; gap: 4px;
  padding-left: 10px; margin-left: 4px;
  border-left: 1px solid var(--line-soft);
  font-size: 13.5px; color: var(--muted);
}

.layout {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
  gap: 22px;
  align-items: start;
}

/* ---------------------------------------------------------------- composer */
.panel {
  background: linear-gradient(180deg, rgba(22, 25, 34, .92), rgba(15, 17, 24, .92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer { position: sticky; top: 82px; overflow: hidden; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, .18);
}
.tab {
  flex: 1;
  padding: 10px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 550;
  font-size: 13.5px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, .03); }
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: rgba(124, 92, 255, .08);
}
.tab.off { opacity: .38; cursor: not-allowed; }
.tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.tab[aria-selected="true"] .dot { background: var(--accent); }

.composer-body { padding: 16px; }
.advanced { margin: 4px 0 12px; }
.advanced summary {
  cursor: pointer; color: var(--muted); font-size: 13px;
  list-style: none; padding: 4px 0; user-select: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: "＋ "; }
.advanced[open] summary::before { content: "− "; }
.advanced textarea { margin-top: 6px; }

.params {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 4px 0 10px;
}
.params .field { margin: 0; }
.params .field wide { grid-column: 1 / -1; }
.params .span-2 { grid-column: 1 / -1; }

.composer-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 6px;
}
.queue-note { font-size: 12.5px; color: var(--muted); text-align: right; }

/* -------------------------------------------------------------------- feed */
.feed { min-width: 0; }
.feed-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 12px;
}
.feed-head h2 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.01em; }

.filters { display: flex; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit; font-size: 12.5px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: #42377a; color: #dcd6ff; }

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

.job {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color .15s, transform .15s;
}
.job:hover { border-color: #313748; transform: translateY(-1px); }

.media {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #0c0e13;
  display: grid; place-items: center;
  overflow: hidden;
}
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.media .placeholder {
  color: #454c5e; font-size: 12.5px; text-align: center; padding: 18px;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}

.badge {
  position: absolute; top: 8px; left: 8px;
  font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(9, 10, 14, .78); border: 1px solid rgba(255, 255, 255, .1);
  color: #cfd4e2; backdrop-filter: blur(6px);
}
.badge.running { color: #c9c2ff; border-color: rgba(124, 92, 255, .4); }
.badge.done { color: #9ff0cd; border-color: rgba(52, 211, 153, .35); }
.badge.error { color: #ffb4b4; border-color: rgba(248, 113, 113, .4); }

.job-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.job-prompt {
  font-size: 13px; color: #c3c9d8; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.job-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.job-meta .when { font-size: 11.5px; color: #656d80; }
.job-actions { display: flex; gap: 4px; }

.progress {
  height: 3px; background: var(--line-soft); border-radius: 999px; overflow: hidden;
}
.progress > i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .4s ease;
}
.stage { font-size: 11.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.job-error {
  font-size: 12px; color: #ffb0b0; background: rgba(248, 113, 113, .08);
  border: 1px solid rgba(248, 113, 113, .18); border-radius: 8px;
  padding: 7px 9px; word-break: break-word;
}

.empty { color: #545b6d; font-size: 13.5px; padding: 28px 4px; }

/* ------------------------------------------------------------------ drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(460px, 94vw);
  background: #0f1117;
  border-left: 1px solid var(--line);
  box-shadow: -30px 0 60px rgba(0, 0, 0, .5);
  z-index: 40;
  display: flex; flex-direction: column;
  animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: .6; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line-soft);
}
.drawer-head h2 { font-size: 15px; margin: 0; }
.drawer-body { padding: 16px 18px 40px; overflow-y: auto; }
.drawer-section { margin-top: 22px; }
.drawer-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.hint { font-size: 12.5px; color: #6c7488; margin: 0 0 10px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px;
}
.stat b { display: block; font-size: 19px; font-weight: 600; }
.stat span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.inline-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inline-form input { grid-column: 1 / -1; }

.pin-reveal {
  margin-top: 12px; padding: 12px; border-radius: 10px;
  background: rgba(52, 211, 153, .07);
  border: 1px solid rgba(52, 211, 153, .25);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.pin-reveal code {
  font-family: var(--mono); font-size: 16px; letter-spacing: .12em;
  color: #a7f3d0; display: block; margin-top: 4px;
}

.invite-list, .user-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.invite-list li, .user-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 11px; border: 1px solid var(--line-soft); border-radius: 9px;
  font-size: 13px; background: rgba(255, 255, 255, .015);
}
.invite-list li.dead, .user-list li.dead { opacity: .45; }
.row-main { min-width: 0; }
.row-main b { font-weight: 550; }
.row-main small { display: block; color: #6c7488; font-size: 11.5px; }
.pill {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted);
}
.pill.owner { color: #d8ccff; border-color: #453a7d; background: rgba(124, 92, 255, .12); }
.pill.admin { color: #a5f3fc; border-color: #1d5b66; background: rgba(34, 211, 238, .08); }

/* ------------------------------------------------------------------ modal */
.modal {
  position: fixed; inset: 0; z-index: 55;
  display: grid; place-items: center;
  background: rgba(6, 7, 11, .78);
  backdrop-filter: blur(6px);
  padding: 20px;
}
.modal-card {
  width: min(420px, 94vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 6px; font-size: 16px; }
.modal-card .hint { margin-bottom: 14px; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px;
}

/* ----------------------------------------------------------------- viewer */
.viewer {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(6, 7, 11, .78);
  backdrop-filter: blur(6px);
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } }

.viewer-frame {
  width: min(1000px, 92vw);
  height: min(720px, 86vh);
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px; color: var(--muted);
}
.viewer-actions { display: flex; gap: 4px; }
.viewer-stage { flex: 1; min-height: 0; position: relative; }
.viewer-stage canvas { display: block; width: 100%; height: 100%; }
.viewer-hint {
  margin: 0; padding: 8px 14px 12px;
  font-size: 11.5px; color: #545b6d; text-align: center;
  border-top: 1px solid var(--line-soft);
}

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(14px);
  background: #1b1f2a; border: 1px solid var(--line);
  color: var(--text); font-size: 13.5px; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: rgba(248, 113, 113, .4); color: #ffc9c9; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1040px) {
  .layout { grid-template-columns: 1fr; }
  .composer { position: static; }
}
@media (max-width: 620px) {
  .layout { padding: 14px; gap: 16px; }
  .topbar { padding: 10px 14px; }
  .backend span:last-child { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .params { grid-template-columns: 1fr; }
}
