:root {
  --bg: #07080c;
  --panel: #12151e;
  --panel-2: #1a1f2c;
  --border: #2a3144;
  --text: #f2f4fa;
  --muted: #8b93a7;
  --accent: #a78bfa;
  --accent-2: #38bdf8;
  --warn: #fbbf24;
  --ok: #34d399;
  --danger: #f87171;
  --radius: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
em { font-style: normal; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 20% -10%, #1b2450, transparent), var(--bg);
}
.login-card {
  width: min(380px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card h1 em { color: var(--accent); }
.login-card label { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.login-card button {
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #1a1028;
  font-weight: 700;
  cursor: pointer;
}
.muted { color: var(--muted); margin: 0; }
.error { color: var(--danger); margin: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 8, 12, 0.92);
  position: sticky;
  top: 0;
  backdrop-filter: blur(10px);
  z-index: 20;
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.brand em { color: var(--accent); }
.topbar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.mode-toggle {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.mode-pill {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
.mode-pill.on { background: var(--accent); color: #1a1028; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 58px);
}
.studio-layout { grid-template-columns: 260px 1fr; }
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 12px;
  overflow: auto;
}
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}
.chip.active { color: #1a1028; border-color: transparent; background: var(--accent); }
.chip.primary { background: var(--accent); border-color: transparent; color: #1a1028; }
.chip.ghost { color: var(--muted); }
.chip.disabled, .chip:disabled { opacity: 0.4; pointer-events: none; }

.queue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.queue-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
}
.queue-item:hover, .queue-item.active { border-color: var(--accent); }
.queue-item h3 { margin: 0 0 4px; font-size: 0.95rem; }
.queue-item .meta { color: var(--muted); font-size: 0.75rem; display: flex; gap: 8px; flex-wrap: wrap; }

.detail, .studio-detail {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.empty { color: var(--muted); padding: 40px; text-align: center; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: transparent; color: #1a1028; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(248,113,113,0.12); border-color: rgba(248,113,113,0.35); color: #fca5a5; }
.btn.sm { padding: 5px 8px; font-size: 0.8rem; }
.btn.sec { background: var(--panel-2); color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.2); }

.status-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.status-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
}
.status-btn.active.draft { color: #c9d1e0; border-color: #5a6478; }
.status-btn.active.ready { color: #9ecbff; border-color: #3d6ea8; background: #1a2b44; }
.status-btn.active.processing { color: #ffd789; border-color: #8a6a28; background: #2d2614; }
.status-btn.active.done { color: #9af0c4; border-color: #2f7a55; background: #163528; }

.badge {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
}

.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.field input, .field textarea, .field select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
.field textarea { min-height: 64px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ——— Empty bench ——— */
.empty-bench {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 48px 24px;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(42,49,68,0.28) 23px, rgba(42,49,68,0.28) 24px),
    repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(42,49,68,0.28) 23px, rgba(42,49,68,0.28) 24px);
}
.empty-bench-icon {
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px dashed var(--border);
  display: grid; place-items: center;
  color: var(--muted); font-size: 1.2rem; background: rgba(7,8,12,0.5);
}
.empty-bench h2 { margin: 0; font-size: 1.15rem; font-weight: 650; }
.empty-bench p { margin: 0; color: var(--muted); font-size: 0.9rem; max-width: 42ch; line-height: 1.45; }
.empty-bench-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

/* ——— Studio shell: stream + scene/tune ——— */
.studio-shell {
  display: grid;
  grid-template-columns: 1fr 300px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.studio-shell.tune-open { grid-template-columns: 1fr 340px; }
.stream-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.stream {
  flex: 1;
  overflow: auto;
  padding: 20px 24px 24px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}
.batch-chrome {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.batch-chrome h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  outline: none;
}
.batch-chrome .batch-meta { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }

.stream-beat { margin-bottom: 22px; }
.prompt-bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 6px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.prompt-bubble .who {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.prompt-bubble p { margin: 0; line-height: 1.45; font-size: 0.95rem; }

.clip-card {
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  position: relative;
}
.clip-card.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.clip-visual {
  aspect-ratio: 16/9;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 40% 30%, #2a1f55, #0a1020 65%);
  position: relative;
}
.clip-visual video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.clip-play {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0,0,0,0.45);
  display: grid; place-items: center;
  font-size: 1.25rem; color: #fff;
  pointer-events: none;
}
.clip-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  flex-wrap: wrap;
}
.clip-bar strong { font-size: 0.85rem; }
.clip-bar .meta { color: var(--muted); font-size: 0.75rem; }
.clip-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.stitch {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 12px 8px;
  color: var(--muted);
  font-size: 0.78rem;
}
.stitch::before {
  content: "";
  width: 2px;
  height: 28px;
  background: linear-gradient(var(--accent), transparent);
  border-radius: 2px;
}
.stitch.branch::before { background: linear-gradient(#60a5fa, transparent); }

/* Cooking stage */
.cook-stage {
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #5b4a1e;
  position: relative;
  aspect-ratio: 16/9;
}
.cook-poster {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(7,8,12,0.15), rgba(7,8,12,0.55)),
    radial-gradient(ellipse at 60% 40%, #1a4a3a 0%, #0a1020 70%);
}
.cook-poster::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(167,139,250,0.08) 50%, transparent 60%);
  background-size: 200% 100%;
  animation: shimmer 2.4s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .cook-poster::after, .pulse-ring, .thumb.cooking { animation: none !important; }
}
.cook-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: rgba(10, 12, 22, 0.42);
}
.cook-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fde68a;
  display: flex;
  align-items: center;
  gap: 10px;
}
.pulse-ring {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(251,191,36,0.55);
  animation: pulse-ring 1.6s ease-out infinite;
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(251,191,36,0.55); opacity: 1; }
  70% { box-shadow: 0 0 0 14px rgba(251,191,36,0); opacity: 0.85; }
  100% { box-shadow: 0 0 0 0 rgba(251,191,36,0); opacity: 1; }
}
.eta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(30, 42, 74, 0.9);
  border: 1px solid #3d4f7a;
  color: #c7d2fe;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
}
.cooking-eta { margin: 0 0 8px; font-size: 0.85rem; color: var(--warn); }

/* Composer */
.composer {
  position: sticky;
  bottom: 0;
  padding: 14px 20px 18px;
  background: linear-gradient(transparent, var(--bg) 28%);
  z-index: 5;
}
.composer-inner {
  max-width: 820px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.45);
}
.composer-inner.locked { opacity: 0.78; }
.composer-context {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.composer-context .pill {
  background: #2a2150;
  color: #d8ccff;
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 600;
}
.composer-parent-thumb {
  width: 36px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: radial-gradient(ellipse at 40% 30%, #2a1f55, #0a1020 70%);
  flex-shrink: 0;
  overflow: hidden;
}
.composer-parent-thumb video,
.composer-parent-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.composer textarea {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  resize: none;
  min-height: 52px;
  font: inherit;
  outline: none;
}
.composer textarea:disabled {
  color: var(--muted);
  cursor: not-allowed;
}
.composer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.composer-row .left { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.composer-row .right { display: flex; gap: 8px; flex-wrap: wrap; }
.lock-note {
  font-size: 0.72rem;
  color: var(--warn);
  margin-top: 8px;
}
.length-chip input {
  width: 3.2rem;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: center;
  padding: 0;
}

/* Right rail: Scene + Tune */
.rail {
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.rail h2 { margin: 0 0 4px; font-size: 0.95rem; }
.rail .sub { color: var(--muted); font-size: 0.78rem; margin-bottom: 10px; }
.scene-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
}
.scene-card h3 { margin: 0 0 8px; font-size: 0.85rem; }
.scene-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.thumb {
  width: 44px;
  aspect-ratio: 1.2;
  border-radius: 8px;
  background: linear-gradient(135deg, #2a1f55, #143028);
  border: 1px solid var(--border);
  cursor: pointer;
}
.thumb.on { outline: 2px solid var(--accent); }
.thumb.cooking {
  background: transparent;
  border: 1px dashed var(--warn);
  position: relative;
  animation: pulse 1.4s ease-in-out infinite;
}
.thumb.cooking::after {
  content: "…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--warn);
  font-size: 1.1rem;
  font-weight: 700;
}
@keyframes pulse { 50% { opacity: 0.55; } }
.scene-card .meta { margin-top: 8px; font-size: 0.72rem; color: var(--muted); }
.scene-beats {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.scene-beat {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.82rem;
  background: #0c0e14;
}
.scene-beat:hover, .scene-beat.active { border-color: var(--accent); }

/* Tune drawer — collapsed by default */
.tune-panel {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #0c0e14;
}
.tune-panel.collapsed .tune-body { display: none; }
.tune-panel .tune-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.tune-panel .tune-head strong { font-size: 0.85rem; }
.tune-panel .tune-hint { font-size: 0.72rem; color: var(--muted); }
.tune-body { margin-top: 12px; }
.tune-body .job {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.job-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; }
.job-head-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.parent-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 8px;
  background: #12151c;
}
.building-on {
  font-size: 0.85rem;
  color: var(--ok);
  margin: 8px 0 4px;
}
.beat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.job.focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.35);
}
.artifacts-mini { display: grid; gap: 8px; margin-top: 8px; }
.artifact-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
  padding: 8px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.dev-only {
  font-size: 0.7rem;
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  opacity: 0.65;
}
.studio-shell:not(.tune-open) .dev-only { display: none; }

.rail-note {
  margin-top: auto;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

@media (max-width: 1100px) {
  .studio-shell, .studio-shell.tune-open { grid-template-columns: 1fr; }
  .rail { border-left: 0; border-top: 1px solid var(--border); max-height: 42vh; }
}
@media (max-width: 900px) {
  .layout, .studio-layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); max-height: 32vh; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* HTML class aliases (server appPage / loginPage) */
.login-body { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, #1b2450, transparent), var(--bg); }
.login-card { width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card h1 em { color: var(--accent); }
.login-card label { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.login-card input { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.login-card button { background: var(--accent); border: 0; border-radius: 8px; padding: 10px 14px; color: #1a1028; font-weight: 700; cursor: pointer; }
.studio-body { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: rgba(7, 8, 12, 0.92); position: sticky; top: 0;
  backdrop-filter: blur(10px); z-index: 20; flex-wrap: wrap;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.empty-bench {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 10px; padding: 48px 24px;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(42,49,68,0.28) 23px, rgba(42,49,68,0.28) 24px),
    repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(42,49,68,0.28) 23px, rgba(42,49,68,0.28) 24px);
}
.empty-bench-icon {
  width: 44px; height: 44px; border-radius: 12px; border: 1px dashed var(--border);
  display: grid; place-items: center; color: var(--muted); font-size: 1.2rem; background: rgba(7,8,12,0.5);
}
.empty-bench h2 { margin: 0; font-size: 1.15rem; font-weight: 650; }
.empty-bench p { margin: 0; color: var(--muted); font-size: 0.9rem; max-width: 42ch; line-height: 1.45; }
.empty-bench-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }


/* Speed UX S1–S3 */
.eta-primary {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text, #f2f2f2);
}
.cook-poster-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.55);
}
.cook-poster { position: relative; overflow: hidden; }
.sound-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: rgba(255, 196, 80, 0.15);
  color: var(--warn, #ffc450);
  border: 1px solid rgba(255, 196, 80, 0.35);
}
.sound-chip.on {
  background: rgba(80, 200, 120, 0.15);
  color: #7ddea0;
  border-color: rgba(80, 200, 120, 0.35);
}
