:root {
  color-scheme: dark;
  --bg: #07080f;
  --ink: #f4f2ff;
  --muted: #9a97b8;
  --faint: #6b688a;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --glass: rgba(18, 18, 32, 0.72);
  --violet: #8b7cff;
  --violet-2: #b4a7ff;
  --magenta: #ff6bcb;
  --cyan: #5ce1ff;
  --ok: #4ade80;
  --danger: #ff6b8a;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.glow {
  position: fixed; border-radius: 50%; filter: blur(70px);
  pointer-events: none; z-index: 0; opacity: 0.45;
}
.glow-a {
  width: min(420px, 40vw); height: min(420px, 40vw);
  top: -10%; left: -6%;
  background: radial-gradient(circle, rgba(139,124,255,.55), transparent 70%);
}
.glow-b {
  width: min(340px, 32vw); height: min(340px, 32vw);
  top: 25%; right: -8%;
  background: radial-gradient(circle, rgba(255,107,203,.32), transparent 70%);
}
.glow-c {
  width: min(280px, 28vw); height: min(280px, 28vw);
  bottom: -6%; left: 35%;
  background: radial-gradient(circle, rgba(92,225,255,.2), transparent 70%);
}

.app {
  position: relative; z-index: 1;
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Header */
.header {
  display: flex; align-items: center; justify-content: space-between;
  height: 48px; padding: 0 12px; border-radius: 14px; flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-orb {
  position: relative; width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #a794ff, #6d5cff 45%, #ff6bcb);
  font-weight: 800; font-size: 13px;
  box-shadow: 0 6px 18px rgba(139,124,255,.4);
  overflow: hidden;
}
.logo-orb i {
  position: absolute; inset: -40%;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.45), transparent 70%);
  animation: sheen 3.5s ease-in-out infinite;
}
@keyframes sheen {
  0%, 100% { transform: translateX(-30%) rotate(20deg); opacity: 0; }
  40% { opacity: 1; }
  70% { transform: translateX(30%) rotate(20deg); opacity: 0; }
}
.logo-copy { display: flex; flex-direction: column; line-height: 1.05; }
.logo-copy strong { font-size: 13px; font-weight: 700; }
.logo-copy em {
  font-style: normal; font-size: 9px; color: var(--muted);
  letter-spacing: 0.08em; text-transform: uppercase;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.server-inline input {
  width: min(220px, 28vw); height: 30px;
  font-family: var(--mono); font-size: 10px;
  background: rgba(0,0,0,.28); border: 1px solid var(--line);
  border-radius: 8px; padding: 0 8px; outline: none;
}
.server-inline input:focus { border-color: rgba(139,124,255,.5); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px; border-radius: 999px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}
.pill .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.pill[data-state="on"] { color: #b8f7d1; border-color: rgba(74,222,128,.28); }
.pill[data-state="on"] .pulse {
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(74,222,128,.5);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74,222,128,.5); }
  70% { box-shadow: 0 0 0 8px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 11px; border-radius: 9px;
  font-size: 11px; font-weight: 600;
  transition: .12s ease;
}
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-soft {
  background: rgba(255,255,255,0.06); border: 1px solid var(--line-strong);
}
.btn-soft:hover:not(:disabled) { background: rgba(255,255,255,0.1); }
.btn-ghost {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line); color: var(--ink);
}
.btn-ghost:hover:not(:disabled) {
  border-color: rgba(180,167,255,.4); background: rgba(139,124,255,.1);
}
.btn-mini {
  height: 26px; min-width: 26px; padding: 0 8px; font-size: 11px;
  border-radius: 7px; background: rgba(255,255,255,0.05); border: 1px solid var(--line);
}
.btn-mini:hover { border-color: var(--violet-2); }

.btn-glow {
  position: relative; flex-shrink: 0;
  width: 100%; height: 42px; border-radius: 12px;
  overflow: hidden; isolation: isolate;
}
.btn-glow-bg {
  position: absolute; inset: 0;
  background: linear-gradient(120deg, #7c6bff, #a78bfa 35%, #ff6bcb 70%, #5ce1ff);
  background-size: 220% 220%;
  animation: gradientMove 6s ease infinite;
}
@keyframes gradientMove {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.btn-glow::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,.2), transparent 45%);
  pointer-events: none;
}
.btn-glow-label {
  position: relative; z-index: 1;
  font-size: 13px; font-weight: 750; color: #0b0618;
}
.btn-glow kbd {
  position: relative; z-index: 1; margin-left: 8px;
  font-family: var(--mono); font-size: 9px;
  padding: 2px 6px; border-radius: 5px;
  background: rgba(0,0,0,.18); color: rgba(10,6,24,.75);
}
.btn-glow:disabled .btn-glow-bg { animation: none; background: #2a2a3d; }
.btn-glow:disabled .btn-glow-label,
.btn-glow:disabled kbd { color: var(--faint); }
.btn-glow.busy .btn-glow-bg {
  animation: none; background: linear-gradient(120deg, #3a3758, #2c2a44);
}
.btn-glow.busy .btn-glow-label { color: var(--muted); }

.text-btn { font-size: 10px; color: var(--muted); }
.text-btn:hover { color: var(--violet-2); }

/* Main: fills remaining height, no page scroll */
.layout {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 360px);
  gap: 8px;
  overflow: hidden;
}

/* Stage */
.stage {
  min-height: 0;
  border-radius: 16px;
  padding: 10px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.stage-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; flex-shrink: 0;
}
.stage-top h1 {
  margin: 0; font-size: 13px; font-weight: 650;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.status-chip {
  height: 24px; padding: 0 10px; border-radius: 999px;
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 600;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line); color: var(--muted);
}
.status-chip.running {
  color: #d6ceff; border-color: rgba(139,124,255,.4); background: rgba(139,124,255,.14);
}
.status-chip.done {
  color: #b8f7d1; border-color: rgba(74,222,128,.35); background: rgba(74,222,128,.1);
}
.status-chip.error {
  color: #ffc0cc; border-color: rgba(255,107,138,.35); background: rgba(255,107,138,.1);
}

.frame {
  position: relative; flex: 1; min-height: 0;
  border-radius: 12px; overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(139,124,255,.12), transparent 55%),
    linear-gradient(180deg, #10101c, #0a0a14);
  border: 1px solid var(--line);
  display: grid; place-items: center;
}
.frame-shine {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.04), transparent 35%);
  pointer-events: none;
}
.empty { position: relative; z-index: 1; text-align: center; padding: 16px; }
.empty-ring {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(from 180deg, rgba(139,124,255,.55), rgba(255,107,203,.35), rgba(92,225,255,.35), rgba(139,124,255,.55));
  animation: spinSlow 10s linear infinite;
}
@keyframes spinSlow { to { transform: rotate(360deg); } }
.empty-core {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: #0d0d18; color: var(--violet-2); font-size: 18px;
}
.empty h2 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.empty p { margin: 0; font-size: 11px; color: var(--muted); }
.result {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #07080f; z-index: 2;
}
.result:not([hidden]) ~ .empty,
.result:not([hidden]) ~ .frame-shine { opacity: 0; pointer-events: none; }

.progress {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: rgba(7,8,15,.72); backdrop-filter: blur(6px);
}
.progress-orb {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--violet-2); border-right-color: var(--magenta);
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-track {
  width: min(200px, 50%); height: 5px; border-radius: 999px;
  background: rgba(255,255,255,.08); overflow: hidden;
}
.progress-track i {
  display: block; height: 100%; width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--violet), var(--magenta), var(--cyan));
  background-size: 200% 100%;
  animation: gradientMove 2s linear infinite;
  transition: width .2s ease;
}
#progressText {
  font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: var(--violet-2);
}

.stage-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 8px; flex-shrink: 0;
}
.filename {
  font-size: 11px; color: var(--faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stage-btns { display: flex; gap: 6px; flex-shrink: 0; }

/* Side panel — single column, fixed to viewport */
.side {
  min-height: 0;
  border-radius: 16px;
  padding: 10px;
  display: flex; flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.side-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(139,124,255,.3) transparent;
}

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.card-head.tight { margin-top: 2px; }
.card-head h3, .fold summary {
  margin: 0; font-size: 10px; font-weight: 650;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.card-head span { font-size: 10px; color: var(--faint); }

.refs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex-shrink: 0;
}
.ref {
  border-radius: 10px; overflow: hidden;
  background: rgba(0,0,0,.22); border: 1px solid var(--line);
}
.ref-media {
  height: 72px; position: relative;
  background:
    radial-gradient(circle at 30% 20%, rgba(139,124,255,.18), transparent 55%),
    #0c0c16;
}
.ref-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
}
.ref-placeholder span {
  font-size: 16px; font-weight: 800;
  background: linear-gradient(135deg, var(--violet-2), var(--magenta));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.ref-media img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.ref.has-image .ref-placeholder { display: none; }
.ref-actions {
  display: grid; grid-template-columns: 1fr auto; gap: 4px;
  padding: 5px; border-top: 1px solid var(--line);
}
.ref-actions select { height: 26px; font-size: 9px; }

textarea, select, input[type="number"] {
  width: 100%;
  background: rgba(0,0,0,.28);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
}
textarea {
  padding: 8px 10px;
  font-size: 12px; line-height: 1.4;
  resize: none;
  height: 72px;
  flex-shrink: 0;
}
#negative { height: 56px; }
select, input[type="number"] {
  height: 30px; padding: 0 8px; font-size: 11px;
}
textarea:focus, select:focus, input:focus {
  border-color: rgba(139,124,255,.55);
  box-shadow: 0 0 0 2px rgba(139,124,255,.12);
}

.stack.compact { display: grid; gap: 6px; }
.field { display: grid; gap: 3px; }
.field > span { font-size: 10px; color: var(--muted); display: flex; justify-content: space-between; }
.field > span b { color: var(--ink); font-family: var(--mono); font-size: 10px; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.trio { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 6px; }
.seed { display: grid; grid-template-columns: 1fr auto; gap: 4px; }

.slider { display: grid; gap: 4px; }
.slider-top {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--muted);
}
.slider-top b {
  color: var(--ink); font-family: var(--mono); font-size: 10px;
}
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 999px;
  background: linear-gradient(90deg, rgba(139,124,255,.35), rgba(255,107,203,.25));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(145deg, #fff, #c4b5ff);
  border: 0; box-shadow: 0 2px 8px rgba(139,124,255,.5); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(145deg, #fff, #c4b5ff); border: 0; cursor: pointer;
}

.res {
  height: 28px; display: grid; place-items: center;
  border-radius: 8px;
  background: rgba(139,124,255,.08);
  border: 1px solid rgba(139,124,255,.18);
  font-family: var(--mono); font-size: 11px; color: var(--violet-2);
}

.fold {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0,0,0,.15);
  padding: 6px 8px;
  flex-shrink: 0;
}
.fold summary {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; justify-content: space-between;
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after {
  content: "›"; color: var(--faint); font-size: 14px;
  transition: transform .15s ease;
}
.fold[open] summary::after { transform: rotate(90deg); }
.fold[open] { padding-bottom: 8px; }
.fold .stack, .fold textarea { margin-top: 6px; }

/* Mobile: allow scroll only if needed */
@media (max-width: 900px) {
  html, body { overflow: auto; height: auto; }
  .app {
    height: auto; min-height: 100dvh;
    overflow: visible;
  }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  .stage { min-height: 42vh; }
  .frame { min-height: 36vh; }
  .side { max-height: none; }
  .side-scroll { overflow: visible; }
  .server-inline input { width: 140px; }
  .trio { grid-template-columns: 1fr 1fr; }
  .trio .field:first-child { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .pill-text { display: none; }
  .logo-copy em { display: none; }
  .server-inline { display: none; }
}
